Skip to content

Commit

Permalink
Add PodExecOptions #2332 (#2335)
Browse files Browse the repository at this point in the history
Co-authored-by: Lewis Wolf <[email protected]>
  • Loading branch information
duco-lw and Lewis Wolf authored Jul 13, 2020
1 parent 7b577d2 commit 2904967
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Fix #2233: client.service().getUrl(..) should be able to fetch URL for ClusterIP based services
* Fix #2278: Added type parameters for KubernetesList in KubernetesClient + test verifying waitUntilCondition **always** retrieves resource from server
* Fix #2320: Added JUnit5 extension for mocking KubernetesClient in tests using @EnableKubernetesMockClient
* Fix #2332: Added PodExecOptions model

#### Dependency Upgrade

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ For example lets read a pod, from a yml file and work with it:

### Passing a reference of a resource to the client

In the same spirit you can use an object created externally (either a a reference or using its string representation.
In the same spirit you can use an object created externally (either a reference or using its string representation).

For example:

Expand Down
2 changes: 1 addition & 1 deletion kubernetes-model-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ If everything works well, you would have model upgraded to specified Kubernetes/
- `cmd/generate/generate.go` contains the main entry point and the descriptor of the schema.
Add new entries to the `Schema` struct and `schemagen.PackageDescriptor` to generate
an entry for any additional Go structs.
- `pkg/schenage` package contains the source files with the logic to generate the schema.
- `pkg/schemagen` package contains the source files with the logic to generate the schema.

### Kubernetes-Model-Annotator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.fabric8.kubernetes.api.model.GroupVersionKind;
import io.fabric8.kubernetes.api.model.GroupVersionResource;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.model.authentication.UserInfo;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -75,13 +74,13 @@ public class AdmissionRequest implements KubernetesResource
* Object is the object from the incoming request.
*/
@JsonProperty("object")
private HasMetadata object;
private KubernetesResource object;

/*
* OldObject is the existing object. Only populated for DELETE and UPDATE requests.
*/
@JsonProperty("oldObject")
private HasMetadata oldObject;
private KubernetesResource oldObject;

/*
* Operation is the operation being performed. This may be different than the operation
Expand Down Expand Up @@ -164,7 +163,7 @@ public class AdmissionRequest implements KubernetesResource
public AdmissionRequest() {
}

public AdmissionRequest(Boolean dryRun, GroupVersionKind kind, String name, String namespace, HasMetadata object, HasMetadata oldObject, String operation, HasMetadata options, GroupVersionKind requestKind, GroupVersionResource requestResource, String requestSubResource, GroupVersionResource resource, String subResource, String uid, UserInfo userInfo) {
public AdmissionRequest(Boolean dryRun, GroupVersionKind kind, String name, String namespace, KubernetesResource object, KubernetesResource oldObject, String operation, KubernetesResource options, GroupVersionKind requestKind, GroupVersionResource requestResource, String requestSubResource, GroupVersionResource resource, String subResource, String uid, UserInfo userInfo) {
this.dryRun = dryRun;
this.kind = kind;
this.name = name;
Expand Down Expand Up @@ -267,7 +266,7 @@ public void setNamespace(String namespace) {
* @return The object
*/
@JsonProperty("object")
public HasMetadata getObject() {
public KubernetesResource getObject() {
return object;
}

Expand All @@ -277,7 +276,7 @@ public HasMetadata getObject() {
* @param object The object
*/
@JsonProperty("object")
public void setObject(HasMetadata object) {
public void setObject(KubernetesResource object) {
this.object = object;
}

Expand All @@ -287,7 +286,7 @@ public void setObject(HasMetadata object) {
* @return The oldObject
*/
@JsonProperty("oldObject")
public HasMetadata getOldObject() {
public KubernetesResource getOldObject() {
return oldObject;
}

Expand All @@ -297,7 +296,7 @@ public HasMetadata getOldObject() {
* @param oldObject The oldObject
*/
@JsonProperty("oldObject")
public void setOldObject(HasMetadata oldObject) {
public void setOldObject(KubernetesResource oldObject) {
this.oldObject = oldObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Schema struct {

PodList kapi.PodList
PodTemplateList kapi.PodTemplateList
PodExecOptions kapi.PodExecOptions
ReplicationControllerList kapi.ReplicationControllerList
ServiceList kapi.ServiceList
EndpointPort kapi.EndpointPort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5714,6 +5714,57 @@
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"kubernetes_core_PodExecOptions": {
"type": "object",
"description": "",
"properties": {
"apiVersion": {
"type": "string",
"description": "",
"default": "v1",
"required": true
},
"command": {
"type": "array",
"description": "",
"items": {
"type": "string",
"description": ""
}
},
"container": {
"type": "string",
"description": ""
},
"kind": {
"type": "string",
"description": "",
"default": "PodExecOptions",
"required": true
},
"stderr": {
"type": "boolean",
"description": ""
},
"stdin": {
"type": "boolean",
"description": ""
},
"stdout": {
"type": "boolean",
"description": ""
},
"tty": {
"type": "boolean",
"description": ""
}
},
"additionalProperties": true,
"javaType": "io.fabric8.kubernetes.api.model.PodExecOptions",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"kubernetes_core_PodIP": {
"type": "object",
"description": "",
Expand Down Expand Up @@ -8470,6 +8521,10 @@
"$ref": "#/definitions/kubernetes_core_PersistentVolumeList",
"javaType": "io.fabric8.kubernetes.api.model.PersistentVolumeList"
},
"PodExecOptions": {
"$ref": "#/definitions/kubernetes_core_PodExecOptions",
"javaType": "io.fabric8.kubernetes.api.model.PodExecOptions"
},
"PodList": {
"$ref": "#/definitions/kubernetes_core_PodList",
"javaType": "io.fabric8.kubernetes.api.model.PodList"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5714,6 +5714,57 @@
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"kubernetes_core_PodExecOptions": {
"type": "object",
"description": "",
"properties": {
"apiVersion": {
"type": "string",
"description": "",
"default": "v1",
"required": true
},
"command": {
"type": "array",
"description": "",
"items": {
"type": "string",
"description": ""
}
},
"container": {
"type": "string",
"description": ""
},
"kind": {
"type": "string",
"description": "",
"default": "PodExecOptions",
"required": true
},
"stderr": {
"type": "boolean",
"description": ""
},
"stdin": {
"type": "boolean",
"description": ""
},
"stdout": {
"type": "boolean",
"description": ""
},
"tty": {
"type": "boolean",
"description": ""
}
},
"additionalProperties": true,
"javaType": "io.fabric8.kubernetes.api.model.PodExecOptions",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"kubernetes_core_PodIP": {
"type": "object",
"description": "",
Expand Down Expand Up @@ -8470,6 +8521,10 @@
"$ref": "#/definitions/kubernetes_core_PersistentVolumeList",
"javaType": "io.fabric8.kubernetes.api.model.PersistentVolumeList"
},
"PodExecOptions": {
"$ref": "#/definitions/kubernetes_core_PodExecOptions",
"javaType": "io.fabric8.kubernetes.api.model.PodExecOptions"
},
"PodList": {
"$ref": "#/definitions/kubernetes_core_PodList",
"javaType": "io.fabric8.kubernetes.api.model.PodList"
Expand Down Expand Up @@ -13001,6 +13056,51 @@
},
"additionalProperties": true
},
"podexecoptions": {
"properties": {
"apiVersion": {
"type": "string",
"description": "",
"default": "v1",
"required": true
},
"command": {
"type": "array",
"description": "",
"items": {
"type": "string",
"description": ""
}
},
"container": {
"type": "string",
"description": ""
},
"kind": {
"type": "string",
"description": "",
"default": "PodExecOptions",
"required": true
},
"stderr": {
"type": "boolean",
"description": ""
},
"stdin": {
"type": "boolean",
"description": ""
},
"stdout": {
"type": "boolean",
"description": ""
},
"tty": {
"type": "boolean",
"description": ""
}
},
"additionalProperties": true
},
"podip": {
"properties": {
"ip": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
*/
package io.fabric8.kubernetes.client.mock;

import io.fabric8.kubernetes.api.model.PodExecOptions;
import io.fabric8.kubernetes.api.model.admission.AdmissionReview;
import io.fabric8.kubernetes.client.utils.Serialization;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;

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

public class AdmissionReviewTest {
class AdmissionReviewTest {
@Test
@DisplayName("Should be able to deserialize from AdmissionRequest option set to CreateOption")
public void testJacksonParsingWithCreateOptions() throws IOException {
void testJacksonParsingWithCreateOptions() {
InputStream jsonStream = getClass().getResourceAsStream("/admissionreview.json");
AdmissionReview admissionReview = Serialization.unmarshal(jsonStream, AdmissionReview.class);
assertEquals("CREATE", admissionReview.getRequest().getOperation());
Expand All @@ -38,7 +38,7 @@ public void testJacksonParsingWithCreateOptions() throws IOException {

@Test
@DisplayName("Should be able to deserialize from AdmissionRequest option set to UpdateOption")
public void testJacksonParsingWithUpdateOptions() throws IOException {
void testJacksonParsingWithUpdateOptions() {
InputStream jsonStream = getClass().getResourceAsStream("/admissionreview-withupdateoptions.json");
AdmissionReview admissionReview = Serialization.unmarshal(jsonStream, AdmissionReview.class);
assertEquals("UPDATE", admissionReview.getRequest().getOperation());
Expand All @@ -47,13 +47,25 @@ public void testJacksonParsingWithUpdateOptions() throws IOException {

@Test
@DisplayName("Should be able to deserialize from AdmissionRequest option set to PatchOption")
public void testJacksonParsingWithPathOptions() throws IOException {
void testJacksonParsingWithPathOptions() {
InputStream jsonStream = getClass().getResourceAsStream("/admissionreview-withpatchoptions.json");
AdmissionReview admissionReview = Serialization.unmarshal(jsonStream, AdmissionReview.class);
assertEquals("PATCH", admissionReview.getRequest().getOperation());
assertRequest(admissionReview);
}

@Test
@DisplayName("Should be able to deserialize from AdmissionRequest object set to PodExecOptions")
void testJacksonParsingWithPodExecOptions() {
InputStream jsonStream = getClass().getResourceAsStream("/admissionreview-withconnectexec.json");
AdmissionReview admissionReview = Serialization.unmarshal(jsonStream, AdmissionReview.class);
assertEquals("CONNECT", admissionReview.getRequest().getOperation());
PodExecOptions podExecOptions = (PodExecOptions) admissionReview.getRequest().getObject();
assertEquals("PodExecOptions", podExecOptions.getKind());
assertEquals("myContainer", podExecOptions.getContainer());
assertRequest(admissionReview);
}

private void assertRequest(AdmissionReview admissionReview) {
assertEquals("myNamespace", admissionReview.getRequest().getNamespace());
assertEquals("66105089-3471-46ff-b4c8-293546c2aa6c", admissionReview.getRequest().getUid());
Expand Down
Loading

0 comments on commit 2904967

Please sign in to comment.