io.fabric8.openshift.client.OpenShiftAPIGroups Java Examples

The following examples show how to use io.fabric8.openshift.client.OpenShiftAPIGroups. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListBuildConfigs.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  try {
    OpenShiftClient client = new DefaultOpenShiftClient();
    if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.BUILD)) {
      System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.BUILD);
      return;
    }
    BuildConfigList list = client.buildConfigs().list();
    if (list == null) {
      System.out.println("ERROR no list returned!");
      return;
    }
    List<BuildConfig> items = list.getItems();
    for (BuildConfig item : items) {
      System.out.println("BuildConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
    }
  } catch (KubernetesClientException e) {
    System.out.println("Failed: " + e);
    e.printStackTrace();
  }
}
 
Example #2
Source File: ListImageStreams.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  try {
    OpenShiftClient client = new DefaultOpenShiftClient();
    if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE)) {
      System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.IMAGE);
      return;
    }
    ImageStreamList list = client.imageStreams().list();
    if (list == null) {
      System.out.println("ERROR no list returned!");
      return;
    }
    List<ImageStream> items = list.getItems();
    for (ImageStream item : items) {
      System.out.println("ImageStream " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
    }
    System.out.println("Found " + items.size() + " ImageStream(s)");
  } catch (KubernetesClientException e) {
    System.out.println("Failed: " + e);
    e.printStackTrace();
  }
}
 
Example #3
Source File: ClusterAccess.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns true if this cluster is a traditional OpenShift cluster with the <code>/oapi</code> REST API
 * or supports the new <code>/apis/image.openshift.io</code> API Group
 */
public boolean isOpenShiftImageStream() {
    if (isOpenShift()) {
        try (final OpenShiftClient client = createOpenShiftClient()) {
            return client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE);
        }
    }
    return false;
}
 
Example #4
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Lets run the <a href="https://github.com/fabric8io/exposecontroller/">exposecontroller</a> in one shot mode to update any Services
 * to use their external URLs
 */
protected void runExposeController(KubernetesClient kubernetes, String environment) throws Exception {
    if (exposeControllerInstalled()) {
        String commands = "exposecontroller --watch-namespace " + environment;
        OpenShiftClient oClient = openShiftClient();
        if (isOpenShift() && oClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.ROUTE)) {
            commands += " --exposer Route";
        } else {
            commands = loadKubernetesExposeControllerCommandLine(kubernetes, commands);
        }

        if (commands == null) {
            return;
        }

        // lets avoid using any input
        commands = "echo | " + commands;
        try {
            listener.getLogger().println("Running: " + commands);
            runProcess(commands, true);
            listener.getLogger().println("exposecontroller completed");
        } catch (Exception e) {
            throw new Exception("Failed to invoke command " + commands + " due to: " + e, e);
        }
    } else {
        listener.getLogger().println("WARNING: no exposecontroller on the PATH to cannot annotate the Services with their external URLs. You could try the fabric8 docker image for jenkins?");
    }
}
 
Example #5
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
private void createEnvironment(String environment, Controller controller) {
    boolean found = false;
    OpenShiftClient oClient = openShiftClient();
    if (isOpenShift() && oClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
        ProjectList ps = oClient.projects().list();
        for(Project p : ps.getItems()){
            listener.getLogger().println("Found namespace " +p.getMetadata().getName());
            if (environment.equalsIgnoreCase(p.getMetadata().getName())){
                found = true;
                listener.getLogger().println("Found existing environment " + environment);
                break;
            }
        }
    } else {
        NamespaceList ns = getKubernetes().namespaces().list();
        for(Namespace n : ns.getItems()){
            listener.getLogger().println("Found namespace " +n.getMetadata().getName());
            if (environment.equalsIgnoreCase(n.getMetadata().getName())){
                found = true;
                listener.getLogger().println("Found existing environment " + environment);
                break;
            }
        }

    }
    if (!found){
        listener.getLogger().println("Creating environment " + environment);
        controller.applyNamespace(environment);
    }
}
 
Example #6
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
private String getRegistry() {
    if (Strings.isNullOrBlank(step.getRegistry())) {
        // lets try and find an external docker registry in the users home namespace pipeline config
        KubernetesClient client = getKubernetes();
        ConfigMap cm = client.configMaps().inNamespace(this.buildConfigNamespace).withName(Constants.USERS_PIPELINE_CONFIGMAP_NAME).get();
        if (cm != null){
            Map<String, String> data = cm.getData();
            if (data != null){
                String rs = data.get(Constants.EXTERNAL_DOCKER_REGISTRY_URL);
                if (Strings.isNotBlank(rs)){
                    return rs;
                }
            }
        }

        // fall back to namespace env vars to support old fabric8 version
        if (isOpenShift() && openShiftClient().supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE)) {
            if (Strings.isNotBlank(env.get(Constants.OPENSHIFT_DOCKER_REGISTRY_SERVICE_HOST))){
                return env.get(Constants.OPENSHIFT_DOCKER_REGISTRY_SERVICE_HOST) + ":" + env.get(Constants.OPENSHIFT_DOCKER_REGISTRY_SERVICE_PORT);
            }
        } else if (Strings.isNotBlank(env.get(Constants.FABRIC8_DOCKER_REGISTRY_SERVICE_HOST))) {
            return env.get(Constants.FABRIC8_DOCKER_REGISTRY_SERVICE_HOST) + ":" + env.get(Constants.FABRIC8_DOCKER_REGISTRY_SERVICE_PORT);
        }
        return null;
    } else {
        return step.getRegistry();
    }
}
 
Example #7
Source File: ListDeploymentConfigs.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  try {
    OpenShiftClient client = new DefaultOpenShiftClient();
    if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) {
      System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.APPS);
      return;
    }
    DeploymentConfigList list = client.deploymentConfigs().list();
    if (list == null) {
      System.out.println("ERROR no list returned!");
      return;
    }
    List<DeploymentConfig> items = list.getItems();
    for (DeploymentConfig item : items) {
      System.out.println("DeploymentConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
    }

    if (items.size() > 0) {
      // lets check .get() too
      DeploymentConfig deploymentConfig = items.get(0);
      String name = deploymentConfig.getMetadata().getName();
      deploymentConfig = client.deploymentConfigs().withName(name).get();
      assertNotNull("No DeploymentConfig found for name " + name, deploymentConfig);
      System.out.println("get() DeploymentConfig " + name + " has version: " + deploymentConfig.getApiVersion());
    }
  } catch (KubernetesClientException e) {
    System.out.println("Failed: " + e);
    e.printStackTrace();
  }
}