Skip to content

Commit da2c1ef

Browse files
committed
Fix API design issues and address PR feedback
Addresses feedback from PR reviewers and linting issues. Signed-off-by: Daniel Mellado <dmellado@fedoraproject.org>
1 parent c427299 commit da2c1ef

File tree

6 files changed

+400
-108777
lines changed

6 files changed

+400
-108777
lines changed

config/v1alpha1/tests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ tests:
359359
userDefined:
360360
mode: "Disabled"
361361
prometheusK8sConfig:
362-
logLevel: "Info"
362+
logLevel: "info"
363363
expected: |
364364
apiVersion: config.openshift.io/v1alpha1
365365
kind: ClusterMonitoring
366366
spec:
367367
userDefined:
368368
mode: "Disabled"
369369
prometheusK8sConfig:
370-
logLevel: "Info"
370+
logLevel: "info"
371371
- name: Should accept PrometheusK8sConfig with valid nodeSelector
372372
initial: |
373373
apiVersion: config.openshift.io/v1alpha1

config/v1alpha1/types_cluster_monitoring.go

Lines changed: 79 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,19 @@ const (
297297
)
298298

299299
// logLevel defines the verbosity of logs emitted by Alertmanager.
300-
// Valid values are Error, Warn, Info and Debug.
301-
// +kubebuilder:validation:Enum=Error;Warn;Info;Debug
300+
// Valid values are error, warn, info and debug.
301+
// +kubebuilder:validation:Enum=error;warn;info;debug
302302
type LogLevel string
303303

304304
const (
305-
// Error only errors will be logged.
306-
LogLevelError LogLevel = "Error"
307-
// Warn, both warnings and errors will be logged.
308-
LogLevelWarn LogLevel = "Warn"
309-
// Info, general information, warnings, and errors will all be logged.
310-
LogLevelInfo LogLevel = "Info"
311-
// Debug, detailed debugging information will be logged.
312-
LogLevelDebug LogLevel = "Debug"
305+
// LogLevelError only errors will be logged.
306+
LogLevelError LogLevel = "error"
307+
// LogLevelWarn, both warnings and errors will be logged.
308+
LogLevelWarn LogLevel = "warn"
309+
// LogLevelInfo, general information, warnings, and errors will all be logged.
310+
LogLevelInfo LogLevel = "info"
311+
// LogLevelDebug, detailed debugging information will be logged.
312+
LogLevelDebug LogLevel = "debug"
313313
)
314314

315315
// ContainerResource defines a single resource requirement for a container.
@@ -446,7 +446,16 @@ type MetricsServerConfig struct {
446446
// +kubebuilder:validation:MinProperties=1
447447
type PrometheusK8sConfig struct {
448448
// additionalAlertmanagerConfigs configures additional Alertmanager instances that receive alerts from
449-
// the Prometheus component. By default, no additional Alertmanager instances are configured.
449+
// the Prometheus component. This is useful for organizations that need to:
450+
// - Send alerts to external monitoring systems (like PagerDuty, Slack, or custom webhooks)
451+
// - Route different types of alerts to different teams or systems
452+
// - Integrate with existing enterprise alerting infrastructure
453+
// - Maintain separate alert routing for compliance or organizational requirements
454+
// By default, no additional Alertmanager instances are configured.
455+
// Maximum of 10 additional Alertmanager configurations can be specified.
456+
// Each configuration must have a unique apiVersion.
457+
// When omitted, no additional Alertmanager instances are configured (default behavior).
458+
// When set to an empty array [], the behavior is the same as omitting the field.
450459
// +optional
451460
// +kubebuilder:validation:MaxItems=10
452461
// +listType=map
@@ -471,6 +480,8 @@ type PrometheusK8sConfig struct {
471480
// externalLabels defines labels to be added to any time series or alerts when
472481
// communicating with external systems such as federation, remote storage,
473482
// and Alertmanager. By default, no labels are added.
483+
// When omitted, no external labels are applied (default behavior).
484+
// When set to an empty struct {}, the behavior is the same as omitting the field.
474485
// +optional
475486
ExternalLabels ExternalLabels `json:"externalLabels,omitempty,omitzero"`
476487
// logLevel defines the verbosity of logs emitted by Alertmanager.
@@ -619,21 +630,6 @@ const (
619630
AlertmanagerAPIVersionV2 AlertmanagerAPIVersion = "v2"
620631
)
621632

622-
// SecretKeyReference represents a reference to a secret key.
623-
type SecretKeyReference struct {
624-
// name of the secret in the pod's namespace to select from.
625-
// +required
626-
// +kubebuilder:validation:MaxLength=253
627-
Name *string `json:"name,omitempty"`
628-
// key of the secret to select from. Must be a valid secret key.
629-
// +required
630-
// +kubebuilder:validation:MaxLength=253
631-
Key *string `json:"key,omitempty"`
632-
// optional specifies whether the Secret or its key must be defined
633-
// +optional
634-
// +kubebuilder:validation:Enum=true;false
635-
Optional string `json:"optional,omitempty"`
636-
}
637633

638634
type AlertmanagerScheme string
639635

@@ -655,8 +651,11 @@ type AdditionalAlertmanagerConfig struct {
655651
// to use when authenticating to Alertmanager.
656652
// This is a custom type to allow for admission time validations.
657653
// +optional
658-
BearerToken SecretKeyReference `json:"bearerToken,omitempty,omitzero"`
659-
// pathPrefix defines the path prefix to add in front of the push endpoint path.
654+
BearerToken SecretKeySelector `json:"bearerToken,omitempty,omitzero"`
655+
// pathPrefix defines an optional URL path prefix to prepend to the Alertmanager API endpoints.
656+
// For example, if your Alertmanager is behind a reverse proxy at "/alertmanager/",
657+
// set this to "/alertmanager" so requests go to "/alertmanager/api/v1/alerts" instead of "/api/v1/alerts".
658+
// This is commonly needed when Alertmanager is deployed behind ingress controllers or load balancers.
660659
// +kubebuilder:validation:MaxLength=255
661660
// +kubebuilder:validation:MinLength=1
662661
// +optional
@@ -669,6 +668,7 @@ type AdditionalAlertmanagerConfig struct {
669668
Scheme AlertmanagerScheme `json:"scheme,omitempty"`
670669
// staticConfigs is a list of statically configured Alertmanager endpoints in the form
671670
// of `<host>:<port>`. Each entry must be a valid hostname or IP address followed by a colon and a valid port number (1-65535).
671+
// Maximum of 10 endpoints can be specified.
672672
// +kubebuilder:validation:MaxItems=10
673673
// +kubebuilder:validation:items:MaxLength=255
674674
// +kubebuilder:validation:items:Pattern=`^([a-zA-Z0-9.-]+|\[[a-fA-F0-9:]+\]):([1-9][0-9]{0,4})$`
@@ -705,6 +705,8 @@ type Label struct {
705705
// ExternalLabels represents labels to be added to time series and alerts.
706706
type ExternalLabels struct {
707707
// labels is a list of label key/value pairs.
708+
// At least 1 label must be specified, with a maximum of 50 labels allowed.
709+
// This field is required when ExternalLabels is specified - an empty array [] is not allowed.
708710
// +required
709711
// +kubebuilder:validation:MinItems=1
710712
// +kubebuilder:validation:MaxItems=50
@@ -734,6 +736,7 @@ type RemoteWriteSpec struct {
734736
// +kubebuilder:validation:MinLength=2
735737
RemoteTimeout string `json:"remoteTimeout,omitempty"`
736738
// writeRelabelConfigs is a list of relabeling rules to apply before sending data to the remote endpoint.
739+
// Maximum of 10 relabeling rules can be specified.
737740
// +optional
738741
// +kubebuilder:validation:MaxItems=10
739742
// +listType=atomic
@@ -770,9 +773,11 @@ type RelabelConfig struct {
770773
// +kubebuilder:validation:MaxLength=255
771774
Replacement *string `json:"replacement,omitempty"`
772775
// action is the action to perform.
776+
// Valid actions are: replace (default), keep, drop, hashmod, labelmap, labeldrop, labelkeep.
777+
// When omitted, defaults to "replace".
773778
// +optional
774-
// +kubebuilder:validation:MaxLength=20
775-
Action *string `json:"action,omitempty"`
779+
// +kubebuilder:default=replace
780+
Action *RelabelAction `json:"action,omitempty"`
776781
}
777782

778783
// TLSConfig represents TLS configuration for Alertmanager connections.
@@ -795,7 +800,7 @@ type TLSConfig struct {
795800
ServerName string `json:"serverName,omitempty"`
796801
// insecureSkipVerify determines the policy for TLS certificate verification.
797802
// Allowed values are "Verify" (default, secure) and "InsecureSkipVerify" (skip certificate verification, insecure).
798-
// By default, certificate verification is performed ("Verify").
803+
// When omitted, defaults to "Verify" (secure certificate verification is performed).
799804
// +optional
800805
// +kubebuilder:validation:Enum=Verify;InsecureSkipVerify
801806
// +kubebuilder:default=Verify
@@ -840,22 +845,58 @@ type SecretKeySelector struct {
840845
// +kubebuilder:validation:MinLength=1
841846
// +kubebuilder:validation:MaxLength=253
842847
Key string `json:"key,omitempty" protobuf:"bytes,2,opt,name=key"`
843-
// optional specifies whether the Secret or its key must be defined
844-
// +optional
845-
// +kubebuilder:validation:Enum=true;false
846-
Optional string `json:"optional,omitempty" protobuf:"varint,3,opt,name=optional"`
848+
// optional specifies whether the Secret or its key must be defined.
849+
// When set to "Required", the Secret and key must exist.
850+
// When set to "Optional", missing Secret or key will not cause an error.
851+
// When omitted, defaults to "Required".
852+
// +optional
853+
// +kubebuilder:validation:Enum=Required;Optional
854+
// +kubebuilder:default=Required
855+
Optional SecretRequirement `json:"optional,omitempty" protobuf:"varint,3,opt,name=optional"`
847856
}
848857

858+
// SecretRequirement defines whether a secret reference is required or optional.
859+
// +kubebuilder:validation:Enum=Required;Optional
860+
type SecretRequirement string
861+
862+
const (
863+
// SecretRequirementRequired means the Secret and its key must exist.
864+
SecretRequirementRequired SecretRequirement = "Required"
865+
// SecretRequirementOptional means missing Secret or key will not cause an error.
866+
SecretRequirementOptional SecretRequirement = "Optional"
867+
)
868+
869+
// RelabelAction defines the action to perform in a relabeling rule.
870+
// +kubebuilder:validation:Enum=replace;keep;drop;hashmod;labelmap;labeldrop;labelkeep
871+
type RelabelAction string
872+
873+
const (
874+
// RelabelActionReplace replaces the target label with the replacement value.
875+
RelabelActionReplace RelabelAction = "replace"
876+
// RelabelActionKeep keeps metrics that match the regex.
877+
RelabelActionKeep RelabelAction = "keep"
878+
// RelabelActionDrop drops metrics that match the regex.
879+
RelabelActionDrop RelabelAction = "drop"
880+
// RelabelActionHashMod sets the target label to the modulus of a hash of the source labels.
881+
RelabelActionHashMod RelabelAction = "hashmod"
882+
// RelabelActionLabelMap maps label names based on regex matching.
883+
RelabelActionLabelMap RelabelAction = "labelmap"
884+
// RelabelActionLabelDrop removes labels that match the regex.
885+
RelabelActionLabelDrop RelabelAction = "labeldrop"
886+
// RelabelActionLabelKeep removes labels that do not match the regex.
887+
RelabelActionLabelKeep RelabelAction = "labelkeep"
888+
)
889+
849890
// CollectionProfile defines the metrics collection profile for Prometheus.
850-
// +kubebuilder:validation:Enum=Full;Minimal
891+
// +kubebuilder:validation:Enum=full;minimal
851892
type CollectionProfile string
852893

853894
const (
854895
// CollectionProfileFull means Prometheus collects all metrics that are exposed by the platform components.
855-
CollectionProfileFull CollectionProfile = "Full"
896+
CollectionProfileFull CollectionProfile = "full"
856897
// CollectionProfileMinimal means Prometheus only collects metrics necessary for the default
857898
// platform alerts, recording rules, telemetry and console dashboards.
858-
CollectionProfileMinimal CollectionProfile = "Minimal"
899+
CollectionProfileMinimal CollectionProfile = "minimal"
859900
)
860901

861902
// AuditProfile defines the audit log level for the Metrics Server.

config/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/v1alpha1/zz_generated.swagger_doc_generated.go

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)