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 @@ -577,3 +577,193 @@ tests:
prometheusOperatorAdmissionWebhookConfig:
resources: []
expectedError: 'spec.prometheusOperatorAdmissionWebhookConfig.resources: Invalid value: 0: spec.prometheusOperatorAdmissionWebhookConfig.resources in body should have at least 1 items'
- name: Should be able to create MonitoringPluginConfig with valid resources
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
resources:
- name: "cpu"
request: "10m"
- name: "memory"
request: "50Mi"
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
resources:
- name: "cpu"
request: "10m"
- name: "memory"
request: "50Mi"
- name: Should be able to create MonitoringPluginConfig with valid tolerations
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
tolerations:
- key: "node-role.kubernetes.io/infra"
operator: "Exists"
effect: "NoSchedule"
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
tolerations:
- key: "node-role.kubernetes.io/infra"
operator: "Exists"
effect: "NoSchedule"
- name: Should be able to create MonitoringPluginConfig with valid topologySpreadConstraints
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- name: Should be able to create MonitoringPluginConfig with all fields
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
nodeSelector:
kubernetes.io/os: linux
resources:
- name: "cpu"
request: "10m"
limit: "50m"
- name: "memory"
request: "50Mi"
limit: "100Mi"
tolerations:
- operator: "Exists"
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
expected: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
nodeSelector:
kubernetes.io/os: linux
resources:
- name: "cpu"
request: "10m"
limit: "50m"
- name: "memory"
request: "50Mi"
limit: "100Mi"
tolerations:
- operator: "Exists"
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- name: Should reject MonitoringPluginConfig with empty object
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig: {}
expectedError: 'spec.monitoringPluginConfig: Invalid value: 0: spec.monitoringPluginConfig in body should have at least 1 properties'
- name: Should reject MonitoringPluginConfig with too many resources
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
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"
- name: "example.com/foo"
request: "1"
- name: "example.com/bar"
request: "1"
- name: "example.com/baz"
request: "1"
- name: "example.com/qux"
request: "1"
- name: "example.com/quux"
request: "1"
expectedError: 'spec.monitoringPluginConfig.resources: Too many: 11: must have at most 10 items'
- name: Should reject MonitoringPluginConfig with duplicate resource names
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
resources:
- name: "cpu"
request: "100m"
- name: "cpu"
request: "200m"
expectedError: "Duplicate value"
- name: Should reject MonitoringPluginConfig with duplicate topologySpreadConstraints
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- maxSkew: 2
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
expectedError: "Duplicate value"
- name: Should reject MonitoringPluginConfig with limit less than request
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
resources:
- name: "cpu"
request: "500m"
limit: "200m"
expectedError: 'spec.monitoringPluginConfig.resources[0]: Invalid value: "object": limit must be greater than or equal to request'
- name: Should reject MonitoringPluginConfig with empty resources array
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
resources: []
expectedError: 'spec.monitoringPluginConfig.resources: Invalid value: 0: spec.monitoringPluginConfig.resources in body should have at least 1 items'
- name: Should reject MonitoringPluginConfig with empty topologySpreadConstraints array
initial: |
apiVersion: config.openshift.io/v1alpha1
kind: ClusterMonitoring
spec:
monitoringPluginConfig:
topologySpreadConstraints: []
expectedError: 'spec.monitoringPluginConfig.topologySpreadConstraints: Invalid value: 0: spec.monitoringPluginConfig.topologySpreadConstraints in body should have at least 1 items'
80 changes: 80 additions & 0 deletions config/v1alpha1/types_cluster_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ type ClusterMonitoringSpec struct {
// When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time.
// +optional
PrometheusOperatorAdmissionWebhookConfig PrometheusOperatorAdmissionWebhookConfig `json:"prometheusOperatorAdmissionWebhookConfig,omitempty,omitzero"`
// monitoringPluginConfig is an optional field that can be used to configure the
// monitoring-plugin component that runs as a Deployment in the openshift-monitoring namespace.
// The monitoring-plugin is the OpenShift console web plugin for monitoring, providing the
// monitoring UI in the OpenShift web console.
// When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time.
// +optional
MonitoringPluginConfig MonitoringPluginConfig `json:"monitoringPluginConfig,omitempty,omitzero"`
}

// UserDefinedMonitoring config for user-defined projects.
Expand Down Expand Up @@ -566,6 +573,79 @@ type PrometheusOperatorAdmissionWebhookConfig struct {
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
}

// MonitoringPluginConfig provides configuration options for the monitoring-plugin component
// that runs as a Deployment in the `openshift-monitoring` namespace. The monitoring-plugin is the
// OpenShift console web plugin for monitoring, providing the monitoring UI in the OpenShift web console.
// +kubebuilder:validation:MinProperties=1
type MonitoringPluginConfig struct {
Comment on lines +576 to +580

Choose a reason for hiding this comment

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

Action required

1. minproperties not documented 📘 Rule violation ✓ Correctness

MonitoringPluginConfig is validated with +kubebuilder:validation:MinProperties=1, but the API
comments do not document that an empty monitoringPluginConfig: {} is invalid. This violates the
requirement that validation markers and optional-field omitted behavior be fully documented for API
users.
Agent Prompt
## Issue description
`MonitoringPluginConfig` is marked with `+kubebuilder:validation:MinProperties=1`, but the comments for the type and the `monitoringPluginConfig` field do not document that an empty object is invalid and that at least one property must be set.

## Issue Context
Compliance requires that all kubebuilder validation markers (including MinProperties) and optional-field behavior are documented in comments so users understand what inputs are accepted.

## Fix Focus Areas
- config/v1alpha1/types_cluster_monitoring.go[110-116]
- config/v1alpha1/types_cluster_monitoring.go[576-580]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

// nodeSelector defines the nodes on which the Pods are scheduled.
// nodeSelector is optional.
//
// When omitted, this means the user has no opinion and the platform is left
// to choose reasonable defaults. These defaults are subject to change over time.
// The current default value is `kubernetes.io/os: linux`.
// When specified, nodeSelector must contain at least 1 entry and must not contain more than 10 entries.
// +optional
// +kubebuilder:validation:MinProperties=1
// +kubebuilder:validation:MaxProperties=10
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// resources defines the compute resource requests and limits for the monitoring-plugin container.
// This includes CPU, memory and HugePages constraints to help control scheduling and resource usage.
// When not specified, defaults are used by the platform. Requests cannot exceed limits.
// This field is optional.
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// This is a simplified API that maps to Kubernetes ResourceRequirements.
// The current default values are:
// resources:
// - name: cpu
// request: 10m
// limit: null
// - name: memory
// request: 50Mi
// limit: null
// Maximum length for this list is 10.
// Minimum length for this list is 1.
// Each resource name must be unique within this list.
// +optional
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=10
// +kubebuilder:validation:MinItems=1
Resources []ContainerResource `json:"resources,omitempty"`
// tolerations defines tolerations for the pods.
// tolerations is optional.
//
// When omitted, this means the user has no opinion and the platform is left
// to choose reasonable defaults. These defaults are subject to change over time.
// Defaults are empty/unset.
// Maximum length for this list is 10.
// Minimum length for this list is 1.
// +kubebuilder:validation:MaxItems=10
// +kubebuilder:validation:MinItems=1
// +listType=atomic
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// topologySpreadConstraints defines rules for how monitoring-plugin Pods should be distributed
// across topology domains such as zones, nodes, or other user-defined labels.
// topologySpreadConstraints is optional.
// This helps improve high availability and resource efficiency by avoiding placing
// too many replicas in the same failure domain.
//
// When omitted, this means no opinion and the platform is left to choose a default, which is subject to change over time.
// This field maps directly to the `topologySpreadConstraints` field in the Pod spec.
// Default is empty list.
// Maximum length for this list is 10.
// Minimum length for this list is 1.
// Entries must have unique topologyKey and whenUnsatisfiable pairs.
// +kubebuilder:validation:MaxItems=10
// +kubebuilder:validation:MinItems=1
// +listType=map
// +listMapKey=topologyKey
// +listMapKey=whenUnsatisfiable
// +optional
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
}

// AuditProfile defines the audit log level for the Metrics Server.
// +kubebuilder:validation:Enum=None;Metadata;Request;RequestResponse
type AuditProfile string
Expand Down
Loading