Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster.get_kubeconfig() doesn't work with pulumi preview when gcp project is created programmatically and project_id is generated #950

Open
jancespivo opened this issue Dec 22, 2023 · 3 comments
Labels
impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec

Comments

@jancespivo
Copy link

What happened?

cluster.get_kubeconfig() doesn't work with pulumi preview when gcp project is created programmatically and project_id is generated via pulumi_random

pulumi up --skip-preview works fine.

When project_id is set manually, it works fine.

Example

import pulumi
import pulumi_gcp as gcp
import pulumi_google_native as google_native
import pulumi_google_native.container.v1 as container
import pulumi_kubernetes as kubernetes
import pulumi_random as random

random_string = random.RandomString(
    "project-id-suffix",
    length=6,
    special=False,
    lower=True,
    upper=False,
    number=False,
).result

config = pulumi.Config()

gcp_project = gcp.organizations.Project(
    "cluster",
    name="minimal",
    project_id=pulumi.Output.concat("minimal-", random_string),
    billing_account=config.require("gcp_billing_account_id"),
)

gcp_provider = gcp.Provider(
    "gcp-provider",
    project=gcp_project.project_id,
)

google_native_provider = google_native.Provider(
    "google-native-provider",
    project=gcp_project.project_id,
)

compute_service = gcp.projects.Service(
    "compute.googleapis.com",
    service="compute.googleapis.com",
    opts=pulumi.ResourceOptions(
        providers={
            "gcp": gcp_provider,
        },
    ),
)

container_service = gcp.projects.Service(
    "container.googleapis.com",
    service="container.googleapis.com",
    opts=pulumi.ResourceOptions(
        depends_on=[compute_service],
        providers={
            "gcp": gcp_provider,
        },
    )
)

cluster = container.Cluster(
    "cluster",
    node_pools=[
        container.NodePoolArgs(
            name="default",
            initial_node_count=1,
            config=container.NodeConfigArgs(
                machine_type="e2-custom-4-8192",
                disk_type='pd-balanced',
            ),
            locations=[
                "europe-west1-b",
            ]
        )
    ],
    initial_cluster_version="1.25",
    location="europe-west1-b",
    opts=pulumi.ResourceOptions(
        depends_on=[container_service],
        providers={
            "google-native": google_native_provider,
        },
    )
)

k8s_provider = kubernetes.Provider(
    "k8s_provider",
    kubeconfig=cluster.get_kubeconfig(),
)

pulumi preview or pulumi up raises

error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "/home/beer/.pulumi/bin/pulumi-language-python-exec", line 197, in <module>
        loop.run_until_complete(coro)
      File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
        return future.result()
               ^^^^^^^^^^^^^^^
      File "/home/beer/projects/tacr/platform/cluster-deploy/.venv/lib/python3.11/site-packages/pulumi/runtime/stack.py", line 137, in run_in_stack
        await run_pulumi_func(lambda: Stack(func))
      File "/home/beer/projects/tacr/platform/cluster-deploy/.venv/lib/python3.11/site-packages/pulumi/runtime/stack.py", line 51, in run_pulumi_func
        await wait_for_rpcs()
      File "/home/beer/projects/tacr/platform/cluster-deploy/.venv/lib/python3.11/site-packages/pulumi/runtime/stack.py", line 121, in wait_for_rpcs
        raise exception
      File "/home/beer/projects/tacr/platform/cluster-deploy/.venv/lib/python3.11/site-packages/pulumi/output.py", line 200, in run
        transformed: Input[U] = func(value)
                                ^^^^^^^^^^^
      File "/home/beer/projects/tacr/platform/cluster-deploy/.venv/lib/python3.11/site-packages/pulumi/output.py", line 250, in lift
        return UNKNOWN if isinstance(v, Unknown) else getattr(v, item)
                                                      ^^^^^^^^^^^^^^^^
    AttributeError: 'NoneType' object has no attribute 'kubeconfig'

pulumi up --skip-preview works fine as expected.

Output of pulumi about

CLI          
Version      3.99.0
Go Version   go1.21.5
Go Compiler  gc

Plugins
NAME           VERSION
gcp            7.4.0
google-native  0.32.0
kubernetes     4.6.1
python         unknown
random         4.15.0

Host     
OS       arch
Version  "23.1.0"
Arch     x86_64

This project is written in python: executable='<REDACTED>/.venv/bin/python3' version='3.11.6'

Backend        
Name         <REDACTED>
URL           <REDACTED>
User           <REDACTED>
Organizations  
Token type     personal

Dependencies:
NAME                  VERSION
pulumi-gcp            7.4.0
pulumi-google-native  0.32.0
pulumi-kubernetes     4.6.1
pulumi-random         4.15.0

Additional context

No response

Contributing

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).

@jancespivo jancespivo added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Dec 22, 2023
@mjeffryes
Copy link
Contributor

Thanks for the bug report @jancespivo. Based on the exception, it looks like the container.Cluster constructor isn't returning anything in the failing case.

I notice that you're using a gcp provider that you configure explicitly with the project id, but, although you create a similar google-native provider with the project name, you call containter.Cluster directly without using the google-native provider you configured. I wonder if that's causing the cluster creation to fail?

@mjeffryes mjeffryes added awaiting-feedback and removed needs-triage Needs attention from the triage team labels Jan 3, 2024
@jancespivo
Copy link
Author

@mjeffryes
There is google-native provider configured:

providers={
     "google-native": google_native_provider,
},

The code I pasted can create Cluster successfully. The only problem is pulumi preview doesn't work.
So pulumi up --skip-preview works, pulumi up doesn't. It fails during preview step.

@mikhailshilkov mikhailshilkov added needs-triage Needs attention from the triage team and removed awaiting-feedback labels May 8, 2024
@mjeffryes
Copy link
Contributor

I apologize, I did miss the provider configuration in the container.Cluster config. The core issue still remains that during preview, the container.Cluster call should return an UNKNOWN, rather than None.

@mjeffryes mjeffryes added impact/panic This bug represents a panic or unexpected crash and removed needs-triage Needs attention from the triage team labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

3 participants