-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Add applyset-namespace flag to kubectl apply #132527
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
base: master
Are you sure you want to change the base?
Conversation
Welcome @scaliby! |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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-sigs/prow repository. |
Hi @scaliby. 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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: scaliby 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 |
@@ -2315,7 +2315,7 @@ func TestApplySetParentValidation(t *testing.T) { | |||
"other namespaced builtin parents types are correctly parsed but invalid": { | |||
applysetFlag: "deployments.apps/thename", | |||
expectParentKind: "Deployment", | |||
expectErr: "[namespace is required to use namespace-scoped ApplySet, resource \"apps/v1, Resource=deployments\" is not permitted as an ApplySet parent]", | |||
expectErr: "[namespace is required to use namespace-scoped ApplySet. You can provide it either using --applyset-namespace or --namespace parameter, resource \"apps/v1, Resource=deployments\" is not permitted as an ApplySet parent]", |
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 propose adding a test case here to this list for passing applysetNamespace
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.
Done :)
tf.FakeDynamicClient = fakeDynamicClient | ||
tf.UnstructuredClient = &fake.RESTClient{ | ||
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, | ||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { |
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.
Maybe it's time to refactor our test clients - though I suggest not in this PR.
This assumes that we can't merge with TestApplyWithPruneV2; though I would say the fact that I can't easily tell whether they are the same is itself a good argument for refactoring a common test client!
cc @soltysh as I think you were not convinced in the past.
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 agree, refactoring is needed here. Probably a mock HTTP client that acts like a real server would be the best choice.
Merging with TestApplyWithPruneV2
wouldn't test what I want to test. I want to check if parent configuration was created successfully and in the correct namespace. This is not being done in that test.
Also, this test has no support for creation of resources other than the Namespace
resource, and I need to create other, scoped resource (ConfigMap
in my case).
@@ -2874,6 +2874,229 @@ metadata: | |||
`, string(updatedCRYaml)) | |||
} | |||
|
|||
func TestApplyWithPruneV2ApplySetNamespace(t *testing.T) { |
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.
Could we add this to TestApplyWithPruneV2 ? It's hard to tell how similar it is / is not :-)
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.
The behavior I want to test here is slightly different compared to TestApplyWithPruneV2
. As described in the comment above, it would be hard to merge that and preserve the behavior I want to get tested.
Quibbles about the test code, this lgtm. For context, @scaliby found that applyset does not always work with namespace-scoped parent objects when applying a multi-namespace manifest. We can't pass |
…e applyset-namespace flag
/ok-to-test |
/retest |
@scaliby: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
/test pull-kubernetes-unit |
Changelog suggestion -Added applyset-namespace flag to kubectl apply.
+Added `--applyset-namespace` command line argument to `kubectl apply`. (Outside of the Go ecosystem, flag means a boolean typed command line parameter) |
What type of PR is this?
/kind feature
What this PR does / why we need it:
With current implementation of ApplySet it is impossible to apply a multi-namespace configuration. This is because we are forcing user to pass
--namespace
parameter to the command that is used for determining in which namespace ApplySet parent configuration is supposed to be stored.Unfortunatelly, supplying this parameter, enforces that all resources in the config to be in the same namespace.
Before the change:
$ cat config.yaml apiVersion: v1 kind: ConfigMap metadata: labels: foo: bar name: a namespace: default --- apiVersion: v1 kind: ConfigMap metadata: labels: foo: bar name: b namespace: test $ kubectl apply -f config.yaml --applyset=testset --all --prune error: namespace is required to use namespace-scoped ApplySet
With the newly introduced parameter, we are able to explicitly specify where, the parent configuration is supposed to live, removing the need for
--namespace=testset
and allowing user to create configuration that spans across multiple namespaces.After the change:
Which issue(s) this PR is related to:
The issue indirectly solves problem described in #106284 and #555. The deviation is that we are adding support for the mentioned use case to the ApplySet instead of fixing the old prune command.
Does this PR introduce a user-facing change?
Yes, we are adding optional
kubectl apply
parameter. When the parameter is not supplied, the old behavior is preserved.Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
kubectl apply -f file.yaml --prune --all --applyset=testapplyset --applyset-namespace=parent-config-ns