Java Code Examples for io.fabric8.kubernetes.client.DefaultKubernetesClient

The following examples show how to use io.fabric8.kubernetes.client.DefaultKubernetesClient. These examples are extracted from open source projects. 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
@Test
public void testVersionDetectionMinikube114(VertxTestContext context) throws InterruptedException {
    String version = "{\n" +
            "  \"major\": \"1\",\n" +
            "  \"minor\": \"14\",\n" +
            "  \"gitVersion\": \"v1.14.0\",\n" +
            "  \"gitCommit\": \"641856db18352033a0d96dbc99153fa3b27298e5\",\n" +
            "  \"gitTreeState\": \"clean\",\n" +
            "  \"buildDate\": \"2019-03-25T15:45:25Z\",\n" +
            "  \"goVersion\": \"go1.12.1\",\n" +
            "  \"compiler\": \"gc\",\n" +
            "  \"platform\": \"linux/amd64\"\n" +
            "}";

    HttpServer mockHttp = startMockApi(context, version, Collections.EMPTY_LIST);

    KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());

    Checkpoint async = context.checkpoint();

    PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
        assertThat("Versions are not equal", pfa.getKubernetesVersion(), is(KubernetesVersion.V1_14));
        stopMockApi(context, mockHttp);
        async.flag();
    })));
}
 
Example 2
@Test
public void testApiDetectionOpenshift(VertxTestContext context) throws InterruptedException {
    List<String> apis = new ArrayList<>();
    apis.add("/apis/route.openshift.io/v1");
    apis.add("/apis/build.openshift.io/v1");
    apis.add("/apis/apps.openshift.io/v1");
    apis.add("/apis/image.openshift.io/v1");

    HttpServer mockHttp = startMockApi(context, apis);

    KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());

    Checkpoint async = context.checkpoint();

    PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
        assertThat(pfa.hasRoutes(), is(true));
        assertThat(pfa.hasBuilds(), is(true));
        assertThat(pfa.hasImages(), is(true));
        assertThat(pfa.hasApps(), is(true));
        stopMockApi(context, mockHttp);
        async.flag();
    })));
}
 
Example 3
@Test
public void testApiDetectionKubernetes(VertxTestContext context) throws InterruptedException {
    HttpServer mockHttp = startMockApi(context, Collections.EMPTY_LIST);

    KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());

    Checkpoint async = context.checkpoint();

    PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
        assertThat(pfa.hasRoutes(), is(false));
        assertThat(pfa.hasBuilds(), is(false));
        assertThat(pfa.hasImages(), is(false));
        assertThat(pfa.hasApps(), is(false));
        stopMockApi(context, mockHttp);
        async.flag();
    })));
}
 
Example 4
@BeforeAll
public static void before() {
    cluster = KubeClusterResource.getInstance();
    cluster.setTestNamespace(namespace);

    assertDoesNotThrow(() -> KubeCluster.bootstrap(), "Could not bootstrap server");
    vertx = Vertx.vertx();
    client = new DefaultKubernetesClient();

    if (cluster.getTestNamespace() != null && System.getenv("SKIP_TEARDOWN") == null) {
        log.warn("Namespace {} is already created, going to delete it", namespace);
        kubeClient().deleteNamespace(namespace);
        cmdKubeClient().waitForResourceDeletion("Namespace", namespace);
    }

    log.info("Creating namespace: {}", namespace);
    kubeClient().createNamespace(namespace);
    cmdKubeClient().waitForResourceCreation("Namespace", namespace);
}
 
Example 5
@AfterClass
public static void cleanup() {
	KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties();
	kubernetesSchedulerProperties.setNamespace("default");

	KubernetesClient kubernetesClient = new DefaultKubernetesClient()
			.inNamespace(kubernetesSchedulerProperties.getNamespace());

	KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient,
			kubernetesSchedulerProperties);

	List<ScheduleInfo> scheduleInfos = kubernetesScheduler.list();

	for (ScheduleInfo scheduleInfo : scheduleInfos) {
		kubernetesScheduler.unschedule(scheduleInfo.getScheduleName());
	}
	// Cleanup the schedules that aren't part of the list() - created from listScheduleWithExternalCronJobs test
	kubernetesScheduler.unschedule("job2");
	kubernetesScheduler.unschedule("job3");
}
 
Example 6
@Test
public void testVersionDetectionOpenShift39(VertxTestContext context) throws InterruptedException {
    String version = "{\n" +
            "  \"major\": \"1\",\n" +
            "  \"minor\": \"9\",\n" +
            "  \"gitVersion\": \"v1.9.1+a0ce1bc657\",\n" +
            "  \"gitCommit\": \"a0ce1bc\",\n" +
            "  \"gitTreeState\": \"clean\",\n" +
            "  \"buildDate\": \"2018-06-24T01:54:00Z\",\n" +
            "  \"goVersion\": \"go1.9\",\n" +
            "  \"compiler\": \"gc\",\n" +
            "  \"platform\": \"linux/amd64\"\n" +
            "}";

    HttpServer mockHttp = startMockApi(context, version, Collections.EMPTY_LIST);

    KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());

    Checkpoint a = context.checkpoint();

    PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
        assertThat("Versions are not equal", pfa.getKubernetesVersion(), is(KubernetesVersion.V1_9));
        stopMockApi(context, mockHttp);
        a.flag();
    })));
}
 
Example 7
Source Project: module-ballerina-kubernetes   Source File: Sample12Test.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_copy_file.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_copy_file.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "Deployment":
                deployment = (Deployment) data;
                break;
            case "Service":
            case "Ingress":
            case "Secret":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 8
Source Project: module-ballerina-kubernetes   Source File: Sample5Test.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "pizzashack.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("pizzashack.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "HorizontalPodAutoscaler":
                podAutoscaler = (HorizontalPodAutoscaler) data;
                break;
            case "Service":
            case "Ingress":
            case "Secret":
            case "Deployment":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 9
Source Project: module-ballerina-kubernetes   Source File: Sample1Test.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_k8s.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_k8s.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "Deployment":
                deployment = (Deployment) data;
                break;
            case "Service":
                service = (Service) data;
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 10
Source Project: module-ballerina-kubernetes   Source File: Sample4Test.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_ssl_k8s.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_ssl_k8s.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "Deployment":
                deployment = (Deployment) data;
                break;
            case "Secret":
                secret = (Secret) data;
                break;
            case "Ingress":
                ingress = (Ingress) data;
                break;
            case "Service":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 11
Source Project: syndesis   Source File: PodMetricsReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test @Ignore
public void readTest() {
    String podName = "dbtest1-2-3nvf3";
    String integration = "DBTest1";
    String integrationId = "-L5ApZneYNfmLWG-PKQt";
    String version = "1";
    PodMetricsReader reader = new PodMetricsReader(
            new DefaultKubernetesClient(),
            podName,
            integration,
            integrationId,
            version,
            new LogRawMetrics());
    reader.run();

}
 
Example 12
private void testEnvironmentVariables(KubernetesSchedulerProperties kubernetesSchedulerProperties,
		Map<String, String> schedulerProperties, EnvVar[] expectedVars) {
	if (kubernetesSchedulerProperties.getNamespace() == null) {
		kubernetesSchedulerProperties.setNamespace("default");
	}
	KubernetesClient kubernetesClient = new DefaultKubernetesClient()
			.inNamespace(kubernetesSchedulerProperties.getNamespace());

	KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient,
			kubernetesSchedulerProperties);

	AppDefinition appDefinition = new AppDefinition(randomName(), getAppProperties());
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, schedulerProperties,
			null, getCommandLineArgs(), randomName(), testApplication());

	CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest);
	CronJobSpec cronJobSpec = cronJob.getSpec();

	Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0);

	assertTrue("Environment variables should not be empty", !container.getEnv().isEmpty());

	assertThat(container.getEnv()).contains(expectedVars);

	kubernetesScheduler.unschedule(cronJob.getMetadata().getName());
}
 
Example 13
@Test
public void testImagePullPolicyDefault() {
	KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties();
	if (kubernetesSchedulerProperties.getNamespace() == null) {
		kubernetesSchedulerProperties.setNamespace("default");
	}
	KubernetesClient kubernetesClient = new DefaultKubernetesClient()
			.inNamespace(kubernetesSchedulerProperties.getNamespace());

	KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient,
			kubernetesSchedulerProperties);

	AppDefinition appDefinition = new AppDefinition(randomName(), getAppProperties());
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, getSchedulerProperties(),
			getDeploymentProperties(), getCommandLineArgs(), randomName(), testApplication());

	CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest);
	CronJobSpec cronJobSpec = cronJob.getSpec();

	Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0);

	assertEquals("Unexpected default image pull policy", ImagePullPolicy.IfNotPresent,
			ImagePullPolicy.relaxedValueOf(container.getImagePullPolicy()));

	kubernetesScheduler.unschedule(cronJob.getMetadata().getName());
}
 
Example 14
@Test
public void testImagePullSecretDefault() {
	KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties();
	if (kubernetesSchedulerProperties.getNamespace() == null) {
		kubernetesSchedulerProperties.setNamespace("default");
	}
	KubernetesClient kubernetesClient = new DefaultKubernetesClient()
			.inNamespace(kubernetesSchedulerProperties.getNamespace());

	KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient,
			kubernetesSchedulerProperties);

	AppDefinition appDefinition = new AppDefinition(randomName(), getAppProperties());
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, getSchedulerProperties(),
			getDeploymentProperties(), getCommandLineArgs(), randomName(), testApplication());

	CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest);
	CronJobSpec cronJobSpec = cronJob.getSpec();

	List<LocalObjectReference> secrets = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec()
			.getImagePullSecrets();
	assertTrue("There should be no secrets", secrets.isEmpty());

	kubernetesScheduler.unschedule(cronJob.getMetadata().getName());
}
 
Example 15
Source Project: yaks   Source File: CamelKSteps.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Lazy initialize a default Kubernetes client.
 * @return
 */
private KubernetesClient client() {
    if (this.client == null) {
        this.client = new DefaultKubernetesClient();
    }
    return this.client;
}
 
Example 16
Source Project: enmasse   Source File: DeviceRegistryTokenAuthProvider.java    License: Apache License 2.0 5 votes vote down vote up
public DeviceRegistryTokenAuthProvider(final Tracer tracer, final Duration tokenExpiration) {
    log.info("Using token cache expiration of {}", tokenExpiration);
    this.tracer = tracer;
    this.client = new DefaultKubernetesClient();
    this.authApi = new KubeAuthApi(this.client, this.client.getConfiguration().getOauthToken());
    final ConfigurationBuilder config = new ConfigurationBuilder();
    config.expiration().lifespan(tokenExpiration.toSeconds(), TimeUnit.SECONDS);
    this.cacheManager.defineConfiguration("tokens", config.build());
    this.cacheManager.defineConfiguration("subjects", config.build());
    this.tokens = cacheManager.getCache("tokens");
    this.authorizations = cacheManager.getCache("subjects");

}
 
Example 17
Source Project: java-operator-sdk   Source File: WebServerOperator.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    log.info("WebServer Operator starting!");

    Config config = new ConfigBuilder().withNamespace(null).build();
    KubernetesClient client = new DefaultKubernetesClient(config);
    Operator operator = new Operator(client);
    operator.registerControllerForAllNamespaces(new WebServerController(client));

    new FtBasic(
            new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080
    ).start(Exit.NEVER);
}
 
Example 18
Source Project: java-operator-sdk   Source File: MySQLSchemaOperator.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    log.info("MySQL Schema Operator starting");

    Config config = new ConfigBuilder().withNamespace(null).build();
    KubernetesClient client = new DefaultKubernetesClient(config);
    Operator operator = new Operator(client);
    operator.registerControllerForAllNamespaces(new SchemaController(client));

    new FtBasic(
            new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080
    ).start(Exit.NEVER);
}
 
Example 19
Source Project: vault-crd   Source File: KubernetesServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KubernetesClient client() {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    TestHelper.createCrd(kubernetesClient);

    return kubernetesClient;
}
 
Example 20
Source Project: vault-crd   Source File: CertChainTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KubernetesClient client() {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    TestHelper.createCrd(kubernetesClient);

    return kubernetesClient;
}
 
Example 21
Source Project: vault-crd   Source File: PropertiesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KubernetesClient client() {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    TestHelper.createCrd(kubernetesClient);

    return kubernetesClient;
}
 
Example 22
Source Project: enmasse   Source File: Minikube.java    License: Apache License 2.0 5 votes vote down vote up
protected Minikube(Environment environment) {
    super(environment, () -> {
        Config config = new ConfigBuilder().build();
        OkHttpClient httpClient = HttpClientUtils.createHttpClient(config);
        // Workaround https://github.com/square/okhttp/issues/3146
        httpClient = httpClient.newBuilder()
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .connectTimeout(environment.getKubernetesApiConnectTimeout())
                .writeTimeout(environment.getKubernetesApiWriteTimeout())
                .readTimeout(environment.getKubernetesApiReadTimeout())
                .build();
        return new DefaultKubernetesClient(httpClient, config);
    });
}
 
Example 23
Source Project: vault-crd   Source File: PKIChainTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KubernetesClient client() {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    TestHelper.createCrd(kubernetesClient);

    return kubernetesClient;
}
 
Example 24
Source Project: module-ballerina-kubernetes   Source File: ServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void nodePortTest() throws IOException, InterruptedException, KubernetesPluginException,
        DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "node_port.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("node_port.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
    for (HasMetadata data : k8sItems) {
        if ("Service".equals(data.getKind())) {
            Service service = (Service) data;
            Assert.assertNotNull(service);
            Assert.assertEquals("hello", service.getMetadata().getName());
            Assert.assertEquals("node_port", service.getMetadata().getLabels().get(KubernetesConstants
                    .KUBERNETES_SELECTOR_KEY));
            Assert.assertEquals(KubernetesConstants.ServiceType.NodePort.name(), service.getSpec().getType());
            Assert.assertEquals(1, service.getSpec().getPorts().size());
            Assert.assertEquals(31100, service.getSpec().getPorts().get(0).getNodePort().intValue());
        }
    }

    validateDockerfile();
    validateDockerImage(DOCKER_IMAGE);

    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
 
Example 25
@Test(timeOut = 90000)
public void mainWithNoAnnotationTest() throws IOException, InterruptedException, DockerTestException,
        KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_annotations_main.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("no_annotations_main.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
    for (HasMetadata data : k8sItems) {
        if ("Job".equals(data.getKind())) {
            Job job = (Job) data;
            Assert.assertEquals(job.getMetadata().getName(), "no-annotations-main-job");
            Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1);

            Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
            Assert.assertEquals(container.getImage(), "no_annotations_main:latest");
            Assert.assertEquals(container.getImagePullPolicy(),
                    KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
            Assert.assertEquals(job.getSpec().getTemplate().getSpec()
                    .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name());
        }
    }
    
    validateDockerfile();
    
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage("no_annotations_main:latest");
}
 
Example 26
Source Project: module-ballerina-kubernetes   Source File: Sample8Test.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_config_map_k8s.bal")
            , 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_config_map_k8s.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "Deployment":
                deployment = (Deployment) data;
                break;
            case "ConfigMap":
                switch (data.getMetadata().getName()) {
                    case "helloworld-ballerina-conf-config-map":
                        ballerinaConf = (ConfigMap) data;
                        break;
                    case "helloworld-config-map":
                        dataMap = (ConfigMap) data;
                        break;
                    default:
                        break;
                }
                break;
            case "Service":
            case "Secret":
            case "Ingress":
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 27
Source Project: module-ballerina-kubernetes   Source File: Sample19Test.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KnativeTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_knative_config_map.bal")
            , 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve(KNATIVE).resolve("hello_world_knative_config_map.yaml")
            .toFile();
    Assert.assertTrue(artifactYaml.exists());
    Handlers.register(new KnativeTestUtils.ServiceHandler());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        switch (data.getKind()) {
            case "Service":
                this.knativeService = (Service) data;
                break;
            case "ConfigMap":
                switch (data.getMetadata().getName()) {
                    case "helloworld-ballerina-conf-config-map":
                        this.ballerinaConf = (ConfigMap) data;
                        break;
                    case "helloworld-config-map":
                        this.dataMap = (ConfigMap) data;
                        break;
                    default:
                        break;
                }
                break;
            default:
                Assert.fail("Unexpected k8s resource found: " + data.getKind());
                break;
        }
    }
}
 
Example 28
Source Project: module-ballerina-kubernetes   Source File: Sample11Test.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_job.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_job.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        if ("Job".equals(data.getKind())) {
            job = (Job) data;
        } else {
            Assert.fail("Unexpected k8s resource found: " + data.getKind());
        }
    }
}
 
Example 29
private KubernetesClient createClientFor(PluginSettings pluginSettings) {
    final ConfigBuilder configBuilder = new ConfigBuilder()
            .withOauthToken(pluginSettings.getSecurityToken())
            .withMasterUrl(pluginSettings.getClusterUrl())
            .withCaCertData(pluginSettings.getCaCertData())
            .withNamespace(pluginSettings.getNamespace());

    return new DefaultKubernetesClient(configBuilder.build());
}
 
Example 30
Source Project: microbean-helm   Source File: TestCharts.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRoundTrip() throws ExecutionException, IOException, InterruptedException {
  assumeFalse(Boolean.getBoolean("skipClusterTests"));
  try (final DefaultKubernetesClient client = new DefaultKubernetesClient();
       final Tiller tiller = new Tiller(client);
       final org.microbean.helm.ReleaseManager chartManager = new org.microbean.helm.ReleaseManager(tiller)) {
    final InstallReleaseRequest.Builder requestBuilder = InstallReleaseRequest.newBuilder();
    assertNotNull(requestBuilder);
    requestBuilder.setTimeout(300L);
    requestBuilder.setName("test-charts");
    requestBuilder.setWait(true);

    Chart.Builder chartBuilder = null;
    try (final AbstractChartLoader<URL> loader = new URLChartLoader()) {
      chartBuilder = loader.load(this.redisUrl);
    }
    assertNotNull(chartBuilder);
    
    final Future<InstallReleaseResponse> releaseFuture = chartManager.install(requestBuilder, chartBuilder);
    assertNotNull(releaseFuture);
    final Release release = releaseFuture.get().getRelease();
    assertNotNull(release);
    assertNotNull(release.getName());
    assertTrue(release.hasChart());
    assertTrue(release.hasConfig());

    final UninstallReleaseRequest.Builder uninstallRequestBuilder = UninstallReleaseRequest.newBuilder();
    assertNotNull(uninstallRequestBuilder);
    uninstallRequestBuilder.setTimeout(300L);
    uninstallRequestBuilder.setName("test-charts");
    uninstallRequestBuilder.setPurge(true);

    final Future<UninstallReleaseResponse> uninstallReleaseResponseFuture = chartManager.uninstall(uninstallRequestBuilder.build());
    assertNotNull(uninstallReleaseResponseFuture);
    final UninstallReleaseResponse response = uninstallReleaseResponseFuture.get();
    assertNotNull(response);
    assertNotNull(response.getRelease());
  }
}