use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class KubernetesClientUtil method resizeApp.
public static void resizeApp(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, int replicas, Logger log) {
for (HasMetadata entity : entities) {
String name = KubernetesHelper.getName(entity);
Scaleable<?> scalable = null;
if (entity instanceof Deployment) {
scalable = kubernetes.extensions().deployments().inNamespace(namespace).withName(name);
} else if (entity instanceof ReplicaSet) {
scalable = kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name);
} else if (entity instanceof ReplicationController) {
scalable = kubernetes.replicationControllers().inNamespace(namespace).withName(name);
} else if (entity instanceof DeploymentConfig) {
OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes);
if (openshiftClient == null) {
log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
continue;
}
scalable = openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name);
}
if (scalable != null) {
log.info("Scaling " + KubernetesHelper.getKind(entity) + " " + namespace + "/" + name + " to replicas: " + replicas);
scalable.scale(replicas, true);
}
}
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class DebugEnricher method enableDebug.
private boolean enableDebug(HasMetadata entity) {
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
return enableDebugging(entity, spec.getTemplate());
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
return enableDebugging(entity, spec.getTemplate());
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
return enableDebugging(entity, spec.getTemplate());
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
return enableDebugging(entity, spec.getTemplate());
}
}
return false;
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.
the class DeploymentTest method testDelete.
@Test
void testDelete() {
Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").addToLabels("key1", "value1").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key1", "value1").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
ReplicaSet replicaSet1 = new ReplicaSetBuilder().withNewMetadata().withName("rs1").addToLabels("key1", "value1").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key1", "value1").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
Deployment deployment2 = new DeploymentBuilder().withNewMetadata().withName("deployment2").addToLabels("key2", "value2").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key2", "value2").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, deployment1).once();
server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, new DeploymentBuilder(deployment1).editSpec().withReplicas(0).endSpec().build()).times(5);
server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets?labelSelector=key1%3Dvalue1").andReturn(200, new ReplicaSetListBuilder().addToItems(replicaSet1).build()).once();
server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/rs1").andReturn(200, replicaSet1).once();
server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, deployment2).once();
server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, new DeploymentBuilder(deployment2).editSpec().withReplicas(0).endSpec().build()).times(5);
Boolean deleted = client.apps().deployments().withName("deployment1").delete();
assertTrue(deleted);
deleted = client.apps().deployments().withName("deployment2").delete();
assertFalse(deleted);
deleted = client.apps().deployments().inNamespace("ns1").withName("deployment2").delete();
assertTrue(deleted);
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.
the class DeploymentTest method testDeploymentGetLog.
@Test
@DisplayName("Should get logs for a Deployment")
void testDeploymentGetLog() {
// Given
ReplicaSet replicaSet = createMockReplicaSet("deploy1", "136581bf-82c2-4675-af05-63c55500b378", "deploy1-hk9nf", Collections.singletonMap("app", "nginx"), "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4");
Pod deployPod = createMockPod("1", "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4", "deploy1-hk9nf", Collections.singletonMap("controller-uid", "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4"));
server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1").andReturn(HttpURLConnection.HTTP_OK, createDeploymentBuilder().build()).always();
server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets?labelSelector=app%3Dnginx").andReturn(HttpURLConnection.HTTP_OK, new ReplicaSetListBuilder().withItems(replicaSet).build()).once();
server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets/deploy1-hk9nf").andReturn(HttpURLConnection.HTTP_OK, replicaSet).once();
server.expect().get().withPath("/api/v1/namespaces/ns1/pods?labelSelector=app%3Dnginx").andReturn(HttpURLConnection.HTTP_OK, new PodListBuilder().withItems(deployPod).build()).once();
server.expect().get().withPath("/api/v1/namespaces/ns1/pods/deploy1-hk9nf/log?pretty=false").andReturn(HttpURLConnection.HTTP_OK, "hello").once();
// When
String log = client.apps().deployments().inNamespace("ns1").withName("deploy1").getLog();
// Then
assertNotNull(log);
assertEquals("hello", log);
}
use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.
the class ReplicaSetOperationsImpl method updateImage.
@Override
public ReplicaSet updateImage(String image) {
ReplicaSet oldRC = get();
if (oldRC == null) {
throw new KubernetesClientException("Existing replication controller doesn't exist");
}
if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) {
throw new KubernetesClientException("Image update is not supported for multicontainer pods");
}
if (oldRC.getSpec().getTemplate().getSpec().getContainers().isEmpty()) {
throw new KubernetesClientException("Pod has no containers!");
}
Container container = oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next();
return updateImage(Collections.singletonMap(container.getName(), image));
}
Aggregations