Skip to content
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

patch_namespaced_secret does not delete keys when passing them via string_data #2262

Open
mpw96 opened this issue Aug 12, 2024 · 2 comments
Open
Assignees
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@mpw96
Copy link

mpw96 commented Aug 12, 2024

What happened (please include outputs or screenshots):
I want to remove a key from a secret. So I'm creating the patch data with a None value for this key. This key is not deleted (secret is unchanged).

What you expected to happen:
The key is deleted.

How to reproduce it (as minimally and precisely as possible):
Create a secret my-secret in some namespace mpw. It should contain a key test with some value.
Then run this program:

import kubernetes
import yaml

with open("my-kubeconfig.yaml", encoding="utf-8") as k_config_file:
    k_config = yaml.safe_load(k_config_file) 

k8s_api_client = kubernetes.config.new_client_from_config_dict(k_config)
core_v1_api = kubernetes.client.CoreV1Api(k8s_api_client)

secret_data = {
    "test": None,
}

core_v1_api.patch_namespaced_secret("my-secret", "mpw", kubernetes.client.V1Secret(string_data=secret_data))

Anything else we need to know?:
Note that I'm passing the secret_data to the parameter string_data. When I passing it to data, the key is deleted as expected.

Environment:

  • Kubernetes version (kubectl version): Server Version: v1.29.3
  • OS (e.g., MacOS 10.13.6): MacOS 14.6.1
  • Python version (python --version): Python 3.11.9
  • Python client version (pip list | grep kubernetes): kubernetes 30.1.0
@mpw96 mpw96 added the kind/bug Categorizes issue or PR as related to a bug. label Aug 12, 2024
@roycaihw
Copy link
Member

/assign

We should have some example on patch types (JSON, JSONMERGE, STRATEGIC). Let me find some examples

@roycaihw roycaihw added kind/support Categorizes issue or PR as a support question. and removed kind/bug Categorizes issue or PR as related to a bug. labels Aug 14, 2024
@mpw96
Copy link
Author

mpw96 commented Aug 15, 2024

@roycaihw thank you for responding. Please note that I think I understand how to remove a key from a secret by patching it.

In my code example above, let's look at the last line. This deletes the key test as expected:

core_v1_api.patch_namespaced_secret("my-secret", "mpw", kubernetes.client.V1Secret(data=secret_data))
                                                                                   ^^^^

Where this does not delete it, but I would expect it to be deleted:

core_v1_api.patch_namespaced_secret("my-secret", "mpw", kubernetes.client.V1Secret(string_data=secret_data))
                                                                                   ^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

2 participants