diff --git a/.github/workflows/pre-main.yml b/.github/workflows/pre-main.yml new file mode 100644 index 00000000..f65fa560 --- /dev/null +++ b/.github/workflows/pre-main.yml @@ -0,0 +1,52 @@ +name: Test Incoming Changes + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version-file: go.mod + cache: true + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v9 + with: + version: latest + args: --timeout=5m + + - name: Install shfmt + uses: mfinelli/setup-shfmt@v3 + + - name: Run shfmt + run: shfmt -d -i 4 -ci hack/ + + test: + name: Run Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version-file: go.mod + cache: true + + - name: Run tests + run: make test + diff --git a/.golangci.yml b/.golangci.yml index 8758ad5f..d6146be3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,135 +1,117 @@ ---- -new: true -new-from-rev: 722af08 +version: "2" run: concurrency: 6 - timeout: 5m linters: - disable-all: true + default: none enable: - depguard + - errorlint - goconst - gocritic - - revive - - gofmt - - goimports + - gocyclo + - gosec - govet - ineffassign + - loggercheck - misspell + - revive - staticcheck - - typecheck - unconvert - unparam - - gocyclo - unused - - errorlint - - loggercheck - - gosec - wrapcheck -linters-settings: - revive: - rules: - - name: if-return - severity: warning - disabled: true - - name: string-format - severity: warning - disabled: false - arguments: - - - 'core.WriteError[1].Message' - - '/^([^A-Z]|$)/' - - must not start with a capital letter - - - 'fmt.Errorf[0]' - - '/^([^A-Z]|$)/' - - must not start with a capital letter - - - 'fmt.Errorf[0]' - - '/(^|[^\.!?])$/' - - must not end in punctuation - - - panic - - '/^[^\n]*$/' - - must not contain line breaks - gocritic: - enabled-checks: - # Diagnostic - - commentedOutCode - - nilValReturn - - weakCond - - octalLiteral - - sloppyReassign - - # Performance - - equalFold - - indexAlloc - - rangeExprCopy - - appendCombine - - # Style - - boolExprSimplify - - commentedOutImport - - docStub - - emptyFallthrough - - emptyStringTest - - hexLiteral - - methodExprCall - - stringXbytes - - typeAssertChain - - unlabelStmt - - yodaStyleExpr - - # Opinionated - - initClause - - nestingReduce - - ptrToRefParam - - typeUnparen - - unnecessaryBlock - - paramTypeCombine - depguard: - # Rules to apply. - # - # Variables: - # - File Variables - # you can still use and exclamation mark ! in front of a variable to say not to use it. - # Example !$test will match any file that is not a go test file. - # - # `$all` - matches all go files - # `$test` - matches all go test files - # - # - Package Variables - # - # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) - # - # Default: Only allow $gostd in all files. - rules: - # Name of a rule. - main: - # Used to determine the package matching priority. - # There are three different modes: `original`, `strict`, and `lax`. - # Default: "original" - list-mode: lax - # List of file globs that will match this list of settings to compare against. - # Default: $all - files: - - $all - # List of allowed packages. - # allow: - # - $gostd - # Packages that are not allowed where the value is a suggestion. - deny: - - pkg: "github.com/pkg/errors" - desc: Should be replaced by standard lib errors package - wrapcheck: - ignoreSigs: - # defaults - - .Errorf( - - errors.New( - - errors.Unwrap( - - errors.Join( - - .Wrap( - - .Wrapf( - - .WithMessage( - - .WithMessagef( - - .WithStack( - # from kyaml's errors package - - .WrapPrefixf( - # from kcmdutil - - .UsageErrorf( + settings: + depguard: + rules: + main: + list-mode: lax + files: + - $all + deny: + - pkg: github.com/pkg/errors + desc: Should be replaced by standard lib errors package + gocritic: + enabled-checks: + - commentedOutCode + - nilValReturn + - weakCond + - octalLiteral + - sloppyReassign + - equalFold + - indexAlloc + - rangeExprCopy + - appendCombine + - boolExprSimplify + - commentedOutImport + - docStub + - emptyFallthrough + - emptyStringTest + - hexLiteral + - methodExprCall + - stringXbytes + - typeAssertChain + - unlabelStmt + - yodaStyleExpr + - initClause + - nestingReduce + - ptrToRefParam + - typeUnparen + - unnecessaryBlock + - paramTypeCombine + revive: + rules: + - name: if-return + severity: warning + disabled: true + - name: string-format + arguments: + - - core.WriteError[1].Message + - /^([^A-Z]|$)/ + - must not start with a capital letter + - - fmt.Errorf[0] + - /^([^A-Z]|$)/ + - must not start with a capital letter + - - fmt.Errorf[0] + - /(^|[^\.!?])$/ + - must not end in punctuation + - - panic + - /^[^\n]*$/ + - must not contain line breaks + severity: warning + disabled: false + wrapcheck: + ignore-sigs: + - .Errorf( + - errors.New( + - errors.Unwrap( + - errors.Join( + - .Wrap( + - .Wrapf( + - .WithMessage( + - .WithMessagef( + - .WithStack( + - .WrapPrefixf( + - .UsageErrorf( + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - vendor$ + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - vendor$ + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 2ec63f87..86e1ed98 100644 --- a/Makefile +++ b/Makefile @@ -135,11 +135,19 @@ build-helm-convert: test-helm-convert: go test --race ./addon-tools/helm-convert/*/ +.PHONY: lint +lint: golangci-lint shfmt ## Run all linters + .PHONY: golangci-lint golangci-lint: ## Run golangci-lint against code. @echo "Running golangci-lint" hack/golangci-lint.sh +.PHONY: shfmt +shfmt: ## Run shfmt against shell scripts in hack/ + @echo "Running shfmt" + shfmt -d -i 4 -ci hack/*.sh + # markdownlint rules, following: https://github.com/openshift/enhancements/blob/master/Makefile .PHONY: markdownlint-image markdownlint-image: ## Build local container markdownlint-image diff --git a/addon-tools/helm-convert/convert/expectedvaluesfinder.go b/addon-tools/helm-convert/convert/expectedvaluesfinder.go index 93fad218..c8338686 100644 --- a/addon-tools/helm-convert/convert/expectedvaluesfinder.go +++ b/addon-tools/helm-convert/convert/expectedvaluesfinder.go @@ -14,7 +14,6 @@ func (v *ExpectedValuesFinder) Visit() func(parse.Node) bool { switch n := node.(type) { case *parse.FieldNode: v.expected = append(v.expected, getNodeField(n)...) - break case *parse.RangeNode: for _, fieldRangedOn := range getFieldsAccessInNode(n.Pipe) { // for complex range statements get the path of the map/slice to be ranged on // in case of range, the minimum list length will be always in length 1, including only element with index 0: @@ -33,10 +32,8 @@ func (v *ExpectedValuesFinder) Visit() func(parse.Node) bool { switch node := n.Args[2].(type) { // n.Args[2] is the second argument for index function case *parse.NumberNode: text = node.Text - break case *parse.StringNode: text = node.Text - break } v.expected = append(v.expected, append(fieldRangedOn, text)) } diff --git a/hack/krew-bump.sh b/hack/krew-bump.sh index 5ca0d4ae..e9435325 100755 --- a/hack/krew-bump.sh +++ b/hack/krew-bump.sh @@ -1,7 +1,7 @@ #!/bin/bash -e TAG=$(gh release view --json name | jq -r .name) -checksums=$(gh release download --pattern '*_checksums.txt' -O -) +checksums=$(gh release download --pattern '*_checksums.txt' -O -) echo "Creating krew bump for $TAG" # Tmpdir for krew-index clone @@ -26,7 +26,7 @@ done <<<"$checksums" # Commit and push git commit -asm "Version bump cluster-compare to $TAG" git push -u origin "$BRANCH" -gh pr create --fill +gh pr create --fill # Cleanup popd && popd && rm -rf _release_tmp diff --git a/hack/markdownlint.sh b/hack/markdownlint.sh index 511e9008..313a6b10 100755 --- a/hack/markdownlint.sh +++ b/hack/markdownlint.sh @@ -8,7 +8,7 @@ function handle_exit { # If the exit code we were given indicates an error, suggest that # the author run the linter locally. if [ "$1" != "0" ]; then - cat - < 1 { errs = append(errs, fmt.Errorf( - "More than one template with same %s. By Default for each Cluster CR that is correlated "+ - "to one of these templates the template with the least number of diffs will be used. "+ - "To use a different template for a specific CR specify it in the diff-config (-c flag) "+ - "Template names are: %s", + "more than one template with same %s: by default for each cluster CR that is correlated "+ + "to one of these templates the template with the least number of diffs will be used; "+ + "to use a different template for a specific CR specify it in the diff-config (-c flag); "+ + "template names are: %s", getFields(f.Fields), getTemplatesNames(values)), ) } diff --git a/pkg/compare/referenceV1.go b/pkg/compare/referenceV1.go index 00133e24..8b4fb391 100644 --- a/pkg/compare/referenceV1.go +++ b/pkg/compare/referenceV1.go @@ -254,7 +254,7 @@ const noValue = "" func (rf ReferenceTemplateV1) Exec(params map[string]any) (*unstructured.Unstructured, error) { var buf bytes.Buffer - err := rf.Template.Execute(&buf, params) + err := rf.Execute(&buf, params) if err != nil { return nil, fmt.Errorf("failed to constuct template: %w", err) } diff --git a/pkg/compare/referenceV2.go b/pkg/compare/referenceV2.go index 7eabad64..51df463c 100644 --- a/pkg/compare/referenceV2.go +++ b/pkg/compare/referenceV2.go @@ -184,7 +184,7 @@ func (entry *FieldsToOmitV2Entry) process(previousKeys []string, toOmit *FieldsT errs := make([]error, 0) if entry.ManifestPathV1 != nil && entry.PathToKey != "" { - err := entry.ManifestPathV1.Process() + err := entry.Process() if err != nil { errs = append(errs, err) } else { diff --git a/pkg/compare/testdata/AllRequiredTemplatesExistAndThereAreNoDiffs/localwith_diff_yout.golden b/pkg/compare/testdata/AllRequiredTemplatesExistAndThereAreNoDiffs/localwith_diff_yout.golden index 3915d05d..8de59ba1 100644 --- a/pkg/compare/testdata/AllRequiredTemplatesExistAndThereAreNoDiffs/localwith_diff_yout.golden +++ b/pkg/compare/testdata/AllRequiredTemplatesExistAndThereAreNoDiffs/localwith_diff_yout.golden @@ -1,363 +1,3 @@ -********************************** - -Cluster CR: v1_ConfigMap_kubernetes-dashboard_kubernetes-dashboard-settings -Reference File: cm.yaml -Diff Output: diff -y -W 150 TEMP/v1_configmap_kubernetes-dashboard_kubernetes-dashboard-settings TEMP/v1_configmap_kubernetes-dashboard_kubernetes-dashboard-settings -apiVersion: v1 apiVersion: v1 -kind: ConfigMap kind: ConfigMap -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard-settings name: kubernetes-dashboard-settings - namespace: kubernetes-dashboard namespace: kubernetes-dashboard - -********************************** - -Cluster CR: rbac.authorization.k8s.io/v1_ClusterRole_kubernetes-dashboard -Reference File: cr.yaml -Diff Output: diff -y -W 150 TEMP/rbac-authorization-k8s-io-v1_clusterrole_kubernetes-dashboard TEMP/rbac-authorization-k8s-io-v1_clusterrole_kubernetes-dashboard -apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole kind: ClusterRole -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard -rules: rules: -- apiGroups: - apiGroups: - - metrics.k8s.io - metrics.k8s.io - resources: resources: - - pods - pods - - nodes - nodes - verbs: verbs: - - get - get - - list - list - - watch - watch - -********************************** - -Cluster CR: rbac.authorization.k8s.io/v1_ClusterRoleBinding_kubernetes-dashboard -Reference File: crb.yaml -Diff Output: diff -y -W 150 TEMP/rbac-authorization-k8s-io-v1_clusterrolebinding_kubernetes-dashboard TEMP/rbac-authorization-k8s-io-v1_clusterrolebinding_kubernetes-dashboard -apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding kind: ClusterRoleBinding -metadata: metadata: - name: kubernetes-dashboard name: kubernetes-dashboard -roleRef: roleRef: - apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io - kind: ClusterRole kind: ClusterRole - name: kubernetes-dashboard name: kubernetes-dashboard -subjects: subjects: -- kind: ServiceAccount - kind: ServiceAccount - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard - -********************************** - -Cluster CR: apps/v1_Deployment_kubernetes-dashboard_kubernetes-dashboard -Reference File: deploymentDashboard.yaml -Diff Output: diff -y -W 150 TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard -apiVersion: apps/v1 apiVersion: apps/v1 -kind: Deployment kind: Deployment -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -spec: spec: - replicas: 1 replicas: 1 - revisionHistoryLimit: 10 revisionHistoryLimit: 10 - selector: selector: - matchLabels: matchLabels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - template: template: - metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - spec: spec: - containers: containers: - - args: - args: - - --auto-generate-certificates - --auto-generate-certificates - - --namespace=kubernetes-dashboard - --namespace=kubernetes-dashboard - image: kubernetesui/dashboard:v2.7.0 image: kubernetesui/dashboard:v2.7.0 - imagePullPolicy: Always imagePullPolicy: Always - livenessProbe: livenessProbe: - httpGet: httpGet: - path: / path: / - port: 8443 port: 8443 - scheme: HTTPS scheme: HTTPS - initialDelaySeconds: 30 initialDelaySeconds: 30 - timeoutSeconds: 30 timeoutSeconds: 30 - name: kubernetes-dashboard name: kubernetes-dashboard - ports: ports: - - containerPort: 8443 - containerPort: 8443 - protocol: TCP protocol: TCP - securityContext: securityContext: - allowPrivilegeEscalation: false allowPrivilegeEscalation: false - readOnlyRootFilesystem: true readOnlyRootFilesystem: true - runAsGroup: 2001 runAsGroup: 2001 - runAsUser: 1001 runAsUser: 1001 - volumeMounts: volumeMounts: - - mountPath: /certs - mountPath: /certs - name: kubernetes-dashboard-certs name: kubernetes-dashboard-certs - - mountPath: /tmp - mountPath: /tmp - name: tmp-volume name: tmp-volume - nodeSelector: nodeSelector: - kubernetes.io/os: linux kubernetes.io/os: linux - securityContext: securityContext: - seccompProfile: seccompProfile: - type: RuntimeDefault type: RuntimeDefault - serviceAccountName: kubernetes-dashboard serviceAccountName: kubernetes-dashboard - tolerations: tolerations: - - effect: NoSchedule - effect: NoSchedule - key: node-role.kubernetes.io/master key: node-role.kubernetes.io/master - volumes: volumes: - - name: kubernetes-dashboard-certs - name: kubernetes-dashboard-certs - secret: secret: - secretName: kubernetes-dashboard-certs secretName: kubernetes-dashboard-certs - - emptyDir: {} - emptyDir: {} - name: tmp-volume name: tmp-volume - -********************************** - -Cluster CR: apps/v1_Deployment_kubernetes-dashboard_dashboard-metrics-scraper -Reference File: deploymentMetrics.yaml -Diff Output: diff -y -W 150 TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper -apiVersion: apps/v1 apiVersion: apps/v1 -kind: Deployment kind: Deployment -metadata: metadata: - labels: labels: - k8s-app: dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper - name: dashboard-metrics-scraper name: dashboard-metrics-scraper - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -spec: spec: - replicas: 1 replicas: 1 - revisionHistoryLimit: 10 revisionHistoryLimit: 10 - selector: selector: - matchLabels: matchLabels: - k8s-app: dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper - template: template: - metadata: metadata: - labels: labels: - k8s-app: dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper - spec: spec: - containers: containers: - - image: kubernetesui/metrics-scraper:v1.0.8 - image: kubernetesui/metrics-scraper:v1.0.8 - livenessProbe: livenessProbe: - httpGet: httpGet: - path: / path: / - port: 8000 port: 8000 - scheme: HTTP scheme: HTTP - initialDelaySeconds: 30 initialDelaySeconds: 30 - timeoutSeconds: 30 timeoutSeconds: 30 - name: dashboard-metrics-scraper name: dashboard-metrics-scraper - ports: ports: - - containerPort: 8000 - containerPort: 8000 - protocol: TCP protocol: TCP - securityContext: securityContext: - allowPrivilegeEscalation: false allowPrivilegeEscalation: false - readOnlyRootFilesystem: true readOnlyRootFilesystem: true - runAsGroup: 2001 runAsGroup: 2001 - runAsUser: 1001 runAsUser: 1001 - volumeMounts: volumeMounts: - - mountPath: /tmp - mountPath: /tmp - name: tmp-volume name: tmp-volume - nodeSelector: nodeSelector: - kubernetes.io/os: linux kubernetes.io/os: linux - securityContext: securityContext: - seccompProfile: seccompProfile: - type: RuntimeDefault type: RuntimeDefault - serviceAccountName: kubernetes-dashboard serviceAccountName: kubernetes-dashboard - tolerations: tolerations: - - effect: NoSchedule - effect: NoSchedule - key: node-role.kubernetes.io/master key: node-role.kubernetes.io/master - volumes: volumes: - - emptyDir: {} - emptyDir: {} - name: tmp-volume name: tmp-volume - -********************************** - -Cluster CR: v1_Namespace_kubernetes-dashboard -Reference File: ns.yaml -Diff Output: diff -y -W 150 TEMP/v1_namespace_kubernetes-dashboard TEMP/v1_namespace_kubernetes-dashboard -apiVersion: v1 apiVersion: v1 -kind: Namespace kind: Namespace -metadata: metadata: - name: kubernetes-dashboard name: kubernetes-dashboard - -********************************** - -Cluster CR: rbac.authorization.k8s.io/v1_RoleBinding_kubernetes-dashboard_kubernetes-dashboard -Reference File: rb.yaml -Diff Output: diff -y -W 150 TEMP/rbac-authorization-k8s-io-v1_rolebinding_kubernetes-dashboard_kubernetes-dashboard TEMP/rbac-authorization-k8s-io-v1_rolebinding_kubernetes-dashboard_kubernetes-dashboard -apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding kind: RoleBinding -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -roleRef: roleRef: - apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io - kind: Role kind: Role - name: kubernetes-dashboard name: kubernetes-dashboard -subjects: subjects: -- kind: ServiceAccount - kind: ServiceAccount - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard - -********************************** - -Cluster CR: rbac.authorization.k8s.io/v1_Role_kubernetes-dashboard_kubernetes-dashboard -Reference File: role.yaml -Diff Output: diff -y -W 150 TEMP/rbac-authorization-k8s-io-v1_role_kubernetes-dashboard_kubernetes-dashboard TEMP/rbac-authorization-k8s-io-v1_role_kubernetes-dashboard_kubernetes-dashboard -apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1 -kind: Role kind: Role -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -rules: rules: -- apiGroups: - apiGroups: - - "" - "" - resourceNames: resourceNames: - - kubernetes-dashboard-key-holder - kubernetes-dashboard-key-holder - - kubernetes-dashboard-certs - kubernetes-dashboard-certs - - kubernetes-dashboard-csrf - kubernetes-dashboard-csrf - resources: resources: - - secrets - secrets - verbs: verbs: - - get - get - - update - update - - delete - delete -- apiGroups: - apiGroups: - - "" - "" - resourceNames: resourceNames: - - kubernetes-dashboard-settings - kubernetes-dashboard-settings - resources: resources: - - configmaps - configmaps - verbs: verbs: - - get - get - - update - update -- apiGroups: - apiGroups: - - "" - "" - resourceNames: resourceNames: - - heapster - heapster - - dashboard-metrics-scraper - dashboard-metrics-scraper - resources: resources: - - services - services - verbs: verbs: - - proxy - proxy -- apiGroups: - apiGroups: - - "" - "" - resourceNames: resourceNames: - - heapster - heapster - - 'http:heapster:' - 'http:heapster:' - - 'https:heapster:' - 'https:heapster:' - - dashboard-metrics-scraper - dashboard-metrics-scraper - - http:dashboard-metrics-scraper - http:dashboard-metrics-scraper - resources: resources: - - services/proxy - services/proxy - verbs: verbs: - - get - get - -********************************** - -Cluster CR: v1_ServiceAccount_kubernetes-dashboard_kubernetes-dashboard -Reference File: sa.yaml -Diff Output: diff -y -W 150 TEMP/v1_serviceaccount_kubernetes-dashboard_kubernetes-dashboard TEMP/v1_serviceaccount_kubernetes-dashboard_kubernetes-dashboard -apiVersion: v1 apiVersion: v1 -kind: ServiceAccount kind: ServiceAccount -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard - -********************************** - -Cluster CR: v1_Secret_kubernetes-dashboard_kubernetes-dashboard-certs -Reference File: secret.yaml -Diff Output: diff -y -W 150 TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-certs TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-certs -apiVersion: v1 apiVersion: v1 -kind: Secret kind: Secret -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard-certs name: kubernetes-dashboard-certs - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -type: Opaque type: Opaque - -********************************** - -Cluster CR: v1_Secret_kubernetes-dashboard_kubernetes-dashboard-csrf -Reference File: secret.yaml -Diff Output: diff -y -W 150 TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-csrf TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-csrf -apiVersion: v1 apiVersion: v1 -data: data: - csrf: '***' csrf: '***' -kind: Secret kind: Secret -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard-csrf name: kubernetes-dashboard-csrf - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -type: Opaque type: Opaque - -********************************** - -Cluster CR: v1_Secret_kubernetes-dashboard_kubernetes-dashboard-key-holder -Reference File: secret.yaml -Diff Output: diff -y -W 150 TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-key-holder TEMP/v1_secret_kubernetes-dashboard_kubernetes-dashboard-key-holder -apiVersion: v1 apiVersion: v1 -kind: Secret kind: Secret -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard-key-holder name: kubernetes-dashboard-key-holder - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -type: Opaque type: Opaque - -********************************** - -Cluster CR: v1_Service_kubernetes-dashboard_dashboard-metrics-scraper -Reference File: service.yaml -Diff Output: diff -y -W 150 TEMP/v1_service_kubernetes-dashboard_dashboard-metrics-scraper TEMP/v1_service_kubernetes-dashboard_dashboard-metrics-scraper -apiVersion: v1 apiVersion: v1 -kind: Service kind: Service -metadata: metadata: - labels: labels: - k8s-app: dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper - name: dashboard-metrics-scraper name: dashboard-metrics-scraper - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -spec: spec: - ports: ports: - - port: 8000 - port: 8000 - targetPort: 8000 targetPort: 8000 - selector: selector: - k8s-app: dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper - -********************************** - -Cluster CR: v1_Service_kubernetes-dashboard_kubernetes-dashboard -Reference File: service.yaml -Diff Output: diff -y -W 150 TEMP/v1_service_kubernetes-dashboard_kubernetes-dashboard TEMP/v1_service_kubernetes-dashboard_kubernetes-dashboard -apiVersion: v1 apiVersion: v1 -kind: Service kind: Service -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -spec: spec: - ports: ports: - - port: 443 - port: 443 - targetPort: 8443 targetPort: 8443 - selector: selector: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - -********************************** - Summary CRs with diffs: 0/14 No validation issues with the cluster diff --git a/pkg/compare/testdata/SomeDiffs/localwith_diff_yout.golden b/pkg/compare/testdata/SomeDiffs/localwith_diff_yout.golden index 86955e3b..65c4264a 100644 --- a/pkg/compare/testdata/SomeDiffs/localwith_diff_yout.golden +++ b/pkg/compare/testdata/SomeDiffs/localwith_diff_yout.golden @@ -1,75 +1,8 @@ ********************************** -Cluster CR: apps/v1_Deployment_kubernetes-dashboard_kubernetes-dashboard -Reference File: deploymentDashboard.yaml -Diff Output: diff -y -W 150 TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard -apiVersion: apps/v1 apiVersion: apps/v1 -kind: Deployment kind: Deployment -metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - name: kubernetes-dashboard name: kubernetes-dashboard - namespace: kubernetes-dashboard namespace: kubernetes-dashboard -spec: spec: - replicas: 1 replicas: 1 - revisionHistoryLimit: 10 revisionHistoryLimit: 10 - selector: selector: - matchLabels: matchLabels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - template: template: - metadata: metadata: - labels: labels: - k8s-app: kubernetes-dashboard k8s-app: kubernetes-dashboard - spec: spec: - containers: containers: - - args: - args: - - --auto-generate-certificates - --auto-generate-certificates - - --namespace=kubernetes-dashboard - --namespace=kubernetes-dashboard - image: kubernetesui/dashboard:v2.7.0 image: kubernetesui/dashboard:v2.7.0 - imagePullPolicy: Always imagePullPolicy: Always - livenessProbe: livenessProbe: - httpGet: httpGet: - path: / path: / - port: 8443 port: 8443 - scheme: HTTPS scheme: HTTPS - initialDelaySeconds: 30 initialDelaySeconds: 30 - timeoutSeconds: 30 timeoutSeconds: 30 - name: kubernetes-dashboard name: kubernetes-dashboard - ports: ports: - - containerPort: 8443 - containerPort: 8443 - protocol: TCP protocol: TCP - securityContext: securityContext: - allowPrivilegeEscalation: false allowPrivilegeEscalation: false - readOnlyRootFilesystem: true readOnlyRootFilesystem: true - runAsGroup: 2001 runAsGroup: 2001 - runAsUser: 1001 runAsUser: 1001 - volumeMounts: volumeMounts: - - mountPath: /certs - mountPath: /certs - name: kubernetes-dashboard-certs name: kubernetes-dashboard-certs - - mountPath: /tmp - mountPath: /tmp - name: tmp-volume name: tmp-volume - nodeSelector: nodeSelector: - kubernetes.io/os: linux kubernetes.io/os: linux - securityContext: securityContext: - seccompProfile: seccompProfile: - type: RuntimeDefault type: RuntimeDefault - serviceAccountName: kubernetes-dashboard serviceAccountName: kubernetes-dashboard - tolerations: tolerations: - - effect: NoSchedule - effect: NoSchedule - key: node-role.kubernetes.io/master key: node-role.kubernetes.io/master - volumes: volumes: - - name: kubernetes-dashboard-certs - name: kubernetes-dashboard-certs - secret: secret: - secretName: kubernetes-dashboard-certs secretName: kubernetes-dashboard-certs - - emptyDir: {} - emptyDir: {} - name: tmp-volume name: tmp-volume - -********************************** - Cluster CR: apps/v1_Deployment_kubernetes-dashboard_dashboard-metrics-scraper Reference File: deploymentMetrics.yaml -Diff Output: diff -y -W 150 TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper -apiVersion: apps/v1 apiVersion: apps/v1 +Diff Output: apiVersion: apps/v1 apiVersion: apps/v1 kind: Deployment kind: Deployment metadata: metadata: labels: labels: @@ -81,6 +14,7 @@ spec: spec: revisionHistoryLimit: 10 revisionHistoryLimit: 10 selector: selector: matchLabels: matchLabels: +diff -y - TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper TEMP/apps-v1_deployment_kubernetes-dashboard_dashboard-metrics-scraper k8s-app: dashboard-metrics-scraper | k8s-app: dashboard-metrics-scraper-diff template: template: metadata: metadata: diff --git a/pkg/compare/testdata/TwoTemplatesWithSameKindNamespace/localVerboseout.golden b/pkg/compare/testdata/TwoTemplatesWithSameKindNamespace/localVerboseout.golden index ec58abf0..6235d9b4 100644 --- a/pkg/compare/testdata/TwoTemplatesWithSameKindNamespace/localVerboseout.golden +++ b/pkg/compare/testdata/TwoTemplatesWithSameKindNamespace/localVerboseout.golden @@ -1,6 +1,6 @@ Pre-processing template apps.v1.DaemonSet.kube-system.kindnet.yaml with empty data Pre-processing template apps.v1.DaemonSet.kube-system.kindnet2.yaml with empty data -More than one template with same apiVersion, metadata_namespace, kind. By Default for each Cluster CR that is correlated to one of these templates the template with the least number of diffs will be used. To use a different template for a specific CR specify it in the diff-config (-c flag) Template names are: apps.v1.DaemonSet.kube-system.kindnet.yaml, apps.v1.DaemonSet.kube-system.kindnet2.yaml +more than one template with same apiVersion, metadata_namespace, kind: by default for each cluster CR that is correlated to one of these templates the template with the least number of diffs will be used; to use a different template for a specific CR specify it in the diff-config (-c flag); template names are: apps.v1.DaemonSet.kube-system.kindnet.yaml, apps.v1.DaemonSet.kube-system.kindnet2.yaml Loading object apps/v1_DaemonSet_SomeNS_Name Executing template apps.v1.DaemonSet.kube-system.kindnet.yaml Executing template apps.v1.DaemonSet.kube-system.kindnet2.yaml diff --git a/pkg/compare/testdata/TwoTemplatesWithSameapiVersionKindNameNamespace/localVerboseout.golden b/pkg/compare/testdata/TwoTemplatesWithSameapiVersionKindNameNamespace/localVerboseout.golden index f3e20868..91b8cc40 100644 --- a/pkg/compare/testdata/TwoTemplatesWithSameapiVersionKindNameNamespace/localVerboseout.golden +++ b/pkg/compare/testdata/TwoTemplatesWithSameapiVersionKindNameNamespace/localVerboseout.golden @@ -1,6 +1,6 @@ Pre-processing template apps.v1.DaemonSet.kube-system.kindnet.yaml with empty data Pre-processing template apps.v1.DaemonSet.kube-system.kindnet.yaml with empty data -More than one template with same apiVersion, metadata_name, metadata_namespace, kind. By Default for each Cluster CR that is correlated to one of these templates the template with the least number of diffs will be used. To use a different template for a specific CR specify it in the diff-config (-c flag) Template names are: apps.v1.DaemonSet.kube-system.kindnet.yaml, apps.v1.DaemonSet.kube-system.kindnet.yaml +more than one template with same apiVersion, metadata_name, metadata_namespace, kind: by default for each cluster CR that is correlated to one of these templates the template with the least number of diffs will be used; to use a different template for a specific CR specify it in the diff-config (-c flag); template names are: apps.v1.DaemonSet.kube-system.kindnet.yaml, apps.v1.DaemonSet.kube-system.kindnet.yaml Loading object apps/v1_DaemonSet_SomeNS_Name Executing template apps.v1.DaemonSet.kube-system.kindnet.yaml Executing template apps.v1.DaemonSet.kube-system.kindnet.yaml diff --git a/pkg/compare/testdata/YAMLOutput/localout.golden b/pkg/compare/testdata/YAMLOutput/localout.golden index 8fa14de0..61c76eed 100644 --- a/pkg/compare/testdata/YAMLOutput/localout.golden +++ b/pkg/compare/testdata/YAMLOutput/localout.golden @@ -3,9 +3,9 @@ Diffs: 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" + 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: MetadataHash: aa4c94f1307788e1da81f57718a9f1364d35d4ff6099fc633724bcf9d051a094 NumDiffCRs: 1 diff --git a/pkg/compare/unstructured.go b/pkg/compare/unstructured.go index 47f441f8..526bc7d1 100644 --- a/pkg/compare/unstructured.go +++ b/pkg/compare/unstructured.go @@ -13,7 +13,7 @@ import ( // This is a copy of unstructured.NestedFieldNoCopy but can also traverse slices // If the value is a slice it will try to convert the field into an int (and use it as the index) func NestedField(obj any, fields ...string) (any, bool, error) { - var val any = obj + val := obj for i, field := range fields { if val == nil {