Search in sources :

Example 1 with DefaultOpenShiftClient

use of io.fabric8.openshift.client.DefaultOpenShiftClient in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method buildConfig.

/**
 * Builds the Config required by DefaultOpenShiftClient
 * Also sets the system properties
 * (1) to not refer .kube/config file and
 * (2) the client to use service account procedure to get authenticated and authorised
 *
 * @return {@link io.fabric8.kubernetes.client.Config} object to build the client
 * @throws ServiceDiscoveryException if an error occurs while building the config using externally stored token
 */
private Config buildConfig(Map<String, String> implParameters) throws ServiceDiscoveryException, APIMgtDAOException {
    System.setProperty(TRY_KUBE_CONFIG, "false");
    System.setProperty(TRY_SERVICE_ACCOUNT, "true");
    /*
         *  Common to both situations,
         *      - Token found inside APIM pod
         *      - Token stored in APIM resources/security folder }
         */
    ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(implParameters.get(MASTER_URL)).withCaCertFile(implParameters.get(CA_CERT_PATH));
    /*
         *  Check if a service account token File Name is given in the configuration
         *      - if not : assume APIM is running inside a pod and look for the pod's token
         */
    String externalSATokenFileName = implParameters.get(EXTERNAL_SA_TOKEN_FILE_NAME);
    if (StringUtils.isEmpty(externalSATokenFileName)) {
        log.debug("Looking for service account token in " + POD_MOUNTED_SA_TOKEN_FILE_PATH);
        String podMountedSAToken = APIFileUtils.readFileContentAsText(implParameters.get(POD_MOUNTED_SA_TOKEN_FILE_PATH));
        return configBuilder.withOauthToken(podMountedSAToken).build();
    } else {
        log.info("Using externally stored service account token");
        return configBuilder.withOauthToken(resolveToken("encrypted" + externalSATokenFileName)).build();
    }
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder)

Example 2 with DefaultOpenShiftClient

use of io.fabric8.openshift.client.DefaultOpenShiftClient in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method initImpl.

/**
 * Initializes OpenShiftClient (extended KubernetesClient) and sets the necessary parameters
 *
 * @param implParameters implementation parameters added by the super class #initImpl(java.util.Map) method
 * @throws ServiceDiscoveryException if an error occurs while initializing the client
 */
@Override
public void initImpl(Map<String, String> implParameters) throws ServiceDiscoveryException {
    try {
        setClient(new DefaultOpenShiftClient(buildConfig(implParameters)));
    } catch (KubernetesClientException | APIMgtDAOException e) {
        String msg = "Error occurred while creating Kubernetes client";
        throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
    } catch (ArrayIndexOutOfBoundsException e) {
        String msg = "Error occurred while reading filtering criteria from the configuration";
        throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
    }
    includeClusterIP = Boolean.parseBoolean(implParameters.get(INCLUDE_CLUSTER_IPS));
    includeExternalNameTypeServices = Boolean.parseBoolean(implParameters.get(INCLUDE_EXTERNAL_NAME_SERVICES));
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with DefaultOpenShiftClient

use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8-maven-plugin by fabric8io.

the class BaseBoosterIT method setupSampleTestRepository.

protected Repository setupSampleTestRepository(String repositoryUrl, String relativePomPath) throws IOException, GitAPIException, XmlPullParserException {
    openShiftClient = new DefaultOpenShiftClient(new ConfigBuilder().build());
    testsuiteNamespace = openShiftClient.getNamespace();
    Repository repository = cloneRepositoryUsingHttp(repositoryUrl);
    modifyPomFileToProjectVersion(repository, relativePomPath);
    return repository;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Example 4 with DefaultOpenShiftClient

use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8 by fabric8io.

the class WatchBuildsExample method main.

public static void main(String... args) throws Exception {
    OpenShiftClient client = new DefaultOpenShiftClient();
    client.builds().watch(new Watcher<Build>() {

        @Override
        public void eventReceived(Action action, Build build) {
            System.out.println(action + ": " + build);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            System.out.println("Closed: " + e);
        }
    });
    client.close();
}
Also used : Build(io.fabric8.openshift.api.model.Build) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 5 with DefaultOpenShiftClient

use of io.fabric8.openshift.client.DefaultOpenShiftClient in project fabric8 by fabric8io.

the class KubernetesHelper method createJenkinshiftOpenShiftClient.

public static OpenShiftClient createJenkinshiftOpenShiftClient(String jenkinshiftUrl) {
    Config config = createJenkinshiftConfig(jenkinshiftUrl);
    // TODO until jenkinshift supports HTTPS lets disable HTTPS by default
    // openShiftClient = new DefaultOpenShiftClient(jenkinshiftUrl);
    JenkinShiftClient jenkinShiftClient = new JenkinShiftClient(config);
    jenkinShiftClient.updateHttpClient(config);
    return jenkinShiftClient;
}
Also used : DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Config(io.fabric8.kubernetes.client.Config)

Aggregations

DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)2 BuildFinishedEvent (io.fabric8.kubernetes.api.builds.BuildFinishedEvent)1 BuildListener (io.fabric8.kubernetes.api.builds.BuildListener)1 BuildWatcher (io.fabric8.kubernetes.api.builds.BuildWatcher)1 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 DeploymentList (io.fabric8.kubernetes.api.model.extensions.DeploymentList)1 DoneableDeployment (io.fabric8.kubernetes.api.model.extensions.DoneableDeployment)1 Config (io.fabric8.kubernetes.client.Config)1 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)1 BuildService (io.fabric8.maven.core.service.BuildService)1 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 Build (io.fabric8.openshift.api.model.Build)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 WebHookTrigger (io.fabric8.openshift.api.model.WebHookTrigger)1 OpenShiftConfig (io.fabric8.openshift.client.OpenShiftConfig)1 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)1 IOException (java.io.IOException)1