Skip to content

🐛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

Merged

Conversation

fabriziopandini
Copy link
Member

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

@k8s-ci-robot
Copy link
Contributor

@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:

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

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.

@k8s-ci-robot k8s-ci-robot added the area/clusterctl Issues or PRs related to clusterctl label Feb 3, 2020
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 3, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 3, 2020
@vincepri vincepri changed the title 🐛clusterct: move ensure all the namespaces exists 🐛clusterctl: move ensure all the namespaces exists Feb 3, 2020
@ncdc ncdc added this to the v0.3.0 milestone Feb 3, 2020
@fabriziopandini fabriziopandini force-pushed the clusterctl-move-ensure-ns branch from 438a04c to b1e54a3 Compare February 3, 2020 16:20
@fabriziopandini
Copy link
Member Author

@vincepri comment addressed!

Comment on lines 265 to 281
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
}
}
}
Copy link
Member

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?

Copy link
Member Author

@fabriziopandini fabriziopandini Feb 3, 2020

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

@fabriziopandini fabriziopandini force-pushed the clusterctl-move-ensure-ns branch from b1e54a3 to ecb51bc Compare February 3, 2020 16:34
Comment on lines 266 to 280
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
}
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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

@fabriziopandini
Copy link
Member Author

@vincepri PTAL

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 3, 2020
@vincepri
Copy link
Member

vincepri commented Feb 3, 2020

Should we add tests in a follow up issue?

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 3, 2020
@vincepri
Copy link
Member

vincepri commented Feb 3, 2020

/test pull-cluster-api-test

@k8s-ci-robot k8s-ci-robot merged commit 5cfd0f1 into kubernetes-sigs:master Feb 3, 2020
@fabriziopandini fabriziopandini deleted the clusterctl-move-ensure-ns branch February 4, 2020 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants