Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move crd validation #3580

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions apis/v1beta1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-12-19T16:56:26Z"
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6943,6 +6943,7 @@ spec:
- unmanaged
type: string
mode:
default: deployment
enum:
- daemonset
- deployment
Expand Down Expand Up @@ -8247,6 +8248,7 @@ spec:
type: object
type: array
upgradeStrategy:
default: automatic
enum:
- automatic
- none
Expand Down Expand Up @@ -9261,6 +9263,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6943,6 +6943,7 @@ spec:
- unmanaged
type: string
mode:
default: deployment
enum:
- daemonset
- deployment
Expand Down Expand Up @@ -8247,6 +8248,7 @@ spec:
type: object
type: array
upgradeStrategy:
default: automatic
enum:
- automatic
- none
Expand Down Expand Up @@ -9261,6 +9263,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:
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6929,6 +6929,7 @@ spec:
- unmanaged
type: string
mode:
default: deployment
enum:
- daemonset
- deployment
Expand Down Expand Up @@ -8233,6 +8234,7 @@ spec:
type: object
type: array
upgradeStrategy:
default: automatic
enum:
- automatic
- none
Expand Down Expand Up @@ -9247,6 +9249,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:
Expand Down
1 change: 0 additions & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
resources:
- manager.yaml

59 changes: 59 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ webhooks:
resources:
- pods
sideEffects: None
- admissionReviewVersions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why this is being added. Can you try running make generate manifests bundle api-docs reset to see if it goes away?

- 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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34462,6 +34462,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)<br/>
<br/>
<i>Enum</i>: daemonset, deployment, sidecar, statefulset<br/>
<i>Default</i>: deployment<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -34636,6 +34637,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<br/>
<br/>
<i>Enum</i>: automatic, none<br/>
<i>Default</i>: automatic<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down
Loading