https://pulumi.com logo
s

silly-match-22314

07/20/2023, 1:28 PM
Hi All! For some reason there is a python automation api code that is not working for me.
Copy code
class PulumiProgram:
    def __init__(self):
        self._work_dir = os.path.join(os.path.dirname(__file__))
        self._data = self._load_config_file('defaults.yaml')
        self._stack = auto.create_or_select_stack('dev', project_name='test-eks', work_dir=self._work_dir,
                                                  program=self._create_resources())
        self._stack.set_config('aws:region', auto.ConfigValue('us-east-1'))
        self._stack.set_config('values', auto.ConfigValue(json.dumps(self._data.get('values'))))

    def preview(self):
        self._stack.refresh(on_output=print)
        self._stack.preview(on_output=print)

    def up(self):
        self._stack.refresh(on_output=print)
        self._stack.up(on_output=print)

    def _load_config_file(self, path: str):
        with open(path, "r") as f:
            data = yaml.full_load(f)
            return data

    def _create_resources(self):
        chart_values = self._data.get('values')
        kube = open("/Users/nathanell/.kube/lab-okta-playground-eks").read()
        k8s_provider = k8s.Provider(resource_name="k8s-provider", kubeconfig=pulumi.Output.secret(kube))
        ui_app_chart = Release(
            "ui-app-micro-fe",
            ReleaseArgs(
                name='nginx-test-nati',
                chart="../helm",
                values=chart_values,
                namespace=f'{chart_values.get("project")}-{chart_values.get("app")}',
                create_namespace=True,
                version='1.0.0'
            ),
            opts=ResourceOptions(provider=k8s_provider)
        )

if __name__ == "__main__":
    PulumiProgram().up()
While the same code is working for me while using Pulumi CLI program:
Copy code
config = pulumi.Config()
 chart_values = json.loads(config.get('values'))
 kube = open("/Users/nathanell/.kube/lab-okta-playground-eks").read()
 provider = k8s.Provider(resource_name="k8s-provider", kubeconfig=pulumi.Output.secret(kube))
 print(chart_values)
 nginx_chart = Release(
     "nginx-ingress",
     ReleaseArgs(
         name='nginx-test-nati',
         chart="../helm",
         values=chart_values,
         namespace=f'{chart_values.get("project")}-{chart_values.get("app")}',
         create_namespace=True,
         version='1.0.0'
     ),
     opts=ResourceOptions(provider=provider)
 )
This is the error that I'm getting:
Copy code
kubernetes:core/v1:Namespace (ui-app-nginx):
    error: configured Kubernetes cluster is unreachable: unable to load schema information from the API server: the server has asked for the client to provide credentials
Although I have verified that the kubeconfig is ok and working in the pulumi CLI program Someone can assist?
e

echoing-dinner-19531

07/21/2023, 3:15 PM
self._create_resources()
I think that should be
self._create_resources
, you want a reference to the function there, not to call it.
s

silly-match-22314

07/22/2023, 8:04 PM
@echoing-dinner-19531 I will try that and update.. thanks
@echoing-dinner-19531 getting the same error.. 😞
e

echoing-dinner-19531

07/23/2023, 10:54 AM
Are you getting any other output? Only thing I can think is maybe that namespace isn't being set correctly in the automation program vs reading from config in the CLI program
s

silly-match-22314

07/23/2023, 10:55 AM
@echoing-dinner-19531 I have found the issue, There were some problematic env variables while running the pulumi API program from the pycharm. So, I have removed them and now its working. BTW, do you know how to get a kubeconfig content from pulumi w/o creating an actual file?
e

echoing-dinner-19531

07/23/2023, 11:50 AM
BTW, do you know how to get a kubeconfig content from pulumi w/o creating an actual file?
As in from aws clusters and the like? Or creating them in code? The former I'm pretty sure things like eks cluster resources have a kubeconfig property on them. The later, there's nothing built-in really but it's just building up a json file which should be pretty simple in most languages.
s

silly-match-22314

07/30/2023, 2:55 PM
@echoing-dinner-19531 I have managed it using dynamic kubeconfig creation.
2 Views