Search in sources :

Example 71 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project devspaces-images by redhat-developer.

the class ContainerSearchTest method setup.

@BeforeMethod
public void setup() {
    // These are all the object types that can be contained in a KubernetesList which can contain a
    // container:
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    Container container1 = new ContainerBuilder().withName("container1").build();
    Container container2 = new ContainerBuilder().withName("container2").build();
    Container container3 = new ContainerBuilder().withName("container3").build();
    Container container4 = new ContainerBuilder().withName("container4").build();
    Container container5 = new ContainerBuilder().withName("container5").build();
    Container container6 = new ContainerBuilder().withName("container6").build();
    Container container7 = new ContainerBuilder().withName("container7").build();
    Container container8 = new ContainerBuilder().withName("container8").build();
    Container container9 = new ContainerBuilder().withName("container9").build();
    Container container10 = new ContainerBuilder().withName("container10").build();
    Container container11 = new ContainerBuilder().withName("container11").build();
    Container container12 = new ContainerBuilder().withName("container12").build();
    Pod podWithName = new PodBuilder().withNewMetadata().withName("podWithName").addToLabels("app", "che").endMetadata().withNewSpec().withContainers(container1).endSpec().build();
    Pod podWithGenerateName = new PodBuilder().withNewMetadata().withGenerateName("podWithGenerateName").endMetadata().withNewSpec().withContainers(container2).endSpec().build();
    PodTemplate podTemplate = new PodTemplateBuilder().withNewMetadata().withName("podTemplate").addToLabels("app", "che").endMetadata().withNewTemplate().withNewSpec().withContainers(container3).endSpec().endTemplate().build();
    DaemonSet daemonSet = new DaemonSetBuilder().withNewMetadata().withName("daemonSet").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container4).endSpec().endTemplate().endSpec().build();
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container5).endSpec().endTemplate().endSpec().build();
    Job job = new JobBuilder().withNewMetadata().withName("job").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container6).endSpec().endTemplate().endSpec().build();
    ReplicaSet replicaSet = new ReplicaSetBuilder().withNewMetadata().withName("replicaSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container7).endSpec().endTemplate().endSpec().build();
    ReplicationController replicationController = new ReplicationControllerBuilder().withNewMetadata().withName("replicationController").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container8).endSpec().endTemplate().endSpec().build();
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName("statefulSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container9).endSpec().endTemplate().endSpec().build();
    CronJob cronJob = new CronJobBuilder().withNewMetadata().withName("cronJob").endMetadata().withNewSpec().withNewJobTemplate().withNewSpec().withNewTemplate().withNewSpec().withContainers(container10).endSpec().endTemplate().endSpec().endJobTemplate().endSpec().build();
    DeploymentConfig deploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName("deploymentConfig").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container11).endSpec().endTemplate().endSpec().build();
    Template template = new TemplateBuilder().addToObjects(new DeploymentBuilder().withNewMetadata().withName("deploymentWithName").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container12).endSpec().endTemplate().endSpec().build()).build();
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    testList = asList(podWithName, podWithGenerateName, podTemplate, daemonSet, deployment, job, replicaSet, replicationController, statefulSet, cronJob, deploymentConfig, template);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationControllerBuilder(io.fabric8.kubernetes.api.model.ReplicationControllerBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Template(io.fabric8.openshift.api.model.Template) DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 72 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project Kuvel by AzisabaNetwork.

the class RedisLoadBalancerDiscovery method registerLoadBalancersForStartup.

@Override
public void registerLoadBalancersForStartup() {
    if (redisConnectionLeader.isLeader()) {
        try (Jedis jedis = jedisPool.getResource()) {
            Map<String, String> uidAndServerNameMapInRedis = jedis.hgetAll(RedisKeys.LOAD_BALANCERS_PREFIX.getKey() + groupName);
            for (Map.Entry<String, String> entry : uidAndServerNameMapInRedis.entrySet()) {
                ReplicaSet replicaSet = getReplicaSetFromUid(entry.getKey());
                if (replicaSet == null) {
                    jedis.hdel(RedisKeys.LOAD_BALANCERS_PREFIX.getKey() + groupName, entry.getKey());
                    continue;
                }
                registerOrIgnore(replicaSet, true);
            }
            client.apps().replicaSets().inAnyNamespace().withLabel(LabelKeys.SERVER_DISCOVERY.getKey(), "true").withLabel(LabelKeys.SERVER_NAME.getKey()).list().getItems().stream().filter(replicaSet -> !uidAndServerNameMapInRedis.containsKey(replicaSet.getMetadata().getUid())).forEach(this::registerOrIgnore);
        }
    } else {
        try (Jedis jedis = jedisPool.getResource()) {
            Map<String, String> uidAndServerNameMapInRedis = jedis.hgetAll(RedisKeys.LOAD_BALANCERS_PREFIX.getKey() + groupName);
            for (Map.Entry<String, String> entry : uidAndServerNameMapInRedis.entrySet()) {
                ReplicaSet replicaSet = getReplicaSetFromUid(entry.getKey());
                if (replicaSet == null) {
                    continue;
                }
                registerOrIgnore(replicaSet, true);
            }
        }
    }
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) RedisKeys(net.azisaba.kuvel.redis.RedisKeys) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) RoundRobinLoadBalancingStrategy(net.azisaba.kuvel.loadbalancer.strategy.impl.RoundRobinLoadBalancingStrategy) Watcher(io.fabric8.kubernetes.client.Watcher) Kuvel(net.azisaba.kuvel.Kuvel) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) KuvelServiceHandler(net.azisaba.kuvel.KuvelServiceHandler) WatcherException(io.fabric8.kubernetes.client.WatcherException) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) LabelKeys(net.azisaba.kuvel.util.LabelKeys) Jedis(redis.clients.jedis.Jedis) Map(java.util.Map) LoadBalancer(net.azisaba.kuvel.loadbalancer.LoadBalancer) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) RedisConnectionLeader(net.azisaba.kuvel.redis.RedisConnectionLeader) JedisPool(redis.clients.jedis.JedisPool) LoadBalancerDiscovery(net.azisaba.kuvel.discovery.LoadBalancerDiscovery) ExecutorService(java.util.concurrent.ExecutorService) Jedis(redis.clients.jedis.Jedis) Map(java.util.Map) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 73 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project jkube by eclipse.

the class DockerImageWatcher method updateImageName.

private void updateImageName(KubernetesClient kubernetes, String namespace, HasMetadata entity, String imagePrefix, String imageName) {
    String name = KubernetesHelper.getName(entity);
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null && updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
            kubernetes.apps().deployments().inNamespace(namespace).withName(name).replace(resource);
            kubernetes.apps().deployments().inNamespace(namespace).withName(name).rolling().restart();
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null && updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
            kubernetes.apps().replicaSets().inNamespace(namespace).withName(name).replace(resource);
            kubernetes.apps().replicaSets().inNamespace(namespace).withName(name).rolling().restart();
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null && updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
            kubernetes.replicationControllers().inNamespace(namespace).withName(name).replace(resource);
            kubernetes.replicationControllers().inNamespace(namespace).withName(name).rolling().restart();
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null && updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
            OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes);
            if (openshiftClient == null) {
                log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
            } else {
                openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
            }
        }
    }
}
Also used : DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 74 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project jkube by eclipse.

the class KubernetesClientUtil method resizeApp.

public static void resizeApp(KubernetesClient kubernetes, String namespace, Collection<HasMetadata> entities, int replicas, KitLogger log) {
    for (HasMetadata entity : entities) {
        String name = KubernetesHelper.getName(entity);
        Scaleable<?> scalable = null;
        if (entity instanceof Deployment) {
            scalable = kubernetes.apps().deployments().inNamespace(namespace).withName(name);
        } else if (entity instanceof ReplicaSet) {
            scalable = kubernetes.apps().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);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 75 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project jkube by eclipse.

the class ApplyService method applyEntity.

/**
 * Applies the given DTOs onto the Kubernetes master
 */
private void applyEntity(Object dto, String sourceName) {
    if (dto instanceof Pod) {
        applyPod((Pod) dto, sourceName);
    } else if (dto instanceof ReplicationController) {
        applyReplicationController((ReplicationController) dto, sourceName);
    } else if (dto instanceof Service) {
        applyService((Service) dto, sourceName);
    } else if (dto instanceof Route) {
        applyRoute((Route) dto, sourceName);
    } else if (dto instanceof BuildConfig) {
        applyBuildConfig((BuildConfig) dto, sourceName);
    } else if (dto instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) dto;
        OpenShiftClient openShiftClient = getOpenShiftClient();
        if (openShiftClient != null) {
            applyResource(resource, sourceName, openShiftClient.deploymentConfigs());
        } else {
            log.warn("Not connected to OpenShift cluster so cannot apply entity %s", dto);
        }
    } else if (dto instanceof RoleBinding) {
        applyRoleBinding((RoleBinding) dto, sourceName);
    } else if (dto instanceof Role) {
        applyResource((Role) dto, sourceName, kubernetesClient.rbac().roles());
    } else if (dto instanceof ImageStream) {
        applyImageStream((ImageStream) dto, sourceName);
    } else if (dto instanceof OAuthClient) {
        applyOAuthClient((OAuthClient) dto, sourceName);
    } else if (dto instanceof Template) {
        applyTemplate((Template) dto, sourceName);
    } else if (dto instanceof ServiceAccount) {
        applyServiceAccount((ServiceAccount) dto, sourceName);
    } else if (dto instanceof Secret) {
        applySecret((Secret) dto, sourceName);
    } else if (dto instanceof ConfigMap) {
        applyResource((ConfigMap) dto, sourceName, kubernetesClient.configMaps());
    } else if (dto instanceof DaemonSet) {
        applyResource((DaemonSet) dto, sourceName, kubernetesClient.apps().daemonSets());
    } else if (dto instanceof Deployment) {
        applyResource((Deployment) dto, sourceName, kubernetesClient.apps().deployments());
    } else if (dto instanceof ReplicaSet) {
        applyResource((ReplicaSet) dto, sourceName, kubernetesClient.apps().replicaSets());
    } else if (dto instanceof StatefulSet) {
        applyResource((StatefulSet) dto, sourceName, kubernetesClient.apps().statefulSets());
    } else if (dto instanceof Ingress) {
        applyResource((Ingress) dto, sourceName, kubernetesClient.extensions().ingresses());
    } else if (dto instanceof PersistentVolumeClaim) {
        applyPersistentVolumeClaim((PersistentVolumeClaim) dto, sourceName);
    } else if (dto instanceof CustomResourceDefinition) {
        applyCustomResourceDefinition((CustomResourceDefinition) dto, sourceName);
    } else if (dto instanceof Job) {
        applyJob((Job) dto, sourceName);
    } else if (dto instanceof NetworkPolicy) {
        applyResource((NetworkPolicy) dto, sourceName, kubernetesClient.network().networkPolicies());
    } else if (dto instanceof Namespace) {
        applyNamespace((Namespace) dto);
    } else if (dto instanceof Project) {
        applyProject((Project) dto);
    } else if (dto instanceof GenericKubernetesResource) {
        applyGenericKubernetesResource((GenericKubernetesResource) dto, sourceName);
    } else if (dto instanceof HasMetadata) {
        HasMetadata entity = (HasMetadata) dto;
        try {
            log.info("Applying %s %s from %s", getKind(entity), getName(entity), sourceName);
            kubernetesClient.resource(entity).inNamespace(applicableNamespace((HasMetadata) dto, namespace, fallbackNamespace)).createOrReplace();
        } catch (Exception e) {
            onApplyError("Failed to create " + getKind(entity) + " from " + sourceName + ". " + e, e);
        }
    } else {
        throw new IllegalArgumentException("Unknown entity type " + dto);
    }
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) ImageStream(io.fabric8.openshift.api.model.ImageStream) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Template(io.fabric8.openshift.api.model.Template) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Route(io.fabric8.openshift.api.model.Route) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Namespace(io.fabric8.kubernetes.api.model.Namespace) KubernetesClientUtil.applicableNamespace(org.eclipse.jkube.kit.config.service.kubernetes.KubernetesClientUtil.applicableNamespace) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Role(io.fabric8.kubernetes.api.model.rbac.Role) Secret(io.fabric8.kubernetes.api.model.Secret) Project(io.fabric8.openshift.api.model.Project) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet)

Aggregations

ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)50 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)26 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)22 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)22 Test (org.junit.Test)19 ReplicaSetBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder)18 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)17 Test (org.junit.jupiter.api.Test)15 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)14 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)10 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)9 ReplicaSetSpec (io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec)9 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)9 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 Container (io.fabric8.kubernetes.api.model.Container)7 DaemonSet (io.fabric8.kubernetes.api.model.apps.DaemonSet)7 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)7