with an azure-native ManagedCluster and pulumi_kub...
# kubernetes
h
with an azure-native ManagedCluster and pulumi_kubernetes, how do I: 1. create a namespace conditionally (check if it exists, create if if doesn't) 2. create a secret scoped to the namespace
I came up with the following - it seems to work with
pulumi up
, but no namespace or secret is reported as present by kubectl or azure portal:
Copy code
for name in NAMESPACE_KEYS:
    NAMESPACES[name] = k8s.core.v1.Namespace(
            resource_name=f'namespace-{name}',
            opts=p.ResourceOptions(
                    depends_on=[
                        aks,
                    ],
                    parent=aks,
            ),
    )
...
Copy code
for name, namespace in NAMESPACES.items():
    namespace_name = namespace.metadata.name
    k8s.core.v1.Secret(
            resource_name=f'storageSecret-{name}',
            metadata=k8s.meta.v1.ObjectMetaArgs(
                    name=f'azure-secret-{name}',
                    namespace=namespace_name,
            ),
            type='Opaque',
            string_data={
                'azurestorageaccountname': storage_account.name,
                'azurestorageaccountkey': storage_account_key,
            },
            opts=p.ResourceOptions(
                    parent=namespace,
            ),
    )