pulumi-eks icon indicating copy to clipboard operation
pulumi-eks copied to clipboard

eks namespace with provider in python not working, but eks namespace with provider in typescript works.

Open tusharshahrs opened this issue 3 years ago • 1 comments

Hello!

  • Vote on this issue by adding a 👍 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already)

Issue details

EKS with typescript and having a namespace works. EKS with python and having a namespace configured almost the exact same way, doesn't pass pulumi preview. The following error message is thrown in python:

raise ValueError(
    ValueError: Attempted to register resource kubernetes:core/v1:Namespace with a provider for '<pulumi.output.Output object at 0x10c216700>'

Steps to reproduce

  1. Validate the eks stack works in typescript
    git clone [email protected]:tusharshahrs/pulumi-home.git cd aws-classic-ts-eks
  2. pulumi about in typescript stack
 pulumi about
CLI          
Version      3.24.1
Go Version   go1.17.6
Go Compiler  gc

Plugins
NAME        VERSION
aws         4.37.2
eks         0.37.0
kubernetes  3.15.1
nodejs      unknown

Host     
OS       darwin
Version  11.6.3
Arch     x86_64
..
..
Backend  
Name     pulumi.com
URL      https://app.pulumi.com/myuser
User     myuser

NAME                VERSION
@pulumi/eks         0.37.0
@pulumi/kubernetes  3.15.1
@pulumi/pulumi      3.24.1
@types/node         14.18.10

This project is written in nodejs (/usr/local/bin/node v17.4.0)
  1. Stand up the stack in typescript pulumi stack init dev npm install pulumi config set aws:region us-east-2 pulumi up -y Wait ~12 minutes and the namespace will get created. The output will show it
  2. Everything works in typescript.
  3. Try to stand up the eks stack in python git clone [email protected]:tusharshahrs/pulumi-home.git cd aws-classic-py-eks
  4. pulumi about in python stack
CLI          
Version      3.24.1
Go Version   go1.17.6
Go Compiler  gc

Plugins
NAME        VERSION
aws         4.37.2
eks         0.37.0
kubernetes  3.15.2
python      unknown

Host     
OS       darwin
Version  11.6.3
Arch     x86_64

This project is written in python (/usr/local/bin/python3 v3.9.10)

Current Stack: dev
Backend  
Name     pulumi.com
URL      https://app.pulumi.com/myuser
User     myuser

NAME        VERSION
pip         22.0.3
pulumi-eks  0.37.0
setuptools  60.8.2
wheel       0.37.1
  1. Stand up the stack in python pulumi stack init dev python3 -m venv venv source venv/bin/activate pip3 install -r requirements.txt pulumi config set aws:region us-east-2
  2. Uncomment aws_ns_broken
  3. Run pulumi up and the preview will fail with:
    raise ValueError(
       ValueError: Attempted to register resource kubernetes:core/v1:Namespace with a provider for '<pulumi.output.Output object at 
    0x10c216700>'
    
  4. We have a workaround, meaning we can comment OUT the last line.
  5. Question. Should a user expect the python code for namespace to work similar as typescript or this expected behavior in python?

Expected: Eks with namespace in python works the same as eks with namespace in typescript.

Actual: Python throws this error on preview:

    raise ValueError(
       ValueError: Attempted to register resource kubernetes:core/v1:Namespace with a provider for '<pulumi.output.Output object at 
    0x10c216700>'

tusharshahrs avatar Feb 10 '22 15:02 tusharshahrs

The main problem is that the ResourceOptions' provider arg doesn't yet accept Output[ProviderResource], which is tracked by https://github.com/pulumi/pulumi/issues/7012.

In the meantime, this can be worked around by creating a new instance of the pulumi_kubernetes.Provider using the Cluster's kubeconfig output:

import json

from pulumi import ResourceOptions
from pulumi_eks import Cluster
from pulumi_kubernetes import Provider
from pulumi_kubernetes.core.v1 import Namespace

cluster = Cluster("test")

provider = Provider("eks-k8s", kubeconfig=cluster.kubeconfig.apply(lambda k: json.dumps(k)))

namespace = Namespace("test", opts=ResourceOptions(provider=provider))

Since the Cluster.provider output isn't really usable currently given https://github.com/pulumi/pulumi/issues/7012, we're considering removing it: https://github.com/pulumi/pulumi-eks/issues/602.

justinvp avatar Feb 23 '22 00:02 justinvp

Linking to this ticket or stating the workaround in the docs for the Cluster.provider attribute (and ideally the Namespace too) would be a great help, as long as this issue remains.

markfickett avatar Oct 24 '22 15:10 markfickett

The provider output property was removed in https://github.com/pulumi/pulumi-eks/pull/746

Closing this issue as complete but have created a new issue to capture adding a helpful example to the docs: https://github.com/pulumi/pulumi-eks/issues/812

danielrbradley avatar Nov 15 '22 10:11 danielrbradley