Skip to content
Merged
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
43 changes: 35 additions & 8 deletions internal/controller/operatorconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import (
)

const (
finalizerName = "operatorconfig.automotive.sdv.cloud.redhat.com/finalizer"
buildAPIName = "ado-build-api"
phaseFailed = "Failed"
internalJWTSecretName = "ado-build-api-internal-jwt"
finalizerName = "operatorconfig.automotive.sdv.cloud.redhat.com/finalizer"
buildAPIName = "ado-build-api"
phaseFailed = "Failed"
internalJWTSecretName = "ado-build-api-internal-jwt"
unmanagedAnnotationKey = "automotive.sdv.cloud.redhat.com/unmanaged"
unmanagedAnnotationTrue = "true"
)

// isNoMatchError checks if error is "no matches for kind" error (CRD doesn't exist)
Expand Down Expand Up @@ -483,6 +485,12 @@ func (r *OperatorConfigReconciler) createOrUpdate(
return err
}

// Skip update if resource is marked as unmanaged
if annotations := existing.GetAnnotations(); annotations != nil && annotations[unmanagedAnnotationKey] == unmanagedAnnotationTrue {
r.Log.Info("Skipping update for unmanaged resource", "name", obj.GetName(), "kind", obj.GetObjectKind().GroupVersionKind().Kind)
return nil
}
Comment on lines +488 to +492

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

obj.GetObjectKind().GroupVersionKind().Kind may log an empty string.

In-memory objects built by your build* helpers typically don't have TypeMeta set, so obj.GetObjectKind().GroupVersionKind().Kind will resolve to "". Consider using existing (which has GVK populated after r.Get) or use fmt.Sprintf("%T", obj) as a fallback.

Proposed fix
-		r.Log.Info("Skipping update for unmanaged resource", "name", obj.GetName(), "kind", obj.GetObjectKind().GroupVersionKind().Kind)
+		r.Log.Info("Skipping update for unmanaged resource", "name", obj.GetName(), "kind", existing.GetObjectKind().GroupVersionKind().Kind)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Skip update if resource is marked as unmanaged
if annotations := existing.GetAnnotations(); annotations != nil && annotations[unmanagedAnnotationKey] == unmanagedAnnotationTrue {
r.Log.Info("Skipping update for unmanaged resource", "name", obj.GetName(), "kind", obj.GetObjectKind().GroupVersionKind().Kind)
return nil
}
// Skip update if resource is marked as unmanaged
if annotations := existing.GetAnnotations(); annotations != nil && annotations[unmanagedAnnotationKey] == unmanagedAnnotationTrue {
r.Log.Info("Skipping update for unmanaged resource", "name", obj.GetName(), "kind", existing.GetObjectKind().GroupVersionKind().Kind)
return nil
}
🤖 Prompt for AI Agents
In `@internal/controller/operatorconfig/controller.go` around lines 488 - 492, The
log call in the unmanaged-resource check uses
obj.GetObjectKind().GroupVersionKind().Kind which can be empty for in-memory
objects; change the log to use the reconciled object's GVK
(existing.GetObjectKind().GroupVersionKind().Kind) and, if that is empty, fall
back to a type string such as fmt.Sprintf("%T", obj) before calling r.Log.Info
(keep the same message and keys and still return nil); reference: existing, obj,
unmanagedAnnotationKey, unmanagedAnnotationTrue, and r.Log.Info.


// Resource exists, update it
obj.SetResourceVersion(existing.GetResourceVersion())
return r.Update(ctx, obj)
Expand Down Expand Up @@ -572,10 +580,20 @@ func (r *OperatorConfigReconciler) createOrUpdatePartitionConfig(ctx context.Con
"partition-rules.yaml": `targets:
ridesx4:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ridesx4_r3:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ridesx4_scmi:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ride4_sa8775p_sx_r3:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ride4_sa8775p_sx:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ride4_sa8775p_sx_legacy:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ride4_sa8775p_sx_legacy_r3:
include: ["system_a", "system_b", "boot_a", "boot_b"]
ride4_sa8650p_sx_r3:
include: ["system_a", "system_b", "boot_a", "boot_b"]
`,
},
}
Expand All @@ -584,7 +602,17 @@ func (r *OperatorConfigReconciler) createOrUpdatePartitionConfig(ctx context.Con
return fmt.Errorf("failed to set controller reference: %w", err)
}

return r.createOrUpdate(ctx, configMap, owner)
// Only create the ConfigMap if it doesn't exist; never overwrite user changes
existing := &corev1.ConfigMap{}
err := r.Get(ctx, client.ObjectKeyFromObject(configMap), existing)
if err != nil {
if errors.IsNotFound(err) {
return r.Create(ctx, configMap)
}
return err
}

return nil
}

func (r *OperatorConfigReconciler) deployBuildController(ctx context.Context, config *automotivev1alpha1.OperatorConfig) error {
Expand Down Expand Up @@ -754,7 +782,7 @@ func (r *OperatorConfigReconciler) createOrUpdateTask(ctx context.Context, task
}

// Skip update if task is marked as unmanaged
if existingTask.Annotations != nil && existingTask.Annotations["automotive.sdv.cloud.redhat.com/unmanaged"] == "true" {
if existingTask.Annotations != nil && existingTask.Annotations[unmanagedAnnotationKey] == unmanagedAnnotationTrue {
r.Log.Info("Skipping update for unmanaged task", "name", task.Name)
return nil
}
Expand All @@ -774,8 +802,7 @@ func (r *OperatorConfigReconciler) createOrUpdatePipeline(ctx context.Context, p
}

// Skip update if pipeline is marked as unmanaged
unmanagedAnnotation := "automotive.sdv.cloud.redhat.com/unmanaged"
if existingPipeline.Annotations != nil && existingPipeline.Annotations[unmanagedAnnotation] == "true" {
if existingPipeline.Annotations != nil && existingPipeline.Annotations[unmanagedAnnotationKey] == unmanagedAnnotationTrue {
r.Log.Info("Skipping update for unmanaged pipeline", "name", pipeline.Name)
return nil
}
Expand Down