https://pulumi.com logo
Title
w

witty-belgium-75866

10/27/2021, 9:34 AM
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
:
kubectl patch deployment coredns \
    -n kube-system \
    --type json \
    -p='[{"op": "remove", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1compute-type"}]'
thanks!
b

billowy-army-68599

10/27/2021, 4:06 PM
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

witty-belgium-75866

10/27/2021, 4:22 PM
@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

billowy-army-68599

10/27/2021, 4:25 PM
once you've imported it into your state, you'd just update the code that has been imported too
w

witty-belgium-75866

10/27/2021, 4:28 PM
thanks, will try!
@billowy-army-68599 I'm having some issues with the import. As i'm executing the following python command:
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:
  ~/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

enough-leather-70274

11/18/2021, 8:04 AM
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

witty-belgium-75866

11/18/2021, 8:29 AM
hi @boundless-traffic-88044 my workaround was to patch
coredns
deployment every time:
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)
core_dns_patch = Output.all(fargate_profile.arn, kubeconfig).apply(patch_coredns)
e

enough-leather-70274

11/19/2021, 3:12 AM
Thanks for the workaround Amit - definitely seems less than optimal.
👍 1