Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,344 @@ tests:
request: "100m"
limit: "0"
expectedError: 'spec.nodeExporterConfig.resources[0].limit: Invalid value: "": limit must be a positive, non-zero quantity'
- name: Should be able to create KubeStateMetricsConfig with valid resources
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "50m"
limit: "200m"
- name: "memory"
request: "50Mi"
limit: "200Mi"
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "50m"
limit: "200m"
- name: "memory"
request: "50Mi"
limit: "200Mi"
- name: Should be able to create KubeStateMetricsConfig with valid topologySpreadConstraints
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: kube-state-metrics
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: kube-state-metrics
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: kube-state-metrics
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: kube-state-metrics
- name: Should be able to create KubeStateMetricsConfig with all fields
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
nodeSelector:
kubernetes.io/os: linux
resources:
- name: "cpu"
request: "50m"
limit: "200m"
tolerations:
- key: "node-role.kubernetes.io/infra"
operator: "Exists"
effect: "NoSchedule"
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: kube-state-metrics
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
nodeSelector:
kubernetes.io/os: linux
resources:
- name: "cpu"
request: "50m"
limit: "200m"
tolerations:
- key: "node-role.kubernetes.io/infra"
operator: "Exists"
effect: "NoSchedule"
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: kube-state-metrics
- name: Should reject KubeStateMetricsConfig with empty object
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig: {}
expectedError: 'spec.kubeStateMetricsConfig: Invalid value: 0: spec.kubeStateMetricsConfig in body should have at least 1 properties'
- name: Should reject KubeStateMetricsConfig with too many resources
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "100m"
- name: "memory"
request: "64Mi"
- name: "hugepages-2Mi"
request: "32Mi"
- name: "hugepages-1Gi"
request: "1Gi"
- name: "ephemeral-storage"
request: "1Gi"
- name: "nvidia.com/gpu"
request: "1"
expectedError: 'spec.kubeStateMetricsConfig.resources: Too many: 6: must have at most 5 items'
- name: Should reject KubeStateMetricsConfig with limit less than request
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "500m"
limit: "200m"
expectedError: 'spec.kubeStateMetricsConfig.resources[0]: Invalid value: "object": limit must be greater than or equal to request'
- name: Should reject KubeStateMetricsConfig with zero request
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "0"
expectedError: 'spec.kubeStateMetricsConfig.resources[0].request: Invalid value: "": request must be a positive, non-zero quantity'
- name: Should reject KubeStateMetricsConfig with zero limit
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "100m"
limit: "0"
expectedError: 'spec.kubeStateMetricsConfig.resources[0].limit: Invalid value: "": limit must be a positive, non-zero quantity'
- name: Should reject KubeStateMetricsConfig with too many topologySpreadConstraints
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "zone1"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone2"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone3"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone4"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone5"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone6"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone7"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone8"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone9"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone10"
whenUnsatisfiable: DoNotSchedule
- maxSkew: 1
topologyKey: "zone11"
whenUnsatisfiable: DoNotSchedule
expectedError: 'spec.kubeStateMetricsConfig.topologySpreadConstraints: Too many: 11: must have at most 10 items'
- name: Should reject KubeStateMetricsConfig with empty resources array
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources: []
expectedError: 'spec.kubeStateMetricsConfig.resources: Invalid value: 0: spec.kubeStateMetricsConfig.resources in body should have at least 1 items'
- name: Should reject KubeStateMetricsConfig with empty topologySpreadConstraints array
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
topologySpreadConstraints: []
expectedError: 'spec.kubeStateMetricsConfig.topologySpreadConstraints: Invalid value: 0: spec.kubeStateMetricsConfig.topologySpreadConstraints in body should have at least 1 items'
- name: Should reject KubeStateMetricsConfig with duplicate resource names
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
resources:
- name: "cpu"
request: "100m"
- name: "cpu"
request: "200m"
expectedError: 'spec.kubeStateMetricsConfig.resources[1]: Duplicate value: map[string]interface {}{"name":"cpu"}'
- name: Should reject KubeStateMetricsConfig with duplicate topologySpreadConstraints
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- maxSkew: 2
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
expectedError: "Duplicate value"
- name: Should be able to create KubeStateMetricsConfig with valid additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- foo
- bar
- resource: cronjobs
labels:
- "*"
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- foo
- bar
- resource: cronjobs
labels:
- "*"
- name: Should be able to create KubeStateMetricsConfig with single additionalResourceLabels entry
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- "*"
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- "*"
- name: Should reject KubeStateMetricsConfig with unsupported resource in additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: pods
labels:
- foo
expectedError: 'spec.kubeStateMetricsConfig.additionalResourceLabels[0].resource: Unsupported value: "pods"'
- name: Should reject KubeStateMetricsConfig with empty labels in additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels: []
expectedError: "spec.kubeStateMetricsConfig.additionalResourceLabels[0].labels: Invalid value"
- name: Should reject KubeStateMetricsConfig with duplicate resource in additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- foo
- resource: jobs
labels:
- bar
expectedError: "Duplicate value"
Comment on lines +2145 to +2158
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Duplicate resource test uses invalid resource values.

This test intends to validate duplicate detection for additionalResourceLabels, but uses jobs which is not a valid resource value. The test may fail for the wrong reason (invalid enum) before reaching the duplicate validation. Use valid resource values to properly test duplicate detection.

🔧 Proposed fix
     - name: Should reject KubeStateMetricsConfig with duplicate resource in additionalResourceLabels
       initial: |
         apiVersion: config.openshift.io/v1alpha1
         kind: ClusterMonitoring
         spec:
           kubeStateMetricsConfig:
             additionalResourceLabels:
-              - resource: jobs
+              - resource: nodes
                 labels:
                   - foo
-              - resource: jobs
+              - resource: nodes
                 labels:
                   - bar
       expectedError: "Duplicate value"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Should reject KubeStateMetricsConfig with duplicate resource in additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: jobs
labels:
- foo
- resource: jobs
labels:
- bar
expectedError: "Duplicate value"
- name: Should reject KubeStateMetricsConfig with duplicate resource in additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels:
- resource: nodes
labels:
- foo
- resource: nodes
labels:
- bar
expectedError: "Duplicate value"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml`
around lines 2145 - 2158, The test "Should reject KubeStateMetricsConfig with
duplicate resource in additionalResourceLabels" uses an invalid resource value
"jobs" which triggers enum validation before duplicate detection; update the two
entries under spec.kubeStateMetricsConfig.additionalResourceLabels to use a
valid resource (for example "pods" or another accepted enum value) so the YAML
passes resource validation and the duplicate-resource check is exercised by
ClusterMonitoring validation.

- name: Should reject KubeStateMetricsConfig with empty additionalResourceLabels
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
kubeStateMetricsConfig:
additionalResourceLabels: []
expectedError: "spec.kubeStateMetricsConfig.additionalResourceLabels: Invalid value"
onUpdate:
- name: Should reject updating TelemeterClientConfig to empty object
initial: |
Expand Down
Loading