Skip to content

Produce a KubernetesDevServiceInfoBuildItem forDevServices requiring to use a Kubernetes cluster #46330

@cmoulliard

Description

@cmoulliard

Description

Until now, if a DevService, part of an extension (example: quarkus-argocd) would like to use the Kubernetes cluster created by the quarkus-kubernetes-client extension, this is not possible as the cluster is created asynchronously and can take place before or after the devServices will start and by consequence the DevService will not be able to get the proper KubeConfig generated by the Kind Testcontainer.

Such an issue could be fixed if the existing quarkus-kubernetes-client extension produce a KubernetesDevServiceInfoBuildItem when the kubernetes cluster is created

            devServicesKube.produce(new KubernetesDevServiceInfoBuildItem(container.getKubeconfig(), container));

Then, the DevServices consuming it will be able to be sync with the Kind cluster created and will be able to get the Kind TestContainer kubeconfig

    @BuildStep
    public DevServicesResultBuildItem deployArgocd(
        ArgocdBuildTimeConfig config,
        KubernetesDevServiceInfoBuildItem kubeServiceInfo) {
...
        // Convert the kube config yaml to its Java Class
        Config kubeConfig = KubeConfigUtils.parseConfigFromString(kubeServiceInfo.getKubeConfig());
        
        if (config.devservices().debugEnabled()) {
            LOG.info(">>> Cluster container name : " + kubeServiceInfo.getContainer().getContainerName());
            kubeConfig.getClusters().stream().forEach(c -> {
                LOG.debugf(">>> Cluster name: %s", c.getName());
                LOG.debugf(">>> API URL: %s", c.getCluster().getServer());
            });
            kubeConfig.getUsers().stream().forEach(u -> LOG.debugf(">>> User key: %s", u.getUser().getClientKeyData()));
            kubeConfig.getContexts().stream().forEach(ctx -> LOG.debugf(">>> Context : %s", ctx.getContext().getUser()));
        }

        // Create the Kubernetes client using the Kube YAML Config
        KubernetesClient client = new KubernetesClientBuilder()
            .withConfig(io.fabric8.kubernetes.client.Config.fromKubeconfig(kubeServiceInfo.getKubeConfig()))
            .build();
...

Implementation ideas

See snippet code added to the description

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions