-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🐛clusterctl: move ensure all the namespaces exists #2245
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
🐛clusterctl: move ensure all the namespaces exists #2245
Conversation
@fabriziopandini: You must be a member of the kubernetes-sigs/cluster-api-maintainers GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your Cluster API Maintainers and have them propose you as an additional delegate for this responsibility. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
438a04c
to
b1e54a3
Compare
@vincepri comment addressed! |
if apierrors.IsForbidden(err) { | ||
namespaces := &corev1.NamespaceList{} | ||
if err := cs.List(ctx, namespaces); err != nil { | ||
return err | ||
} | ||
|
||
for _, ns := range namespaces.Items { | ||
if ns.Name == namespace { | ||
return nil | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular use case that we're dealing with here? I'm wondering why this fallback to list is necessary.
Also shouldn't we check the Continue
ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making the code tolerant to use cases where the user is allowed to list namespaces but not to get namespaces (copied from the old clusterctl, and it makes sense IMO)
Also shouldn't we check the Continue ID?
Fixed, sorry for this leftover
b1e54a3
to
ecb51bc
Compare
namespaces := &corev1.NamespaceList{} | ||
if err := cs.List(ctx, namespaces); err != nil { | ||
return err | ||
} | ||
|
||
namespaceExists := false | ||
for _, ns := range namespaces.Items { | ||
if ns.Name == namespace { | ||
namespaceExists = true | ||
break | ||
} | ||
} | ||
if namespaceExists { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was to check NamespaceList
Continue flag and use client.Continue
in the List call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, now I got it
@vincepri PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/lgtm
Should we add tests in a follow up issue? |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini, vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-cluster-api-test |
What this PR does / why we need it:
This PR ensures all the required namespaces are in place before starting the move process
Which issue(s) this PR fixes
rif #1729
/area clusterctl
/milestone v0.3.0
/assign @ncdc
/assign @vincepri