use of io.fabric8.kubernetes.api.Controller 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 = 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 = new Controller(kubernetes).getOpenShiftClientOrNull();
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 " + getKind(entity) + " " + namespace + "/" + name + " to replicas: " + replicas);
scalable.scale(replicas, true);
}
}
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class KubernetesClientUtil method deleteEntities.
public static void deleteEntities(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, String s2iBuildNameSuffix, Logger log) {
List<HasMetadata> list = new ArrayList<>(entities);
// For OpenShift cluster, also delete s2i buildconfig
OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
if (openshiftClient != null) {
for (HasMetadata entity : list) {
if ("ImageStream".equals(getKind(entity))) {
ImageName imageName = new ImageName(entity.getMetadata().getName());
String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
log.info("Deleting resource BuildConfig " + namespace + "/" + buildName);
openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
}
}
}
// lets delete in reverse order
Collections.reverse(list);
for (HasMetadata entity : list) {
log.info("Deleting resource " + getKind(entity) + " " + namespace + "/" + getName(entity));
kubernetes.resource(entity).inNamespace(namespace).cascading(true).delete();
}
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class DaemonSetHandlerTest method daemonTemplateHandlerWithoutControllerTest.
@Test(expected = IllegalArgumentException.class)
public void daemonTemplateHandlerWithoutControllerTest() {
// without controller name
ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
DaemonSetHandler daemonSetHandler = new DaemonSetHandler(podTemplateHandler);
// without controller name
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").volumes(volumes1).build();
daemonSetHandler.getDaemonSet(config, images);
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class DeploymentHandlerTest method deploymentTemplateHandlerWithoutControllerTest.
@Test(expected = IllegalArgumentException.class)
public void deploymentTemplateHandlerWithoutControllerTest() {
// without controller name
ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
DeploymentHandler deploymentHandler = new DeploymentHandler(podTemplateHandler);
// without controller name
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
deploymentHandler.getDeployment(config, images);
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class JobHandlerTest method daemonTemplateHandlerWithoutControllerTest.
@Test(expected = IllegalArgumentException.class)
public void daemonTemplateHandlerWithoutControllerTest() {
// without controller name
ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
JobHandler jobHandler = new JobHandler(podTemplateHandler);
// without controller name
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").volumes(volumes1).build();
jobHandler.getJob(config, images);
}
Aggregations