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<>();
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations