Search in sources :

Example 51 with HasMetadata

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

the class KubernetesHelper method findKubernetesResourcesOnClasspath.

/**
 * Returns the kubernetes resources on the classpath of the current project
 */
public static List<HasMetadata> findKubernetesResourcesOnClasspath(Controller controller) throws IOException {
    String resourceName = "kubernetes.yml";
    OpenShiftClient openShiftClient = controller.getOpenShiftClientOrNull();
    if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE) && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.ROUTE)) {
        resourceName = "openshift.yml";
    }
    URL configUrl = findConfigResource("/META-INF/fabric8/" + resourceName);
    if (configUrl == null) {
        configUrl = findConfigResource("kubernetes.json");
    }
    if (configUrl != null) {
        String configText = IOHelpers.loadFully(configUrl);
        Object dto = null;
        String configPath = configUrl.getPath();
        if (configPath.endsWith(".yml") || configPath.endsWith(".yaml")) {
            dto = loadYaml(configText, KubernetesResource.class);
        } else {
            dto = loadJson(configText);
        }
        KubernetesList kubeList = KubernetesHelper.asKubernetesList(dto);
        List<HasMetadata> items = kubeList.getItems();
        return items;
    } else {
        return new ArrayList<>();
    }
}
Also used : DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) FileObject(javax.tools.FileObject) URL(java.net.URL)

Example 52 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project vertx-openshift-it by cescoffier.

the class OpenShiftTestAssistant method deployApplication.

public String deployApplication() throws IOException {
    applicationName = System.getProperty("app.name");
    List<? extends HasMetadata> entities = deploy("application", new File("target/classes/META-INF/fabric8/openshift.yml"));
    Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
    if (applicationName == null && first.isPresent()) {
        applicationName = first.get();
    }
    Route route = client.adapt(OpenShiftClient.class).routes().inNamespace(project).withName(applicationName).get();
    assertThat(route).isNotNull();
    RestAssured.baseURI = "http://" + Objects.requireNonNull(route).getSpec().getHost();
    System.out.println("Route url: " + RestAssured.baseURI);
    return applicationName;
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Awaitility.await(org.awaitility.Awaitility.await) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Route(io.fabric8.openshift.api.model.Route) Map(java.util.Map) Optional(java.util.Optional) RestAssured(io.restassured.RestAssured) Comparator(java.util.Comparator) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) File(java.io.File) Route(io.fabric8.openshift.api.model.Route)

Example 53 with HasMetadata

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

the class HadoopConfMountDecorator method buildAccompanyingKubernetesResources.

@Override
public List<HasMetadata> buildAccompanyingKubernetesResources() throws IOException {
    if (kubernetesParameters.getExistingHadoopConfigurationConfigMap().isPresent()) {
        return Collections.emptyList();
    }
    final Optional<String> localHadoopConfigurationDirectory = kubernetesParameters.getLocalHadoopConfigurationDirectory();
    if (!localHadoopConfigurationDirectory.isPresent()) {
        return Collections.emptyList();
    }
    final List<File> hadoopConfigurationFileItems = getHadoopConfigurationFileItems(localHadoopConfigurationDirectory.get());
    if (hadoopConfigurationFileItems.isEmpty()) {
        LOG.warn("Found 0 files in directory {}, skip to create the Hadoop Configuration ConfigMap.", localHadoopConfigurationDirectory.get());
        return Collections.emptyList();
    }
    final Map<String, String> data = new HashMap<>();
    for (File file : hadoopConfigurationFileItems) {
        data.put(file.getName(), FileUtils.readFileUtf8(file));
    }
    final ConfigMap hadoopConfigMap = new ConfigMapBuilder().withApiVersion(Constants.API_VERSION).withNewMetadata().withName(getHadoopConfConfigMapName(kubernetesParameters.getClusterId())).withLabels(kubernetesParameters.getCommonLabels()).endMetadata().addToData(data).build();
    return Collections.singletonList(hadoopConfigMap);
}
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 54 with HasMetadata

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

the class KerberosMountDecorator method buildAccompanyingKubernetesResources.

@Override
public List<HasMetadata> buildAccompanyingKubernetesResources() throws IOException {
    final List<HasMetadata> resources = new ArrayList<>();
    if (!StringUtils.isNullOrWhitespaceOnly(securityConfig.getKeytab()) && !StringUtils.isNullOrWhitespaceOnly(securityConfig.getPrincipal())) {
        final File keytab = new File(securityConfig.getKeytab());
        if (!keytab.exists()) {
            LOG.warn("Could not found the kerberos keytab file in {}.", keytab.getAbsolutePath());
        } else {
            resources.add(new SecretBuilder().withNewMetadata().withName(getKerberosKeytabSecretName(kubernetesParameters.getClusterId())).endMetadata().addToData(keytab.getName(), Base64.getEncoder().encodeToString(Files.toByteArray(keytab))).build());
            // Set keytab path in the container. One should make sure this decorator is
            // triggered before FlinkConfMountDecorator.
            kubernetesParameters.getFlinkConfiguration().set(SecurityOptions.KERBEROS_LOGIN_KEYTAB, String.format("%s/%s", Constants.KERBEROS_KEYTAB_MOUNT_POINT, keytab.getName()));
        }
    }
    if (!StringUtils.isNullOrWhitespaceOnly(kubernetesParameters.getFlinkConfiguration().get(SecurityOptions.KERBEROS_KRB5_PATH))) {
        final File krb5Conf = new File(kubernetesParameters.getFlinkConfiguration().get(SecurityOptions.KERBEROS_KRB5_PATH));
        if (!krb5Conf.exists()) {
            LOG.warn("Could not found the kerberos config file in {}.", krb5Conf.getAbsolutePath());
        } else {
            resources.add(new ConfigMapBuilder().withNewMetadata().withName(getKerberosKrb5confConfigMapName(kubernetesParameters.getClusterId())).endMetadata().addToData(krb5Conf.getName(), Files.toString(krb5Conf, StandardCharsets.UTF_8)).build());
        }
    }
    return resources;
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ArrayList(java.util.ArrayList) File(java.io.File)

Example 55 with HasMetadata

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

the class KubernetesJobManagerFactory method buildKubernetesJobManagerSpecification.

public static KubernetesJobManagerSpecification buildKubernetesJobManagerSpecification(FlinkPod podTemplate, KubernetesJobManagerParameters kubernetesJobManagerParameters) throws IOException {
    FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
    List<HasMetadata> accompanyingResources = new ArrayList<>();
    final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitJobManagerDecorator(kubernetesJobManagerParameters), new EnvSecretsDecorator(kubernetesJobManagerParameters), new MountSecretsDecorator(kubernetesJobManagerParameters), new CmdJobManagerDecorator(kubernetesJobManagerParameters), new InternalServiceDecorator(kubernetesJobManagerParameters), new ExternalServiceDecorator(kubernetesJobManagerParameters), new HadoopConfMountDecorator(kubernetesJobManagerParameters), new KerberosMountDecorator(kubernetesJobManagerParameters), new FlinkConfMountDecorator(kubernetesJobManagerParameters), new PodTemplateMountDecorator(kubernetesJobManagerParameters) };
    for (KubernetesStepDecorator stepDecorator : stepDecorators) {
        flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
        accompanyingResources.addAll(stepDecorator.buildAccompanyingKubernetesResources());
    }
    final Deployment deployment = createJobManagerDeployment(flinkPod, kubernetesJobManagerParameters);
    return new KubernetesJobManagerSpecification(deployment, accompanyingResources);
}
Also used : InternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InternalServiceDecorator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KubernetesStepDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator) EnvSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.EnvSecretsDecorator) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) InitJobManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InitJobManagerDecorator) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PodTemplateMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.PodTemplateMountDecorator) FlinkConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator) HadoopConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator) CmdJobManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.CmdJobManagerDecorator) KerberosMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator) ExternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator) KubernetesJobManagerSpecification(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification) MountSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.MountSecretsDecorator)

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