-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Update prune's behaviour for namespaces #119687
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Mon Jul 31 10:15:47 UTC 2023. |
Welcome @Affan-7! |
Hi @Affan-7. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/auto-cc |
/cc pacoxu |
/ok-to-test |
/assign @KnVerey @brianpursley |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Affan-7 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-kubernetes-unit |
cf4e651
to
86cb193
Compare
Signed-off-by: Mohammed Affan <mohammed.affan.727@gmail.com>
86cb193
to
3c4a813
Compare
@@ -905,17 +905,14 @@ func TestApplyPruneObjectsWithAllowlist(t *testing.T) { | |||
"namespace/test-apply pruned", |
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 test case should be updated as well.
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 it should prune the non-namespaced items when a namespace and a allow list is not specified.
It's interesting that this test case is failing, but this test under the prune_test.go is passing.
{
mapper: &testRESTMapper{},
pr: []Resource{},
namespaceSpecified: false,
expectedns: 14,
expectednns: 2,
expectederr: 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.
It's interesting that this test case is failing, but this test under the prune_test.go is passing.
This case should pass.
- If the namespace is not specified, default 14 namespace resources and 2 none-namespaced resources will be pruned.
- If the namespace is specified, only the default 14 namespace resources will be pruned.
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 case should pass.
- If the namespace is not specified, default 14 namespace resources and 2 none-namespaced resources will be pruned.
- If the namespace is specified, only the default 14 namespace resources will be pruned.
Yes that's true, but this test under the apply_test.go is failing.
=== FAIL: vendor/k8s.io/kubectl/pkg/cmd/apply TestApplyPruneObjectsWithAllowlist/prune_without_namespace_and_allowlist_should_delete_resources_that_are_not_in_the_specified_file (0.03s)
apply_test.go:1040: expected output to contain "namespace/test-apply pruned", but it did not. Actual Output:
replicationcontroller/test-rc unchanged
configmap/test-cm pruned
replicationcontroller/test-rc2 pruned
It should have pruned the namesapce.
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, after investigation, I think we have made a mistake here.
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go
Lines 462 to 463 in 3c4a813
NamespaceParam(o.Namespace).DefaultNamespace(). | |
FilenameParam(o.EnforceNamespace, &o.DeleteOptions.FilenameOptions). |
- the namespace will default to
default
if not set.
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/apply/prune.go
Lines 74 to 75 in 3c4a813
namespacedRESTMappings, nonNamespacedRESTMappings, err := prune.GetRESTMappings(o.Mapper, o.PruneResources, o.Namespace != "") | |
if err != nil { |
namespaceSpecified o.Namespace != ""
will always be true.
The warning message will be there for everyone(no matter users specified namespace for the kubectl apply --prune
) if I understand correctly.
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.
/hold
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 wonder what should we do now?
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.
@pacoxu I was referring to the original issue and I ended up in this PR. where does the validation for the namespace will default to default if not set.
happens. I dont see it in DefaultNamespace() IIUC. Could you please provide the pointer to that
/priority important-soon |
740ef9e
to
71d9913
Compare
/remove-hold |
Is anything else needed for this PR? I took a look and it looks OK to me, but I'd like to see what @seans3 or @soltysh thinks about it since they are more familiar than I am with prune. It could cause a problem if someone relies on the old behavior, but it has gone through the deprecation period with a warning, so it should be ok(?). |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
I don't think that this PR is producing much impact, closing this. |
What type of PR is this?
/kind bug
/kind deprecation
What this PR does / why we need it:
This PR changes the behaviour of
--prune
flag ofkubectl apply
.Previously if you use
--prune
with a namespace flag like-n sandbox
it also prunes other non-namespaced items as described in #110905.After this PR, the
--prune
flag no longer prunes non-namespaced items if used with a namesapce falg like-n sandbox
.(It still prunes the non-namespaced items if namespace is not sepcifed )
Which issue(s) this PR fixes:
Fixes #110905
Does this PR introduce a user-facing change?