-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes-client-api): add pod ephemeral container operations
Add new interface EphemeralContainersResource to expose operations on this new operation context and is returned by a new method on PodResource. OperationContext and OperationSupport have been updated to support implementing operations on named resource sub-resources. Fixes #4758
- Loading branch information
Showing
14 changed files
with
698 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...tes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/StatusMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.api.model.Status; | ||
import io.fabric8.kubernetes.api.model.StatusBuilder; | ||
import io.fabric8.kubernetes.client.utils.Serialization; | ||
import io.fabric8.mockwebserver.internal.WebSocketMessage; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* {@link WebSocketMessage} that outputs a {@link Status} message. | ||
*/ | ||
public class StatusMessage extends WebSocketMessage { | ||
|
||
private static final byte ERROR_CHANNEL_STREAM_ID = 3; | ||
|
||
/** | ||
* Create websocket message that returns {@link Status} on the error channel. | ||
* | ||
* @param status status response | ||
*/ | ||
public StatusMessage(Status status) { | ||
super(0L, getBodyBytes(ERROR_CHANNEL_STREAM_ID, status), true, true); | ||
} | ||
|
||
/** | ||
* Create websocket message that returns a {@link Status} with the given status code | ||
* on the error channel. | ||
* | ||
* @param exitCode exit code | ||
*/ | ||
public StatusMessage(int exitCode) { | ||
this(new StatusBuilder() | ||
.withCode(exitCode) | ||
.withStatus(exitCode == 0 ? "Success" : "Failure") | ||
.build()); | ||
} | ||
|
||
private static byte[] getBodyBytes(byte prefix, Status status) { | ||
byte[] original = Serialization.asJson(status).getBytes(StandardCharsets.UTF_8); | ||
byte[] prefixed = new byte[original.length + 1]; | ||
prefixed[0] = prefix; | ||
System.arraycopy(original, 0, prefixed, 1, original.length); | ||
return prefixed; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/StatusMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.server.mock; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class StatusMessageTest { | ||
|
||
@Test | ||
void exitCode() { | ||
assertEquals("\u0003{\"apiVersion\":\"v1\",\"kind\":\"Status\",\"code\":0,\"status\":\"Success\"}", | ||
new StatusMessage(0).getBody()); | ||
assertEquals("\u0003{\"apiVersion\":\"v1\",\"kind\":\"Status\",\"code\":1,\"status\":\"Failure\"}", | ||
new StatusMessage(1).getBody()); | ||
assertEquals("\u0003{\"apiVersion\":\"v1\",\"kind\":\"Status\",\"code\":-1,\"status\":\"Failure\"}", | ||
new StatusMessage(-1).getBody()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...lient-api/src/main/java/io/fabric8/kubernetes/client/dsl/EphemeralContainersResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.dsl; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
|
||
/** | ||
* Operations for Pod Ephemeral Containers. Ephemeral containers are a special type of container that runs temporarily | ||
* in an existing Pod to accomplish user-initiated actions such as troubleshooting. You use ephemeral containers to | ||
* inspect services rather than to build applications. | ||
* | ||
* @see <a href="https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/">About Ephemeral Containers</a> | ||
* @see <a href= | ||
* "hhttps://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#-strong-ephemeralcontainers-operations-pod-v1-core-strong-">Ephemeral | ||
* Containers Operations</a> | ||
*/ | ||
public interface EphemeralContainersResource extends EditReplacePatchable<Pod> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.