use of io.fabric8.kubernetes.api.model.apps.StatefulSetSpec in project fabric8-maven-plugin by fabric8io.
the class DefaultControllerEnricher method addMissingResources.
@Override
public void addMissingResources(KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
final List<ImageConfiguration> images = getImages();
// 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 (!Lists.isNullOrEmpty(images)) {
String type = getConfig(Config.type);
if ("deployment".equalsIgnoreCase(type)) {
log.info("Adding a default Deployment");
builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
} else if ("statefulSet".equalsIgnoreCase(type)) {
log.info("Adding a default StatefulSet");
builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
} else if ("daemonSet".equalsIgnoreCase(type)) {
log.info("Adding a default DaemonSet");
builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
} else if ("replicaSet".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicaSet");
builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
} else if ("replicationController".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicationController");
builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
} else if ("job".equalsIgnoreCase(type)) {
log.info("Adding a default Job");
builder.addToJobItems(jobHandler.getJob(config, images));
}
}
} else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<StatefulSetBuilder>() {
@Override
public void visit(StatefulSetBuilder statefulSetBuilder) {
statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeStatefulSetSpec(statefulSetBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
} else {
final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeDeploymentSpec(deploymentBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
}
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetSpec 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.StatefulSetSpec in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockTest method testReconcileUpdatesKafkaStorageType.
@ParameterizedTest
@MethodSource("data")
public void testReconcileUpdatesKafkaStorageType(Params params, VertxTestContext context) {
init(params);
AtomicReference<List<PersistentVolumeClaim>> originalPVCs = new AtomicReference<>();
AtomicReference<List<Volume>> originalVolumes = new AtomicReference<>();
AtomicReference<List<Container>> originalInitContainers = new AtomicReference<>();
Checkpoint async = context.checkpoint();
initialReconcile(context).onComplete(context.succeeding(v -> context.verify(() -> {
originalPVCs.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getVolumeClaimTemplates).orElse(new ArrayList<>()));
originalVolumes.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getVolumes).orElse(new ArrayList<>()));
originalInitContainers.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getInitContainers).orElse(new ArrayList<>()));
// Update the storage type
// ephemeral -> persistent
// or
// persistent -> ephemeral
Kafka updatedStorageKafka = null;
if (kafkaStorage instanceof EphemeralStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewPersistentClaimStorage().withSize("123").endPersistentClaimStorage().endKafka().endSpec().build();
} else if (kafkaStorage instanceof PersistentClaimStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewEphemeralStorage().endEphemeralStorage().endKafka().endSpec().build();
} else {
context.failNow(new Exception("If storage is not ephemeral or persistent something has gone wrong"));
}
kafkaAssembly(NAMESPACE, CLUSTER_NAME).patch(updatedStorageKafka);
LOGGER.info("Updating with changed storage type");
}))).compose(v -> operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME))).onComplete(context.succeeding(v -> context.verify(() -> {
// Check the Volumes and PVCs were not changed
assertPVCs(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalPVCs.get());
assertVolumes(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalVolumes.get());
assertInitContainers(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalInitContainers.get());
async.flag();
})));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetSpec in project strimzi-kafka-operator by strimzi.
the class KafkaAssemblyOperatorMockTest method testReconcileUpdatesKafkaStorageType.
@ParameterizedTest
@MethodSource("data")
public void testReconcileUpdatesKafkaStorageType(Params params, VertxTestContext context) {
init(params);
AtomicReference<List<PersistentVolumeClaim>> originalPVCs = new AtomicReference<>();
AtomicReference<List<Volume>> originalVolumes = new AtomicReference<>();
AtomicReference<List<Container>> originalInitContainers = new AtomicReference<>();
Checkpoint async = context.checkpoint();
initialReconcile(context).onComplete(context.succeeding(v -> context.verify(() -> {
originalPVCs.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getVolumeClaimTemplates).orElse(new ArrayList<>()));
originalVolumes.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getVolumes).orElse(new ArrayList<>()));
originalInitContainers.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getInitContainers).orElse(new ArrayList<>()));
// Update the storage type
// ephemeral -> persistent
// or
// persistent -> ephemeral
Kafka updatedStorageKafka = null;
if (kafkaStorage instanceof EphemeralStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewPersistentClaimStorage().withSize("123").endPersistentClaimStorage().endKafka().endSpec().build();
} else if (kafkaStorage instanceof PersistentClaimStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewEphemeralStorage().endEphemeralStorage().endKafka().endSpec().build();
} else {
context.failNow(new Exception("If storage is not ephemeral or persistent something has gone wrong"));
}
kafkaAssembly(NAMESPACE, CLUSTER_NAME).patch(updatedStorageKafka);
LOGGER.info("Updating with changed storage type");
}))).compose(v -> operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME))).onComplete(context.succeeding(v -> context.verify(() -> {
// Check the Volumes and PVCs were not changed
assertPVCs(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalPVCs.get());
assertVolumes(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalVolumes.get());
assertInitContainers(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalInitContainers.get());
async.flag();
})));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetSpec 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