I'm trying to set up a simple K8s cluster script i...
# general
s
I'm trying to set up a simple K8s cluster script in Azure using Scala and I'm wondering what is the correct way to export a kubeconfig from my cluster definition. I have the following:
val k8sCluster = new ManagedCluster(...)
I do not see any function in the ManagedCluster class that I can use to export the KubeConfig object. Is there any mechanism in the API that can be used to build a KubeConfig from a clsuer instance?
b
@sparse-nail-47035 I’m not familiar with scala, but in Java there’s a
ctx.export
method:
Copy code
import com.pulumi.Context;


ctx.export("kubeconfig" ...)
m
Hi @sparse-nail-47035, In "vanilla" Java, I had to do this to get the
kubeconfig
Copy code
Output<String> kubeconfig = Output.all(minecraftGroup.name(), mc.name()).apply(values -> {
                try {
                    CompletableFuture<ListManagedClusterUserCredentialsResult> cred = ContainerserviceFunctions.listManagedClusterUserCredentials(ListManagedClusterUserCredentialsArgs.builder()
                            .resourceGroupName(values.get(0))
                            .resourceName(values.get(1)).build());
                    String kubeconfigString = cred.get().kubeconfigs().get(0).value();
                    byte[] decodedBytes = Base64.getDecoder().decode(kubeconfigString);
                    return Output.of(new String(decodedBytes));
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
I can't rewrite this "quickly" into Scala but should be similar at the end 😄 #jvm
s
@billowy-army-68599 I don't think it works. I already have tried this!
@many-telephone-49025 Is that so complicated to export a KubeConfig?
m
yeah, Easier it is when you use the azure cli to get the kubeconfig
but not practical, when you want to use it to autodeploy
s
Under what circumstances would I be needing to export KubeConfig from a Java or Scala code?
m
If you want to deploy k8s resources via Pulumi
In most aks tutorials you see: 1. Deploy 2. ??? 3. `az aks get-credential ...`` 4. Profit 😄
s
Could you share that full source code
I could not make out what some of those variables stand for
As a sidenote, that piece of Java code is not pleasing to the eyes. My sinceere advice is to use Scala!
s
That returned a 404
m
Try again please, it was private somehow
s
Yes, I will take a look, but thank you very much for the help!
m
If you manage it, would love to see the Scala code! So if you could share your results i would be very happy!
s
I will sure do that! I'm hitting another problem now
I have the following as dependencies
Copy code
libraryDependencies += "com.pulumi" % "pulumi" % "0.7.1",
libraryDependencies += "com.pulumi" % "azure" % "5.28.0",
libraryDependencies += "com.pulumi" % "command" % "4.5.0"
m
ah you are not using the native provider?
s
I guess not
m
you should use the azure native provider
Copy code
libraryDependencies += "com.pulumi" % "azure-native" % "1.90.0",
s
Here is the project that I'm working on:
What is that cred.get?
I cannot find that
It is resolving not to a Future, but this
Copy code
val cred: Output[ListManagedClusterUserCredentialsResult]
m
its a CompletableFuture<ListManagedClusterUserCredentialsResult>
From java.util.concurrent
s
It does not resole to a future
If it does, I can get it into a Scala Future, but it resolved to Output[...]
docs state it's a Future
s
Wierd, it won't resolve to a Future
I guess I'm calling one of the overloaded methods
This is what I see:
Copy code
/**
 * The list of credential result response.
 * API Version: 2021-03-01.
 * 
 */
public static Output<ListManagedClusterMonitoringUserCredentialsResult> listManagedClusterMonitoringUserCredentials(ListManagedClusterMonitoringUserCredentialsArgs args) {
    return listManagedClusterMonitoringUserCredentials(args, InvokeOptions.Empty);
}
/**
 * The list of credential result response.
 * API Version: 2021-03-01.
 * 
 */
public static CompletableFuture<ListManagedClusterMonitoringUserCredentialsResult> listManagedClusterMonitoringUserCredentialsPlain(ListManagedClusterMonitoringUserCredentialsPlainArgs args) {
    return listManagedClusterMonitoringUserCredentialsPlain(args, InvokeOptions.Empty);
}
/**
 * The list of credential result response.
 * API Version: 2021-03-01.
 * 
 */
public static Output<ListManagedClusterMonitoringUserCredentialsResult> listManagedClusterMonitoringUserCredentials(ListManagedClusterMonitoringUserCredentialsArgs args, InvokeOptions options) {
    return Deployment.getInstance().invoke("azure-native:containerservice:listManagedClusterMonitoringUserCredentials", TypeShape.of(ListManagedClusterMonitoringUserCredentialsResult.class), args, Utilities.withVersion(options));
}
/**
 * The list of credential result response.
 * API Version: 2021-03-01.
 * 
 */
public static CompletableFuture<ListManagedClusterMonitoringUserCredentialsResult> listManagedClusterMonitoringUserCredentialsPlain(ListManagedClusterMonitoringUserCredentialsPlainArgs args, InvokeOptions options) {
    return Deployment.getInstance().invokeAsync("azure-native:containerservice:listManagedClusterMonitoringUserCredentials", TypeShape.of(ListManagedClusterMonitoringUserCredentialsResult.class), args, Utilities.withVersion(options));
}
m
unfortunately I am very basic in my Scala skills and would not much of a help.
s
I'm trying to get that done!
That atleast compiles, but that way of calling get on Futures and Try is not idomatic
I will change that later
but thanks for the help!