Skip to content

Commit

Permalink
Merge pull request #36 from keisku/issue31
Browse files Browse the repository at this point in the history
Enrich console output with breadcrumbs
  • Loading branch information
keisku authored May 3, 2024
2 parents 37d3a7f + d4c94a8 commit 77b0ae2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
sudo install kubectl-explore /usr/local/bin
- name: Compare whether the outputs of kubectl-explore and kubectl-explain are the same
run: |
diff <(sudo microk8s kubectl explore no.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore node.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore nodes.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore provider | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
- name: Since 1.27+, kubectl-explain has been upgraded to v2 which enables OpenAPI v3 by default
diff <(sudo microk8s kubectl explore --disable-print-path no.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore --disable-print-path node.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore --disable-print-path nodes.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
diff <(sudo microk8s kubectl explore --disable-print-path provider | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
- name: Since 1.27+, kubectl-explain has --disable-print-path been upgraded to v2 which enables OpenAPI v3 by default
run: |
diff <(sudo microk8s kubectl explore hpa.*own.*id | tr -d '[:space:]') <(sudo microk8s kubectl explain horizontalpodautoscaler.metadata.ownerReferences.uid | tr -d [':space:'])
diff <(sudo microk8s kubectl explore --disable-print-path hpa.*own.*id | tr -d '[:space:]') <(sudo microk8s kubectl explain horizontalpodautoscaler.metadata.ownerReferences.uid | tr -d [':space:'])
if: ${{ 26 < matrix.k8s-minor }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Flags:
--cluster string The name of the kubeconfig cluster to use
--context string The name of the kubeconfig context to use
--disable-compression If true, opt-out of response compression for all requests to the server
--disable-print-path Disable printing the path to explain
-h, --help help for kubectl
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
Expand Down Expand Up @@ -95,7 +96,7 @@ Download the binary from [GitHub Releases](https://github.com/keisku/kubectl-exp
```shell
# Other available architectures are linux_arm64, darwin_amd64, darwin_arm64, windows_amd64.
export ARCH=linux_amd64
export VERSION=v0.8.3
export VERSION=v0.9.0
wget -O- "https://github.com/keisku/kubectl-explore/releases/download/${VERSION}/kubectl-explore_${VERSION}_${ARCH}.tar.gz" | sudo tar -xzf - -C /usr/local/bin && sudo chmod +x /usr/local/bin/kubectl-explore
```

Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions explore/explainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package explore

import (
"errors"
"fmt"
"io"
"strings"

Expand All @@ -13,6 +14,7 @@ import (
type explainer struct {
gvr schema.GroupVersionResource
openAPIV3Client openapiclient.Client
enablePrintPath bool
}

func (e explainer) explain(w io.Writer, path string) error {
Expand All @@ -24,6 +26,9 @@ func (e explainer) explain(w io.Writer, path string) error {
// Remove resource name
fields = fields[1:]
}
if e.enablePrintPath {
w.Write([]byte(fmt.Sprintf("PATH: %s\n", path)))
}
return explainv2.PrintModelDescription(
fields,
w,
Expand Down
7 changes: 5 additions & 2 deletions explore/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (

type Options struct {
// User input
apiVersion string
inputFieldPath string
apiVersion string
inputFieldPath string
disablePrintPath bool

// After completion
inputFieldPathRegex *regexp.Regexp
Expand Down Expand Up @@ -67,6 +68,7 @@ kubectl explore --context=onecontext
`,
}
cmd.Flags().StringVar(&o.apiVersion, "api-version", o.apiVersion, "Get different explanations for particular API version (API group/version)")
cmd.Flags().BoolVar(&o.disablePrintPath, "disable-print-path", o.disablePrintPath, "Disable printing the path to explain")
kubeConfigFlags := defaultConfigFlags().WithWarningPrinter(o.IOStreams)
flags := cmd.PersistentFlags()
kubeConfigFlags.AddFlags(flags)
Expand Down Expand Up @@ -203,6 +205,7 @@ func (o *Options) Run() error {
pathExplainers[p] = explainer{
gvr: gvr,
openAPIV3Client: o.cachedOpenAPIV3Client,
enablePrintPath: !o.disablePrintPath,
}
paths = append(paths, p)
}
Expand Down
5 changes: 5 additions & 0 deletions explore/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func Test_Run(t *testing.T) {
expectKeywords: []string{
"Node",
"providerID",
"PATH: nodes.spec.providerID",
},
},
{
Expand All @@ -224,6 +225,7 @@ func Test_Run(t *testing.T) {
expectKeywords: []string{
"Node",
"providerID",
"PATH: nodes.spec.providerID",
},
},
{
Expand All @@ -232,6 +234,7 @@ func Test_Run(t *testing.T) {
expectKeywords: []string{
"Node",
"providerID",
"PATH: nodes.spec.providerID",
},
},
{
Expand All @@ -240,6 +243,7 @@ func Test_Run(t *testing.T) {
expectKeywords: []string{
"Node",
"providerID",
"PATH: nodes.spec.providerID",
},
},
{
Expand All @@ -249,6 +253,7 @@ func Test_Run(t *testing.T) {
"autoscaling",
"HorizontalPodAutoscaler",
"v2",
"PATH: horizontalpodautoscalers.metadata.ownerReferences.uid",
},
},
}
Expand Down

0 comments on commit 77b0ae2

Please sign in to comment.