Hi all, What is the best way to patch an existing ...
# kubernetes
w
Hi all, What is the best way to patch an existing deployment with pulumi? for example, I want to 'translate' the following
kubectl
command to python-pulumi:
coredns
:
Copy code
kubectl patch deployment coredns \
    -n kube-system \
    --type json \
    -p='[{"op": "remove", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1compute-type"}]'
thanks!
b
you can't do this at the moment. you'd need to import the coredns pod into your state, and manage it from there
w
@billowy-army-68599 thanks for the answer. As soon as I will import the coredns deployment into my code, how can I edit it and redeploy it?
b
once you've imported it into your state, you'd just update the code that has been imported too
w
thanks, will try!
@billowy-army-68599 I'm having some issues with the import. As i'm executing the following python command:
Copy code
core_dns_deployment = k8s.apps.v1.Deployment(
        resource_name=f'{cluster_name}-coredns-deployment',
        args=k8s.apps.v1.DeploymentInitArgs(
            metadata=k8s.meta.v1.ObjectMetaArgs(
                namespace='kube-system',
                name='coredns'
            ),
        ),
        opts=ResourceOptions(import_='deployment/coredns', provider=k8s_provider, depends_on=[k8s_provider])
    )
I'm getting:
Copy code
  ~/sentra/sentra-app/infra   pulumi-infra-as-code +8 !1 ?8 ❯ pulumi up                                                                                                              ✘ 255  12s  infra  19:46:11
Previewing update (sentraio/dev)

View Live: <https://app.pulumi.com/sentraio/infra/dev/previews/d6bfcb28-f350-4c09-95c2-c0111fb0ed63>

     Type                              Name                               Plan       Info
     pulumi:pulumi:Stack               infra-dev                                     1 error
 =   └─ kubernetes:apps/v1:Deployment  sentra-dev-eks-coredns-deployment  import     1 error

Diagnostics:
  pulumi:pulumi:Stack (infra-dev):
    error: preview failed

  kubernetes:apps/v1:Deployment (sentra-dev-eks-coredns-deployment):
    error: Preview failed: resource 'deployment/coredns' does not exist
how can i find this resource?
e
We're trying to do exactly the same thing. Did you ever get this working @witty-belgium-75866? Are you aware of any code examples @billowy-army-68599?
w
hi @boundless-traffic-88044 my workaround was to patch
coredns
deployment every time:
Copy code
def patch_coredns(args):
    kube_config = args[1]

    # Only do the imperative patching during deployments, not previews.
    if not pulumi.runtime.is_dry_run():
        <http://pulumi.log.info|pulumi.log.info>('patching the coredns deployment ..')
        patch = [{"op": "remove", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1compute-type"}]

        with tempfile.NamedTemporaryFile('w') as temp_file:
            temp_file.write(kube_config)
            temp_file.flush()

            args = [
                'kubectl',
                'patch', 'deployment', 'coredns', '-n', 'kube-system', '--type', 'json', '-p', json.dumps(patch)
            ]

            new_env = os.environ.copy()
            new_env['KUBECONFIG'] = temp_file.name
            subprocess.run(args, env=new_env)
Copy code
core_dns_patch = Output.all(fargate_profile.arn, kubeconfig).apply(patch_coredns)
e
Thanks for the workaround Amit - definitely seems less than optimal.
👍 1