io.kubernetes.client.ApiClient Java Examples

The following examples show how to use io.kubernetes.client.ApiClient. 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: KubernetesEnvImpl.java    From kruize with Apache License 2.0 6 votes vote down vote up
private boolean checkMonitoringAgentRunning() throws IOException, ApiException
{
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();

    V1ServiceList serviceList = api.listServiceForAllNamespaces(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null
    );

    for (V1Service service : serviceList.getItems()) {
        String serviceName = service.getMetadata().getName();
        if (serviceName.toUpperCase().contains(DeploymentInfo.getMonitoringAgent()))
            return true;
    }

    return false;
}
 
Example #2
Source File: ExperimentRestApiIT.java    From submarine with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startUp() throws IOException {
  Assert.assertTrue(checkIfServerIsRunning());

  // The kube config path defined by kind-cluster-build.sh
  String confPath = System.getProperty("user.home") + "/.kube/kind-config-kind";
  KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(confPath));
  ApiClient client = ClientBuilder.kubeconfig(config).build();
  Configuration.setDefaultApiClient(client);
  k8sApi = new CustomObjectsApi();

  kfOperatorMap = new HashMap<>();
  kfOperatorMap.put("tensorflow", new KfOperator("v1", "tfjobs"));
  kfOperatorMap.put("pytorch", new KfOperator("v1", "pytorchjobs"));
}
 
Example #3
Source File: KubernetesNatManager.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() throws NatInitializationException {
  LOG.info("Starting kubernetes NAT manager.");
  try {

    KubeConfig.registerAuthenticator(new GCPAuthenticator());

    LOG.debug("Trying to update information using Kubernetes client SDK.");
    final ApiClient client = ClientBuilder.cluster().build();

    // set the global default api-client to the in-cluster one from above
    Configuration.setDefaultApiClient(client);

    // the CoreV1Api loads default api-client from global configuration.
    final CoreV1Api api = new CoreV1Api();
    // invokes the CoreV1Api client
    final V1Service service =
        api.listServiceForAllNamespaces(null, null, null, null, null, null, null, null, null)
            .getItems().stream()
            .filter(v1Service -> v1Service.getMetadata().getName().contains(besuPodNameFilter))
            .findFirst()
            .orElseThrow(() -> new NatInitializationException("Service not found"));
    updateUsingBesuService(service);
  } catch (Exception e) {
    throw new NatInitializationException(e.getMessage(), e);
  }
}
 
Example #4
Source File: KubernetesEnvImpl.java    From kruize with Apache License 2.0 5 votes vote down vote up
private void getMonitoringEndpointFromService() throws IOException, ApiException
{
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();

    V1ServiceList serviceList = api.listServiceForAllNamespaces(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null
    );

    for (V1Service service : serviceList.getItems()) {
        String serviceName = service.getMetadata().getName();
        if (serviceName.toUpperCase().equals(DeploymentInfo.getMonitoringAgentService())) {
            String clusterIP = service.getSpec().getClusterIP();
            int port = service.getSpec().getPorts().get(0).getPort();
            DeploymentInfo.setMonitoringAgentEndpoint("http://" + clusterIP + ":" + port);
        }
    }
}
 
Example #5
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 4 votes vote down vote up
/**
 * Constructor
 */
public KubernetesOperation() {
    ApiClient client = Config.fromToken(API_SERVER_NAME, ACCESS_TOKEN, false);
    Configuration.setDefaultApiClient(client);
    corev1Api = new CoreV1Api(client);
}