Skip to content

Commit

Permalink
fix fabric8io#4014: adding support for build version, and removing th…
Browse files Browse the repository at this point in the history
…e context
  • Loading branch information
shawkins authored and manusa committed Dec 12, 2022
1 parent ad33027 commit 065200e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 161 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -16,9 +16,10 @@
* Fix #4569: fixing jdk httpclient regression with 0 timeouts

#### Improvements
* Fix #4014: added support for OpenShift Build log version.
* Fix #4201: Removed sendAsync from the individual http client implementations
* Fix #4355: for exec, attach, upload, and copy operations the container id/name will be validated or chosen prior to the remote call. You may also use the kubectl.kubernetes.io/default-container annotation to specify the default container.
* Fix #4530: generalizing the Serialization logic to allow for primitive values and clarifying the type expectations.
* Fix #4201: Removed sendAsync from the individual http client implementations

#### Dependency Upgrade

Expand Down
Expand Up @@ -15,14 +15,16 @@
*/
package io.fabric8.openshift.client.server.mock;

import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.fabric8.openshift.client.OpenShiftClient;
import org.junit.jupiter.api.Test;

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

@EnableOpenShiftMockClient
@EnableKubernetesMockClient
class BuildTest {
OpenShiftMockServer server;
KubernetesMockServer server;
OpenShiftClient openShiftClient;

@Test
Expand All @@ -42,4 +44,13 @@ void testLogWithTimestamps() {
String log = openShiftClient.builds().inNamespace("ns1").withName("test-build").usingTimestamps().getLog();
assertEquals("test build output", log);
}

@Test
void testLogWithVersion() {
server.expect().withPath("/apis/build.openshift.io/v1/namespaces/ns1/builds/test-build/log?pretty=false&version=2")
.andReturn(200, "test build output").times(2);

String log = openShiftClient.builds().inNamespace("ns1").withName("test-build").withVersion(2).getLog();
assertEquals("test build output", log);
}
}
Expand Up @@ -22,4 +22,6 @@

public interface BuildResource extends Resource<Build>,
TimestampBytesLimitTerminateTimeTailPrettyLoggable {

TimestampBytesLimitTerminateTimeTailPrettyLoggable withVersion(Integer version);
}

This file was deleted.

Expand Up @@ -24,16 +24,17 @@
import io.fabric8.kubernetes.client.dsl.PrettyLoggable;
import io.fabric8.kubernetes.client.dsl.TailPrettyLoggable;
import io.fabric8.kubernetes.client.dsl.TimeTailPrettyLoggable;
import io.fabric8.kubernetes.client.dsl.TimestampBytesLimitTerminateTimeTailPrettyLoggable;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.LogWatchCallback;
import io.fabric8.kubernetes.client.dsl.internal.OperationContext;
import io.fabric8.kubernetes.client.dsl.internal.PodOperationContext;
import io.fabric8.kubernetes.client.utils.URLUtils;
import io.fabric8.kubernetes.client.utils.internal.PodOperationUtil;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.BuildList;
import io.fabric8.openshift.client.dsl.BuildResource;
import io.fabric8.openshift.client.dsl.internal.BuildOperationContext;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -50,69 +51,37 @@ public class BuildOperationsImpl extends HasMetadataOperation<Build, BuildList,
BuildResource {

public static final String OPENSHIFT_IO_BUILD_NAME = "openshift.io/build.name";
private final boolean withTerminatedStatus;
private final boolean withTimestamps;
private final String sinceTimestamp;
private final Integer sinceSeconds;
private final Integer withTailingLines;
private final boolean withPrettyOutput;
private final String version;
private final Integer limitBytes;
private Integer version;
private static final Integer DEFAULT_POD_LOG_WAIT_TIMEOUT = 5;
private Integer podLogWaitTimeout;
private final BuildOperationContext buildOperationContext;
private final PodOperationContext operationContext;

public BuildOperationsImpl(Client client) {
this(new BuildOperationContext(), HasMetadataOperationsImpl.defaultContext(client));
this(new PodOperationContext(), HasMetadataOperationsImpl.defaultContext(client), null);
}

public BuildOperationsImpl(BuildOperationContext context, OperationContext superContext) {
public BuildOperationsImpl(PodOperationContext context, OperationContext superContext, Integer version) {
super(superContext.withApiGroupName(BUILD)
.withPlural("builds"), Build.class, BuildList.class);
this.buildOperationContext = context;
this.withTerminatedStatus = context.isTerminatedStatus();
this.withTimestamps = context.isTimestamps();
this.sinceTimestamp = context.getSinceTimestamp();
this.sinceSeconds = context.getSinceSeconds();
this.withTailingLines = context.getTailingLines();
this.withPrettyOutput = context.isPrettyOutput();
this.version = context.getVersion();
this.limitBytes = context.getLimitBytes();
this.operationContext = context;
this.context = superContext;
this.version = version;
}

@Override
public BuildOperationsImpl newInstance(OperationContext context) {
return new BuildOperationsImpl(buildOperationContext, context);
return new BuildOperationsImpl(operationContext, context, version);
}

BuildOperationContext getContext() {
return buildOperationContext;
PodOperationContext getContext() {
return operationContext;
}

protected String getLogParameters() {
StringBuilder sb = new StringBuilder();
sb.append("log?pretty=").append(withPrettyOutput);
if (version != null && !version.isEmpty()) {
sb.append("&version=").append(version);
String params = operationContext.getLogParameters();
if (version != null) {
params += ("&version=" + version);
}
if (withTerminatedStatus) {
sb.append("&previous=true");
}
if (sinceSeconds != null) {
sb.append("&sinceSeconds=").append(sinceSeconds);
} else if (sinceTimestamp != null) {
sb.append("&sinceTime=").append(sinceTimestamp);
}
if (withTailingLines != null) {
sb.append("&tailLines=").append(withTailingLines);
}
if (limitBytes != null) {
sb.append("&limitBytes=").append(limitBytes);
}
if (withTimestamps) {
sb.append("&timestamps=true");
}
return sb.toString();
return params;
}

protected <T> T doGetLog(Class<T> type) {
Expand All @@ -131,7 +100,7 @@ public String getLog() {

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

/**
Expand Down Expand Up @@ -174,52 +143,56 @@ public LogWatch watchLog(OutputStream out) {

@Override
public Loggable withLogWaitTimeout(Integer logWaitTimeout) {
BuildOperationsImpl result = newInstance(context);
result.podLogWaitTimeout = logWaitTimeout;
return result;
return new BuildOperationsImpl(getContext().withLogWaitTimeout(logWaitTimeout), context, version);
}

@Override
public Loggable withPrettyOutput() {
return new BuildOperationsImpl(getContext().withPrettyOutput(true), context);
return new BuildOperationsImpl(getContext().withPrettyOutput(true), context, version);
}

@Override
public PrettyLoggable tailingLines(int tailingLines) {
return new BuildOperationsImpl(getContext().withTailingLines(tailingLines), context);
return new BuildOperationsImpl(getContext().withTailingLines(tailingLines), context, version);
}

@Override
public TimeTailPrettyLoggable terminated() {
return new BuildOperationsImpl(getContext().withTerminatedStatus(true), context);
return new BuildOperationsImpl(getContext().withTerminatedStatus(true), context, version);
}

@Override
public TailPrettyLoggable sinceTime(String sinceTimestamp) {
return new BuildOperationsImpl(getContext().withSinceTimestamp(sinceTimestamp), context);
return new BuildOperationsImpl(getContext().withSinceTimestamp(sinceTimestamp), context, version);
}

@Override
public TailPrettyLoggable sinceSeconds(int sinceSeconds) {
return new BuildOperationsImpl(getContext().withSinceSeconds(sinceSeconds), context);
return new BuildOperationsImpl(getContext().withSinceSeconds(sinceSeconds), context, version);
}

@Override
public BytesLimitTerminateTimeTailPrettyLoggable limitBytes(int limitBytes) {
return new BuildOperationsImpl(getContext().withLimitBytes(limitBytes), context);
return new BuildOperationsImpl(getContext().withLimitBytes(limitBytes), context, version);
}

@Override
public TimestampBytesLimitTerminateTimeTailPrettyLoggable withVersion(Integer version) {
return new BuildOperationsImpl(getContext(), context, version);
}

@Override
public BytesLimitTerminateTimeTailPrettyLoggable usingTimestamps() {
return new BuildOperationsImpl(getContext().withTimestamps(true), context);
return new BuildOperationsImpl(getContext().withTimestamps(true), context, version);
}

private void waitUntilBuildPodBecomesReady(Build build) {
List<PodResource> podOps = PodOperationUtil.getPodOperationsForController(context,
buildOperationContext.getPodOperationContext(), build.getMetadata().getUid(),
operationContext, build.getMetadata().getUid(),
getBuildPodLabels(build));

waitForBuildPodToBecomeReady(podOps, podLogWaitTimeout != null ? podLogWaitTimeout : DEFAULT_POD_LOG_WAIT_TIMEOUT);
waitForBuildPodToBecomeReady(podOps,
operationContext.getLogWaitTimeout() != null ? operationContext.getLogWaitTimeout() : DEFAULT_POD_LOG_WAIT_TIMEOUT);
}

private static void waitForBuildPodToBecomeReady(List<PodResource> podOps, Integer podLogWaitTimeout) {
Expand Down

0 comments on commit 065200e

Please sign in to comment.