Search in sources :

Example 1 with TokenStreamProvider

use of org.jgroups.protocols.kubernetes.stream.TokenStreamProvider in project jgroups-kubernetes by jgroups-extras.

the class KUBE_PING method init.

public void init() throws Exception {
    super.init();
    tp_bind_port = transport.getBindPort();
    if (tp_bind_port <= 0)
        throw new IllegalArgumentException(String.format("%s only works with  %s.bind_port > 0", KUBE_PING.class.getSimpleName(), transport.getClass().getSimpleName()));
    checkDeprecatedProperties();
    if (namespace == null) {
        log.warn("namespace not set; clustering disabled");
        // no further initialization necessary
        return;
    }
    log.info("namespace %s set; clustering enabled", namespace);
    Map<String, String> headers = new HashMap<>();
    StreamProvider streamProvider;
    if (clientCertFile != null) {
        if (masterProtocol == null)
            masterProtocol = "http";
        streamProvider = new CertificateStreamProvider(clientCertFile, clientKeyFile, clientKeyPassword, clientKeyAlgo, caCertFile);
    } else {
        String saToken = readFileToString(saTokenFile);
        if (saToken != null) {
            // curl -k -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
            // https://172.30.0.2:443/api/v1/namespaces/dward/pods?labelSelector=application%3Deap-app
            headers.put("Authorization", "Bearer " + saToken);
        }
        streamProvider = new TokenStreamProvider(saToken, caCertFile);
    }
    String url = String.format("%s://%s:%s/api/%s", masterProtocol, masterHost, masterPort, apiVersion);
    client = new Client(url, headers, connectTimeout, readTimeout, operationAttempts, operationSleep, streamProvider, log);
    log.debug("KubePING configuration: " + toString());
}
Also used : CertificateStreamProvider(org.jgroups.protocols.kubernetes.stream.CertificateStreamProvider) StreamProvider(org.jgroups.protocols.kubernetes.stream.StreamProvider) TokenStreamProvider(org.jgroups.protocols.kubernetes.stream.TokenStreamProvider) CertificateStreamProvider(org.jgroups.protocols.kubernetes.stream.CertificateStreamProvider) TokenStreamProvider(org.jgroups.protocols.kubernetes.stream.TokenStreamProvider) Utils.readFileToString(org.jgroups.protocols.kubernetes.Utils.readFileToString)

Aggregations

Utils.readFileToString (org.jgroups.protocols.kubernetes.Utils.readFileToString)1 CertificateStreamProvider (org.jgroups.protocols.kubernetes.stream.CertificateStreamProvider)1 StreamProvider (org.jgroups.protocols.kubernetes.stream.StreamProvider)1 TokenStreamProvider (org.jgroups.protocols.kubernetes.stream.TokenStreamProvider)1