Skip to content

Commit 77b0ae2

Browse files
authored
Merge pull request #36 from keisku/issue31
Enrich console output with breadcrumbs
2 parents 37d3a7f + d4c94a8 commit 77b0ae2

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

.github/workflows/test.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
sudo install kubectl-explore /usr/local/bin
3232
- name: Compare whether the outputs of kubectl-explore and kubectl-explain are the same
3333
run: |
34-
diff <(sudo microk8s kubectl explore no.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
35-
diff <(sudo microk8s kubectl explore node.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
36-
diff <(sudo microk8s kubectl explore nodes.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
37-
diff <(sudo microk8s kubectl explore provider | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
38-
- name: Since 1.27+, kubectl-explain has been upgraded to v2 which enables OpenAPI v3 by default
34+
diff <(sudo microk8s kubectl explore --disable-print-path no.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
35+
diff <(sudo microk8s kubectl explore --disable-print-path node.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
36+
diff <(sudo microk8s kubectl explore --disable-print-path nodes.*pro | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
37+
diff <(sudo microk8s kubectl explore --disable-print-path provider | tr -d '[:space:]') <(sudo microk8s kubectl explain node.spec.providerID | tr -d [':space:'])
38+
- name: Since 1.27+, kubectl-explain has --disable-print-path been upgraded to v2 which enables OpenAPI v3 by default
3939
run: |
40-
diff <(sudo microk8s kubectl explore hpa.*own.*id | tr -d '[:space:]') <(sudo microk8s kubectl explain horizontalpodautoscaler.metadata.ownerReferences.uid | tr -d [':space:'])
40+
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:'])
4141
if: ${{ 26 < matrix.k8s-minor }}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Flags:
5454
--cluster string The name of the kubeconfig cluster to use
5555
--context string The name of the kubeconfig context to use
5656
--disable-compression If true, opt-out of response compression for all requests to the server
57+
--disable-print-path Disable printing the path to explain
5758
-h, --help help for kubectl
5859
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
5960
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
@@ -95,7 +96,7 @@ Download the binary from [GitHub Releases](https://github.com/keisku/kubectl-exp
9596
```shell
9697
# Other available architectures are linux_arm64, darwin_amd64, darwin_arm64, windows_amd64.
9798
export ARCH=linux_amd64
98-
export VERSION=v0.8.3
99+
export VERSION=v0.9.0
99100
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
100101
```
101102

demo.gif

-538 KB
Loading

explore/explainer.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package explore
22

33
import (
44
"errors"
5+
"fmt"
56
"io"
67
"strings"
78

@@ -13,6 +14,7 @@ import (
1314
type explainer struct {
1415
gvr schema.GroupVersionResource
1516
openAPIV3Client openapiclient.Client
17+
enablePrintPath bool
1618
}
1719

1820
func (e explainer) explain(w io.Writer, path string) error {
@@ -24,6 +26,9 @@ func (e explainer) explain(w io.Writer, path string) error {
2426
// Remove resource name
2527
fields = fields[1:]
2628
}
29+
if e.enablePrintPath {
30+
w.Write([]byte(fmt.Sprintf("PATH: %s\n", path)))
31+
}
2732
return explainv2.PrintModelDescription(
2833
fields,
2934
w,

explore/options.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424

2525
type Options struct {
2626
// User input
27-
apiVersion string
28-
inputFieldPath string
27+
apiVersion string
28+
inputFieldPath string
29+
disablePrintPath bool
2930

3031
// After completion
3132
inputFieldPathRegex *regexp.Regexp
@@ -67,6 +68,7 @@ kubectl explore --context=onecontext
6768
`,
6869
}
6970
cmd.Flags().StringVar(&o.apiVersion, "api-version", o.apiVersion, "Get different explanations for particular API version (API group/version)")
71+
cmd.Flags().BoolVar(&o.disablePrintPath, "disable-print-path", o.disablePrintPath, "Disable printing the path to explain")
7072
kubeConfigFlags := defaultConfigFlags().WithWarningPrinter(o.IOStreams)
7173
flags := cmd.PersistentFlags()
7274
kubeConfigFlags.AddFlags(flags)
@@ -203,6 +205,7 @@ func (o *Options) Run() error {
203205
pathExplainers[p] = explainer{
204206
gvr: gvr,
205207
openAPIV3Client: o.cachedOpenAPIV3Client,
208+
enablePrintPath: !o.disablePrintPath,
206209
}
207210
paths = append(paths, p)
208211
}

explore/options_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func Test_Run(t *testing.T) {
216216
expectKeywords: []string{
217217
"Node",
218218
"providerID",
219+
"PATH: nodes.spec.providerID",
219220
},
220221
},
221222
{
@@ -224,6 +225,7 @@ func Test_Run(t *testing.T) {
224225
expectKeywords: []string{
225226
"Node",
226227
"providerID",
228+
"PATH: nodes.spec.providerID",
227229
},
228230
},
229231
{
@@ -232,6 +234,7 @@ func Test_Run(t *testing.T) {
232234
expectKeywords: []string{
233235
"Node",
234236
"providerID",
237+
"PATH: nodes.spec.providerID",
235238
},
236239
},
237240
{
@@ -240,6 +243,7 @@ func Test_Run(t *testing.T) {
240243
expectKeywords: []string{
241244
"Node",
242245
"providerID",
246+
"PATH: nodes.spec.providerID",
243247
},
244248
},
245249
{
@@ -249,6 +253,7 @@ func Test_Run(t *testing.T) {
249253
"autoscaling",
250254
"HorizontalPodAutoscaler",
251255
"v2",
256+
"PATH: horizontalpodautoscalers.metadata.ownerReferences.uid",
252257
},
253258
},
254259
}

0 commit comments

Comments
 (0)