io.fabric8.kubernetes.client.dsl.RollableScalableResource Java Examples

The following examples show how to use io.fabric8.kubernetes.client.dsl.RollableScalableResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeploymentConfigOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private List<RollableScalableResource<ReplicaSet, DoneableReplicaSet>> doGetLog() {
  List<RollableScalableResource<ReplicaSet, DoneableReplicaSet>> rcs = new ArrayList<>();
  DeploymentConfig deploymentConfig = fromServer().get();
  String rcUid = deploymentConfig.getMetadata().getUid();

  ReplicaSetOperationsImpl rsOperations = new ReplicaSetOperationsImpl((RollingOperationContext) context);
  ReplicaSetList rcList = rsOperations.withLabels(deploymentConfig.getMetadata().getLabels()).list();

  for (ReplicaSet rs : rcList.getItems()) {
    OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(rs);
    if (ownerReference != null && ownerReference.getUid().equals(rcUid)) {
      rcs.add(rsOperations.withName(rs.getMetadata().getName()));
    }
  }
  return rcs;
}
 
Example #2
Source File: StatefulSetMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Override
protected void mockDelete(String resourceName, RollableScalableResource<StatefulSet, DoneableStatefulSet> resource) {
    when(resource.cascading(true).delete()).thenAnswer(i -> {
        LOGGER.debug("delete {} {}", resourceType, resourceName);
        StatefulSet removed = db.remove(resourceName);
        if (removed != null) {
            fireWatchers(resourceName, removed, Watcher.Action.DELETED, "delete");
            for (Map.Entry<String, Pod> pod : new HashMap<>(podDb).entrySet()) {
                if (pod.getKey().matches(resourceName + "-[0-9]+")) {
                    mockPods.inNamespace(removed.getMetadata().getNamespace()).withName(pod.getKey()).cascading(true).delete();
                }
            }
        }
        return removed != null;
    });
}
 
Example #3
Source File: WebServerController.java    From java-operator-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteResource(WebServer nginx) {
    log.info("Execution deleteResource for: {}", nginx.getMetadata().getName());

    log.info("Deleting ConfigMap {}", configMapName(nginx));
    Resource<ConfigMap, DoneableConfigMap> configMap = kubernetesClient.configMaps()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(configMapName(nginx));
    if (configMap.get() != null) {
        configMap.delete();
    }

    log.info("Deleting Deployment {}", deploymentName(nginx));
    RollableScalableResource<Deployment, DoneableDeployment> deployment = kubernetesClient.apps().deployments()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(deploymentName(nginx));
    if (deployment.get() != null) {
        deployment.cascading(true).delete();
    }

    log.info("Deleting Service {}", serviceName(nginx));
    ServiceResource<Service, DoneableService> service = kubernetesClient.services()
            .inNamespace(nginx.getMetadata().getNamespace())
            .withName(serviceName(nginx));
    if (service.get() != null) {
        service.delete();
    }
    return true;
}
 
Example #4
Source File: DeploymentConfigOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public LogWatch watchLog(OutputStream out) {
  List<RollableScalableResource<ReplicaSet, DoneableReplicaSet>> podResources = doGetLog();
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Watching logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).watchLog(out);
  }
  return null;
}
 
Example #5
Source File: DeploymentConfigOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an unclosed Reader. It's the caller responsibility to close it.
 * @return Reader
 */
@Override
public Reader getLogReader() {
  List<RollableScalableResource<ReplicaSet, DoneableReplicaSet>> podResources = doGetLog();
  if (podResources.size() > 1) {
    throw new KubernetesClientException("Reading logs is not supported for multicontainer jobs");
  } else if (podResources.size() == 1) {
    return podResources.get(0).getLogReader();
  }
  return null;
}
 
Example #6
Source File: DeploymentConfigOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public String getLog(Boolean isPretty) {
  StringBuilder stringBuilder = new StringBuilder();
  List<RollableScalableResource<ReplicaSet, DoneableReplicaSet>> rcList = doGetLog();
  for (RollableScalableResource<ReplicaSet, DoneableReplicaSet> rcOperation : rcList) {
    stringBuilder.append(rcOperation.getLog(isPretty));
  }
  return stringBuilder.toString();
}
 
Example #7
Source File: StatefulSetMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
protected void mockCreate(String resourceName, RollableScalableResource<StatefulSet, DoneableStatefulSet> resource) {
    when(resource.create(any())).thenAnswer(cinvocation -> {
        checkNotExists(resourceName);
        StatefulSet argument = cinvocation.getArgument(0);
        LOGGER.debug("create {} {} -> {}", resourceType, resourceName, argument);
        StatefulSet value = copyResource(argument);
        value.setStatus(new StatefulSetStatus());
        db.put(resourceName, value);
        for (int i = 0; i < argument.getSpec().getReplicas(); i++) {
            final int podNum = i;
            String podName = argument.getMetadata().getName() + "-" + podNum;
            LOGGER.debug("create Pod {} because it's in StatefulSet {}", podName, resourceName);
            mockPods.inNamespace(argument.getMetadata().getNamespace()).createOrReplace(doCreatePod(argument, podName));

            if (value.getSpec().getVolumeClaimTemplates().size() > 0) {

                for (PersistentVolumeClaim pvcTemplate: value.getSpec().getVolumeClaimTemplates()) {

                    String pvcName = pvcTemplate.getMetadata().getName() + "-" + podName;
                    if (mockPvcs.inNamespace(argument.getMetadata().getNamespace()).withName(pvcName).get() == null) {

                        LOGGER.debug("create Pvc {} because it's in VolumeClaimTemplate of StatefulSet {}", pvcName, resourceName);
                        PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder()
                                .withNewMetadata()
                                    .withLabels(argument.getSpec().getSelector().getMatchLabels())
                                    .withNamespace(argument.getMetadata().getNamespace())
                                    .withName(pvcName)
                                .endMetadata()
                                .build();
                        mockPvcs.inNamespace(argument.getMetadata().getNamespace()).withName(pvcName).create(pvc);
                    }
                }

            }
        }
        return argument;
    });
}
 
Example #8
Source File: StatefulSetMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void nameScopedMocks(String resourceName, RollableScalableResource<StatefulSet, DoneableStatefulSet> resource) {
    super.nameScopedMocks(resourceName, resource);
    EditReplacePatchDeletable<StatefulSet, StatefulSet, DoneableStatefulSet, Boolean> c = mock(EditReplacePatchDeletable.class);
    when(c.withGracePeriod(anyLong())).thenReturn(resource);
    when(resource.cascading(false)).thenReturn(c);
    mockNoncascadingPatch(resourceName, c);
    mockScale(resourceName, resource);
    mockNoncascadingDelete(resourceName, c);
}
 
Example #9
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
private MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>>
    buildStatefulSets(MockBuilder<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> podMockBuilder, MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods,
                      MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim,
                              Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> mockPvcs) {
    MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet,
            DoneableStatefulSet>> result = new StatefulSetMockBuilder(podMockBuilder, ssDb, podDb, mockPods, mockPvcs).build();
    return result;
}
 
Example #10
Source File: SparkClusterOperator.java    From spark-operator with Apache License 2.0 5 votes vote down vote up
private Map<String, Integer> getActual() {
    MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> aux1 =
            client.replicationControllers();
    FilterWatchListMultiDeletable<ReplicationController, ReplicationControllerList, Boolean, Watch, Watcher<ReplicationController>> aux2 =
            "*".equals(namespace) ? aux1.inAnyNamespace() : aux1.inNamespace(namespace);
    Map<String, String> labels =new HashMap<>(2);
    labels.put(prefix + OPERATOR_KIND_LABEL, entityName);
    labels.put(prefix + OPERATOR_RC_TYPE_LABEL, "worker");
    List<ReplicationController> workerRcs = aux2.withLabels(labels).list().getItems();
    Map<String, Integer> retMap = workerRcs
            .stream()
            .collect(Collectors.toMap(rc -> rc.getMetadata().getLabels().get(prefix + entityName),
                    rc -> rc.getSpec().getReplicas()));
    return retMap;
}
 
Example #11
Source File: DeploymentMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
protected void mockCreate(String resourceName, RollableScalableResource<Deployment, DoneableDeployment> resource) {
    when(resource.create(any())).thenAnswer(invocation -> {
        checkNotExists(resourceName);
        Deployment deployment = invocation.getArgument(0);
        LOGGER.debug("create {} {} -> {}", resourceType, resourceName, deployment);
        deployment.getMetadata().setGeneration(Long.valueOf(0));
        deployment.setStatus(new DeploymentStatusBuilder().withObservedGeneration(Long.valueOf(0)).build());
        db.put(resourceName, copyResource(deployment));
        for (int i = 0; i < deployment.getSpec().getReplicas(); i++) {
            String uuid = UUID.randomUUID().toString();
            String podName = deployment.getMetadata().getName() + "-" + uuid;
            LOGGER.debug("create Pod {} because it's in Deployment {}", podName, resourceName);
            Pod pod = new PodBuilder()
                    .withNewMetadataLike(deployment.getSpec().getTemplate().getMetadata())
                        .withUid(uuid)
                        .withNamespace(deployment.getMetadata().getNamespace())
                        .withName(podName)
                    .endMetadata()
                    .withNewSpecLike(deployment.getSpec().getTemplate().getSpec()).endSpec()
                    .build();
            mockPods.inNamespace(deployment.getMetadata().getNamespace()).withName(podName).create(pod);
            podsForDeployments.compute(deployment.getMetadata().getName(), (deploymentName, podsInDeployment) -> {
                if (podsInDeployment == null) {
                    podsInDeployment = new ArrayList<>(2);
                }
                podsInDeployment.add(podName);
                return podsInDeployment;
            });
        }
        return deployment;
    });
}
 
Example #12
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public RollableScalableResource<ReplicationController, DoneableReplicationController> load(InputStream is) {
    ReplicationController item = unmarshal(is, ReplicationController.class);
    return new ReplicationControllerOperationsImpl((RollingOperationContext) context.withItem(item));
}
 
Example #13
Source File: StatefulSetController.java    From rabbitmq-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> operation() {
    return getClient().apps().statefulSets();
}
 
Example #14
Source File: StatefulSetOperator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> operation() {
    return client.apps().statefulSets();
}
 
Example #15
Source File: StatefulSetOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<RollableScalableResource> resourceType() {
    return RollableScalableResource.class;
}
 
Example #16
Source File: AppsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> statefulSets() {
  return new StatefulSetOperationsImpl(httpClient, getConfiguration());
}
 
Example #17
Source File: AppsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ReplicaSet, ReplicaSetList, DoneableReplicaSet, RollableScalableResource<ReplicaSet, DoneableReplicaSet>> replicaSets() {
  return new ReplicaSetOperationsImpl(httpClient, getConfiguration());
}
 
Example #18
Source File: AppsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments() {
  return new DeploymentOperationsImpl(httpClient, getConfiguration());
}
 
Example #19
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers() {
  return delegate.replicationControllers();
}
 
Example #20
Source File: ExtensionsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public MixedOperation<ReplicaSet, ReplicaSetList, DoneableReplicaSet, RollableScalableResource<ReplicaSet, DoneableReplicaSet>> replicaSets() {
  return new ReplicaSetOperationsImpl(httpClient, getConfiguration());
}
 
Example #21
Source File: ExtensionsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> deployments() {
  return new DeploymentOperationsImpl(httpClient, getConfiguration());
}
 
Example #22
Source File: ReplicationControllerRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Operation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> resources() {
  return new ReplicationControllerOperationsImpl(client, config);
}
 
Example #23
Source File: ReplicaSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Operation<ReplicaSet, ReplicaSetList, DoneableReplicaSet, RollableScalableResource<ReplicaSet, DoneableReplicaSet>> resources() {
  return new ReplicaSetOperationsImpl(client, config);
}
 
Example #24
Source File: StatefulSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Operation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> resources() {
  return new StatefulSetOperationsImpl(client, config);
}
 
Example #25
Source File: DeploymentRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Operation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> resources() {
  return new DeploymentOperationsImpl(client, config);
}
 
Example #26
Source File: KubeClient.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Gets stateful set
 */
public RollableScalableResource<StatefulSet, DoneableStatefulSet> statefulSet(String statefulSetName) {
    return client.apps().statefulSets().inNamespace(getNamespace()).withName(statefulSetName);
}
 
Example #27
Source File: DeploymentOperator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected MixedOperation<Deployment, DeploymentList, DoneableDeployment, RollableScalableResource<Deployment, DoneableDeployment>> operation() {
    return client.apps().deployments();
}
 
Example #28
Source File: DeploymentOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<RollableScalableResource> resourceType() {
    return RollableScalableResource.class;
}
 
Example #29
Source File: DeploymentMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public DeploymentMockBuilder(Map<String, Deployment> depDb, MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods) {
    super(Deployment.class, DeploymentList.class, DoneableDeployment.class, castClass(RollableScalableResource.class), depDb);
    this.mockPods = mockPods;
}
 
Example #30
Source File: RollingUpdater.java    From kubernetes-client with Apache License 2.0 votes vote down vote up
protected abstract Operation<T, L, D, RollableScalableResource<T, D>> resources();