本文整理汇总了Java中io.fabric8.kubernetes.api.model.extensions.Deployment类的典型用法代码示例。如果您正苦于以下问题:Java Deployment类的具体用法?Java Deployment怎么用?Java Deployment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deployment类属于io.fabric8.kubernetes.api.model.extensions包,在下文中一共展示了Deployment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequest
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Deployment, DeploymentList, ?, ?>> ctx = createContext(request.getIntent(), session);
String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
LOGGER.info("Listing all deployments for namespace:" + namespace);
try {
List<String> deployments = list(ctx)
.getItems()
.stream()
.map(d -> d.getMetadata().getName()).collect(Collectors.toList());
if (deployments.isEmpty()) {
return newResponse("No deployments found.");
} else {
return newResponse("The available deployments are: " + join(deployments, ","));
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例2: getDeploymentReport
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
/**
* Returns a simple report of the deployments.
* @return A string containing the text of the report.
*/
private String getDeploymentReport() {
StringBuilder sb = new StringBuilder();
List<Deployment> all = kubernetesClient.extensions().deployments().list().getItems();
List<Deployment> pending = all.stream()
.filter(d -> !Readiness.isDeploymentReady(d))
.collect(Collectors.toList());
try {
sb.append(createDeploymentReport(all.size(), all.size() - pending.size()));
sb.append(createPendingReportForDeployment(pending));
} catch (Throwable t) {
//ignore
}
return sb.toString();
}
示例3: createDeployment
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
protected Deployment createDeployment(String namespace,
final String deploymentName,
Map<String, String> labels,
final String serviceAccountName,
final String imageName,
final ImagePullPolicy imagePullPolicy,
final boolean hostNetwork,
final boolean tls,
final boolean verifyTls) {
namespace = normalizeNamespace(namespace);
labels = normalizeLabels(labels);
final Deployment deployment = new Deployment();
final ObjectMeta metadata = new ObjectMeta();
metadata.setNamespace(namespace);
metadata.setName(normalizeDeploymentName(deploymentName));
metadata.setLabels(labels);
deployment.setMetadata(metadata);
deployment.setSpec(this.createDeploymentSpec(labels, serviceAccountName, imageName, imagePullPolicy, namespace, hostNetwork, tls, verifyTls));
return deployment;
}
示例4: getDeploymentByName
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
private KubernetesDeployment getDeploymentByName(String namespace, String name) throws VmidcException {
KubernetesDeployment resultDeployment = null;
try {
Deployment deployment = getKubernetesClient().extensions().deployments().inNamespace(namespace).withName(name).get();
if (deployment != null) {
resultDeployment = new KubernetesDeployment(
deployment.getMetadata().getName(),
deployment.getMetadata().getNamespace(),
deployment.getMetadata().getUid(),
deployment.getSpec().getReplicas(),
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage(),
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImagePullPolicy());
resultDeployment.setDeploymentResource(deployment);
Integer availableReplicas = deployment.getStatus().getAvailableReplicas();
resultDeployment.setAvailableReplicaCount(availableReplicas == null ? 0 : availableReplicas.intValue());
}
} catch (KubernetesClientException e) {
throw new VmidcException("Failed to get the deployment");
}
return resultDeployment;
}
示例5: testGetDeploymentById_WhenK8sReturnsDeploymentWithMatchingId_ReturnsDeployment
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
@Test
public void testGetDeploymentById_WhenK8sReturnsDeploymentWithMatchingId_ReturnsDeployment() throws Exception {
// Arrange.
String name = UUID.randomUUID().toString();
String namespace = UUID.randomUUID().toString();
String uid = UUID.randomUUID().toString();
Deployment deployment = newDeployment(uid, namespace, name, 1, "image-sample-name");
mockDeploymentByName(namespace, name, deployment);
// Act.
KubernetesDeployment result = this.deploymentApi.getDeploymentById(uid, namespace, name);
// Assert.
assertNotNull("The result should not be null.", result);
assertDeploymentFields(deployment, result);
}
示例6: testUpdateDeploymentReplicaCount_WhenK8sReturnsDeploymentWithMatchingId_DeploymentUpdated
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
@Test
public void testUpdateDeploymentReplicaCount_WhenK8sReturnsDeploymentWithMatchingId_DeploymentUpdated() throws Exception {
// Arrange.
String name = UUID.randomUUID().toString();
String namespace = UUID.randomUUID().toString();
String uid = UUID.randomUUID().toString();
Deployment deployment = newDeployment(uid, namespace, name, 1, "image-sample-name");
ScalableResource<Deployment, DoneableDeployment> resourceMock = mockDeploymentByName(namespace, name, deployment);
int newReplicaCount = 10;
// Act.
this.deploymentApi.updateDeploymentReplicaCount(uid, namespace, name, newReplicaCount);
// Assert.
verify(resourceMock, times(1)).scale(newReplicaCount);
}
示例7: matches
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
@Override
public boolean matches(Object object) {
if (object == null || !(object instanceof Deployment)) {
return false;
}
Deployment deployment = (Deployment)object;
ObjectMeta metadata = deployment.getMetadata();
DeploymentSpec spec = deployment.getSpec();
PodTemplateSpec podTemplateSpec = spec.getTemplate();
String podLabel = podTemplateSpec.getMetadata().getLabels().get("osc-deployment");
Container container = podTemplateSpec.getSpec().getContainers().get(0);
return this.name.equals(metadata.getName()) &&
this.name.equals(podLabel) &&
this.replicaCount == spec.getReplicas() &&
this.imageName.equals(container.getImage()) &&
this.name.equals(container.getName());
}
示例8: testExists
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
public void testExists() throws ResourceException {
// Check that the deployment doesn't exist already
Deployment deployment = KubernetesClientUtil.retrieveDeployment(kubernetesClient, deploymentResourceV1);
assertNull(deployment);
// Test exists method
assertFalse(deploymentResourceV1.exists());
// Create deployment
deploymentResourceV1.create();
// Check that the deployment exists
deployment = KubernetesClientUtil.retrieveDeployment(kubernetesClient, deploymentResourceV1);
assertNotNull(deployment);
// Test exists method
assertTrue(deploymentResourceV1.exists());
}
示例9: testCreate
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
public void testCreate() throws ResourceException {
// Check that the deployment doesn't exist already
Deployment deployment = KubernetesClientUtil.retrieveDeployment(kubernetesClient, deploymentResourceV1);
assertNull(deployment);
// Create deployment
deploymentResourceV1.create();
// Check that the deployment exists
deployment = KubernetesClientUtil.retrieveDeployment(kubernetesClient, deploymentResourceV1);
assertNotNull(deployment);
// Check if the pods were created
assertEquals(3, KubernetesClientUtil.retrievePods(kubernetesClient, deploymentResourceV1).getItems().size());
// Check if the replica set was created
List<ReplicaSet> replicaSets = KubernetesClientUtil.retrieveReplicaSets(kubernetesClient, deploymentResourceV1).getItems();
assertEquals(1, replicaSets.size());
assertEquals(deploymentResourceV1.getId(), replicaSets.get(0).getMetadata().getLabels().get(DEPLOYMENT_MARKER_LABEL));
// Compare deployments
assertEquals(deployment.getMetadata().getName(), deploymentResourceV1.getId());
assertEquals(deployment.getApiVersion(), deploymentResourceV1.getResourceConfig().getResourceVersion());
assertEquals(deployment.getKind(), deploymentResourceV1.getResourceConfig().getResourceType());
}
示例10: addMissingResources
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
@Override
public void addMissingResources(KubernetesListBuilder builder) {
log.info("addMissingResources");
List<HasMetadata> items = builder.getItems();
for (HasMetadata item : items) {
if (item instanceof Deployment) {
Deployment deployment = (Deployment)item;
List<Container> containers = getCandidateContainers(deployment);
for (Container container : containers) {
if (container.getResources() == null) {
ResourceRequirements resourceRequirements = buildResourceRequirements();
log.info(describe(resourceRequirements));
container.setResources(resourceRequirements);
}
}
}
}
builder.withItems(items);
}
示例11: getFailedEvents
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
public static List<Event> getFailedEvents(KubernetesClient client, Deployment deployment) {
List<Event> result = new ArrayList<>();
for (Pod pod : podsOf(client, deployment).getItems()) {
result.addAll(getFailedEvents(client, pod));
}
return result;
}
示例12: findMatching
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
/**
* Returns the {@link PodList} that match the specified {@link Deployment}.
*
* @param deployment The {@link Deployment}
*/
public static PodList findMatching(KubernetesClient client, Deployment deployment) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister =
client.pods().inNamespace(deployment.getMetadata().getNamespace());
if (deployment.getSpec().getSelector().getMatchLabels() != null) {
podLister.withLabels(deployment.getSpec().getSelector().getMatchLabels());
}
if (deployment.getSpec().getSelector().getMatchExpressions() != null) {
for (LabelSelectorRequirement req : deployment.getSpec().getSelector().getMatchExpressions()) {
switch (req.getOperator()) {
case "In":
podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "NotIn":
podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "DoesNotExist":
podLister.withoutLabel(req.getKey());
break;
case "Exists":
podLister.withLabel(req.getKey());
break;
}
}
}
return podLister.list();
}
示例13: podsOf
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
/**
* Finds the pod that correspond to the specified resource.
*
* @param resource The resource.
* @return The podList with the matching pods.
*/
public static <T extends HasMetadata> PodList podsOf(KubernetesClient client, T resource) {
if (resource instanceof Pod) {
return new PodListBuilder().withItems((Pod) resource).build();
} else if (resource instanceof Endpoints) {
return podsOf(client, client.services()
.inNamespace(resource.getMetadata().getNamespace())
.withName(resource.getMetadata().getName())
.get());
} else if (resource instanceof Service) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((Service) resource).getSpec().getSelector())
.list();
} else if (resource instanceof ReplicationController) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((ReplicationController) resource).getSpec().getSelector())
.list();
} else if (resource instanceof Deployment) {
return findMatching(client, (Deployment) resource);
} else if (resource instanceof DeploymentConfig) {
return client.pods().inNamespace(resource.getMetadata().getNamespace()).withLabel("deploymentconfig",
resource.getMetadata().getName()).list();
} else {
return new PodListBuilder().build();
}
}
示例14: createPendingReportForDeployment
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
private String createPendingReportForDeployment(List<Deployment> pending) {
if (pending == null || pending.isEmpty()) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append("Failed deployments are: ");
for (Deployment p : pending) {
sb.append(p.getMetadata().getName()).append(" ");
List<Event> events = FeedbackUtils.getFailedEvents(kubernetesClient, p);
if (!events.isEmpty()) {
sb.append(" , due to:" + FeedbackUtils.normalize(events.get(0).getMessage()));
}
}
return sb.toString();
}
示例15: createDeployment
import io.fabric8.kubernetes.api.model.extensions.Deployment; //导入依赖的package包/类
/**
* Creates a Kubernetes deployment.
*
* @param deployment the deployment to be created
* @return the unique identifier of the deployment
* @throws VmidcException if a K8s SDK specific exception is caught
*/
public String createDeployment(KubernetesDeployment deployment) throws VmidcException {
if (deployment == null) {
throw new IllegalArgumentException("The deployment should not be null");
}
try {
Deployment newDeployment = new DeploymentBuilder()
.withKind("Deployment")
.withNewMetadata()
.withName(deployment.getName())
.endMetadata()
.withNewSpec()
.withReplicas(deployment.getDesiredReplicaCount())
.withNewTemplate()
.withNewMetadata()
.addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName())
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName(deployment.getName()).withImage(deployment.getContainerImageName())
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();
Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment);
return result.getMetadata().getUid();
} catch (KubernetesClientException e) {
throw new VmidcException(String.format("Failed to create a deployment %s", e));
}
}