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

Ensures that we only skip reconciliation for unmanaged resources #2197

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions .chloggen/default-managed.yaml
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. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: fixes scenario where an old CRD would cause the operator to default to an unmanaged state

# One or more tracking issues related to the change
issues: [2039]

# (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:
5 changes: 5 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (r *OpenTelemetryCollector) Default() {
if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Ingress.RuleType == "" {
r.Spec.Ingress.RuleType = IngressRuleTypePath
}
// If someone upgrades to a later version without upgrading their CRD they will not have a management state set.
// This results in a default state of unmanaged preventing reconciliation from continuing.
if len(r.Spec.ManagementState) == 0 {
r.Spec.ManagementState = ManagementStateManaged
}
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-opentelemetrycollector,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1alpha1,name=vopentelemetrycollectorcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
Expand Down
31 changes: 30 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
Mode: ModeDeployment,
Replicas: &one,
UpgradeStrategy: UpgradeStrategyAutomatic,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
Expand Down Expand Up @@ -77,6 +78,31 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
Mode: ModeSidecar,
Replicas: &five,
UpgradeStrategy: "adhoc",
ManagementState: ManagementStateManaged,
},
},
},
{
name: "doesn't override unmanaged",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
ManagementState: ManagementStateUnmanaged,
Mode: ModeSidecar,
Replicas: &five,
UpgradeStrategy: "adhoc",
},
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeSidecar,
Replicas: &five,
UpgradeStrategy: "adhoc",
ManagementState: ManagementStateUnmanaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
Expand Down Expand Up @@ -106,6 +132,7 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
Mode: ModeDeployment,
Replicas: &one,
UpgradeStrategy: UpgradeStrategyAutomatic,
ManagementState: ManagementStateManaged,
Autoscaler: &AutoscalerSpec{
TargetCPUUtilization: &defaultCPUTarget,
MaxReplicas: &five,
Expand Down Expand Up @@ -137,6 +164,7 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
Mode: ModeDeployment,
Replicas: &one,
UpgradeStrategy: UpgradeStrategyAutomatic,
ManagementState: ManagementStateManaged,
Autoscaler: &AutoscalerSpec{
TargetCPUUtilization: &defaultCPUTarget,
// webhook Default adds MaxReplicas to Autoscaler because
Expand Down Expand Up @@ -171,7 +199,8 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Mode: ModeDeployment,
ManagementState: ManagementStateManaged,
Ingress: Ingress{
Type: IngressTypeRoute,
Route: OpenShiftRoute{
Expand Down
2 changes: 1 addition & 1 deletion controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
return ctrl.Result{}, client.IgnoreNotFound(err)
}

if instance.Spec.ManagementState != v1alpha1.ManagementStateManaged {
if instance.Spec.ManagementState == v1alpha1.ManagementStateUnmanaged {
log.Info("Skipping reconciliation for unmanaged OpenTelemetryCollector resource", "name", req.String())
// Stop requeueing for unmanaged OpenTelemetryCollector custom resources
return ctrl.Result{}, nil
Expand Down