From 7c531066837fb38924ea1d23807c816effecc0e7 Mon Sep 17 00:00:00 2001 From: Julia Bier Date: Mon, 30 Dec 2024 00:31:46 -0400 Subject: [PATCH 1/2] Create validation rules for opentelemetrycollector type --- apis/v1beta1/opentelemetrycollector_types.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apis/v1beta1/opentelemetrycollector_types.go b/apis/v1beta1/opentelemetrycollector_types.go index dd20af943d..5cc366a10e 100644 --- a/apis/v1beta1/opentelemetrycollector_types.go +++ b/apis/v1beta1/opentelemetrycollector_types.go @@ -77,6 +77,8 @@ type OpenTelemetryCollectorStatus struct { } // OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector. +// +kubebuilder:validation:XValidation:rule="!(self.Mode != 'statefulset' && size(self.VolumeClaimTemplates) > 0)",message="the OpenTelemetry Collector attribute 'volumeClaimTemplates' is only supported if mode is set to 'statefulset'" +// +kubebuilder:validation:XValidation:rule="!(self.Mode != 'statefulset' && has(self.persistentVolumeClaimRetentionPolicy))",message="the OpenTelemetry Collector attribute 'persistentVolumeClaimRetentionPolicy' is only supported if mode is set to 'statefulset'" type OpenTelemetryCollectorSpec struct { // OpenTelemetryCommonFields are fields that are on all OpenTelemetry CRD workloads. OpenTelemetryCommonFields `json:",inline"` @@ -90,9 +92,11 @@ type OpenTelemetryCollectorSpec struct { // +optional TargetAllocator TargetAllocatorEmbedded `json:"targetAllocator,omitempty"` // Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar) + // +kubebuilder:default:=deployment // +optional Mode Mode `json:"mode,omitempty"` // UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed + // +kubebuilder:default:=automatic // +optional UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy"` // Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details. From f6a1ab564af80f185188ec724ced26afc0c57498 Mon Sep 17 00:00:00 2001 From: Julia Bier Date: Mon, 30 Dec 2024 00:33:03 -0400 Subject: [PATCH 2/2] make bundle --- ...emetry-operator.clusterserviceversion.yaml | 4 +- ...ntelemetry.io_opentelemetrycollectors.yaml | 10 ++++ ...emetry-operator.clusterserviceversion.yaml | 4 +- ...ntelemetry.io_opentelemetrycollectors.yaml | 10 ++++ ...ntelemetry.io_opentelemetrycollectors.yaml | 10 ++++ config/manager/kustomization.yaml | 5 ++ config/webhook/manifests.yaml | 59 +++++++++++++++++++ docs/api.md | 2 + 8 files changed, 100 insertions(+), 4 deletions(-) diff --git a/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml index b7a24d1dde..c222c126d1 100644 --- a/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-11-27T11:54:33Z" + createdAt: "2024-12-30T04:31:52Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -483,7 +483,7 @@ spec: valueFrom: fieldRef: fieldPath: spec.serviceAccountName - image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.114.0 + image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator livenessProbe: httpGet: path: /healthz diff --git a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 6ccb1c9e5f..c67d91751b 100644 --- a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -6943,6 +6943,7 @@ spec: - unmanaged type: string mode: + default: deployment enum: - daemonset - deployment @@ -8195,6 +8196,7 @@ spec: type: object type: array upgradeStrategy: + default: automatic enum: - automatic - none @@ -9209,6 +9211,14 @@ spec: - config - managementState type: object + x-kubernetes-validations: + - message: the OpenTelemetry Collector attribute 'volumeClaimTemplates' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && size(self.VolumeClaimTemplates) + > 0)' + - message: the OpenTelemetry Collector attribute 'persistentVolumeClaimRetentionPolicy' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && has(self.persistentVolumeClaimRetentionPolicy))' status: properties: image: diff --git a/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml index 751ef48728..f0f86e5ca3 100644 --- a/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-11-27T11:54:33Z" + createdAt: "2024-12-30T04:31:56Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -487,7 +487,7 @@ spec: valueFrom: fieldRef: fieldPath: spec.serviceAccountName - image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.114.0 + image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator livenessProbe: httpGet: path: /healthz diff --git a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 6ccb1c9e5f..c67d91751b 100644 --- a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -6943,6 +6943,7 @@ spec: - unmanaged type: string mode: + default: deployment enum: - daemonset - deployment @@ -8195,6 +8196,7 @@ spec: type: object type: array upgradeStrategy: + default: automatic enum: - automatic - none @@ -9209,6 +9211,14 @@ spec: - config - managementState type: object + x-kubernetes-validations: + - message: the OpenTelemetry Collector attribute 'volumeClaimTemplates' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && size(self.VolumeClaimTemplates) + > 0)' + - message: the OpenTelemetry Collector attribute 'persistentVolumeClaimRetentionPolicy' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && has(self.persistentVolumeClaimRetentionPolicy))' status: properties: image: diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index fc36f4deb5..239650f16d 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -6929,6 +6929,7 @@ spec: - unmanaged type: string mode: + default: deployment enum: - daemonset - deployment @@ -8181,6 +8182,7 @@ spec: type: object type: array upgradeStrategy: + default: automatic enum: - automatic - none @@ -9195,6 +9197,14 @@ spec: - config - managementState type: object + x-kubernetes-validations: + - message: the OpenTelemetry Collector attribute 'volumeClaimTemplates' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && size(self.VolumeClaimTemplates) + > 0)' + - message: the OpenTelemetry Collector attribute 'persistentVolumeClaimRetentionPolicy' + is only supported if mode is set to 'statefulset' + rule: '!(self.Mode != ''statefulset'' && has(self.persistentVolumeClaimRetentionPolicy))' status: properties: image: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84cb..40c0846afa 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,7 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 173e2f7420..412267b37d 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -83,6 +83,26 @@ webhooks: resources: - pods sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-opentelemetry-io-v1beta1-opentelemetrycollector + failurePolicy: Fail + name: mopentelemetrycollectorbeta.kb.io + rules: + - apiGroups: + - opentelemetry.io + apiVersions: + - v1beta1 + operations: + - CREATE + - UPDATE + resources: + - opentelemetrycollectors + sideEffects: None --- apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration @@ -206,3 +226,42 @@ webhooks: resources: - opampbridges sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-opentelemetry-io-v1beta1-opentelemetrycollector + failurePolicy: Fail + name: vopentelemetrycollectorcreateupdatebeta.kb.io + rules: + - apiGroups: + - opentelemetry.io + apiVersions: + - v1beta1 + operations: + - CREATE + - UPDATE + resources: + - opentelemetrycollectors + sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-opentelemetry-io-v1beta1-opentelemetrycollector + failurePolicy: Ignore + name: vopentelemetrycollectordeletebeta.kb.io + rules: + - apiGroups: + - opentelemetry.io + apiVersions: + - v1beta1 + operations: + - DELETE + resources: + - opentelemetrycollectors + sideEffects: None diff --git a/docs/api.md b/docs/api.md index 9601cca2fd..98ba9fe7f8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -34463,6 +34463,7 @@ It is only effective when healthcheckextension is configured in the OpenTelemetr Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)

Enum: daemonset, deployment, sidecar, statefulset
+ Default: deployment
false @@ -34637,6 +34638,7 @@ This only works with the following OpenTelemetryCollector mode's: statefulset, a UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed

Enum: automatic, none
+ Default: automatic
false