-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to format output as JSON/YAML
A new flag '-o' ('output') is introduced, allowing the user to choose the output format of the command. The options are json/yaml. The default behavior remains the same. The flag supports auto-completion for the output format options, implemented in the code of the command. To enable auto-completion when using the command as a plugin, an additional file 'kubectl_complete-cluster_compare' was added. The file should be present in a location in PATH along with the plugin to enable auto-completion. Also added supporting tests for JSON and YAML output modes. Signed-off-by: Alina Sudakov <asudakov@redhat.com>
- Loading branch information
1 parent
1d8b12f
commit 433d21c
Showing
15 changed files
with
401 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
kubectl cluster-compare __complete "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
error code:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Summary":{"RequiredCRS":{"ExamplePart":{"Dashboard":["deploymentDashboard.yaml"]}},"NumMissing":1,"UnmatchedCRS":[],"NumDiffCRs":1},"Diffs":[{"DiffOutput":"diff -u -N TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper\n--- TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper\tDATE\n+++ TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper\tDATE\n@@ -10,7 +10,7 @@\n revisionHistoryLimit: 10\n selector:\n matchLabels:\n- k8s-app: dashboard-metrics-scraper\n+ k8s-app: dashboard-metrics-scraper-diff\n template:\n metadata:\n labels:\n","CorrelatedTemplate":"deploymentMetrics.yaml","CRName":"apps/v1_Deployment_kubernetes-dashboard_dashboard-metrics-scraper"}]} |
66 changes: 66 additions & 0 deletions
66
pkg/compare/testdata/JSONOutput/reference/deploymentDashboard.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
name: kubernetes-dashboard | ||
namespace: kubernetes-dashboard | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
k8s-app: kubernetes-dashboard | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: kubernetes-dashboard | ||
spec: | ||
securityContext: | ||
seccompProfile: | ||
type: RuntimeDefault | ||
containers: | ||
- name: kubernetes-dashboard | ||
image: kubernetesui/dashboard:v2.7.0 | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 8443 | ||
protocol: TCP | ||
args: | ||
- --auto-generate-certificates | ||
- --namespace=kubernetes-dashboard | ||
# Uncomment the following line to manually specify Kubernetes API server Host | ||
# If not specified, Dashboard will attempt to auto discover the API server and connect | ||
# to it. Uncomment only if the default does not work. | ||
# - --apiserver-host=http://my-address:port | ||
volumeMounts: | ||
- name: kubernetes-dashboard-certs | ||
mountPath: /certs | ||
# Create on-disk volume to store exec logs | ||
- mountPath: /tmp | ||
name: tmp-volume | ||
livenessProbe: | ||
httpGet: | ||
scheme: HTTPS | ||
path: / | ||
port: 8443 | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 30 | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
readOnlyRootFilesystem: true | ||
runAsUser: 1001 | ||
runAsGroup: 2001 | ||
volumes: | ||
- name: kubernetes-dashboard-certs | ||
secret: | ||
secretName: kubernetes-dashboard-certs | ||
- name: tmp-volume | ||
emptyDir: { } | ||
serviceAccountName: kubernetes-dashboard | ||
nodeSelector: | ||
"kubernetes.io/os": linux | ||
# Comment the following tolerations if Dashboard must not be deployed on master | ||
tolerations: | ||
- key: node-role.kubernetes.io/master | ||
effect: NoSchedule |
19 changes: 19 additions & 0 deletions
19
pkg/compare/testdata/JSONOutput/reference/deploymentMetrics.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
labels: | ||
k8s-app: dashboard-metrics-scraper | ||
name: dashboard-metrics-scraper | ||
namespace: kubernetes-dashboard | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
k8s-app: dashboard-metrics-scraper | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: dashboard-metrics-scraper | ||
spec: | ||
{{ if .spec.template.spec }}{{ .spec.template.spec | toYaml | indent 6 }}{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Parts: | ||
- name: ExamplePart | ||
Components: | ||
- name: Dashboard | ||
type: Required | ||
requiredTemplates: | ||
- deploymentDashboard.yaml | ||
- deploymentMetrics.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
labels: | ||
k8s-app: dashboard-metrics-scraper | ||
name: dashboard-metrics-scraper | ||
namespace: kubernetes-dashboard | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
k8s-app: dashboard-metrics-scraper-diff | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: dashboard-metrics-scraper | ||
spec: | ||
securityContext: | ||
seccompProfile: | ||
type: RuntimeDefault | ||
containers: | ||
- name: dashboard-metrics-scraper | ||
image: kubernetesui/metrics-scraper:v1.0.8 | ||
ports: | ||
- containerPort: 8000 | ||
protocol: TCP | ||
livenessProbe: | ||
httpGet: | ||
scheme: HTTP | ||
path: / | ||
port: 8000 | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 30 | ||
volumeMounts: | ||
- mountPath: /tmp | ||
name: tmp-volume | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
readOnlyRootFilesystem: true | ||
runAsUser: 1001 | ||
runAsGroup: 2001 | ||
serviceAccountName: kubernetes-dashboard | ||
nodeSelector: | ||
"kubernetes.io/os": linux | ||
# Comment the following tolerations if Dashboard must not be deployed on master | ||
tolerations: | ||
- key: node-role.kubernetes.io/master | ||
effect: NoSchedule | ||
volumes: | ||
- name: tmp-volume | ||
emptyDir: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
error code:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Diffs: | ||
- CRName: apps/v1_Deployment_kubernetes-dashboard_kubernetes-dashboard | ||
CorrelatedTemplate: deploymentDashboard.yaml | ||
DiffOutput: "diff -u -N TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard | ||
TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\n--- | ||
TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n+++ TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n@@ -14,7 +14,7 @@\n template:\n metadata:\n labels:\n- | ||
\ k8s-app: kubernetes-dashboard\n+ k8s-app: kubernetes-dashboard-diff\n | ||
\ spec:\n containers:\n - args:\n" | ||
Summary: | ||
NumDiffCRs: 1 | ||
NumMissing: 1 | ||
RequiredCRS: | ||
ExamplePart: | ||
Dashboard: | ||
- deploymentMetrics.yaml | ||
UnmatchedCRS: [] |
Oops, something went wrong.