use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method getPodLabelSelector.
public static LabelSelector getPodLabelSelector(HasMetadata entity) {
LabelSelector selector = null;
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
selector = toLabelSelector(spec.getSelector());
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
selector = toLabelSelector(spec.getSelector());
}
} else if (entity instanceof DaemonSet) {
DaemonSet resource = (DaemonSet) entity;
DaemonSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof StatefulSet) {
StatefulSet resource = (StatefulSet) entity;
StatefulSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof Job) {
Job resource = (Job) entity;
JobSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
}
return selector;
}
use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project fabric8-maven-plugin by fabric8io.
the class DefaultControllerEnricher method create.
@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
ResourceConfig xmlResourceConfig = getConfiguration().getResource().orElse(null);
ResourceConfig config = new ResourceConfig.Builder(xmlResourceConfig).controllerName(name).imagePullPolicy(getImagePullPolicy(xmlResourceConfig, getConfig(Config.pullPolicy))).withReplicas(getReplicaCount(builder, xmlResourceConfig, Configs.asInt(getConfig(Config.replicaCount)))).build();
final List<ImageConfiguration> images = getImages().orElse(Collections.emptyList());
// Check if at least a replica set is added. If not add a default one
if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
// At least one image must be present, otherwise the resulting config will be invalid
if (!images.isEmpty()) {
String type = getConfig(Config.type);
if ("deployment".equalsIgnoreCase(type) || "deploymentConfig".equalsIgnoreCase(type)) {
if (platformMode == PlatformMode.kubernetes || (platformMode == PlatformMode.openshift && useDeploymentforOpenShift())) {
log.info("Adding a default Deployment");
Deployment deployment = deployHandler.getDeployment(config, images);
builder.addToItems(deployment);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(deployment.getSpec().getTemplate()));
} else {
log.info("Adding a default DeploymentConfig");
DeploymentConfig deploymentConfig = deployConfigHandler.getDeploymentConfig(config, images, getOpenshiftDeployTimeoutInSeconds(3600L), getValueFromConfig(IMAGE_CHANGE_TRIGGERS, true), getValueFromConfig(OPENSHIFT_ENABLE_AUTOMATIC_TRIGGER, true), isOpenShiftMode(), getProcessingInstructionViaKey(FABRIC8_GENERATED_CONTAINERS));
builder.addToItems(deploymentConfig);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(deploymentConfig.getSpec().getTemplate()));
}
} else if ("statefulSet".equalsIgnoreCase(type)) {
log.info("Adding a default StatefulSet");
StatefulSet statefulSet = statefulSetHandler.getStatefulSet(config, images);
builder.addToItems(statefulSet);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(statefulSet.getSpec().getTemplate()));
} else if ("daemonSet".equalsIgnoreCase(type)) {
log.info("Adding a default DaemonSet");
DaemonSet daemonSet = daemonSetHandler.getDaemonSet(config, images);
builder.addToItems(daemonSet);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(daemonSet.getSpec().getTemplate()));
} else if ("replicaSet".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicaSet");
ReplicaSet replicaSet = rsHandler.getReplicaSet(config, images);
builder.addToItems(replicaSet);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(replicaSet.getSpec().getTemplate()));
} else if ("replicationController".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicationController");
ReplicationController replicationController = rcHandler.getReplicationController(config, images);
builder.addToReplicationControllerItems(replicationController);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(replicationController.getSpec().getTemplate()));
} else if ("job".equalsIgnoreCase(type)) {
log.info("Adding a default Job");
Job job = jobHandler.getJob(config, images);
builder.addToItems(job);
setProcessingInstruction(FABRIC8_GENERATED_CONTAINERS, getContainersFromPodSpec(job.getSpec().getTemplate()));
}
}
}
}
use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project kubernetes-client by fabric8io.
the class DaemonSetIT method update.
@Test
public void update() {
DaemonSet daemonSet = client.apps().daemonSets().inNamespace(session.getNamespace()).withName("daemonset-update").edit(c -> new DaemonSetBuilder(c).editSpec().editTemplate().editSpec().editContainer(0).withImage("quay.io/fluentd_elasticsearch/fluentd:v3.0.0").endContainer().endSpec().endTemplate().endSpec().build());
assertNotNull(daemonSet);
assertEquals("quay.io/fluentd_elasticsearch/fluentd:v3.0.0", daemonSet.getSpec().getTemplate().getSpec().getContainers().get(0).getImage());
}
use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project elastest-torm by elastest.
the class K8sService method createDaemonSetFromContainerInfo.
public boolean createDaemonSetFromContainerInfo(DockerContainer container, String namespace) {
Boolean created = false;
try {
logger.info("Creating Daemon Set from container name {} in namespace {}", container.getContainerName().get(), namespace);
if (container.getCmd().isPresent()) {
logger.info(String.join(",", container.getCmd().get()));
}
String containerNameWithoutUnderscore = container.getContainerName().get().replace("_", "-");
Map<String, String> k8sPobLabels = container.getLabels().get();
k8sPobLabels.put(LABEL_POD_NAME, container.getContainerName().get());
k8sPobLabels.put(LABEL_COMPONENT, containerNameWithoutUnderscore);
// Create Container
ContainerBuilder containerBuilder = new ContainerBuilder();
containerBuilder.withName(containerNameWithoutUnderscore).withImage(container.getImageId()).withEnv(getEnvVarListFromStringList(container.getEnvs().get()));
// Add ports
if (container.getExposedPorts().isPresent() && !container.getExposedPorts().get().isEmpty()) {
List<ContainerPort> ports = new ArrayList<>();
container.getExposedPorts().get().forEach(port -> {
ContainerPort containerPort = new ContainerPort();
containerPort.setContainerPort(new Integer(port));
ports.add(containerPort);
});
containerBuilder.withPorts(ports);
}
if (container.getCapAdd().isPresent() && !container.getCapAdd().get().isEmpty()) {
SecurityContextBuilder securityContextBuilder = new SecurityContextBuilder();
List<String> stringCapabilities = new ArrayList<>();
container.getCapAdd().get().forEach(cap -> {
stringCapabilities.add(cap);
});
Capabilities capabilities = new CapabilitiesBuilder().withAdd(stringCapabilities).build();
securityContextBuilder.withCapabilities(capabilities);
containerBuilder.withSecurityContext(securityContextBuilder.build());
}
// Add volumes if there are
List<Volume> volumes = new ArrayList<>();
List<VolumeMount> volumeMounts = new ArrayList<>();
if (container.getVolumeBindList().isPresent() && !container.getVolumeBindList().get().isEmpty()) {
int count = 0;
for (Bind dockerVolume : container.getVolumeBindList().get()) {
VolumeMount volumeMount = new VolumeMountBuilder().withName("v-" + count).withMountPath(dockerVolume.to()).build();
volumeMounts.add(volumeMount);
HostPathVolumeSource hostPath = new HostPathVolumeSourceBuilder().withPath(dockerVolume.to()).build();
Volume volume = new VolumeBuilder().withName("v-" + count).withHostPath(hostPath).build();
volumes.add(volume);
count++;
}
containerBuilder.withVolumeMounts(volumeMounts);
}
LabelSelectorBuilder selectorBuilder = new LabelSelectorBuilder();
LabelSelector labelSelector = selectorBuilder.withMatchLabels(Collections.singletonMap(LABEL_COMPONENT, containerNameWithoutUnderscore)).build();
// String dName = "daemonset-" + containerNameWithoutUnderscore;
DaemonSet daemonSet = new DaemonSetBuilder().withNewMetadata().withName(containerNameWithoutUnderscore).withNamespace(namespace).withLabels(k8sPobLabels).endMetadata().withNewSpec().withSelector(labelSelector).withNewTemplate().withNewMetadata().withLabels(k8sPobLabels).endMetadata().withNewSpec().addNewContainerLike(containerBuilder.build()).endContainer().withVolumes(volumes).endSpec().endTemplate().endSpec().build();
client.apps().daemonSets().create(daemonSet);
client.apps().daemonSets().inNamespace(namespace).withName(containerNameWithoutUnderscore).cascading(true);
} catch (Exception e) {
logger.error("Error deploying DaemonSet");
e.printStackTrace();
throw e;
}
return created;
}
use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method getPodLabelSelector.
public static LabelSelector getPodLabelSelector(HasMetadata entity) {
LabelSelector selector = null;
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
selector = toLabelSelector(spec.getSelector());
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
selector = toLabelSelector(spec.getSelector());
}
} else if (entity instanceof DaemonSet) {
DaemonSet resource = (DaemonSet) entity;
DaemonSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof StatefulSet) {
StatefulSet resource = (StatefulSet) entity;
StatefulSetSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
} else if (entity instanceof Job) {
Job resource = (Job) entity;
JobSpec spec = resource.getSpec();
if (spec != null) {
selector = spec.getSelector();
}
}
return selector;
}
Aggregations