Skip to content

Commit

Permalink
fix fabric8io#3364 adding deprecations and editable to VisitFromServe…
Browse files Browse the repository at this point in the history
…r...

also moving the handling of the Readiness to the context as that is more
consistent and doesn't require an additional class for the
NamespaceVisit...
  • Loading branch information
shawkins committed Aug 7, 2021
1 parent fbd5506 commit afaa31c
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
##### DSL Changes:
- #3327 DSL methods mentioning customResources have been deprecated: `KubernetesClient.customResources`, `SharedIndexInformerFactory.sharedIndexInformerForCustomResource`. See replacement resources and sharedIndexInformerFor methods instead. Also `CustomeResourceDefinitionContext` has been replaced by `ResourceDefinitionContext` - for example in `KubernetesClient.genericKubernetesResources`.
- #3358 DSL return type replacements - `NamespacedCreateOnlyResourceOperationsImpl` has been replaced by `NamespacedInOutCreateable`, `ImageSignatureOperationsImpl` has been replaced by `NameableCreateOrDeleteable`
- #3364 `VisitFromServerGetWatchDeleteRecreateWaitApplicable` now implements `Editable` to replace the `Visitable` methods. `ApplicableAnd` and `Recreatable` have also been deprecated.

### 5.6.0 (2021-07-21)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.fabric8.kubernetes.client.internal.CertUtils;
import io.fabric8.kubernetes.client.internal.KubeConfigUtils;
import io.fabric8.kubernetes.client.internal.SSLUtils;
import io.fabric8.kubernetes.client.internal.readiness.Readiness;
import io.fabric8.kubernetes.client.utils.IOHelpers;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.kubernetes.client.utils.Utils;
Expand Down Expand Up @@ -1335,4 +1336,8 @@ public File getFile() {
return file;
}

public Readiness getReadiness() {
return Readiness.getInstance();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@

package io.fabric8.kubernetes.client.dsl;

/**
* @deprecated create an intermediate variable to perform the createOrReplace and subsequent operation
*/
@Deprecated
public interface ApplicableAnd<T> {

/**
* @deprecated create an intermediate variable to perform the createOrReplace and subsequent operation
*/
@Deprecated
T createOrReplaceAnd();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@

package io.fabric8.kubernetes.client.dsl;

/**
* @deprecated create an intermediate variable to perform the delete and subsequent operation
*/
@Deprecated
public interface Recreateable<T> {

/**
* @deprecated create an intermediate variable to perform the delete and subsequent operation
*/
@Deprecated
T deletingExisting();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.fabric8.kubernetes.client.dsl;

import io.fabric8.kubernetes.api.builder.TypedVisitor;
import io.fabric8.kubernetes.api.builder.Visitable;
import io.fabric8.kubernetes.api.builder.Visitor;
import io.fabric8.kubernetes.client.FromServerGettable;
import io.fabric8.kubernetes.client.Watcher;

Expand All @@ -26,5 +28,22 @@ public interface VisitFromServerGetWatchDeleteRecreateWaitApplicable<T> extends
Waitable<T, T>,
VisitFromServerWritable<T>,
DryRunable<VisitFromServerWritable<T>>,
Readiable {
Readiable,
Editable<T> {

/**
* @deprecated use {@link Editable#edit(Visitor...)} instead
*/
@Override
@Deprecated
VisitFromServerGetWatchDeleteRecreateWaitApplicable<T> accept(Visitor... arg0);

/**
* @deprecated use {@link Editable#edit(Class, Visitor)} instead
*/
@Override
@Deprecated
default <V> VisitFromServerGetWatchDeleteRecreateWaitApplicable<T> accept(Class<V> type, Visitor<V> visitor) {
return accept(new TypedVisitor<V>() {@Override public Class<V> getType() {return type;} @Override public void visit(V element) {visitor.visit(element);}});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ protected void updateApiVersion(HasMetadata hasMetadata) {
}

public Readiness getReadiness() {
return Readiness.getInstance();
return config.getReadiness();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;
import okhttp3.OkHttpClient;

import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -218,7 +220,27 @@ public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl newInsta
public HasMetadata waitUntilCondition(Predicate<HasMetadata> condition, long amount, TimeUnit timeUnit) {
return getResource().waitUntilCondition(condition, amount, timeUnit);
}


@Override
public <V> HasMetadata edit(Class<V> visitorType, Visitor<V> visitor) {
return getResource().edit(visitorType, visitor);
}

@Override
public HasMetadata edit(UnaryOperator<HasMetadata> function) {
return getResource().edit(function);
}

@Override
public HasMetadata edit(Visitor... visitors) {
return getResource().edit(visitors);
}

@Override
public HasMetadata accept(Consumer<HasMetadata> function) {
return getResource().accept(function);
}

static HasMetadata acceptVisitors(HasMetadata item, List<Visitor> visitors, String explicitNamespace) {
ResourceHandler<HasMetadata, ?> h = handlerOf(item);
VisitableBuilder<HasMetadata, ?> builder = h.edit(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@EnableOpenShiftMockClient(crud = true)
Expand All @@ -33,6 +34,20 @@ class DeploymentConfigCrudTest {
OpenShiftMockServer server;
OpenShiftClient client;

@Test
void testReadiness() {
DeploymentConfig deploymentConfig1 = new DeploymentConfigBuilder().withNewMetadata()
.withName("deploymentConfig1")
.withNamespace("ns1")
.addToLabels("testKey", "testValue")
.endMetadata()
.build();

client.deploymentConfigs().inNamespace("ns1").create(deploymentConfig1);

assertFalse(client.deploymentConfigs().inNamespace("ns1").withName("deploymentConfig1").isReady());
}

@Test
void testCrud() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
import io.fabric8.openshift.client.dsl.internal.user.GroupOperationsImpl;
import io.fabric8.openshift.client.dsl.internal.user.UserOperationsImpl;
import io.fabric8.openshift.client.internal.OpenShiftClusterOperationsImpl;
import io.fabric8.openshift.client.internal.OpenShiftNamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl;
import io.fabric8.openshift.client.internal.OpenShiftNamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl;
import io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor;
import okhttp3.Authenticator;
Expand Down Expand Up @@ -703,9 +702,4 @@ public boolean supportsOpenShiftAPIGroup(String apiGroup) {
return false;
}

@Override
public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicable<HasMetadata> resource(HasMetadata item) {
return new OpenShiftNamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl(httpClient, getConfiguration(), item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.OAuthTokenProvider;
import io.fabric8.kubernetes.client.internal.readiness.Readiness;
import io.fabric8.kubernetes.client.utils.URLUtils;
import io.fabric8.kubernetes.client.utils.Utils;
import io.fabric8.openshift.client.internal.readiness.OpenShiftReadiness;
import io.sundr.builder.annotations.Buildable;
import io.sundr.builder.annotations.BuildableReference;
import okhttp3.TlsVersion;
Expand Down Expand Up @@ -189,4 +191,9 @@ public boolean isOpenshiftApiGroupsEnabled() {
public void setOpenshiftApiGroupsEnabled(boolean openshiftApiGroupsEnabled) {
this.openshiftApiGroupsEnabled = openshiftApiGroupsEnabled;
}

@Override
public Readiness getReadiness() {
return OpenShiftReadiness.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation;
import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import io.fabric8.kubernetes.client.internal.readiness.Readiness;
import io.fabric8.kubernetes.client.utils.ApiVersionUtil;
import io.fabric8.kubernetes.client.utils.URLUtils;
import io.fabric8.kubernetes.client.utils.Utils;
import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
import io.fabric8.openshift.client.internal.readiness.OpenShiftReadiness;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -101,11 +99,6 @@ public URL getRootUrl() {
}
}

@Override
public Readiness getReadiness() {
return OpenShiftReadiness.getInstance();
}

private void updateApiVersion() {
this.apiVersion = ApiVersionUtil.joinApiGroupAndVersion(apiGroupName, apiGroupVersion);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.fabric8.kubernetes.client.utils.Utils;
import io.fabric8.openshift.api.model.Parameter;
import io.fabric8.openshift.api.model.Template;
import io.fabric8.openshift.client.internal.readiness.OpenShiftReadiness;
import okhttp3.OkHttpClient;

import java.io.IOException;
Expand All @@ -46,11 +45,6 @@ public OpenShiftNamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableList
super(context, namespaceVisitOperationContext);
}

@Override
protected OpenShiftReadiness getReadiness() {
return OpenShiftReadiness.getInstance();
}

@Override
protected List<HasMetadata> asHasMetadata(Object item) {
if (item instanceof Template) {
Expand Down

0 comments on commit afaa31c

Please sign in to comment.