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

Support creation of non namespaced objects in createk8scr #86

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
13 changes: 10 additions & 3 deletions internal/controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ func CreateK8sCR(ctx context.Context, c client.Client,
// Get the name and namespace of the object:
key := client.ObjectKeyFromObject(newObject)
oranUtilsLog.Info("[CreateK8sCR] Resource", "name", key.Name)
// Set owner reference.
if err = controllerutil.SetControllerReference(ownerObject, newObject, runtimeScheme); err != nil {
return err

// We can set the owner reference only for objects that live in the same namespace, as cross
// namespace owners are forbidden. This also applies to non-namespaced objects like cluster
// roles or cluster role bindings; those have empty namespaces so the equals comparison
// should also work.
if ownerObject.GetNamespace() == key.Namespace {
err = controllerutil.SetControllerReference(ownerObject, newObject, runtimeScheme)
if err != nil {
return err
}
}

// Check if the CR already exists.
Expand Down
Loading