Skip to content

Could I use apply in DynamicClient ? #2030

@hermitgreen

Description

@hermitgreen

What is the feature and why do you need it:

Can 'DynamicClient' support 'apply'?

Describe the solution you'd like to see:

While I try https://github.com/kubernetes-client/python/blob/master/examples/dynamic-client/service.py example,I replace .create to .apply and except this can create if not exist or patch(like kubectl apply), but I got

AttributeError: 'DynamicClient' object has no attribute 'apply

how could I use apply?

my code

from kubernetes import config, dynamic
from kubernetes.client import api_client


def main():
    client = dynamic.DynamicClient(
        api_client.ApiClient(configuration=config.load_kube_config())
    )
    api = client.resources.get(api_version="v1", kind="Service")
    name = "frontend-service"
    service_manifest = {
        "apiVersion": "v1",
        "kind": "Service",
        "metadata": {"labels": {"name": name}, "name": name, "resourceversion": "v1"},
        "spec": {
            "ports": [
                {"name": "port", "port": 80, "protocol": "TCP", "targetPort": 80}
            ],
            "selector": {"name": name},
        },
    }
    service = api.apply(body=service_manifest, namespace="default")


if __name__ == "__main__":
    main()

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions