Skip to content

Commit

Permalink
fix fabric8io#3853: replacing Boolean with boolean and throwing a 404…
Browse files Browse the repository at this point in the history
… from evict
  • Loading branch information
shawkins committed Mar 2, 2022
1 parent 14e3071 commit b64cd7e
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 56 deletions.
12 changes: 11 additions & 1 deletion doc/MIGRATION-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- [Adapt Changes](#adapt-changes)
- [Deprecations](#deprecations)
- [Object sorting](#object-sorting)
- [Boolean Changes](#boolean-changes)
- [evict Changes](#evict-changes)

## Namespace Changes

Expand Down Expand Up @@ -157,4 +159,12 @@ Client.isAdaptable and Client.adapt will check first if the existing instance is

## Object Sorting

KubernetesList and Template will no longer automatically sort their objects by default. You may use the HasMetadataComparator to sort the items as needed.
KubernetesList and Template will no longer automatically sort their objects by default. You may use the HasMetadataComparator to sort the items as needed.

## Boolean Changes

The usage of Boolean in the api was removed where it was not a nullable value. Please expect a boolean primitive from methods such as delete, copy, or as an argument in Loggable.getLog

## Evict Changes

Evictable.evict will throw an exception rather than returning false if the pod is not found. This ensures that false strictly means that the evict failed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.fabric8.kubernetes.client.dsl;


public interface ContainerResource<W, I, PI, O, PO, X, T, B, IS, UB>
public interface ContainerResource<W, I, PI, O, PO, X, T, IS>
extends TtyExecInputOutputErrorable<X, O, PO, I, PI, T>,
FileSelector<CopyOrReadable<B, IS, UB>>,
FileSelector<CopyOrReadable<IS>>,
TimestampBytesLimitTerminateTimeTailPrettyLoggable<W> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.nio.file.Path;

public interface Copiable<T> {
T copy(Path destination);
public interface Copiable {

boolean copy(Path destination);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/
package io.fabric8.kubernetes.client.dsl;

public interface CopyOrReadable<B, I, UB> extends Copiable<B>, Readable<I>, Uploadable<UB> {
public interface CopyOrReadable<I> extends Copiable, Readable<I>, Uploadable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public interface Deletable {
* @return value indicating object was deleted or not
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs.
*/
Boolean delete();
boolean delete();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

import io.fabric8.kubernetes.api.model.policy.v1.Eviction;

public interface Evictable<B> {
public interface Evictable {
/**
* Evicts resource, respecting {@link io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget}
* @return value indicating object was evicted or not
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs.
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs, including if the Pod is not found.
*/
B evict();
boolean evict();

/**
* Evicts a pod from its node subject to certain policies and safety constraints.
*
* @param eviction Eviction object
* @return value indicating object was evicted or not
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs.
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs, including if the Pod is not found.
*/
B evict(Eviction eviction);
boolean evict(Eviction eviction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface Loggable<W> {
* @param isPretty whether we need logs with pretty output or not
* @return logs as string
*/
String getLog(Boolean isPretty);
String getLog(boolean isPretty);

/**
* Get a Reader for reading logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public interface MultiDeleteable<T> {

Boolean delete(T... items);
boolean delete(T... items);

Boolean delete(List<T> items);
boolean delete(List<T> items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*/
package io.fabric8.kubernetes.client.dsl;

import io.fabric8.kubernetes.client.LocalPortForward;
import io.fabric8.kubernetes.client.PortForward;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;

import io.fabric8.kubernetes.client.LocalPortForward;
import io.fabric8.kubernetes.client.PortForward;

public interface PodResource<T> extends Resource<T>,
Loggable<LogWatch>,
Containerable<String, ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, Boolean, InputStream, Boolean>>,
ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, Boolean, InputStream, Boolean>,
Containerable<String, ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>>,
ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>,
PortForwardable<PortForward, LocalPortForward, ReadableByteChannel, WritableByteChannel>,
Evictable<Boolean>{
Evictable{
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
import java.io.InputStream;
import java.nio.file.Path;

public interface Uploadable<T> {
public interface Uploadable {

/**
* Upload file located at specified {@link Path} to Pod
*
* @param path path of the file which needs to be uploaded
* @return boolean value regarding upload was successful or not.
*/
T upload(Path path);
boolean upload(Path path);

/**
* Upload file extracted from provided InputStream to Pod
*
* @param inputStream {@link InputStream} which will be uploaded
* @return boolean value regarding upload was successful or not.
*/
T upload(InputStream inputStream);
boolean upload(InputStream inputStream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ResourceAdapter(Resource<T> resource) {
}

@Override
public Boolean delete() {
public boolean delete() {
return resource.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private ListOptions defaultListOptions(ListOptions options, Boolean watch) {
}

@Override
public Boolean delete() {
public boolean delete() {
if (item != null || (name != null && !name.isEmpty())) {
try {
deleteThis();
Expand All @@ -465,12 +465,12 @@ public Boolean delete() {

@SafeVarargs
@Override
public final Boolean delete(T... items) {
public final boolean delete(T... items) {
return delete(Arrays.asList(items));
}

@Override
public Boolean delete(List<T> items) {
public boolean delete(List<T> items) {
boolean deleted = true;
if (items != null) {
for (T toDelete : items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ public Waitable<List<HasMetadata>, HasMetadata> createOrReplaceAnd() {
}

@Override
public Boolean delete() {
public boolean delete() {
for (Resource<HasMetadata> impl : getResources()) {
if (Boolean.FALSE.equals(impl.delete())) {
if (!impl.delete()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private void waitUntilDeploymentIsScaled(final int count) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
StringBuilder stringBuilder = new StringBuilder();
List<RollableScalableResource<ReplicaSet>> rcList = doGetLog();
for (RollableScalableResource<ReplicaSet> rcOperation : rcList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Status rollback(DeploymentRollback deploymentRollback) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
return PodOperationUtil.getLog(doGetLog(isPretty), isPretty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Status rollback(DeploymentRollback deploymentRollback) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
return PodOperationUtil.getLog(doGetLog(isPretty), isPretty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public String getLog() {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
StringBuilder stringBuilder = new StringBuilder();
List<PodResource<Pod>> podOperationList = doGetLog(false);
for (PodResource<Pod> podOperation : podOperationList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -86,7 +85,7 @@
import io.fabric8.kubernetes.client.utils.internal.PodOperationUtil;
import io.fabric8.kubernetes.client.lib.FilenameUtils;

public class PodOperationsImpl extends HasMetadataOperation<Pod, PodList, PodResource<Pod>> implements PodResource<Pod>,CopyOrReadable<Boolean,InputStream, Boolean> {
public class PodOperationsImpl extends HasMetadataOperation<Pod, PodList, PodResource<Pod>> implements PodResource<Pod>,CopyOrReadable<InputStream> {

public static final int HTTP_TOO_MANY_REQUESTS = 429;
private static final Integer DEFAULT_POD_LOG_WAIT_TIMEOUT = 5;
Expand Down Expand Up @@ -201,7 +200,7 @@ public Reader getLogReader() {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
return new PodOperationsImpl(getContext().withPrettyOutput(isPretty), context).getLog();
}

Expand Down Expand Up @@ -266,7 +265,7 @@ public LocalPortForward portForward(int port, InetAddress localInetAddress, int
}

@Override
public Boolean evict() {
public boolean evict() {
Eviction eviction = new EvictionBuilder()
.withNewMetadata()
.withName(getName())
Expand All @@ -278,11 +277,11 @@ public Boolean evict() {
}

@Override
public Boolean evict(io.fabric8.kubernetes.api.model.policy.v1.Eviction eviction) {
public boolean evict(io.fabric8.kubernetes.api.model.policy.v1.Eviction eviction) {
return handleEvict(eviction);
}

private Boolean handleEvict(HasMetadata eviction) {
private boolean handleEvict(HasMetadata eviction) {
try {
if (Utils.isNullOrEmpty(eviction.getMetadata().getNamespace())) {
throw new KubernetesClientException("Namespace not specified, but operation requires it.");
Expand All @@ -296,7 +295,7 @@ private Boolean handleEvict(HasMetadata eviction) {
handleResponse(requestBuilder, null, Collections.emptyMap());
return true;
} catch (KubernetesClientException e) {
if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND && e.getCode() != HTTP_TOO_MANY_REQUESTS) {
if (e.getCode() != HTTP_TOO_MANY_REQUESTS) {
throw e;
}
return false;
Expand All @@ -309,7 +308,7 @@ private Boolean handleEvict(HasMetadata eviction) {
}

@Override
public ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, Boolean, InputStream, Boolean> inContainer(String containerId) {
public ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream> inContainer(String containerId) {
return new PodOperationsImpl(getContext().withContainerId(containerId), context);
}

Expand Down Expand Up @@ -364,17 +363,17 @@ URL getURLWithCommandParams(String[] commands) throws MalformedURLException {
}

@Override
public CopyOrReadable<Boolean, InputStream, Boolean> file(String file) {
public CopyOrReadable<InputStream> file(String file) {
return new PodOperationsImpl(getContext().withFile(file), context);
}

@Override
public CopyOrReadable<Boolean, InputStream, Boolean> dir(String dir) {
public CopyOrReadable<InputStream> dir(String dir) {
return new PodOperationsImpl(getContext().withDir(dir), context);
}

@Override
public Boolean copy(Path destination) {
public boolean copy(Path destination) {
try {
if (Utils.isNotNullOrEmpty(getContext().getFile())) {
copyFile(getContext().getFile(), destination.toFile());
Expand All @@ -390,7 +389,7 @@ public Boolean copy(Path destination) {
}

@Override
public Boolean upload(InputStream inputStream) {
public boolean upload(InputStream inputStream) {
return wrapRunWithOptionalDependency(() -> {
try {
return PodUpload.uploadFileData(httpClient, getContext(), this, inputStream);
Expand All @@ -402,7 +401,7 @@ public Boolean upload(InputStream inputStream) {
}

@Override
public Boolean upload(Path path) {
public boolean upload(Path path) {
return wrapRunWithOptionalDependency(() -> {
try {
return PodUpload.upload(httpClient, getContext(), this, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Status rollback(DeploymentRollback deploymentRollback) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
return PodOperationUtil.getLog(doGetLog(isPretty), isPretty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void waitUntilDeploymentIsScaled(final int count) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
StringBuilder stringBuilder = new StringBuilder();
List<RollableScalableResource<ReplicaSet>> rcList = doGetLog();
for (RollableScalableResource<ReplicaSet> rcOperation : rcList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Status rollback(DeploymentRollback deploymentRollback) {
}

@Override
public String getLog(Boolean isPretty) {
public String getLog(boolean isPretty) {
StringBuilder stringBuilder = new StringBuilder();
List<PodResource<Pod>> podOperationList = doGetLog(isPretty);
for (PodResource<Pod> podOperation : podOperationList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void testEvict() {
assertTrue(deleted);

// not found
deleted = client.pods().withName("pod2").evict();
assertFalse(deleted);
PodResource<Pod> podResource = client.pods().withName("pod2");
assertThrows(KubernetesClientException.class, () -> podResource.evict());

deleted = client.pods().inNamespace("ns1").withName("pod2").evict();
assertTrue(deleted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public NameableCreateOrDeleteable imageSignatures() {
return new NameableCreateOrDeleteable() {

@Override
public Boolean delete() {
public boolean delete() {
return operation.delete();
}

Expand Down
Loading

0 comments on commit b64cd7e

Please sign in to comment.