All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.playpen.kubernetes.client.KubernetesRemotePlaypenClient Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.quarkiverse.playpen.kubernetes.client;

import java.io.Closeable;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.LocalPortForward;
import io.quarkiverse.playpen.client.RemotePlaypenClient;
import io.quarkiverse.playpen.client.RemotePlaypenConnectionConfig;

public class KubernetesRemotePlaypenClient extends RemotePlaypenClient implements Closeable {
    final KubernetesClient client;
    private PortForward playpenForward;
    private String kubeConnectionUrl;
    private int localPort = 0;

    public KubernetesRemotePlaypenClient(KubernetesClient client, RemotePlaypenConnectionConfig config) {
        super(config);
        this.client = client;
        if (config.connection == null) {
            throw new IllegalArgumentException("Play connection locatio not defined");
        }
        if (config.connection.startsWith("http")) {
            throw new IllegalArgumentException("Cannot use remote kubernetes playpen if connection is http");
        }
    }

    public void setLocalPort(int localPort) {
        this.localPort = localPort;
    }

    public KubernetesClient getClient() {
        return client;
    }

    @Override
    public Boolean isSelfSigned() {
        return false;
    }

    @Override
    public String getBasePlaypenUrl() {
        return kubeConnectionUrl;
    }

    public boolean init() throws IllegalArgumentException {
        playpenForward = new PortForward(config.connection);
        playpenForward.setName(playpenForward.getName() + "-playpen");
        LocalPortForward forward = playpenForward.forward(client, localPort);
        kubeConnectionUrl = "http://localhost:" + forward.getLocalPort();

        return true;
    }

    public PortForward getPlaypenForward() {
        return playpenForward;
    }

    public void close() {
        super.close();
        if (playpenForward != null) {
            playpenForward.close();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy