From e7eb079921622bd896976c5d7c81f0f72dabdcac Mon Sep 17 00:00:00 2001 From: Andrew Suderman Date: Thu, 13 Jul 2023 11:33:15 -0600 Subject: [PATCH] change kubernetes.io/ label from name to instance (#973) * Fix #972 change label from name to instance * Fix tests * more references * fix check * Fix example config --- ...Mismatched.yaml => metadataAndInstanceMismatched.yaml} | 8 ++++---- docs/changelog.md | 3 +++ docs/checks/reliability.md | 4 ++-- examples/config-full.yaml | 2 +- examples/config.yaml | 2 +- pkg/config/checks.go | 2 +- .../failure.unspecified.yaml | 0 .../failure.yaml | 2 +- .../success.yaml | 2 +- 9 files changed, 14 insertions(+), 11 deletions(-) rename checks/{metadataAndNameMismatched.yaml => metadataAndInstanceMismatched.yaml} (57%) rename test/checks/{metadataAndNameMismatched => metadataAndInstanceMismatched}/failure.unspecified.yaml (100%) rename test/checks/{metadataAndNameMismatched => metadataAndInstanceMismatched}/failure.yaml (72%) rename test/checks/{metadataAndNameMismatched => metadataAndInstanceMismatched}/success.yaml (74%) diff --git a/checks/metadataAndNameMismatched.yaml b/checks/metadataAndInstanceMismatched.yaml similarity index 57% rename from checks/metadataAndNameMismatched.yaml rename to checks/metadataAndInstanceMismatched.yaml index 7a15458c..30aea6e5 100644 --- a/checks/metadataAndNameMismatched.yaml +++ b/checks/metadataAndInstanceMismatched.yaml @@ -1,5 +1,5 @@ -successMessage: Label app.kubernetes.io/name matches metadata.name -failureMessage: Label app.kubernetes.io/name must match metadata.name +successMessage: Label app.kubernetes.io/instance matches metadata.name +failureMessage: Label app.kubernetes.io/instance must match metadata.name category: Reliability target: Controller schema: @@ -12,7 +12,7 @@ schema: properties: labels: type: object - required: ["app.kubernetes.io/name"] + required: ["app.kubernetes.io/instance"] properties: - app.kubernetes.io/name: + app.kubernetes.io/instance: const: "{{ .metadata.name }}" diff --git a/docs/changelog.md b/docs/changelog.md index b43d01c7..f443e693 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,9 @@ meta: --- +## Unreleased +* Change `metadataAndNameMismatched` to `metadataAndInstanceMismatched` + ## 8.1.1 * Add category for `metadataAndNameMismatched`. * Fix category for `priorityClassNotSet`. diff --git a/docs/checks/reliability.md b/docs/checks/reliability.md index 956d3434..1eb2d014 100644 --- a/docs/checks/reliability.md +++ b/docs/checks/reliability.md @@ -17,7 +17,7 @@ key | default | description `priorityClassNotSet` | `warning` | Fails when a priorityClassName is not set for a pod. `deploymentMissingReplicas` | `warning` | Fails when there is only one replica for a deployment. `missingPodDisruptionBudget` | `warning` | Fails when PDB is missing. -`metadataAndNameMismatched` | `warning` | Fails when label `app.kubernetes.io/name` and `metadata.name` mismatch +`metadataAndInstanceMismatched` | `warning` | Fails when label `app.kubernetes.io/instance` and `metadata.name` mismatch `topologySpreadConstraint` | `warning` | Fails when there is no topology spread constraint on the pod ## Background @@ -70,4 +70,4 @@ spec: - [Kubernetes Docs: Configure Liveness and Readiness Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/) - [Utilizing Kubernetes Liveness and Readiness Probes to Automatically Recover From Failure](https://medium.com/spire-labs/utilizing-kubernetes-liveness-and-readiness-probes-to-automatically-recover-from-failure-2fe0314f2b2e) - [Kubernetes Liveness and Readiness Probes: How to Avoid Shooting Yourself in the Foot](https://blog.colinbreck.com/kubernetes-liveness-and-readiness-probes-how-to-avoid-shooting-yourself-in-the-foot/) -- [Topology Spread Constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/) \ No newline at end of file +- [Topology Spread Constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/) diff --git a/examples/config-full.yaml b/examples/config-full.yaml index 07b8aa88..128f9b64 100644 --- a/examples/config-full.yaml +++ b/examples/config-full.yaml @@ -9,7 +9,7 @@ checks: topologySpreadConstraint: warning pdbDisruptionsIsZero: warning missingPodDisruptionBudget: warning - metadataAndNameMismatched: warning + metadataAndInstanceMismatched: warning # efficiency cpuRequestsMissing: warning diff --git a/examples/config.yaml b/examples/config.yaml index ea21ff11..5c82272b 100644 --- a/examples/config.yaml +++ b/examples/config.yaml @@ -6,7 +6,7 @@ checks: pullPolicyNotAlways: warning readinessProbeMissing: warning livenessProbeMissing: warning - metadataAndNameMismatched: warning + metadataAndInstanceMismatched: warning pdbDisruptionsIsZero: warning missingPodDisruptionBudget: warning topologySpreadConstraint: warning diff --git a/pkg/config/checks.go b/pkg/config/checks.go index 5404234a..83d463ed 100644 --- a/pkg/config/checks.go +++ b/pkg/config/checks.go @@ -55,7 +55,7 @@ var ( // Other checks "tlsSettingsMissing", "pdbDisruptionsIsZero", - "metadataAndNameMismatched", + "metadataAndInstanceMismatched", "missingPodDisruptionBudget", "missingNetworkPolicy", "sensitiveConfigmapContent", diff --git a/test/checks/metadataAndNameMismatched/failure.unspecified.yaml b/test/checks/metadataAndInstanceMismatched/failure.unspecified.yaml similarity index 100% rename from test/checks/metadataAndNameMismatched/failure.unspecified.yaml rename to test/checks/metadataAndInstanceMismatched/failure.unspecified.yaml diff --git a/test/checks/metadataAndNameMismatched/failure.yaml b/test/checks/metadataAndInstanceMismatched/failure.yaml similarity index 72% rename from test/checks/metadataAndNameMismatched/failure.yaml rename to test/checks/metadataAndInstanceMismatched/failure.yaml index dafaff68..52dcb7b9 100644 --- a/test/checks/metadataAndNameMismatched/failure.yaml +++ b/test/checks/metadataAndInstanceMismatched/failure.yaml @@ -3,7 +3,7 @@ kind: Pod metadata: name: nginx labels: - app.kubernetes.io/name: not-nginx + app.kubernetes.io/instance: not-nginx spec: containers: - name: nginx diff --git a/test/checks/metadataAndNameMismatched/success.yaml b/test/checks/metadataAndInstanceMismatched/success.yaml similarity index 74% rename from test/checks/metadataAndNameMismatched/success.yaml rename to test/checks/metadataAndInstanceMismatched/success.yaml index 5e949d47..36377e92 100644 --- a/test/checks/metadataAndNameMismatched/success.yaml +++ b/test/checks/metadataAndInstanceMismatched/success.yaml @@ -3,7 +3,7 @@ kind: Pod metadata: name: nginx labels: - app.kubernetes.io/name: nginx + app.kubernetes.io/instance: nginx spec: containers: - name: nginx