io.fabric8.kubernetes.api.model.apps.DoneableStatefulSet Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.apps.DoneableStatefulSet. 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: 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 #2
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 #3
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 #4
Source File: StatefulSetMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
private void mockNoncascadingDelete(String resourceName, EditReplacePatchDeletable<StatefulSet, StatefulSet, DoneableStatefulSet, Boolean> c) {
    when(c.delete()).thenAnswer(i -> {
        LOGGER.info("delete {} {}", resourceType, resourceName);
        StatefulSet removed = db.remove(resourceName);
        return removed != null;
    });
}
 
Example #5
Source File: StatefulSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
protected void removeDeploymentKey(DoneableStatefulSet obj) {
  obj.editSpec()
    .editSelector().removeFromMatchLabels(DEPLOYMENT_KEY).endSelector()
    .editTemplate().editMetadata().removeFromLabels(DEPLOYMENT_KEY).endMetadata().endTemplate()
    .endSpec();
}
 
Example #6
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 #7
Source File: StatefulSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateDeploymentKey(DoneableStatefulSet obj, String hash) {
  obj.editSpec()
    .editSelector().addToMatchLabels(DEPLOYMENT_KEY, hash).endSelector()
    .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, hash).endMetadata().endTemplate()
    .endSpec();
}
 
Example #8
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public StatefulSetOperationsImpl(RollingOperationContext context) {
  super(context.withApiGroupName("apps")
    .withApiGroupVersion("v1")
    .withPlural("statefulsets"));
  this.type = StatefulSet.class;
  this.listType = StatefulSetList.class;
  this.doneableType = DoneableStatefulSet.class;
}
 
Example #9
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 #10
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 #11
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 #12
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public ImageEditReplacePatchable<StatefulSet, StatefulSet, DoneableStatefulSet> withTimeoutInMillis(long timeoutInMillis) {
  return new StatefulSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(timeoutInMillis));
}
 
Example #13
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public ImageEditReplacePatchable<StatefulSet, StatefulSet, DoneableStatefulSet> withTimeout(long timeout, TimeUnit unit) {
  return new StatefulSetOperationsImpl(((RollingOperationContext)context).withRollingTimeout(unit.toMillis(timeout)).withRollingTimeUnit(TimeUnit.MILLISECONDS));
}
 
Example #14
Source File: StatefulSetOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public RollingUpdater<StatefulSet, StatefulSetList, DoneableStatefulSet> getRollingUpdater(long rollingTimeout, TimeUnit rollingTimeUnit) {
  return new StatefulSetRollingUpdater(client, config, getNamespace(), rollingTimeUnit.toMillis(rollingTimeout), config.getLoggingInterval());
}
 
Example #15
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 #16
Source File: StatefulSetMockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
private void mockNoncascadingPatch(String resourceName, EditReplacePatchDeletable<StatefulSet, StatefulSet, DoneableStatefulSet, Boolean> c) {
    when(c.patch(any())).thenAnswer(patchInvocation -> {
        StatefulSet argument = patchInvocation.getArgument(0);
        return doPatch(resourceName, argument);
    });
}
 
Example #17
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public MockKube withInitialStatefulSets(Set<StatefulSet> initial) {
    this.ssDb.putAll(db(initial, StatefulSet.class, DoneableStatefulSet.class));
    return this;
}
 
Example #18
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 #19
Source File: AppsAPIGroupDSL.java    From kubernetes-client with Apache License 2.0 votes vote down vote up
MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> statefulSets();