use of io.fabric8.kubernetes.api.model.apps.ReplicaSet 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.ReplicaSet in project halyard by spinnaker.
the class KubernetesV1DistributedService method getRunningServiceDetails.
@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails res = new RunningServiceDetails();
KubernetesClient client = KubernetesV1ProviderUtils.getClient(details);
String name = getServiceName();
String namespace = getNamespace(settings);
RunningServiceDetails.LoadBalancer lb = new RunningServiceDetails.LoadBalancer();
lb.setExists(client.services().inNamespace(namespace).withName(name).get() != null);
res.setLoadBalancer(lb);
List<Pod> pods = client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "true").list().getItems();
pods.addAll(client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "false").list().getItems());
Map<Integer, List<Instance>> instances = res.getInstances();
for (Pod pod : pods) {
String podName = pod.getMetadata().getName();
String serverGroupName = podName.substring(0, podName.lastIndexOf("-"));
Names parsedName = Names.parseName(serverGroupName);
Integer version = parsedName.getSequence();
if (version == null) {
throw new IllegalStateException("Server group for service " + getServiceName() + " has unknown sequence (" + serverGroupName + ")");
}
String location = pod.getMetadata().getNamespace();
String id = pod.getMetadata().getName();
Instance instance = new Instance().setId(id).setLocation(location);
List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(ContainerStatus::getReady)) {
instance.setHealthy(true);
}
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(s -> s.getState().getRunning() != null && s.getState().getTerminated() == null)) {
instance.setRunning(true);
}
List<Instance> knownInstances = instances.getOrDefault(version, new ArrayList<>());
knownInstances.add(instance);
instances.put(version, knownInstances);
}
List<ReplicaSet> replicaSets = client.extensions().replicaSets().inNamespace(settings.getLocation()).list().getItems();
for (ReplicaSet rs : replicaSets) {
String rsName = rs.getMetadata().getName();
Names parsedRsName = Names.parseName(rsName);
if (!parsedRsName.getCluster().equals(getServiceName())) {
continue;
}
instances.computeIfAbsent(parsedRsName.getSequence(), i -> new ArrayList<>());
}
return res;
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class ReplicaSetHandlerTest method replicaSetHandlerTest.
@Test
public void replicaSetHandlerTest() {
ContainerHandler containerHandler = getContainerHandler();
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
ReplicaSetHandler replicaSetHandler = new ReplicaSetHandler(podTemplateHandler);
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("testing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
ReplicaSet replicaSet = replicaSetHandler.getReplicaSet(config, images);
// Assertion
assertNotNull(replicaSet.getSpec());
assertNotNull(replicaSet.getMetadata());
assertEquals(5, replicaSet.getSpec().getReplicas().intValue());
assertNotNull(replicaSet.getSpec().getTemplate());
assertEquals("testing", replicaSet.getMetadata().getName());
assertEquals("test-account", replicaSet.getSpec().getTemplate().getSpec().getServiceAccountName());
assertFalse(replicaSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
assertEquals("test", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
assertEquals("/test/path", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
assertNotNull(replicaSet.getSpec().getTemplate().getSpec().getContainers());
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class ImageEnricherTest method checkEnrichReplicaSet.
@Test
public void checkEnrichReplicaSet() throws Exception {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new ReplicaSetBuilder().build());
imageEnricher.create(PlatformMode.kubernetes, builder);
assertCorrectlyGeneratedResources(builder.build(), "ReplicaSet");
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class TriggersAnnotationEnricherTest method testReplicaSetEnrichment.
@Test
public void testReplicaSetEnrichment() throws IOException {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new ReplicaSetBuilder().withNewSpec().withNewTemplate().withNewSpec().withContainers(createContainers("c1", "is", "c2", "a-docker-user/is:latest")).endSpec().endTemplate().endSpec().build());
TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
enricher.enrich(PlatformMode.kubernetes, builder);
ReplicaSet res = (ReplicaSet) builder.build().getItems().get(0);
String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
assertNotNull(triggers);
List<ImageChangeTrigger> triggerList = OBJECT_MAPPER.readValue(triggers, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, ImageChangeTrigger.class));
assertEquals(1, triggerList.size());
ImageChangeTrigger trigger = triggerList.get(0);
assertEquals("ImageStreamTag", trigger.getFrom().getKind());
assertEquals("is:latest", trigger.getFrom().getName());
assertTrue(trigger.getAdditionalProperties().containsKey("fieldPath"));
}
Aggregations