Thread
#general
    m

    most-mouse-38002

    3 months ago
    I want to access my KUBE_CONFIG while running (AKS created before this method is called). Will this achieve what I want? I need to make sure the env variable is set before I get to the next step where the Kubernetes provider is attempting to talk to the cluster. (Code in comment to avoid spamming).
    func SetEnvKubeConfig(ctx *pulumi.Context, config *configuration.Configuration, cluster *containerservice.ManagedCluster) error {
    	credentials := containerservice.ListManagedClusterAdminCredentialsOutput(ctx, containerservice.ListManagedClusterAdminCredentialsOutputArgs{
    		ResourceGroupName: config.ResourceGroup.Name,
    		ResourceName:      cluster.Name,
    	})
    
    	kubeConfig := credentials.Kubeconfigs().Index(<http://pulumi.Int|pulumi.Int>(0)).Value().ApplyT(func(encode string) string {
    		kubeConfig, err := base64.StdEncoding.DecodeString(encode)
    		if err != nil {
    			return ""
    		}
    		return string(kubeConfig)
    	})
    
    	ctx.Export("KUBE_CONFIG", kubeConfig)
    	
    	outputKubeConfig, exists := ctx.GetConfig("KUBE_CONFIG")
    	if !exists {
    		return errors.New("unknown context key KUBE_CONFIG")
    	}
    	
    	_ = os.Setenv("KUBE_CONFIG", outputKubeConfig)
    
    	return nil
    }
    b

    billowy-army-68599

    3 months ago
    is there a reason it needs to be an env var?
    m

    most-mouse-38002

    3 months ago
    b

    billowy-army-68599

    3 months ago
    are you just trying to set up a kubernetes provider to install things in a clister you've created with Pulumi?
    m

    most-mouse-38002

    3 months ago
    Correct
    b

    billowy-army-68599

    3 months ago
    you don't need to export the kubeconfig variable in that case, use a Kubernetes provider:https://www.pulumi.com/registry/packages/kubernetes/api-docs/provider/
    you can pass that to each resource you create in your cluster and it'll always be installed in the right place
    you can use your
    ctx.Export
    to access it from
    kubectl
    etc but this is the recommended way
    m

    most-mouse-38002

    3 months ago
    Okay, that makes much more sense πŸ‘
    b

    billowy-army-68599

    3 months ago
    m

    most-mouse-38002

    3 months ago
    Oh, I was going to try this, but I will look at your example
    func GetKubeConfig(ctx *pulumi.Context, config *configuration.Configuration, cluster *containerservice.ManagedCluster) *pulumi.StringOutput {
    	credentials := containerservice.ListManagedClusterAdminCredentialsOutput(ctx, containerservice.ListManagedClusterAdminCredentialsOutputArgs{
    		ResourceGroupName: config.ResourceGroup.Name,
    		ResourceName:      cluster.Name,
    	})
    
    	kubeConfig := credentials.Kubeconfigs().Index(<http://pulumi.Int|pulumi.Int>(0)).Value().ApplyT(func(encode string) string {
    		kubeConfig, err := base64.StdEncoding.DecodeString(encode)
    		if err != nil {
    			return ""
    		}
    		return string(kubeConfig)
    	}).(pulumi.StringOutput)
    
    	return &kubeConfig
    }
    Awesome, thanks. Now I understand providers fully as input params to functions as well! πŸ˜„
    b

    billowy-army-68599

    3 months ago
    yay! what's awesome about providers is they're at the resource level
    m

    most-mouse-38002

    3 months ago
    from where I sit it seems like pure magic πŸ˜‚
    b

    billowy-army-68599

    3 months ago
    glad you're enjoying it πŸ˜„
    m

    most-mouse-38002

    3 months ago
    i really like it. so much i created the bridge for the flux terraform provider today, and it seems to be working as well. we will probably be going all in on pulumi for our IaC past summer πŸ‘
    b

    billowy-army-68599

    3 months ago
    that's great to hear! We'd love to get the flux provider into the registry?
    m

    most-mouse-38002

    3 months ago
    Right, I would like that as well, but I need to understand more of the underlying model of Pulumi, write tests, do chores and stuff before I think that’s an option? https://github.com/scav/pulumi-flux
    b

    billowy-army-68599

    3 months ago
    makes sense. cc @broad-dog-22463