Uh oh!
There was an error while loading. Please reload this page.
Add method to dynamically set namespace in yaml files - #782
Conversation
johscheuer
commented
Mar 18, 2019
I will add a test case for the new method. |
micw523
commented
Mar 19, 2019
I think this could be done easily outside of |
johscheuer
commented
Mar 19, 2019
@micw523 yes with the MR it's possible since you can pass complete objects to the method. I still think that the possibility to set the namespace dynamically adds value to the end user, it's easier to set the namespace directly while iterating over the objects in: https://github.com/kubernetes-client/python/pull/783/files#diff-561089da9975de9999b6638341c50914R75 Otherwise I need to read all objects by myself patch them with the desired namespace and then pass them to |
micw523
commented
Mar 20, 2019
I think without this function you still have to have a list of the yaml files you're going to load anyway and load one by one... I don't think patching it will be too much. On a side note, I don't think overriding namespace should be encouraged. I just checked the behavior of the typed client. If you attempt to override the namespace in the yaml file, you get this error: I think it's important that the |
johscheuer
commented
Mar 20, 2019
Currently one benefit would be that the You actually can overwrite the namespace you just need to modify the namespace of the loaded object see: https://github.com/kubernetes-client/python/pull/782/files#diff-561089da9975de9999b6638341c50914R67 but I think your concern is correct and we shouldn't overwrite the namespace of an API object (if defined). I still think that there is a good use case for
Without a If you like I would adjust my PR to match the behaviour of For the following manifest the behavior would be: apiVersion: apps/v1kind: Deploymentmetadata:
labels:
app: webname: webspec:
replicas: 1selector:
matchLabels:
app: webtemplate:
metadata:
labels:
app: webspec:
containers:
- image: nginxname: nginxIf there is no namespace defined in the yaml file I can pass $ kubectl -n test apply -f test.yaml deployment.apps/web created
$ kubectl -n test get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
web 1/1 1 1 6sIf I add a namespace to the yaml file I get the error message you mentioned above: apiVersion: apps/v1kind: Deploymentmetadata:
labels:
app: webname: webnamespace: test # defined a namespacespec:
replicas: 1selector:
matchLabels:
app: webtemplate:
metadata:
labels:
app: webspec:
containers:
- image: nginxname: nginxSee: kubectl -n default apply -f test.yaml error: the namespace from the provided object "test" does not match the namespace "default". You must pass '--namespace=test' to perform this operation.TLDR: My goal would it be to mimic the behavior of |
To be honest, we’re not getting into apply -f behavior. We’re doing create only. See discussion in #504 |
In another thought, if the yaml file didn’t set a namespace, providing an option for setting it should be fine and is consistent with the offering by the current client. I think we should be consistent with what the client does - instead of changing the namespace of the yaml file, we could pass the namespace as a parameter to subsequent calls of |
johscheuer
commented
Mar 20, 2019
That's actually the main use case I would like to support. I will start working on this at the end of the week. Thanks for your great feedback! |
micw523
commented
Mar 20, 2019
/assign |
4c846b0 to
06776ceComparejohscheuer
commented
Mar 25, 2019
@micw523 PTAL :) |
micw523
commented
Mar 26, 2019
In my opinion we do not need a second function for this. Why not add namespace as an optional parameter to the original function since our typed client already does this? |
johscheuer
commented
Mar 26, 2019
Actually I just didn't thought on using an optional parameter. Makes everything much easier/clearer. I adjusted the code. |
Uh oh!
There was an error while loading. Please reload this page.
micw523
commented
Mar 26, 2019
The CI is not working due to a new release of kubernetes. I'll retest the PR after our CI is back up again. |
johscheuer
commented
Apr 8, 2019
@micw523 I added some more docs to the |
johscheuer
commented
May 2, 2019
ping @micw523 |
micw523
commented
May 3, 2019
Hi @johscheuer, this lgtm to me and I already sent it to Roy to review. He might be a little too busy... |
micw523
commented
May 3, 2019
/lgtm |
roycaihw
commented
Jun 18, 2019
I'd expect the namespace field in yaml blobs to be generated, but this won't hurt /approve |
k8s-ci-robot
commented
Jun 18, 2019
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: johscheuer, roycaihw The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes: #781
This PR allows a user to set a custom namespace if creating API objects from a yaml file. This is useful if you generate your namespaces dynamically in the Python code (e.g. e2e tests).