-
Notifications
You must be signed in to change notification settings - Fork 567
Remove duplicated Sidecar mode validations #4469
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: bug_fix | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
| component: collector | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Removed duplicate Sidecar mode validations from the collector webhook in favor of the CRD CEL checks. | ||
|
|
||
| # One or more tracking issues related to the change | ||
| issues: [3319] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: Kubernetes 1.23 and 1.24 support was dropped in v0.131.0, where custom resource validation expressions were disabled by default. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,29 +202,6 @@ func (c CollectorWebhook) Validate(ctx context.Context, r *OpenTelemetryCollecto | |
| return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'persistentVolumeClaimRetentionPolicy'", r.Spec.Mode) | ||
| } | ||
|
|
||
| // validate tolerations | ||
| // NOTE: this validation is also implemented in CRDs using CEL (Common Expression Language) | ||
| if r.Spec.Mode == ModeSidecar && len(r.Spec.Tolerations) > 0 { | ||
| return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'tolerations'", r.Spec.Mode) | ||
| } | ||
|
|
||
| // validate priorityClassName | ||
| // NOTE: this validation is also implemented in CRDs using CEL (Common Expression Language) | ||
| if r.Spec.Mode == ModeSidecar && r.Spec.PriorityClassName != "" { | ||
| return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'priorityClassName'", r.Spec.Mode) | ||
| } | ||
|
|
||
| // validate affinity | ||
| // NOTE: this validation is also implemented in CRDs using CEL (Common Expression Language) | ||
| if r.Spec.Mode == ModeSidecar && r.Spec.Affinity != nil { | ||
| return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'affinity'", r.Spec.Mode) | ||
| } | ||
|
|
||
| // NOTE: this validation is also implemented in CRDs using CEL (Common Expression Language) | ||
| if r.Spec.Mode == ModeSidecar && len(r.Spec.AdditionalContainers) > 0 { | ||
| return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'AdditionalContainers'", r.Spec.Mode) | ||
| } | ||
|
|
||
| // validate target allocator configs | ||
| if r.Spec.TargetAllocator.Enabled { | ||
| taWarnings, err := c.validateTargetAllocatorConfig(ctx, r) | ||
|
|
@@ -295,11 +272,6 @@ func (c CollectorWebhook) Validate(ctx context.Context, r *OpenTelemetryCollecto | |
| ) | ||
| } | ||
|
|
||
| if r.Spec.Ingress.Type == IngressTypeIngress && r.Spec.Mode == ModeSidecar { | ||
| return warnings, fmt.Errorf("the OpenTelemetry Spec Ingress configuiration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s", | ||
| ModeDeployment, ModeDaemonSet, ModeStatefulSet, | ||
| ) | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was simply duplicated with the validation just above. |
||
| if r.Spec.Ingress.RuleType == IngressRuleTypeSubdomain && (r.Spec.Ingress.Hostname == "" || r.Spec.Ingress.Hostname == "*") { | ||
| return warnings, fmt.Errorf("a valid Ingress hostname has to be defined for subdomain ruleType") | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -806,18 +806,6 @@ func TestOTELColValidatingWebhook(t *testing.T) { | |
| }, | ||
| expectedErr: "does not support the attribute 'persistentVolumeClaimRetentionPolicy'", | ||
| }, | ||
| { | ||
| name: "invalid mode with tolerations", | ||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
| Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
| Mode: v1beta1.ModeSidecar, | ||
| OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
| Tolerations: []v1.Toleration{{}, {}}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErr: "does not support the attribute 'tolerations'", | ||
| }, | ||
| { | ||
| name: "invalid mode with target allocator", | ||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
|
|
@@ -1145,62 +1133,6 @@ func TestOTELColValidatingWebhook(t *testing.T) { | |
| }, | ||
| expectedErr: fmt.Sprintf("Ingress can only be used in combination with the modes: %s, %s, %s", v1beta1.ModeDeployment, v1beta1.ModeDaemonSet, v1beta1.ModeStatefulSet), | ||
| }, | ||
| { | ||
| name: "invalid mode with priorityClassName", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we removing these tests because we are not longer able to test the CEL expressions?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They’re now being tested in TestValidationViaCRDAnnotations using envtest 🙂 |
||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
| Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
| Mode: v1beta1.ModeSidecar, | ||
| OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
| PriorityClassName: "test-class", | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErr: "does not support the attribute 'priorityClassName'", | ||
| }, | ||
| { | ||
| name: "invalid mode with affinity", | ||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
| Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
| Mode: v1beta1.ModeSidecar, | ||
| OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
| Affinity: &v1.Affinity{ | ||
| NodeAffinity: &v1.NodeAffinity{ | ||
| RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ | ||
| NodeSelectorTerms: []v1.NodeSelectorTerm{ | ||
| { | ||
| MatchExpressions: []v1.NodeSelectorRequirement{ | ||
| { | ||
| Key: "node", | ||
| Operator: v1.NodeSelectorOpIn, | ||
| Values: []string{"test-node"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErr: "does not support the attribute 'affinity'", | ||
| }, | ||
| { | ||
| name: "invalid AdditionalContainers", | ||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
| Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
| Mode: v1beta1.ModeSidecar, | ||
| OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
| AdditionalContainers: []v1.Container{ | ||
| { | ||
| Name: "test", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'AdditionalContainers'", | ||
| }, | ||
| { | ||
| name: "missing ingress hostname for subdomain ruleType", | ||
| otelcol: v1beta1.OpenTelemetryCollector{ | ||
|
|
@@ -1753,6 +1685,74 @@ func TestValidationViaCRDAnnotations(t *testing.T) { | |
| }, | ||
| expectedErr: "spec.ports[0].hostPort in body should be less than or equal to 65535", | ||
| }, | ||
| { | ||
| name: "Sidecar mode with tolerations", | ||
| collector: func(namespace string) *v1beta1.OpenTelemetryCollector { | ||
| c := minimalCollector(namespace) | ||
| c.Spec.Mode = v1beta1.ModeSidecar | ||
| c.Spec.Tolerations = []v1.Toleration{ | ||
| { | ||
| Key: "key", | ||
| Operator: v1.TolerationOpEqual, | ||
| Value: "value", | ||
| Effect: v1.TaintEffectNoSchedule, | ||
| }, | ||
| } | ||
| return c | ||
| }, | ||
| expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'tolerations'", | ||
| }, | ||
| { | ||
| name: "Sidecar mode with priorityClassName", | ||
| collector: func(namespace string) *v1beta1.OpenTelemetryCollector { | ||
| c := minimalCollector(namespace) | ||
| c.Spec.Mode = v1beta1.ModeSidecar | ||
| c.Spec.PriorityClassName = "test-class" | ||
| return c | ||
| }, | ||
| expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'priorityClassName'", | ||
| }, | ||
| { | ||
| name: "Sidecar mode with affinity", | ||
| collector: func(namespace string) *v1beta1.OpenTelemetryCollector { | ||
| c := minimalCollector(namespace) | ||
| c.Spec.Mode = v1beta1.ModeSidecar | ||
| c.Spec.Affinity = &v1.Affinity{ | ||
| NodeAffinity: &v1.NodeAffinity{ | ||
| RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ | ||
| NodeSelectorTerms: []v1.NodeSelectorTerm{ | ||
| { | ||
| MatchExpressions: []v1.NodeSelectorRequirement{ | ||
| { | ||
| Key: "node", | ||
| Operator: v1.NodeSelectorOpIn, | ||
| Values: []string{"test-node"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| return c | ||
| }, | ||
| expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'affinity'", | ||
| }, | ||
| { | ||
| name: "Sidecar mode with additionalContainers", | ||
| collector: func(namespace string) *v1beta1.OpenTelemetryCollector { | ||
| c := minimalCollector(namespace) | ||
| c.Spec.Mode = v1beta1.ModeSidecar | ||
| c.Spec.AdditionalContainers = []v1.Container{ | ||
| { | ||
| Name: "test", | ||
| Image: "test-image", | ||
| }, | ||
| } | ||
| return c | ||
| }, | ||
| expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'additionalContainers'", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.