Search in sources :

Example 56 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project flink by apache.

the class FlinkConfMountDecorator method buildAccompanyingKubernetesResources.

@Override
public List<HasMetadata> buildAccompanyingKubernetesResources() throws IOException {
    final String clusterId = kubernetesComponentConf.getClusterId();
    final Map<String, String> data = new HashMap<>();
    final List<File> localLogFiles = getLocalLogConfFiles();
    for (File file : localLogFiles) {
        data.put(file.getName(), Files.toString(file, StandardCharsets.UTF_8));
    }
    final Map<String, String> propertiesMap = getClusterSidePropertiesMap(kubernetesComponentConf.getFlinkConfiguration());
    data.put(FLINK_CONF_FILENAME, getFlinkConfData(propertiesMap));
    final ConfigMap flinkConfConfigMap = new ConfigMapBuilder().withApiVersion(Constants.API_VERSION).withNewMetadata().withName(getFlinkConfConfigMapName(clusterId)).withLabels(kubernetesComponentConf.getCommonLabels()).endMetadata().addToData(data).build();
    return Collections.singletonList(flinkConfConfigMap);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) File(java.io.File)

Example 57 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project flink by apache.

the class PodTemplateMountDecorator method buildAccompanyingKubernetesResources.

@Override
public List<HasMetadata> buildAccompanyingKubernetesResources() throws IOException {
    return getTaskManagerPodTemplateFile().map(FunctionUtils.uncheckedFunction(file -> {
        final Map<String, String> data = new HashMap<>();
        data.put(TASK_MANAGER_POD_TEMPLATE_FILE_NAME, Files.toString(file, StandardCharsets.UTF_8));
        final HasMetadata flinkConfConfigMap = new ConfigMapBuilder().withApiVersion(Constants.API_VERSION).withNewMetadata().withName(podTemplateConfigMapName).withLabels(kubernetesComponentConf.getCommonLabels()).endMetadata().addToData(data).build();
        return Collections.singletonList(flinkConfConfigMap);
    })).orElse(Collections.emptyList());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 58 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project flink by apache.

the class ExternalServiceDecoratorTest method testBuildAccompanyingKubernetesResources.

@Test
public void testBuildAccompanyingKubernetesResources() throws IOException {
    final List<HasMetadata> resources = this.externalServiceDecorator.buildAccompanyingKubernetesResources();
    assertEquals(1, resources.size());
    final Service restService = (Service) resources.get(0);
    assertEquals(Constants.API_VERSION, restService.getApiVersion());
    assertEquals(ExternalServiceDecorator.getExternalServiceName(CLUSTER_ID), restService.getMetadata().getName());
    final Map<String, String> expectedLabels = getCommonLabels();
    assertEquals(expectedLabels, restService.getMetadata().getLabels());
    assertEquals(KubernetesConfigOptions.ServiceExposedType.ClusterIP.name(), restService.getSpec().getType());
    final List<ServicePort> expectedServicePorts = Collections.singletonList(new ServicePortBuilder().withName(Constants.REST_PORT_NAME).withPort(REST_PORT).withNewTargetPort(Integer.valueOf(REST_BIND_PORT)).build());
    assertEquals(expectedServicePorts, restService.getSpec().getPorts());
    expectedLabels.put(Constants.LABEL_COMPONENT_KEY, Constants.LABEL_COMPONENT_JOB_MANAGER);
    assertEquals(expectedLabels, restService.getSpec().getSelector());
    final Map<String, String> resultAnnotations = restService.getMetadata().getAnnotations();
    assertThat(resultAnnotations, is(equalTo(customizedAnnotations)));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) HeadlessClusterIPService(org.apache.flink.kubernetes.kubeclient.services.HeadlessClusterIPService) Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Example 59 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project flink by apache.

the class HadoopConfMountDecoratorTest method testHadoopConfConfigMap.

@Test
public void testHadoopConfConfigMap() throws IOException {
    setHadoopConfDirEnv();
    generateHadoopConfFileItems();
    final List<HasMetadata> additionalResources = hadoopConfMountDecorator.buildAccompanyingKubernetesResources();
    assertEquals(1, additionalResources.size());
    final ConfigMap resultConfigMap = (ConfigMap) additionalResources.get(0);
    assertEquals(Constants.API_VERSION, resultConfigMap.getApiVersion());
    assertEquals(HadoopConfMountDecorator.getHadoopConfConfigMapName(CLUSTER_ID), resultConfigMap.getMetadata().getName());
    assertEquals(getCommonLabels(), resultConfigMap.getMetadata().getLabels());
    Map<String, String> resultDatas = resultConfigMap.getData();
    assertEquals("some data", resultDatas.get("core-site.xml"));
    assertEquals("some data", resultDatas.get("hdfs-site.xml"));
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 60 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project flink by apache.

the class Fabric8FlinkKubeClient method setOwnerReference.

private void setOwnerReference(Deployment deployment, List<HasMetadata> resources) {
    final OwnerReference deploymentOwnerReference = new OwnerReferenceBuilder().withName(deployment.getMetadata().getName()).withApiVersion(deployment.getApiVersion()).withUid(deployment.getMetadata().getUid()).withKind(deployment.getKind()).withController(true).withBlockOwnerDeletion(true).build();
    resources.forEach(resource -> resource.getMetadata().setOwnerReferences(Collections.singletonList(deploymentOwnerReference)));
}
Also used : OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)90 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 File (java.io.File)24 IOException (java.io.IOException)24 Template (io.fabric8.openshift.api.model.Template)19 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)18 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)17 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)16 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)14 Service (io.fabric8.kubernetes.api.model.Service)14 URL (java.net.URL)11 HashMap (java.util.HashMap)11 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)10 Map (java.util.Map)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9