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

Don't set ownerReference on cluster-scoped and cross-namespace objects #196

Merged
merged 1 commit into from
Jun 28, 2023
Merged
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
8 changes: 4 additions & 4 deletions controllers/keda/kedacontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func sortMetricsResources(resources *[]unstructured.Unstructured) []unstructured

func (r *KedaControllerReconciler) installSA(logger logr.Logger, instance *kedav1alpha1.KedaController) error {
logger.Info("Reconciling KEDA ServiceAccount")
transforms := []mf.Transformer{mf.InjectOwner(instance)}
transforms := []mf.Transformer{transform.InjectOwner(instance)}

if len(instance.Spec.ServiceAccount.Annotations) > 0 {
transforms = append(transforms, transform.AddServiceAccountAnnotations(instance.Spec.ServiceAccount.Annotations, r.Scheme))
Expand Down Expand Up @@ -352,7 +352,7 @@ func (r *KedaControllerReconciler) installSA(logger logr.Logger, instance *kedav
func (r *KedaControllerReconciler) installController(ctx context.Context, logger logr.Logger, instance *kedav1alpha1.KedaController) error {
logger.Info("Reconciling KEDA Controller deployment")
transforms := []mf.Transformer{
mf.InjectOwner(instance),
transform.InjectOwner(instance),
transform.ReplaceWatchNamespace(instance.Spec.WatchNamespace, "keda-operator", r.Scheme, logger),
}

Expand Down Expand Up @@ -465,7 +465,7 @@ func (r *KedaControllerReconciler) installMetricsServer(ctx context.Context, log
logger.Info("Reconciling KEDA Metrics Server Deployment")

transforms := []mf.Transformer{
mf.InjectOwner(instance),
transform.InjectOwner(instance),
}

// Use alternate image spec if env var set
Expand Down Expand Up @@ -740,7 +740,7 @@ func (r *KedaControllerReconciler) ensureMetricsServerAuditLogPolicyConfigMap(ct
func (r *KedaControllerReconciler) installAdmissionWebhooks(ctx context.Context, logger logr.Logger, instance *kedav1alpha1.KedaController) error {
logger.Info("Reconciling KEDA Admission Webhooks deployment")
transforms := []mf.Transformer{
mf.InjectOwner(instance),
transform.InjectOwner(instance),
transform.ReplaceWatchNamespace(instance.Spec.WatchNamespace, "keda-admission-webhooks", r.Scheme, logger),
}

Expand Down
14 changes: 14 additions & 0 deletions controllers/keda/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,3 +1096,17 @@ func EnsureAuditLogMount(pvc string, path string, scheme *runtime.Scheme) mf.Tra
return nil
}
}

// InjectOwner creates a Transformer which adds an OwnerReference
// pointing to `owner`, but only if the object is in the same namespace as `owner`
func InjectOwner(owner mf.Owner) mf.Transformer {
f := mf.InjectOwner(owner) // This is just a wrapper around manifestival.InjectOwner
return func(u *unstructured.Unstructured) error {
// Since the controller is namespaced, it can only have namespace-scoped dependants in the same namespace
// https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/
if u.GetNamespace() == owner.GetNamespace() {
return f(u)
}
return nil
}
}