Search in sources :

Example 1 with KubeConfig

use of io.kubernetes.client.util.KubeConfig in project submarine by apache.

the class ExperimentRestApiIT method startUp.

@BeforeClass
public static void startUp() throws IOException {
    Assert.assertTrue(checkIfServerIsRunning());
    // The kube config is created when the cluster builds
    String confPath = System.getProperty("user.home") + "/.kube/config";
    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"));
}
Also used : CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) KubeConfig(io.kubernetes.client.util.KubeConfig) FileReader(java.io.FileReader) ApiClient(io.kubernetes.client.openapi.ApiClient) BeforeClass(org.junit.BeforeClass)

Example 2 with KubeConfig

use of io.kubernetes.client.util.KubeConfig in project submarine by apache.

the class NotebookRestApiIT method startUp.

@BeforeClass
public static void startUp() throws IOException {
    Assert.assertTrue(checkIfServerIsRunning());
    // The kube config is created when the cluster builds
    String confPath = System.getProperty("user.home") + "/.kube/config";
    KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(confPath));
    ApiClient client = ClientBuilder.kubeconfig(config).build();
    Configuration.setDefaultApiClient(client);
    k8sApi = new CustomObjectsApi();
}
Also used : CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) KubeConfig(io.kubernetes.client.util.KubeConfig) FileReader(java.io.FileReader) ApiClient(io.kubernetes.client.openapi.ApiClient) BeforeClass(org.junit.BeforeClass)

Example 3 with KubeConfig

use of io.kubernetes.client.util.KubeConfig in project submarine by apache.

the class K8sSubmitter method initialize.

@Override
public void initialize(SubmarineConfiguration conf) {
    try {
        String path = System.getenv(KUBECONFIG_ENV);
        KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(path));
        client = ClientBuilder.kubeconfig(config).build();
    } catch (Exception e) {
        LOG.info("Maybe in cluster mode, try to initialize the client again.");
        try {
            client = ClientBuilder.cluster().build();
        } catch (IOException e1) {
            LOG.error("Initialize K8s submitter failed. " + e.getMessage(), e1);
            throw new SubmarineRuntimeException(500, "Initialize K8s submitter failed.");
        }
    } finally {
        OkHttpClient httpClient = client.getHttpClient();
        client.setHttpClient(httpClient);
        Configuration.setDefaultApiClient(client);
    }
    if (coreApi == null) {
        coreApi = new CoreV1Api(client);
    }
    if (appsV1Api == null) {
        appsV1Api = new AppsV1Api();
    }
    podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", client);
    eventClient = new GenericKubernetesApi<>(CoreV1Event.class, CoreV1EventList.class, "", "v1", "events", client);
    persistentVolumeClaimClient = new GenericKubernetesApi<>(V1PersistentVolumeClaim.class, V1PersistentVolumeClaimList.class, "", "v1", "persistentvolumeclaims", client);
    configMapClient = new GenericKubernetesApi<>(V1ConfigMap.class, V1ConfigMapList.class, "", "v1", "configmaps", client);
    tfJobClient = new GenericKubernetesApi<>(TFJob.class, TFJobList.class, TFJob.CRD_TF_GROUP_V1, TFJob.CRD_TF_VERSION_V1, TFJob.CRD_TF_PLURAL_V1, client);
    pyTorchJobClient = new GenericKubernetesApi<>(PyTorchJob.class, PyTorchJobList.class, PyTorchJob.CRD_PYTORCH_GROUP_V1, PyTorchJob.CRD_PYTORCH_VERSION_V1, PyTorchJob.CRD_PYTORCH_PLURAL_V1, client);
    notebookCRClient = new GenericKubernetesApi<>(NotebookCR.class, NotebookCRList.class, NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, client);
    ingressRouteClient = new GenericKubernetesApi<>(IngressRoute.class, IngressRouteList.class, IngressRoute.CRD_INGRESSROUTE_GROUP_V1, IngressRoute.CRD_INGRESSROUTE_VERSION_V1, IngressRoute.CRD_INGRESSROUTE_PLURAL_V1, client);
    seldonDeploymentClient = new GenericKubernetesApi<>(SeldonDeployment.class, SeldonDeploymentList.class, SeldonConstants.GROUP, SeldonConstants.VERSION, SeldonConstants.PLURAL, client);
    istioVirtualServiceClient = new GenericKubernetesApi<>(IstioVirtualService.class, IstioVirtualServiceList.class, IstioConstants.GROUP, IstioConstants.VERSION, IstioConstants.PLURAL, client);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) IngressRouteList(org.apache.submarine.server.submitter.k8s.model.ingressroute.IngressRouteList) PyTorchJob(org.apache.submarine.server.submitter.k8s.model.pytorchjob.PyTorchJob) SubmarineRuntimeException(org.apache.submarine.commons.utils.exception.SubmarineRuntimeException) NotebookCRList(org.apache.submarine.server.submitter.k8s.model.notebook.NotebookCRList) KubeConfig(io.kubernetes.client.util.KubeConfig) IstioVirtualServiceList(org.apache.submarine.serve.istio.IstioVirtualServiceList) FileReader(java.io.FileReader) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) IstioVirtualService(org.apache.submarine.serve.istio.IstioVirtualService) NotebookCR(org.apache.submarine.server.submitter.k8s.model.notebook.NotebookCR) IngressRoute(org.apache.submarine.server.submitter.k8s.model.ingressroute.IngressRoute) SeldonDeploymentList(org.apache.submarine.serve.seldon.SeldonDeploymentList) V1PersistentVolumeClaim(io.kubernetes.client.openapi.models.V1PersistentVolumeClaim) CoreV1EventList(io.kubernetes.client.openapi.models.CoreV1EventList) IOException(java.io.IOException) TFJob(org.apache.submarine.server.submitter.k8s.model.tfjob.TFJob) V1PersistentVolumeClaimList(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimList) InvalidSpecException(org.apache.submarine.server.api.exception.InvalidSpecException) ApiException(io.kubernetes.client.openapi.ApiException) SubmarineRuntimeException(org.apache.submarine.commons.utils.exception.SubmarineRuntimeException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) TFJobList(org.apache.submarine.server.submitter.k8s.model.tfjob.TFJobList) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) SeldonDeployment(org.apache.submarine.serve.seldon.SeldonDeployment) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) PyTorchJobList(org.apache.submarine.server.submitter.k8s.model.pytorchjob.PyTorchJobList)

Example 4 with KubeConfig

use of io.kubernetes.client.util.KubeConfig in project submarine by apache.

the class ExperimentRestApiTest method startUp.

@BeforeClass
public static void startUp() throws IOException {
    Assert.assertTrue(checkIfServerIsRunning());
    // The kube config is created when the cluster builds
    String confPath = System.getProperty("user.home") + "/.kube/config";
    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"));
}
Also used : CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) KubeConfig(io.kubernetes.client.util.KubeConfig) FileReader(java.io.FileReader) ApiClient(io.kubernetes.client.openapi.ApiClient) BeforeClass(org.junit.BeforeClass)

Example 5 with KubeConfig

use of io.kubernetes.client.util.KubeConfig in project submarine by apache.

the class NotebookRestApiTest method startUp.

@BeforeClass
public static void startUp() throws IOException {
    Assert.assertTrue(checkIfServerIsRunning());
    // The kube config is created when the cluster builds
    String confPath = System.getProperty("user.home") + "/.kube/config";
    KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(confPath));
    ApiClient client = ClientBuilder.kubeconfig(config).build();
    Configuration.setDefaultApiClient(client);
    k8sApi = new CustomObjectsApi();
}
Also used : CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) KubeConfig(io.kubernetes.client.util.KubeConfig) FileReader(java.io.FileReader) ApiClient(io.kubernetes.client.openapi.ApiClient) BeforeClass(org.junit.BeforeClass)

Aggregations

KubeConfig (io.kubernetes.client.util.KubeConfig)11 ApiClient (io.kubernetes.client.openapi.ApiClient)7 FileReader (java.io.FileReader)6 CustomObjectsApi (io.kubernetes.client.openapi.apis.CustomObjectsApi)4 BeforeClass (org.junit.BeforeClass)4 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)3 ArrayList (java.util.ArrayList)3 AccessToken (com.google.auth.oauth2.AccessToken)2 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ApiException (io.kubernetes.client.openapi.ApiException)1 CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)1 CoreV1EventList (io.kubernetes.client.openapi.models.CoreV1EventList)1 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)1