-
Notifications
You must be signed in to change notification settings - Fork 99
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
kctrl
: Flag to create namespace when adding new repo
#1113
Conversation
kctrl
: Flag to create namespace when adding new repo
81666e6
to
e154ab6
Compare
|
||
_, err = coreClient.CoreV1().Namespaces().Create(context.Background(), namespace, metav1.CreateOptions{}) | ||
if err != nil { | ||
o.ui.PrintLinef("The namespace %s already exists", o.NamespaceFlags.Name) |
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.
We should probably return the error if it's not of type IsAlreadyExists and ignore if it already exists.
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.
Good point! I changed it as suggested.
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.
Some thoughts!
In addition to these looks like there is a redundant log line being printed on line 187
(More specifically: o.ui.PrintLinef("Waiting for package repository to be added")
)
That can be removed as a part of this PR but does not block the PR itself!
if errors.IsAlreadyExists(err) { | ||
o.statusUI.PrintMessagef("The namespace '%s' already exists", o.NamespaceFlags.Name) | ||
} else { | ||
return err | ||
} |
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.
if errors.IsAlreadyExists(err) { | |
o.statusUI.PrintMessagef("The namespace '%s' already exists", o.NamespaceFlags.Name) | |
} else { | |
return err | |
} | |
if !errors.IsAlreadyExists(err) { | |
return err | |
} | |
o.statusUI.PrintMessagef("The namespace '%s' already exists", o.NamespaceFlags.Name) |
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.
I have refactored that part to print only a message if the namespace is created as suggested in the previous comment.
1d79ada
to
0be3e96
Compare
@@ -141,6 +145,30 @@ func (o *AddOrUpdateOptions) Run(args []string) error { | |||
return err | |||
} | |||
|
|||
if o.CreateNamespace { | |||
o.statusUI.PrintMessagef("Creating namespace '%s'", o.NamespaceFlags.Name) |
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.
Should we remove this line as well? Or you already did and forgot to push the change?
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.
I think I am good with the changes, once this is resolved ^
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.
Thanks for catching this. You'd think after several commits I'd learn the lesson about signing off commits, but I keep missing that and had to rebase (my Git is configured with the -S
parameter for signing, but the DCA sign-off is with -s
). I guess while doing that, this message popped up again.
When adding a new package repository to a cluster, it's now possible to create the installation namespace automatically by specifying the "--create-namespace" flag. Fixes gh-1001 Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
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.
Changes look good to me! Thank you so much for contributing
@praveenrewar feel free to merge this away if it looks good to you 🚀
logger.Section("creating a repository in a namespace that already exists", func() { | ||
kubectl.Run([]string{"create", "namespace", existingRepoNamespace}) |
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.
We could probably just use env.Namespace instead of this. It would remove the overhead of creating/deleting one namespace.
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.
Sorry didn't take a look at the tests earlier 😅
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.
I considered doing that, but then opted for creating it explicitly to make the test case resemble the current 2-steps way of adding a repo as opposed to the changes I made in the PR (1. create the namespace, 2. add a repo). But I can change it to use the general one, if you want :)
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.
Updated the tests here to re-use env.Namespace: 893f9e7
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
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.
LGTM! Thank you so much for the contribution 🚀
@100mik @praveenrewar thanks a lot for your guidance and review |
What this PR does / why we need it:
When adding a new package repository to a cluster, it's now possible to create the installation namespace automatically by specifying the "--create-namespace" flag.
Which issue(s) this PR fixes:
Fixes gh-1001
Does this PR introduce a user-facing change?
Additional Notes for your reviewer:
After a first review of this pull request to validate the behaviour of the new flag, I will submit a PR to update the documentation on the project website.
Review Checklist:
a link to that PR
change
Additional documentation e.g., Proposal, usage docs, etc.: