use of io.fabric8.kubernetes.api.model.PodTemplate in project flink by apache.
the class KubernetesJobManagerFactoryWithPodTemplateTest method getResultPod.
@Override
protected Pod getResultPod(FlinkPod podTemplate) throws Exception {
final KubernetesJobManagerParameters kubernetesJobManagerParameters = new KubernetesJobManagerParameters(flinkConfig, new KubernetesClusterClientFactory().getClusterSpecification(flinkConfig));
final KubernetesJobManagerSpecification kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(podTemplate, kubernetesJobManagerParameters);
final PodTemplateSpec podTemplateSpec = kubernetesJobManagerSpecification.getDeployment().getSpec().getTemplate();
return new PodBuilder().withMetadata(podTemplateSpec.getMetadata()).withSpec(podTemplateSpec.getSpec()).build();
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8-maven-plugin by fabric8io.
the class AutoTLSEnricherTest method testAdapt.
@Test
public void testAdapt() throws Exception {
final AdaptTestConfig[] data = new AdaptTestConfig[] { new AdaptTestConfig(PlatformMode.kubernetes, null, null, null, null, null, null, null, null), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(PlatformMode.openshift, "test-container-name", "test-container-name", "image/123", "image/123", "tls-a", "tls-a", "jks-b", "jks-b") };
for (final AdaptTestConfig tc : data) {
TreeMap configMap = new TreeMap() {
{
put(AutoTLSEnricher.Config.pemToJKSInitContainerName.name(), tc.initContainerNameConfig);
put(AutoTLSEnricher.Config.pemToJKSInitContainerImage.name(), tc.initContainerImageConfig);
put(AutoTLSEnricher.Config.tlsSecretVolumeName.name(), tc.tlsSecretVolumeNameConfig);
put(AutoTLSEnricher.Config.jksVolumeName.name(), tc.jksVolumeNameConfig);
}
};
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, configMap));
final Properties projectProps = new Properties();
projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
// Setup mock behaviour
new Expectations() {
{
project.getProperties();
result = projectProps;
project.getArtifactId();
result = "projectA";
minTimes = 0;
context.getProject();
result = project;
context.getConfig();
result = config;
}
};
AutoTLSEnricher enricher = new AutoTLSEnricher(context);
KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and();
enricher.adapt(klb);
PodTemplate pt = (PodTemplate) klb.getItems().get(0);
String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
assertEquals(tc.mode == PlatformMode.openshift, initContainers != null);
if (tc.mode == PlatformMode.kubernetes) {
continue;
}
JSONArray ja = new JSONArray(initContainers);
assertEquals(1, ja.length());
JSONObject jo = ja.getJSONObject(0);
assertEquals(tc.initContainerName, jo.get("name"));
assertEquals(tc.initContainerImage, jo.get("image"));
JSONArray mounts = jo.getJSONArray("volumeMounts");
assertEquals(2, mounts.length());
JSONObject mount = mounts.getJSONObject(0);
assertEquals(tc.tlsSecretVolumeName, mount.get("name"));
mount = mounts.getJSONObject(1);
assertEquals(tc.jksVolumeName, mount.get("name"));
}
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8-maven-plugin by fabric8io.
the class VolumePermissionEnricherTest method testAdapt.
@Test
public void testAdapt() throws Exception {
final TestConfig[] data = new TestConfig[] { new TestConfig(null, null), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") };
for (final TestConfig tc : data) {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(VolumePermissionEnricher.Config.permission.name(), tc.permission))));
// Setup mock behaviour
new Expectations() {
{
context.getConfig();
result = config;
}
};
VolumePermissionEnricher enricher = new VolumePermissionEnricher(context);
PodTemplateBuilder ptb = createEmptyPodTemplate();
for (String vn : tc.volumeNames) {
ptb = addVolume(ptb, vn);
}
KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
enricher.adapt(klb);
PodTemplate pt = (PodTemplate) klb.buildItem(0);
String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
assertEquals(shouldHaveInitContainer, initContainers != null);
if (!shouldHaveInitContainer) {
continue;
}
JSONArray ja = new JSONArray(initContainers);
assertEquals(1, ja.length());
JSONObject jo = ja.getJSONObject(0);
assertEquals(tc.initContainerName, jo.get("name"));
String permission = Strings.isNullOrBlank(tc.permission) ? "777" : tc.permission;
JSONArray chmodCmd = new JSONArray();
chmodCmd.put("chmod");
chmodCmd.put(permission);
for (String vn : tc.volumeNames) {
chmodCmd.put("/tmp/" + vn);
}
assertEquals(chmodCmd.toString(), jo.getJSONArray("command").toString());
}
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project flink by apache.
the class KubernetesTaskManagerFactory method buildTaskManagerKubernetesPod.
public static KubernetesPod buildTaskManagerKubernetesPod(FlinkPod podTemplate, KubernetesTaskManagerParameters kubernetesTaskManagerParameters) {
FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitTaskManagerDecorator(kubernetesTaskManagerParameters), new EnvSecretsDecorator(kubernetesTaskManagerParameters), new MountSecretsDecorator(kubernetesTaskManagerParameters), new CmdTaskManagerDecorator(kubernetesTaskManagerParameters), new HadoopConfMountDecorator(kubernetesTaskManagerParameters), new KerberosMountDecorator(kubernetesTaskManagerParameters), new FlinkConfMountDecorator(kubernetesTaskManagerParameters) };
for (KubernetesStepDecorator stepDecorator : stepDecorators) {
flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
}
final Pod resolvedPod = new PodBuilder(flinkPod.getPodWithoutMainContainer()).editOrNewSpec().addToContainers(flinkPod.getMainContainer()).endSpec().build();
return new KubernetesPod(resolvedPod);
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project keycloak by keycloak.
the class PodTemplateTest method testEnvVarsAreMerged.
@Test
public void testEnvVarsAreMerged() {
// Arrange
var env = "KC_SOMETHING";
var value = "some-value";
var additionalPodTemplate = new PodTemplateSpecBuilder().withNewSpec().addNewContainer().addNewEnv().withName(env).withValue(value).endEnv().endContainer().endSpec().build();
// Act
var podTemplate = getDeployment(additionalPodTemplate).getSpec().getTemplate();
// Assert
var envVar = podTemplate.getSpec().getContainers().get(0).getEnv().stream().filter(e -> e.getName().equals(env)).findFirst().get();
assertEquals(env, envVar.getName());
assertEquals(value, envVar.getValue());
}
Aggregations