Refine search
@Override public Deployment transform(Deployment deployment, io.logz.apollo.models.Deployment apolloDeployment, Service apolloService, Environment apolloEnvironment, DeployableVersion apolloDeployableVersion, Group group) { // TODO: This should probably be an externally configured map of key names and desired dynamic values // TODO: Keeping this logz.io specific at the moment Map<String, String> desiredEnvironmentVariables = ImmutableMap.<String, String> builder() .put("ENV", apolloEnvironment.getAvailability()) .put("REGION", apolloEnvironment.getGeoRegion()) .build(); deployment.getSpec().getTemplate().getSpec().getContainers().forEach(container -> { List<EnvVar> envVarList = container.getEnv(); desiredEnvironmentVariables.forEach((key, value) -> { // Do not override values supplied externally if (envVarList.stream().noneMatch(envVar -> envVar.getName().equals(key))) { envVarList.add(new EnvVar(key, value, null)); } }); container.setEnv(envVarList); }); return deployment; } }
public DeploymentBuilder(DeploymentFluent<?> fluent,Deployment instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; } public DeploymentBuilder(Deployment instance){
public DeploymentBuilder(Boolean validationEnabled){ this(new Deployment(), validationEnabled); } public DeploymentBuilder(DeploymentFluent<?> fluent){
public void run() { try { Deployment deployment = get(); //If the deployment is gone, we shouldn't wait. if (deployment == null) { if (count == 0) { queue.put(true); return; } else { queue.put(new IllegalStateException("Can't wait for Deployment: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available.")); return; } } replicasRef.set(deployment.getStatus().getReplicas()); int currentReplicas = deployment.getStatus().getReplicas() != null ? deployment.getStatus().getReplicas() : 0; long generation = deployment.getMetadata().getGeneration() != null ? deployment.getMetadata().getGeneration() : 0; long observedGeneration = deployment.getStatus() != null && deployment.getStatus().getObservedGeneration() != null ? deployment.getStatus().getObservedGeneration() : -1; if (observedGeneration >= generation && Objects.equals(deployment.getSpec().getReplicas(), currentReplicas)) { queue.put(true); } else { LOG.debug("Only {}/{} pods scheduled for Deployment: {} in namespace: {} seconds so waiting...", deployment.getStatus().getReplicas(), deployment.getSpec().getReplicas(), deployment.getMetadata().getName(), namespace); } } catch (Throwable t) { LOG.error("Error while waiting for Deployment to be scaled.", t); } } };
public static boolean isDeploymentReady(Deployment d) { Utils.checkNotNull(d, "Deployment can't be null."); DeploymentSpec spec = d.getSpec(); DeploymentStatus status = d.getStatus(); if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == null) { return false; } //Can be true in testing, so handle it to make test writing easier. if (spec == null || spec.getReplicas() == null) { return false; } return spec.getReplicas().intValue() == status.getReplicas() && spec.getReplicas().intValue() <= status.getAvailableReplicas(); }
Map<String, String> labelsFromDeployment = deployment.getMetadata().getLabels(); deployment.getMetadata().setLabels(labelsFromDeployment); Map<String, String> labelsFromDeploymentPod = deployment.getSpec().getTemplate().getMetadata().getLabels(); labelsFromDeploymentPod.put(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(), ApolloToKubernetes.getApolloPodUniqueIdentifier(apolloEnvironment, apolloService, Optional.ofNullable(apolloDeployment.getGroupName()))); deployment.getSpec().getTemplate().getMetadata().setLabels(labelsFromDeploymentPod);
@Override Deployment applyResource(Deployment original, Deployment current) { return client .extensions() .deployments() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
DeploymentList list = client.extensions().deployments().inNamespace(namespace).list(); for (Deployment d : list.getItems()) { System.out.println(d.getMetadata().getName()); }
@Override public boolean reap() { Deployment deployment = oper.cascading(false).edit().editSpec().withReplicas(0).endSpec().done(); waitForObservedGeneration(deployment.getStatus().getObservedGeneration()); reapMatchingReplicaSets(deployment.getSpec().getSelector()); return false; }
@Override public Deployment transform(Deployment deployment, io.logz.apollo.models.Deployment apolloDeployment, Service apolloService, Environment apolloEnvironment, DeployableVersion apolloDeployableVersion, Group apolloGroup) { if (apolloGroup != null) { deployment.getSpec().setReplicas(apolloGroup.getScalingFactor()); } return deployment; } }
public KubernetesDeploymentStatus getCurrentStatus(Service service, Optional<String> groupName) { io.fabric8.kubernetes.api.model.extensions.Deployment deployment = getKubernetesDeployment(service, groupName); if (deployment == null) { logger.warn("Could not find deployment for environment {} and service {}, can't return the status!", environment.getId(), service.getId()); return null; } List<PodStatus> podStatusList = kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(), ApolloToKubernetes.getApolloPodUniqueIdentifier(environment, service, groupName)) .list() .getItems() .stream() .map(pod -> pod.getMetadata().getName()) .map(this::getPodStatus) .collect(Collectors.toList()); KubernetesDeploymentStatus kubernetesDeploymentStatus = new KubernetesDeploymentStatus(); kubernetesDeploymentStatus.setServiceId(service.getId()); kubernetesDeploymentStatus.setEnvironmentId(environment.getId()); kubernetesDeploymentStatus.setGitCommitSha(deployment.getMetadata().getLabels().get(ApolloToKubernetes.getApolloCommitShaKey())); kubernetesDeploymentStatus.setReplicas(deployment.getStatus().getReplicas()); kubernetesDeploymentStatus.setAvailableReplicas(deployment.getStatus().getAvailableReplicas()); kubernetesDeploymentStatus.setUpdatedReplicas(deployment.getStatus().getUpdatedReplicas()); kubernetesDeploymentStatus.setUnavailableReplicas(deployment.getStatus().getUnavailableReplicas()); kubernetesDeploymentStatus.setPodStatuses(podStatusList); groupName.ifPresent(kubernetesDeploymentStatus::setGroupName); return kubernetesDeploymentStatus; }
labels = normalizeLabels(labels); final Deployment deployment = new Deployment(); metadata.setName(normalizeDeploymentName(deploymentName)); metadata.setLabels(labels); deployment.setMetadata(metadata); deployment.setSpec(this.createDeploymentSpec(labels, nodeSelector, serviceAccountName, final boolean verifyTls) { final DeploymentSpec deploymentSpec = new DeploymentSpec(); final PodTemplateSpec podTemplateSpec = new PodTemplateSpec(); final ObjectMeta metadata = new ObjectMeta(); deploymentSpec.setTemplate(podTemplateSpec); return deploymentSpec;
public void run() { Deployment deployment = oper.getMandatory(); if (observedGeneration <= deployment.getStatus().getObservedGeneration()) { countDownLatch.countDown(); } } };
@Override public void adapt(KubernetesListBuilder builder) { super.adapt(builder); List<HasMetadata> items = builder.getItems(); for (HasMetadata item : items) { if (item instanceof Deployment) { Deployment deployment = (Deployment) item; ObjectMeta metadata = deployment.getMetadata(); DeploymentSpec spec = deployment.getSpec(); if (metadata != null && spec != null) { PodTemplateSpec template = spec.getTemplate(); if (template != null) { ObjectMeta templateMetadata = template.getMetadata(); if (templateMetadata == null) { templateMetadata = new ObjectMeta(); template.setMetadata(templateMetadata); } templateMetadata.setAnnotations(MapUtil.mergeMaps(templateMetadata.getAnnotations(), metadata.getAnnotations())); } } } } builder.withItems(items); } }
@Override public Deployment transform(Deployment deployment, io.logz.apollo.models.Deployment apolloDeployment, Service apolloService, Environment apolloEnvironment, DeployableVersion apolloDeployableVersion, Group apolloGroup) { if (apolloGroup != null) { deployment.getMetadata().setName(deployment.getMetadata().getName() + "-" + apolloGroup.getName()); } return deployment; } }
labels = normalizeLabels(labels); final Deployment deployment = new Deployment(); metadata.setName(normalizeDeploymentName(deploymentName)); metadata.setLabels(labels); deployment.setMetadata(metadata); deployment.setSpec(this.createDeploymentSpec(labels, nodeSelector, serviceAccountName, final boolean verifyTls) { final DeploymentSpec deploymentSpec = new DeploymentSpec(); final PodTemplateSpec podTemplateSpec = new PodTemplateSpec(); final ObjectMeta metadata = new ObjectMeta(); deploymentSpec.setTemplate(podTemplateSpec); return deploymentSpec;
public int getScalingFactor(Service service, String groupName) throws ApolloNotFoundException { io.fabric8.kubernetes.api.model.extensions.Deployment kubernetesDeployment = getKubernetesDeployment(service, Optional.of(groupName)); if (kubernetesDeployment == null) { throw new ApolloNotFoundException("Could not find deployment for environment " + environment.getId() + ", service " + service.getId() + " and group " + groupName + ", can't return the status!"); } return Optional.ofNullable(kubernetesDeployment.getStatus().getAvailableReplicas()).orElse(0); }
deployment.getSpec().getTemplate().getSpec().getContainers().forEach(container -> {
public DeploymentBuilder(Deployment instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
@Override public void eventReceived(Action action, Deployment resource) { if (resource != null) { log.debug("Got event {} for {} {}", action, resourceKind(), resource.getMetadata().getName()); switch (action) { case ADDED: case MODIFIED: onNeedSecret(resource); break; case DELETED: onRemoved(resource); break; case ERROR: log.error("Error event received for {}: {}", resourceKind(), resource); break; } } else { log.warn("Event {} received for null {}", action, resourceKind()); } }