diff --git a/junit/kube-api-test/core/pom.xml b/junit/kube-api-test/core/pom.xml index 6c196be4f8f..6bac5fe7f75 100644 --- a/junit/kube-api-test/core/pom.xml +++ b/junit/kube-api-test/core/pom.xml @@ -102,10 +102,6 @@ bcprov-jdk18on compile - - io.javaoperatorsdk - kubernetes-webhooks-framework-core - com.fasterxml.jackson.dataformat jackson-dataformat-yaml diff --git a/junit/kube-api-test/core/src/test/java/io/fabric8/kubeapitest/sample/KubernetesMutationHookHandlingTest.java b/junit/kube-api-test/core/src/test/java/io/fabric8/kubeapitest/sample/KubernetesMutationHookHandlingTest.java index 29f5819ad20..e68456eac24 100644 --- a/junit/kube-api-test/core/src/test/java/io/fabric8/kubeapitest/sample/KubernetesMutationHookHandlingTest.java +++ b/junit/kube-api-test/core/src/test/java/io/fabric8/kubeapitest/sample/KubernetesMutationHookHandlingTest.java @@ -18,14 +18,17 @@ import io.fabric8.kubeapitest.cert.CertManager; import io.fabric8.kubeapitest.junit.EnableKubeAPIServer; import io.fabric8.kubeapitest.junit.KubeConfig; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.admission.v1.AdmissionRequest; import io.fabric8.kubernetes.api.model.admission.v1.AdmissionReview; +import io.fabric8.kubernetes.api.model.admission.v1.AdmissionReviewBuilder; import io.fabric8.kubernetes.api.model.admissionregistration.v1.MutatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.networking.v1.*; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.Serialization; -import io.javaoperatorsdk.webhook.admission.AdmissionController; +import io.fabric8.zjsonpatch.JsonDiff; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.bouncycastle.asn1.x509.GeneralName; @@ -57,7 +60,8 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Base64; -import java.util.HashMap; +import java.util.Collections; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; @@ -76,23 +80,11 @@ class KubernetesMutationHookHandlingTest { private static final Logger log = LoggerFactory.getLogger(KubernetesMutationHookHandlingTest.class); public static final String PASSWORD = "secret"; - public static final String TEST_LABEL_KEY = "test-label"; - public static final String TEST_LABEL_VALUE = "mutation-test"; static File certFile = new File("target", "mutation.crt"); // server that handles mutation hooks static Server server = new Server(); - // using https://github.com/java-operator-sdk/kubernetes-webooks-framework framework to implement - // the response - static AdmissionController mutationController = new AdmissionController<>((resource, operation) -> { - if (resource.getMetadata().getLabels() == null) { - resource.getMetadata().setLabels(new HashMap<>()); - } - resource.getMetadata().getLabels().putIfAbsent(TEST_LABEL_KEY, TEST_LABEL_VALUE); - return resource; - }); - @Test void handleMutatingWebhook() { var client = new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(kubeConfig)).build(); @@ -100,7 +92,7 @@ void handleMutatingWebhook() { var ingress = client.resource(testIngress()).create(); - assertThat(ingress.getMetadata().getLabels()).containsEntry(TEST_LABEL_KEY, TEST_LABEL_VALUE); + assertThat(ingress.getMetadata().getLabels()).containsEntry("test", "mutation"); } @BeforeAll @@ -112,15 +104,33 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ HttpServletResponse httpServletResponse) { try { request.setHandled(true); - AdmissionReview admissionReview = Serialization.unmarshal(httpServletRequest.getInputStream()); - - var response = mutationController.handle(admissionReview); - - var out = httpServletResponse.getWriter(); - httpServletResponse.setContentType("application/json"); - httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString()); - httpServletResponse.setStatus(HttpServletResponse.SC_OK); - out.println(Serialization.asJson(response)); + final AdmissionReview requestedAdmissionReview = Serialization.unmarshal(httpServletRequest.getInputStream()); + final AdmissionRequest admissionRequest = requestedAdmissionReview.getRequest(); + var originalResource = Objects.equals("DELETE", admissionRequest.getOperation()) + ? admissionRequest.getOldObject() + : admissionRequest.getObject(); + if (originalResource instanceof HasMetadata) { + var originalResourceJson = Serialization.jsonMapper().valueToTree(originalResource); + (((HasMetadata) originalResource)).getMetadata().setLabels(Collections.singletonMap("test", "mutation")); + var editedResourceJson = Serialization.jsonMapper().valueToTree(originalResource); + final AdmissionReview responseAdmissionReview = new AdmissionReviewBuilder() + .withNewResponse() + .withAllowed() + .withPatchType("JSONPatch") + .withPatch(Base64.getEncoder().encodeToString( + JsonDiff.asJson(originalResourceJson, editedResourceJson).toString().getBytes(StandardCharsets.UTF_8))) + .withUid(admissionRequest.getUid()) + .endResponse() + .build(); + + var out = httpServletResponse.getWriter(); + httpServletResponse.setContentType("application/json"); + httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString()); + httpServletResponse.setStatus(HttpServletResponse.SC_OK); + out.println(Serialization.asJson(responseAdmissionReview)); + } else { + httpServletResponse.setStatus(422); + } } catch (Exception e) { log.error("Error in webhook", e); throw new RuntimeException(e); diff --git a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java new file mode 100644 index 00000000000..8bb46d85c75 --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java @@ -0,0 +1,313 @@ + +package io.fabric8.kubernetes.api.model.admission.v1; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.Generated; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.builder.Editable; +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.GroupVersionKind; +import io.fabric8.kubernetes.api.model.GroupVersionResource; +import io.fabric8.kubernetes.api.model.IntOrString; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.LabelSelector; +import io.fabric8.kubernetes.api.model.LocalObjectReference; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.ObjectReference; +import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; +import io.fabric8.kubernetes.api.model.PodTemplateSpec; +import io.fabric8.kubernetes.api.model.ResourceRequirements; +import io.fabric8.kubernetes.api.model.authentication.UserInfo; +import io.sundr.builder.annotations.Buildable; +import io.sundr.builder.annotations.BuildableReference; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "kind", + "dryRun", + "name", + "namespace", + "object", + "oldObject", + "operation", + "options", + "requestKind", + "requestResource", + "requestSubResource", + "resource", + "subResource", + "uid", + "userInfo" +}) +@ToString +@EqualsAndHashCode +@Accessors(prefix = { + "_", + "" +}) +@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { + @BuildableReference(ObjectMeta.class), + @BuildableReference(LabelSelector.class), + @BuildableReference(Container.class), + @BuildableReference(PodTemplateSpec.class), + @BuildableReference(ResourceRequirements.class), + @BuildableReference(IntOrString.class), + @BuildableReference(ObjectReference.class), + @BuildableReference(LocalObjectReference.class), + @BuildableReference(PersistentVolumeClaim.class) +}) +@Generated("jsonschema2pojo") +public class AdmissionRequest implements Editable , KubernetesResource +{ + + @JsonProperty("dryRun") + private Boolean dryRun; + @JsonProperty("kind") + private GroupVersionKind kind; + @JsonProperty("name") + private String name; + @JsonProperty("namespace") + private String namespace; + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object object; + @JsonProperty("oldObject") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object oldObject; + @JsonProperty("operation") + private String operation; + @JsonProperty("options") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object options; + @JsonProperty("requestKind") + private GroupVersionKind requestKind; + @JsonProperty("requestResource") + private GroupVersionResource requestResource; + @JsonProperty("requestSubResource") + private String requestSubResource; + @JsonProperty("resource") + private GroupVersionResource resource; + @JsonProperty("subResource") + private String subResource; + @JsonProperty("uid") + private String uid; + @JsonProperty("userInfo") + private UserInfo userInfo; + @JsonIgnore + private Map additionalProperties = new LinkedHashMap(); + + /** + * No args constructor for use in serialization + * + */ + public AdmissionRequest() { + } + + public AdmissionRequest(Boolean dryRun, GroupVersionKind kind, String name, String namespace, Object object, Object oldObject, String operation, Object options, GroupVersionKind requestKind, GroupVersionResource requestResource, String requestSubResource, GroupVersionResource resource, String subResource, String uid, UserInfo userInfo) { + super(); + this.dryRun = dryRun; + this.kind = kind; + this.name = name; + this.namespace = namespace; + this.object = object; + this.oldObject = oldObject; + this.operation = operation; + this.options = options; + this.requestKind = requestKind; + this.requestResource = requestResource; + this.requestSubResource = requestSubResource; + this.resource = resource; + this.subResource = subResource; + this.uid = uid; + this.userInfo = userInfo; + } + + @JsonProperty("dryRun") + public Boolean getDryRun() { + return dryRun; + } + + @JsonProperty("dryRun") + public void setDryRun(Boolean dryRun) { + this.dryRun = dryRun; + } + + @JsonProperty("kind") + public GroupVersionKind getKind() { + return kind; + } + + @JsonProperty("kind") + public void setKind(GroupVersionKind kind) { + this.kind = kind; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("object") + public Object getObject() { + return object; + } + + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setObject(Object object) { + this.object = object; + } + + @JsonProperty("oldObject") + public Object getOldObject() { + return oldObject; + } + + @JsonProperty("oldObject") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setOldObject(Object oldObject) { + this.oldObject = oldObject; + } + + @JsonProperty("operation") + public String getOperation() { + return operation; + } + + @JsonProperty("operation") + public void setOperation(String operation) { + this.operation = operation; + } + + @JsonProperty("options") + public Object getOptions() { + return options; + } + + @JsonProperty("options") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setOptions(Object options) { + this.options = options; + } + + @JsonProperty("requestKind") + public GroupVersionKind getRequestKind() { + return requestKind; + } + + @JsonProperty("requestKind") + public void setRequestKind(GroupVersionKind requestKind) { + this.requestKind = requestKind; + } + + @JsonProperty("requestResource") + public GroupVersionResource getRequestResource() { + return requestResource; + } + + @JsonProperty("requestResource") + public void setRequestResource(GroupVersionResource requestResource) { + this.requestResource = requestResource; + } + + @JsonProperty("requestSubResource") + public String getRequestSubResource() { + return requestSubResource; + } + + @JsonProperty("requestSubResource") + public void setRequestSubResource(String requestSubResource) { + this.requestSubResource = requestSubResource; + } + + @JsonProperty("resource") + public GroupVersionResource getResource() { + return resource; + } + + @JsonProperty("resource") + public void setResource(GroupVersionResource resource) { + this.resource = resource; + } + + @JsonProperty("subResource") + public String getSubResource() { + return subResource; + } + + @JsonProperty("subResource") + public void setSubResource(String subResource) { + this.subResource = subResource; + } + + @JsonProperty("uid") + public String getUid() { + return uid; + } + + @JsonProperty("uid") + public void setUid(String uid) { + this.uid = uid; + } + + @JsonProperty("userInfo") + public UserInfo getUserInfo() { + return userInfo; + } + + @JsonProperty("userInfo") + public void setUserInfo(UserInfo userInfo) { + this.userInfo = userInfo; + } + + @JsonIgnore + public AdmissionRequestBuilder edit() { + return new AdmissionRequestBuilder(this); + } + + @JsonIgnore + public AdmissionRequestBuilder toBuilder() { + return edit(); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java new file mode 100644 index 00000000000..c8a47a85fcc --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/generated/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java @@ -0,0 +1,313 @@ + +package io.fabric8.kubernetes.api.model.admission.v1beta1; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.Generated; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.builder.Editable; +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.GroupVersionKind; +import io.fabric8.kubernetes.api.model.GroupVersionResource; +import io.fabric8.kubernetes.api.model.IntOrString; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.LabelSelector; +import io.fabric8.kubernetes.api.model.LocalObjectReference; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.ObjectReference; +import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; +import io.fabric8.kubernetes.api.model.PodTemplateSpec; +import io.fabric8.kubernetes.api.model.ResourceRequirements; +import io.fabric8.kubernetes.api.model.authentication.UserInfo; +import io.sundr.builder.annotations.Buildable; +import io.sundr.builder.annotations.BuildableReference; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "kind", + "dryRun", + "name", + "namespace", + "object", + "oldObject", + "operation", + "options", + "requestKind", + "requestResource", + "requestSubResource", + "resource", + "subResource", + "uid", + "userInfo" +}) +@ToString +@EqualsAndHashCode +@Accessors(prefix = { + "_", + "" +}) +@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { + @BuildableReference(ObjectMeta.class), + @BuildableReference(LabelSelector.class), + @BuildableReference(Container.class), + @BuildableReference(PodTemplateSpec.class), + @BuildableReference(ResourceRequirements.class), + @BuildableReference(IntOrString.class), + @BuildableReference(ObjectReference.class), + @BuildableReference(LocalObjectReference.class), + @BuildableReference(PersistentVolumeClaim.class) +}) +@Generated("jsonschema2pojo") +public class AdmissionRequest implements Editable , KubernetesResource +{ + + @JsonProperty("dryRun") + private Boolean dryRun; + @JsonProperty("kind") + private GroupVersionKind kind; + @JsonProperty("name") + private String name; + @JsonProperty("namespace") + private String namespace; + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object object; + @JsonProperty("oldObject") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object oldObject; + @JsonProperty("operation") + private String operation; + @JsonProperty("options") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object options; + @JsonProperty("requestKind") + private GroupVersionKind requestKind; + @JsonProperty("requestResource") + private GroupVersionResource requestResource; + @JsonProperty("requestSubResource") + private String requestSubResource; + @JsonProperty("resource") + private GroupVersionResource resource; + @JsonProperty("subResource") + private String subResource; + @JsonProperty("uid") + private String uid; + @JsonProperty("userInfo") + private UserInfo userInfo; + @JsonIgnore + private Map additionalProperties = new LinkedHashMap(); + + /** + * No args constructor for use in serialization + * + */ + public AdmissionRequest() { + } + + public AdmissionRequest(Boolean dryRun, GroupVersionKind kind, String name, String namespace, Object object, Object oldObject, String operation, Object options, GroupVersionKind requestKind, GroupVersionResource requestResource, String requestSubResource, GroupVersionResource resource, String subResource, String uid, UserInfo userInfo) { + super(); + this.dryRun = dryRun; + this.kind = kind; + this.name = name; + this.namespace = namespace; + this.object = object; + this.oldObject = oldObject; + this.operation = operation; + this.options = options; + this.requestKind = requestKind; + this.requestResource = requestResource; + this.requestSubResource = requestSubResource; + this.resource = resource; + this.subResource = subResource; + this.uid = uid; + this.userInfo = userInfo; + } + + @JsonProperty("dryRun") + public Boolean getDryRun() { + return dryRun; + } + + @JsonProperty("dryRun") + public void setDryRun(Boolean dryRun) { + this.dryRun = dryRun; + } + + @JsonProperty("kind") + public GroupVersionKind getKind() { + return kind; + } + + @JsonProperty("kind") + public void setKind(GroupVersionKind kind) { + this.kind = kind; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("object") + public Object getObject() { + return object; + } + + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setObject(Object object) { + this.object = object; + } + + @JsonProperty("oldObject") + public Object getOldObject() { + return oldObject; + } + + @JsonProperty("oldObject") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setOldObject(Object oldObject) { + this.oldObject = oldObject; + } + + @JsonProperty("operation") + public String getOperation() { + return operation; + } + + @JsonProperty("operation") + public void setOperation(String operation) { + this.operation = operation; + } + + @JsonProperty("options") + public Object getOptions() { + return options; + } + + @JsonProperty("options") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setOptions(Object options) { + this.options = options; + } + + @JsonProperty("requestKind") + public GroupVersionKind getRequestKind() { + return requestKind; + } + + @JsonProperty("requestKind") + public void setRequestKind(GroupVersionKind requestKind) { + this.requestKind = requestKind; + } + + @JsonProperty("requestResource") + public GroupVersionResource getRequestResource() { + return requestResource; + } + + @JsonProperty("requestResource") + public void setRequestResource(GroupVersionResource requestResource) { + this.requestResource = requestResource; + } + + @JsonProperty("requestSubResource") + public String getRequestSubResource() { + return requestSubResource; + } + + @JsonProperty("requestSubResource") + public void setRequestSubResource(String requestSubResource) { + this.requestSubResource = requestSubResource; + } + + @JsonProperty("resource") + public GroupVersionResource getResource() { + return resource; + } + + @JsonProperty("resource") + public void setResource(GroupVersionResource resource) { + this.resource = resource; + } + + @JsonProperty("subResource") + public String getSubResource() { + return subResource; + } + + @JsonProperty("subResource") + public void setSubResource(String subResource) { + this.subResource = subResource; + } + + @JsonProperty("uid") + public String getUid() { + return uid; + } + + @JsonProperty("uid") + public void setUid(String uid) { + this.uid = uid; + } + + @JsonProperty("userInfo") + public UserInfo getUserInfo() { + return userInfo; + } + + @JsonProperty("userInfo") + public void setUserInfo(UserInfo userInfo) { + this.userInfo = userInfo; + } + + @JsonIgnore + public AdmissionRequestBuilder edit() { + return new AdmissionRequestBuilder(this); + } + + @JsonIgnore + public AdmissionRequestBuilder toBuilder() { + return edit(); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java deleted file mode 100644 index f4c8a5962fc..00000000000 --- a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1/AdmissionRequest.java +++ /dev/null @@ -1,497 +0,0 @@ -/* - * 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.api.model.admission.v1; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -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.KubernetesResource; -import io.fabric8.kubernetes.api.model.authentication.UserInfo; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import java.util.HashMap; -import java.util.Map; - -/** - * AdmissionRequest describes the admission.Attributes for the admission request. - * - * This POJO is derived from https://github.com/kubernetes/api/blob/master/admission/v1beta1/types.go - */ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonDeserialize -@ToString -@EqualsAndHashCode -public class AdmissionRequest implements KubernetesResource { - - /* - * DryRun indicates that modifications will definitely not be persisted for this request. - * Defaults to false. - */ - @JsonProperty("dryRun") - private Boolean dryRun; - - /* - * Kind is fully-qualified resource being requested (for example, v1.Pods) - */ - @JsonProperty("kind") - private GroupVersionKind kind; - - /* - * Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and - * rely on the server to generate the name. If that is the case, this field will contain an empty string. - */ - @JsonProperty("name") - private String name; - - /* - * Namespace is the namespace associated with the request (if any). - */ - @JsonProperty("namespace") - private String namespace; - - /* - * Object is the object from the incoming request. - */ - @JsonProperty("object") - private KubernetesResource object; - - /* - * OldObject is the existing object. Only populated for DELETE and UPDATE requests. - */ - @JsonProperty("oldObject") - private KubernetesResource oldObject; - - /* - * Operation is the operation being performed. This may be different than the operation - * requested. e.g. a patch can result in either a CREATE or UPDATE Operation. - */ - @JsonProperty("operation") - private String operation; - - @JsonProperty("options") - private KubernetesResource options; - - /* - * RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). - * If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. - * - * For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of - * `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, - * an API request to apps/v1beta1 deployments would be converted and sent to the webhook - * with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), - * and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original - * API request). - */ - @JsonProperty("requestKind") - private GroupVersionKind requestKind; - - /* - * RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). - * If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. - * - * For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of - * `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, - * an API request to apps/v1beta1 deployments would be converted and sent to the webhook - * with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), - * and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original - * API request). - * - * See documentation for the "matchPolicy" field in the webhook configuration type. - */ - @JsonProperty("requestResource") - private GroupVersionResource requestResource; - - /* - * RequestSubResource is the name of the subresource of the original API request, if any (for example, "status" or "scale") - * If this is specified and differs from the value in "subResource", an equivalent match and conversion was performed. - * See documentation for the "matchPolicy" field in the webhook configuration type. - */ - @JsonProperty("requestSubResource") - private String requestSubResource; - - /* - * Resource is the fully-qualified resource being requested (for example, v1.pods) - */ - @JsonProperty("resource") - private GroupVersionResource resource; - - /* - * SubResource is the subresource being requested (for example, "status" or "scale") - */ - @JsonProperty("subResource") - private String subResource; - - /* - * UID is identifier for individual request/response. It allows us to distinguish instances of - * requests which otherwise identical (parallel requests, requests when earlier requests did not - * modify etc). The UID is meant to track the round trip (request/response) between KAS and - * the WebHook, not the user request. - * It is suitable for correlating log entries between the webhook and apiserver, for either - * auditing or debugging. - */ - @JsonProperty("uid") - private String uid; - - /* - * UserInfo is information about the requesting user - */ - @JsonProperty("userInfo") - private UserInfo userInfo; - - @JsonIgnore - private Map additionalProperties = new HashMap<>(); - - public AdmissionRequest() { - } - - 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; - this.namespace = namespace; - this.object = object; - this.oldObject = oldObject; - this.operation = operation; - this.options = options; - this.requestKind = requestKind; - this.requestResource = requestResource; - this.requestSubResource = requestSubResource; - this.resource = resource; - this.subResource = subResource; - this.uid = uid; - this.userInfo = userInfo; - } - - /** - * Get Dry Run - * - * @return The dryRun - */ - @JsonProperty("dryRun") - public Boolean getDryRun() { - return dryRun; - } - - /** - * Set Dry run - * - * @param dryRun The dryRun - */ - @JsonProperty("dryRun") - public void setDryRun(Boolean dryRun) { - this.dryRun = dryRun; - } - - /** - * Get Kind - * - * @return The kind - */ - @JsonProperty("kind") - public GroupVersionKind getKind() { - return kind; - } - - /** - * Set Kind - * - * @param kind The kind - */ - @JsonProperty("kind") - public void setKind(GroupVersionKind kind) { - this.kind = kind; - } - - /** - * Get Name - * - * @return The name - */ - @JsonProperty("name") - public String getName() { - return name; - } - - /** - * Set Name - * - * @param name The name - */ - @JsonProperty("name") - public void setName(String name) { - this.name = name; - } - - /** - * Get Namespace - * - * @return The namespace - */ - @JsonProperty("namespace") - public String getNamespace() { - return namespace; - } - - /** - * Set Namespace - * - * @param namespace The namespace - */ - @JsonProperty("namespace") - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - /** - * Get Object - * - * @return The object - */ - @JsonProperty("object") - public KubernetesResource getObject() { - return object; - } - - /** - * Set Object - * - * @param object The object - */ - @JsonProperty("object") - public void setObject(KubernetesResource object) { - this.object = object; - } - - /** - * Get old object. - * - * @return The oldObject - */ - @JsonProperty("oldObject") - public KubernetesResource getOldObject() { - return oldObject; - } - - /** - * Set old object. - * - * @param oldObject The oldObject - */ - @JsonProperty("oldObject") - public void setOldObject(KubernetesResource oldObject) { - this.oldObject = oldObject; - } - - /** - * Get operation. - * - * @return The operation - */ - @JsonProperty("operation") - public String getOperation() { - return operation; - } - - /** - * Set operation. - * - * @param operation The operation - */ - @JsonProperty("operation") - public void setOperation(String operation) { - this.operation = operation; - } - - /** - * Get options. - * - * @return The options - */ - @JsonProperty("options") - public KubernetesResource getOptions() { - return options; - } - - /** - * Set options. - * - * @param options The options - */ - @JsonProperty("options") - public void setOptions(KubernetesResource options) { - this.options = options; - } - - /** - * Get Request Kind. - * - * @return The requestKind - */ - @JsonProperty("requestKind") - public GroupVersionKind getRequestKind() { - return requestKind; - } - - /** - * Set RequestKind - * - * @param requestKind The requestKind - */ - @JsonProperty("requestKind") - public void setRequestKind(GroupVersionKind requestKind) { - this.requestKind = requestKind; - } - - /** - * Get RequestResource - * - * @return The requestResource - */ - @JsonProperty("requestResource") - public GroupVersionResource getRequestResource() { - return requestResource; - } - - /** - * Set RequestResource - * - * @param requestResource The requestResource - */ - @JsonProperty("requestResource") - public void setRequestResource(GroupVersionResource requestResource) { - this.requestResource = requestResource; - } - - /** - * Get RequestSubResource - * - * @return The requestSubResource - */ - @JsonProperty("requestSubResource") - public String getRequestSubResource() { - return requestSubResource; - } - - /** - * Set RequestSubResource - * - * @param requestSubResource The requestSubResource - */ - @JsonProperty("requestSubResource") - public void setRequestSubResource(String requestSubResource) { - this.requestSubResource = requestSubResource; - } - - /** - * Get Resource - * - * @return The resource - */ - @JsonProperty("resource") - public GroupVersionResource getResource() { - return resource; - } - - /** - * Set Resource. - * - * @param resource The resource - */ - @JsonProperty("resource") - public void setResource(GroupVersionResource resource) { - this.resource = resource; - } - - /** - * Get SubResource - * - * @return The subResource - */ - @JsonProperty("subResource") - public String getSubResource() { - return subResource; - } - - /** - * Set SubResource - * - * @param subResource The subResource - */ - @JsonProperty("subResource") - public void setSubResource(String subResource) { - this.subResource = subResource; - } - - /** - * Get Uid - * - * @return The uid - */ - @JsonProperty("uid") - public String getUid() { - return uid; - } - - /** - * Set Uid - * - * @param uid The uid - */ - @JsonProperty("uid") - public void setUid(String uid) { - this.uid = uid; - } - - /** - * Get UserInfo - * - * @return The userInfo - */ - @JsonProperty("userInfo") - public UserInfo getUserInfo() { - return userInfo; - } - - /** - * Set UserInfo - * - * @param userInfo The userInfo - */ - @JsonProperty("userInfo") - public void setUserInfo(UserInfo userInfo) { - this.userInfo = userInfo; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java b/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java deleted file mode 100644 index 6ce8b4d99aa..00000000000 --- a/kubernetes-model-generator/kubernetes-model-admissionregistration/src/main/java/io/fabric8/kubernetes/api/model/admission/v1beta1/AdmissionRequest.java +++ /dev/null @@ -1,497 +0,0 @@ -/* - * 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.api.model.admission.v1beta1; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -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.KubernetesResource; -import io.fabric8.kubernetes.api.model.authentication.UserInfo; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import java.util.HashMap; -import java.util.Map; - -/** - * AdmissionRequest describes the admission.Attributes for the admission request. - * - * This POJO is derived from https://github.com/kubernetes/api/blob/master/admission/v1beta1/types.go - */ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonDeserialize -@ToString -@EqualsAndHashCode -public class AdmissionRequest implements KubernetesResource { - - /* - * DryRun indicates that modifications will definitely not be persisted for this request. - * Defaults to false. - */ - @JsonProperty("dryRun") - private Boolean dryRun; - - /* - * Kind is fully-qualified resource being requested (for example, v1.Pods) - */ - @JsonProperty("kind") - private GroupVersionKind kind; - - /* - * Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and - * rely on the server to generate the name. If that is the case, this field will contain an empty string. - */ - @JsonProperty("name") - private String name; - - /* - * Namespace is the namespace associated with the request (if any). - */ - @JsonProperty("namespace") - private String namespace; - - /* - * Object is the object from the incoming request. - */ - @JsonProperty("object") - private KubernetesResource object; - - /* - * OldObject is the existing object. Only populated for DELETE and UPDATE requests. - */ - @JsonProperty("oldObject") - private KubernetesResource oldObject; - - /* - * Operation is the operation being performed. This may be different than the operation - * requested. e.g. a patch can result in either a CREATE or UPDATE Operation. - */ - @JsonProperty("operation") - private String operation; - - @JsonProperty("options") - private KubernetesResource options; - - /* - * RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). - * If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. - * - * For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of - * `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, - * an API request to apps/v1beta1 deployments would be converted and sent to the webhook - * with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), - * and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original - * API request). - */ - @JsonProperty("requestKind") - private GroupVersionKind requestKind; - - /* - * RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). - * If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. - * - * For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of - * `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, - * an API request to apps/v1beta1 deployments would be converted and sent to the webhook - * with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), - * and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original - * API request). - * - * See documentation for the "matchPolicy" field in the webhook configuration type. - */ - @JsonProperty("requestResource") - private GroupVersionResource requestResource; - - /* - * RequestSubResource is the name of the subresource of the original API request, if any (for example, "status" or "scale") - * If this is specified and differs from the value in "subResource", an equivalent match and conversion was performed. - * See documentation for the "matchPolicy" field in the webhook configuration type. - */ - @JsonProperty("requestSubResource") - private String requestSubResource; - - /* - * Resource is the fully-qualified resource being requested (for example, v1.pods) - */ - @JsonProperty("resource") - private GroupVersionResource resource; - - /* - * SubResource is the subresource being requested (for example, "status" or "scale") - */ - @JsonProperty("subResource") - private String subResource; - - /* - * UID is identifier for individual request/response. It allows us to distinguish instances of - * requests which otherwise identical (parallel requests, requests when earlier requests did not - * modify etc). The UID is meant to track the round trip (request/response) between KAS and - * the WebHook, not the user request. - * It is suitable for correlating log entries between the webhook and apiserver, for either - * auditing or debugging. - */ - @JsonProperty("uid") - private String uid; - - /* - * UserInfo is information about the requesting user - */ - @JsonProperty("userInfo") - private UserInfo userInfo; - - @JsonIgnore - private Map additionalProperties = new HashMap<>(); - - public AdmissionRequest() { - } - - 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; - this.namespace = namespace; - this.object = object; - this.oldObject = oldObject; - this.operation = operation; - this.options = options; - this.requestKind = requestKind; - this.requestResource = requestResource; - this.requestSubResource = requestSubResource; - this.resource = resource; - this.subResource = subResource; - this.uid = uid; - this.userInfo = userInfo; - } - - /** - * Get Dry Run - * - * @return The dryRun - */ - @JsonProperty("dryRun") - public Boolean getDryRun() { - return dryRun; - } - - /** - * Set Dry run - * - * @param dryRun The dryRun - */ - @JsonProperty("dryRun") - public void setDryRun(Boolean dryRun) { - this.dryRun = dryRun; - } - - /** - * Get Kind - * - * @return The kind - */ - @JsonProperty("kind") - public GroupVersionKind getKind() { - return kind; - } - - /** - * Set Kind - * - * @param kind The kind - */ - @JsonProperty("kind") - public void setKind(GroupVersionKind kind) { - this.kind = kind; - } - - /** - * Get Name - * - * @return The name - */ - @JsonProperty("name") - public String getName() { - return name; - } - - /** - * Set Name - * - * @param name The name - */ - @JsonProperty("name") - public void setName(String name) { - this.name = name; - } - - /** - * Get Namespace - * - * @return The namespace - */ - @JsonProperty("namespace") - public String getNamespace() { - return namespace; - } - - /** - * Set Namespace - * - * @param namespace The namespace - */ - @JsonProperty("namespace") - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - /** - * Get Object - * - * @return The object - */ - @JsonProperty("object") - public KubernetesResource getObject() { - return object; - } - - /** - * Set Object - * - * @param object The object - */ - @JsonProperty("object") - public void setObject(KubernetesResource object) { - this.object = object; - } - - /** - * Get old object. - * - * @return The oldObject - */ - @JsonProperty("oldObject") - public KubernetesResource getOldObject() { - return oldObject; - } - - /** - * Set old object. - * - * @param oldObject The oldObject - */ - @JsonProperty("oldObject") - public void setOldObject(KubernetesResource oldObject) { - this.oldObject = oldObject; - } - - /** - * Get operation. - * - * @return The operation - */ - @JsonProperty("operation") - public String getOperation() { - return operation; - } - - /** - * Set operation. - * - * @param operation The operation - */ - @JsonProperty("operation") - public void setOperation(String operation) { - this.operation = operation; - } - - /** - * Get options. - * - * @return The options - */ - @JsonProperty("options") - public KubernetesResource getOptions() { - return options; - } - - /** - * Set options. - * - * @param options The options - */ - @JsonProperty("options") - public void setOptions(KubernetesResource options) { - this.options = options; - } - - /** - * Get Request Kind. - * - * @return The requestKind - */ - @JsonProperty("requestKind") - public GroupVersionKind getRequestKind() { - return requestKind; - } - - /** - * Set RequestKind - * - * @param requestKind The requestKind - */ - @JsonProperty("requestKind") - public void setRequestKind(GroupVersionKind requestKind) { - this.requestKind = requestKind; - } - - /** - * Get RequestResource - * - * @return The requestResource - */ - @JsonProperty("requestResource") - public GroupVersionResource getRequestResource() { - return requestResource; - } - - /** - * Set RequestResource - * - * @param requestResource The requestResource - */ - @JsonProperty("requestResource") - public void setRequestResource(GroupVersionResource requestResource) { - this.requestResource = requestResource; - } - - /** - * Get RequestSubResource - * - * @return The requestSubResource - */ - @JsonProperty("requestSubResource") - public String getRequestSubResource() { - return requestSubResource; - } - - /** - * Set RequestSubResource - * - * @param requestSubResource The requestSubResource - */ - @JsonProperty("requestSubResource") - public void setRequestSubResource(String requestSubResource) { - this.requestSubResource = requestSubResource; - } - - /** - * Get Resource - * - * @return The resource - */ - @JsonProperty("resource") - public GroupVersionResource getResource() { - return resource; - } - - /** - * Set Resource. - * - * @param resource The resource - */ - @JsonProperty("resource") - public void setResource(GroupVersionResource resource) { - this.resource = resource; - } - - /** - * Get SubResource - * - * @return The subResource - */ - @JsonProperty("subResource") - public String getSubResource() { - return subResource; - } - - /** - * Set SubResource - * - * @param subResource The subResource - */ - @JsonProperty("subResource") - public void setSubResource(String subResource) { - this.subResource = subResource; - } - - /** - * Get Uid - * - * @return The uid - */ - @JsonProperty("uid") - public String getUid() { - return uid; - } - - /** - * Set Uid - * - * @param uid The uid - */ - @JsonProperty("uid") - public void setUid(String uid) { - this.uid = uid; - } - - /** - * Get UserInfo - * - * @return The userInfo - */ - @JsonProperty("userInfo") - public UserInfo getUserInfo() { - return userInfo; - } - - /** - * Set UserInfo - * - * @param userInfo The userInfo - */ - @JsonProperty("userInfo") - public void setUserInfo(UserInfo userInfo) { - this.userInfo = userInfo; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionRequest.java b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionRequest.java index 7bb9a369244..c1e676a5f70 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionRequest.java +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionRequest.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -25,7 +24,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -54,9 +52,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class ConversionRequest implements Editable , KubernetesResource @@ -65,8 +61,9 @@ public class ConversionRequest implements Editable , K @JsonProperty("desiredAPIVersion") private String desiredAPIVersion; @JsonProperty("objects") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForList.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List objects = new ArrayList<>(); + private List objects = new ArrayList<>(); @JsonProperty("uid") private String uid; @JsonIgnore @@ -79,7 +76,7 @@ public class ConversionRequest implements Editable , K public ConversionRequest() { } - public ConversionRequest(String desiredAPIVersion, List objects, String uid) { + public ConversionRequest(String desiredAPIVersion, List objects, String uid) { super(); this.desiredAPIVersion = desiredAPIVersion; this.objects = objects; @@ -98,12 +95,13 @@ public void setDesiredAPIVersion(String desiredAPIVersion) { @JsonProperty("objects") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public List getObjects() { + public List getObjects() { return objects; } @JsonProperty("objects") - public void setObjects(List objects) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForList.class) + public void setObjects(List objects) { this.objects = objects; } diff --git a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionResponse.java b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionResponse.java index b3084efe6ed..13478970748 100644 --- a/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionResponse.java +++ b/kubernetes-model-generator/kubernetes-model-apiextensions/src/generated/java/io/fabric8/kubernetes/api/model/apiextensions/v1/ConversionResponse.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -26,7 +25,6 @@ import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; import io.fabric8.kubernetes.api.model.Status; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -55,17 +53,16 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class ConversionResponse implements Editable , KubernetesResource { @JsonProperty("convertedObjects") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForList.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List convertedObjects = new ArrayList<>(); + private List convertedObjects = new ArrayList<>(); @JsonProperty("result") private Status result; @JsonProperty("uid") @@ -80,7 +77,7 @@ public class ConversionResponse implements Editable , public ConversionResponse() { } - public ConversionResponse(List convertedObjects, Status result, String uid) { + public ConversionResponse(List convertedObjects, Status result, String uid) { super(); this.convertedObjects = convertedObjects; this.result = result; @@ -89,12 +86,13 @@ public ConversionResponse(List convertedObjects, Status resu @JsonProperty("convertedObjects") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public List getConvertedObjects() { + public List getConvertedObjects() { return convertedObjects; } @JsonProperty("convertedObjects") - public void setConvertedObjects(List convertedObjects) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForList.class) + public void setConvertedObjects(List convertedObjects) { this.convertedObjects = convertedObjects; } diff --git a/kubernetes-model-generator/kubernetes-model-apps/src/generated/java/io/fabric8/kubernetes/api/model/apps/ControllerRevision.java b/kubernetes-model-generator/kubernetes-model-apps/src/generated/java/io/fabric8/kubernetes/api/model/apps/ControllerRevision.java index d31071e5def..14adececb25 100644 --- a/kubernetes-model-generator/kubernetes-model-apps/src/generated/java/io/fabric8/kubernetes/api/model/apps/ControllerRevision.java +++ b/kubernetes-model-generator/kubernetes-model-apps/src/generated/java/io/fabric8/kubernetes/api/model/apps/ControllerRevision.java @@ -13,10 +13,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.IntOrString; -import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; import io.fabric8.kubernetes.api.model.Namespaced; @@ -25,7 +23,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.Version; import io.sundr.builder.annotations.Buildable; @@ -60,9 +57,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @TemplateTransformations({ @TemplateTransformation(value = "/manifest.vm", outputPath = "META-INF/services/io.fabric8.kubernetes.api.model.KubernetesResource", gather = true) @@ -81,7 +76,8 @@ public class ControllerRevision implements Editable , @JsonProperty("apiVersion") private String apiVersion = "apps/v1"; @JsonProperty("data") - private KubernetesResource data; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object data; /** * * (Required) @@ -103,7 +99,7 @@ public class ControllerRevision implements Editable , public ControllerRevision() { } - public ControllerRevision(String apiVersion, KubernetesResource data, String kind, ObjectMeta metadata, Long revision) { + public ControllerRevision(String apiVersion, Object data, String kind, ObjectMeta metadata, Long revision) { super(); this.apiVersion = apiVersion; this.data = data; @@ -133,12 +129,13 @@ public void setApiVersion(String apiVersion) { } @JsonProperty("data") - public KubernetesResource getData() { + public Object getData() { return data; } @JsonProperty("data") - public void setData(KubernetesResource data) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setData(Object data) { this.data = data; } diff --git a/kubernetes-model-generator/kubernetes-model-common/src/main/java/io/fabric8/kubernetes/model/util/Helper.java b/kubernetes-model-generator/kubernetes-model-common/src/main/java/io/fabric8/kubernetes/model/util/Helper.java index 59f5d40e350..389a80db4f7 100644 --- a/kubernetes-model-generator/kubernetes-model-common/src/main/java/io/fabric8/kubernetes/model/util/Helper.java +++ b/kubernetes-model-generator/kubernetes-model-common/src/main/java/io/fabric8/kubernetes/model/util/Helper.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.lang.annotation.Annotation; import java.util.Arrays; +import java.util.Objects; import java.util.Scanner; public class Helper { @@ -31,7 +32,7 @@ private Helper() { public static String loadJson(String path) { try (InputStream resourceAsStream = Helper.class.getResourceAsStream(path)) { - final Scanner scanner = new Scanner(resourceAsStream).useDelimiter("\\A"); + final Scanner scanner = new Scanner(Objects.requireNonNull(resourceAsStream)).useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; } catch (IOException e) { throw new RuntimeException(e); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NamedExtension.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NamedExtension.java index 83667c83489..68d235f35a6 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NamedExtension.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NamedExtension.java @@ -35,7 +35,8 @@ public class NamedExtension implements Editable , Kuberne { @JsonProperty("extension") - private KubernetesResource extension; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object extension; @JsonProperty("name") private String name; @JsonIgnore @@ -48,19 +49,20 @@ public class NamedExtension implements Editable , Kuberne public NamedExtension() { } - public NamedExtension(KubernetesResource extension, String name) { + public NamedExtension(Object extension, String name) { super(); this.extension = extension; this.name = name; } @JsonProperty("extension") - public KubernetesResource getExtension() { + public Object getExtension() { return extension; } @JsonProperty("extension") - public void setExtension(KubernetesResource extension) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setExtension(Object extension) { this.extension = extension; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java index c86b669b395..27b8c80337f 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java @@ -35,7 +35,8 @@ public class WatchEvent implements Editable , KubernetesResou { @JsonProperty("object") - private KubernetesResource object; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object object; @JsonProperty("type") private String type; @JsonIgnore @@ -48,19 +49,20 @@ public class WatchEvent implements Editable , KubernetesResou public WatchEvent() { } - public WatchEvent(KubernetesResource object, String type) { + public WatchEvent(Object object, String type) { super(); this.object = object; this.type = type; } @JsonProperty("object") - public KubernetesResource getObject() { + public Object getObject() { return object; } @JsonProperty("object") - public void setObject(KubernetesResource object) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setObject(Object object) { this.object = object; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java index 3254cec37fe..1c0bce94c45 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java @@ -96,7 +96,11 @@ public KubernetesDeserializer(boolean scanClassloaders) { @Override public KubernetesResource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - JsonNode node = jp.readValueAsTree(); + final JsonNode node = jp.readValueAsTree(); + return deserialize(jp, node); + } + + final KubernetesResource deserialize(JsonParser jp, JsonNode node) throws IOException { if (node.isObject()) { return fromObjectNode(jp, node); } else if (node.isArray()) { diff --git a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForList.java b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForList.java new file mode 100644 index 00000000000..5c4a218e79b --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForList.java @@ -0,0 +1,49 @@ +/* + * 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.internal; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import io.fabric8.kubernetes.api.model.KubernetesResource; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class KubernetesDeserializerForList extends JsonDeserializer> { + + private final KubernetesDeserializer kubernetesDeserializer; + + public KubernetesDeserializerForList() { + this.kubernetesDeserializer = new KubernetesDeserializer(); + } + + @Override + public List deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + final JsonNode node = p.readValueAsTree(); + if (!node.isArray()) { + throw new JsonMappingException(p, "Expected array but found " + node.getNodeType()); + } + final List ret = new ArrayList<>(); + for (JsonNode item : node) { + ret.add(kubernetesDeserializer.deserialize(p, item)); + } + return ret; + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMap.java b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMap.java new file mode 100644 index 00000000000..d909380e38b --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMap.java @@ -0,0 +1,50 @@ +/* + * 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.internal; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import io.fabric8.kubernetes.api.model.KubernetesResource; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; + +public class KubernetesDeserializerForMap extends JsonDeserializer> { + + private final KubernetesDeserializer kubernetesDeserializer; + + public KubernetesDeserializerForMap() { + this.kubernetesDeserializer = new KubernetesDeserializer(); + } + + @Override + public Map deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + final JsonNode node = p.readValueAsTree(); + if (!node.isObject()) { + throw new JsonMappingException(p, "Expected map but found " + node.getNodeType()); + } + final Map ret = new java.util.LinkedHashMap<>(); + for (Iterator> it = node.fields(); it.hasNext();) { + final Map.Entry entry = it.next(); + ret.put(entry.getKey(), kubernetesDeserializer.deserialize(p, entry.getValue())); + } + return ret; + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/APIVersionsTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/APIVersionsTest.java index 4cde37c7ca4..e8fc7757267 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/APIVersionsTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/APIVersionsTest.java @@ -16,24 +16,29 @@ package io.fabric8.kubernetes.api.model; import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collections; -import java.util.Scanner; import static org.assertj.core.api.Assertions.assertThat; class APIVersionsTest { - private final ObjectMapper mapper = new ObjectMapper(); + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test void deserializationAndSerializationShouldWorkAsExpected() throws IOException { // Given - String originalJson = new Scanner(getClass().getResourceAsStream("/valid-apiversions.json")) - .useDelimiter("\\A") - .next(); + String originalJson = Helper.loadJson("/valid-apiversions.json"); // When final APIVersions apiVersions = mapper.readValue(originalJson, APIVersions.class); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/AdditionalPropertiesTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/AdditionalPropertiesTest.java index 231363818d2..b327d488f72 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/AdditionalPropertiesTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/AdditionalPropertiesTest.java @@ -23,7 +23,7 @@ class AdditionalPropertiesTest { @Test - void podBuilderDirectTest() throws Exception { + void podBuilderDirectTest() { // given new method due to setter PodBuilder builder = new PodBuilder().withNewMetadata().addToAdditionalProperties("x", "y").endMetadata(); @@ -34,7 +34,7 @@ void podBuilderDirectTest() throws Exception { } @Test - void podBuilderIndirectTest() throws Exception { + void podBuilderIndirectTest() { // given new method due to setter ObjectMeta meta = new ObjectMeta(); meta.setAdditionalProperty("x", "y"); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapTest.java index fec774d0eab..6e46be1f9dc 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.util.Helper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -28,11 +29,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class ConfigMapTest { - private final ObjectMapper mapper = new ObjectMapper(); +class ConfigMapTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test - public void configMapTest() throws Exception { + void configMapTest() throws Exception { // given final String originalJson = Helper.loadJson("/valid-configMap.json"); @@ -46,8 +53,7 @@ public void configMapTest() throws Exception { } @Test - public void configMapBuilderTest() { - + void configMapBuilderTest() { ConfigMap configMap = new io.fabric8.kubernetes.api.model.ConfigMapBuilder() .withNewMetadata() .withName("game-config") diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapVolumeSourceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapVolumeSourceTest.java index e977f932f87..e845b0d919c 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapVolumeSourceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ConfigMapVolumeSourceTest.java @@ -17,12 +17,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.jackson.GoCompatibilityModule; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.io.InputStream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -39,10 +39,10 @@ void setUp() { @Test void deserializationWithOctalValueShouldWorkAsExpected() throws IOException { // Given - InputStream inputStream = getClass().getResourceAsStream("/configmapvolumesource.json"); + final String originalJson = Helper.loadJson("/configmapvolumesource.json"); // When - ConfigMapVolumeSource configMapVolumeSource = objectMapper.readValue(inputStream, ConfigMapVolumeSource.class); + ConfigMapVolumeSource configMapVolumeSource = objectMapper.readValue(originalJson, ConfigMapVolumeSource.class); // Then assertThat(configMapVolumeSource) diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/DownwardAPIVolumeSourceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/DownwardAPIVolumeSourceTest.java index 9da8b8bb2df..ac70643e05f 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/DownwardAPIVolumeSourceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/DownwardAPIVolumeSourceTest.java @@ -17,12 +17,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.jackson.GoCompatibilityModule; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.io.InputStream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -39,10 +39,10 @@ void setUp() { @Test void deserializationWithOctalValueShouldWorkAsExpected() throws IOException { // Given - InputStream inputStream = getClass().getResourceAsStream("/downwardapivolumesource.json"); + final String originalJson = Helper.loadJson("/downwardapivolumesource.json"); // When - DownwardAPIVolumeSource downwardAPIVolumeSource = objectMapper.readValue(inputStream, DownwardAPIVolumeSource.class); + DownwardAPIVolumeSource downwardAPIVolumeSource = objectMapper.readValue(originalJson, DownwardAPIVolumeSource.class); // Then assertThat(downwardAPIVolumeSource) diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/EventTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/EventTest.java index bb43ca0dafb..b2b48643544 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/EventTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/EventTest.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.util.Helper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; @@ -26,7 +27,13 @@ import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; class EventTest { - private final ObjectMapper mapper = new ObjectMapper(); + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test void testEventSerializationDeserialization() throws JsonProcessingException { diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/GenericKubernetesResourceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/GenericKubernetesResourceTest.java index e7be70aac46..4e379177eac 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/GenericKubernetesResourceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/GenericKubernetesResourceTest.java @@ -17,11 +17,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.model.util.Helper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.io.InputStream; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -43,7 +43,7 @@ void setUp() { void deserializeWithEmptyShouldDeserializeEmpty() throws Exception { // When final GenericKubernetesResource result = objectMapper - .readValue(load("empty.json"), GenericKubernetesResource.class); + .readValue(Helper.loadJson("/generic-kubernetes-resource/empty.json"), GenericKubernetesResource.class); // Then assertThat(result).isEqualTo(new GenericKubernetesResource()); } @@ -52,10 +52,11 @@ void deserializeWithEmptyShouldDeserializeEmpty() throws Exception { @DisplayName("deserialize, with config map structure, should deserialize like ConfigMap") void deserializeWithConfigMapStructureShouldDeserializeLikeConfigMap() throws Exception { // Given - final ConfigMap configMap = objectMapper.readValue(load("config-map.json"), ConfigMap.class); + final ConfigMap configMap = objectMapper.readValue(Helper.loadJson("/generic-kubernetes-resource/config-map.json"), + ConfigMap.class); // When final GenericKubernetesResource result = objectMapper - .readValue(load("config-map.json"), GenericKubernetesResource.class); + .readValue(Helper.loadJson("/generic-kubernetes-resource/config-map.json"), GenericKubernetesResource.class); // Then assertThat(result) .hasFieldOrPropertyWithValue("metadata.namespace", "default") @@ -68,7 +69,7 @@ void deserializeWithConfigMapStructureShouldDeserializeLikeConfigMap() throws Ex void deserializeWithCustomResourceShouldDeserialize() throws Exception { // When final GenericKubernetesResource result = objectMapper - .readValue(load("custom-resource.json"), GenericKubernetesResource.class); + .readValue(Helper.loadJson("/generic-kubernetes-resource/custom-resource.json"), GenericKubernetesResource.class); // Then assertThat(result) .hasFieldOrPropertyWithValue("apiVersion", "the-cr.example.com/v1") @@ -341,7 +342,8 @@ void getWithMultidimensionalArrayInFieldFound() { void getWithComplexStructureShouldRetrieveQueried() throws Exception { // When final GenericKubernetesResource result = objectMapper - .readValue(load("complex-structure-resource.json"), GenericKubernetesResource.class); + .readValue(Helper.loadJson("/generic-kubernetes-resource/complex-structure-resource.json"), + GenericKubernetesResource.class); // Then assertThat(result) .hasFieldOrPropertyWithValue("kind", "SomeCustomResource") @@ -355,20 +357,18 @@ void getWithComplexStructureShouldRetrieveQueried() throws Exception { .returns(true, gkr -> gkr.get("status", "reconciled")); } + @SuppressWarnings("deprecation") @Test @DisplayName("getAdditionalPropertiesNode, with complex-structure-resource, should return queried values") void getAdditionalPropertiesNodeWithComplexStructureShouldRetrieveQueried() throws Exception { // When final GenericKubernetesResource result = objectMapper - .readValue(load("complex-structure-resource.json"), GenericKubernetesResource.class); + .readValue(Helper.loadJson("/generic-kubernetes-resource/complex-structure-resource.json"), + GenericKubernetesResource.class); // Then assertThat(result) .extracting(GenericKubernetesResource::getAdditionalPropertiesNode) .returns("value", node -> node.get("spec").get("field").asText()) .returns(2, node -> node.get("spec").get("nested").get("list").get(1).get("entry").asInt()); } - - private static InputStream load(String resource) { - return GenericKubernetesResource.class.getResourceAsStream("/generic-kubernetes-resource/" + resource); - } } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/IntOrStringTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/IntOrStringTest.java index 2d4e8ab3b08..155a483d548 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/IntOrStringTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/IntOrStringTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -25,7 +26,13 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class IntOrStringTest { - private static final ObjectMapper mapper = new ObjectMapper(); + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test void testIntOrStringJson() throws IOException { diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/KubernetesListTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/KubernetesListTest.java index 094962192f0..fd48ed17089 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/KubernetesListTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/KubernetesListTest.java @@ -23,10 +23,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -public class KubernetesListTest { +class KubernetesListTest { @Test - public void testDefaultValues() { + void testDefaultValues() { Service service = new io.fabric8.kubernetes.api.model.ServiceBuilder() .withNewMetadata() .withName("test-service") @@ -91,7 +91,7 @@ void testVisitor() { } @Test - public void testDefaultNullValues() { + void testDefaultNullValues() { Container container = new io.fabric8.kubernetes.api.model.ContainerBuilder().build(); assertNull(container.getLifecycle()); assertNull(container.getLivenessProbe()); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ListOptionsTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ListOptionsTest.java index 67f537fa6a9..660eac6874e 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ListOptionsTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ListOptionsTest.java @@ -19,9 +19,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class ListOptionsTest { +class ListOptionsTest { @Test - public void testBuilder() { + void testBuilder() { ListOptions listOptions = new io.fabric8.kubernetes.api.model.ListOptionsBuilder() .withLimit(100L) .withContinue("23243434") diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/MicroTimeTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/MicroTimeTest.java index 47a021bcf04..970d14761d2 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/MicroTimeTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/MicroTimeTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; @@ -26,14 +27,16 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; class MicroTimeTest { - private static final ObjectMapper mapper = new ObjectMapper(); - private static final class MicroTimeHolder { - private MicroTime microTime; + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } - public MicroTime getMicroTime() { - return microTime; - } + private static final class MicroTimeHolder { + public MicroTime microTime; } @Test @@ -59,6 +62,6 @@ void testDeserialization() throws JsonProcessingException { MicroTimeHolder microTimeHolder = mapper.readValue(input, MicroTimeHolder.class); assertNotNull(microTimeHolder); - assertEquals(microTimeAsStr, microTimeHolder.getMicroTime().getTime()); + assertEquals(microTimeAsStr, microTimeHolder.microTime.getTime()); } } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ProjectedVolumeSourceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ProjectedVolumeSourceTest.java index 00388fa2fdd..4a80ba1a098 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ProjectedVolumeSourceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ProjectedVolumeSourceTest.java @@ -17,12 +17,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.jackson.GoCompatibilityModule; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.io.InputStream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -39,10 +39,10 @@ void setUp() { @Test void deserializationWithOctalValueShouldWorkAsExpected() throws IOException { // Given - InputStream inputStream = getClass().getResourceAsStream("/projectedvolumesource.json"); + final String originalJson = Helper.loadJson("/projectedvolumesource.json"); // When - ProjectedVolumeSource projectedVolumeSource = objectMapper.readValue(inputStream, ProjectedVolumeSource.class); + ProjectedVolumeSource projectedVolumeSource = objectMapper.readValue(originalJson, ProjectedVolumeSource.class); // Then assertThat(projectedVolumeSource) diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java index 680a9a9b874..99f1f8d3ef7 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/QuantityTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -30,7 +31,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; class QuantityTest { - private final ObjectMapper mapper = new ObjectMapper(); + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test @DisplayName("Test Serialization and Deserialization") @@ -142,7 +149,6 @@ void testEquality() { assertThat(new Quantity("2P")).isNotEqualTo("2P"); Quantity quantity = new Quantity("100.035k"); - assertThat(quantity).isEqualTo(quantity); assertThat(quantity.hashCode()).isEqualTo(100035); } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretTest.java index 6fd143c7401..ad3e3a492e5 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.util.Helper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -28,11 +29,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class SecretTest { - private final ObjectMapper mapper = new ObjectMapper(); +class SecretTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test - public void secretTest() throws Exception { + void secretTest() throws Exception { // given final String originalJson = Helper.loadJson("/valid-secret.json"); @@ -46,8 +53,7 @@ public void secretTest() throws Exception { } @Test - public void secretBuilderTest() { - + void secretBuilderTest() { Secret secret = new io.fabric8.kubernetes.api.model.SecretBuilder() .withNewMetadata() .withName("test-secret") diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretVolumeSourceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretVolumeSourceTest.java index c998975793d..af86692d2ec 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretVolumeSourceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/SecretVolumeSourceTest.java @@ -17,12 +17,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.jackson.GoCompatibilityModule; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.io.InputStream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -39,10 +39,10 @@ void setUp() { @Test void deserializationWithOctalValueShouldWorkAsExpected() throws IOException { // Given - InputStream inputStream = getClass().getResourceAsStream("/secretvolumesource.json"); + final String originalJson = Helper.loadJson("/secretvolumesource.json"); // When - SecretVolumeSource secretVolumeSource = objectMapper.readValue(inputStream, SecretVolumeSource.class); + SecretVolumeSource secretVolumeSource = objectMapper.readValue(originalJson, SecretVolumeSource.class); // Then assertThat(secretVolumeSource) diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ServiceTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ServiceTest.java index bf38d65e43d..f0fe0b818cd 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ServiceTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/ServiceTest.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.fabric8.kubernetes.model.util.Helper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; @@ -26,11 +27,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class ServiceTest { - private final ObjectMapper mapper = new ObjectMapper(); +class ServiceTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } @Test - public void serviceTest() throws Exception { + void serviceTest() throws Exception { // given final String originalJson = Helper.loadJson("/valid-service.json"); @@ -44,8 +51,7 @@ public void serviceTest() throws Exception { } @Test - public void serviceBuilderTest() { - + void serviceBuilderTest() { Service service = new io.fabric8.kubernetes.api.model.ServiceBuilder() .withNewMetadata() .withName("fabric8-maven-sample-zero-config") diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/StatusTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/StatusTest.java index b795ff65524..79241734fb2 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/StatusTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/StatusTest.java @@ -19,9 +19,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class StatusTest { +class StatusTest { + @Test - public void testBuilder() { + void testBuilder() { Status status = new io.fabric8.kubernetes.api.model.StatusBuilder() .withNewMetadata().withContinue("2343212").endMetadata() .withStatus("Some status") diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/WatchEventTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/WatchEventTest.java new file mode 100644 index 00000000000..13b3c34ac07 --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/api/model/WatchEventTest.java @@ -0,0 +1,144 @@ +/* + * 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.api.model; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.api.model.runtime.RawExtension; +import io.fabric8.kubernetes.model.util.Helper; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class WatchEventTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } + + @Nested + class Deserialization { + + private List watchEvents; + + @BeforeEach + void setUp() throws IOException { + watchEvents = mapper.readValue(Helper.loadJson("/watch-events.json"), new TypeReference>() { + }); + } + + @Test + void deserializesRegularFields() { + assertThat(watchEvents) + .extracting("type") + .containsOnly("ADDED", "MODIFIED", "DELETED", "ERROR", "BOOKMARK"); + } + + @Test + void deserializesNull() { + assertThat(watchEvents) + .element(0) + .extracting(WatchEvent::getObject) + .isNull(); + } + + @Test + void deserializesPod() { + assertThat(watchEvents) + .element(1) + .extracting(WatchEvent::getObject) + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "pod-modified"); + } + + @Test + void deserializesGenericKubernetesResource() { + assertThat(watchEvents) + .element(2) + .extracting(WatchEvent::getObject) + .isInstanceOf(GenericKubernetesResource.class) + .hasFieldOrPropertyWithValue("kind", "UnknownKind") + .hasFieldOrPropertyWithValue("apiVersion", "unknown.example.com/v1") + .hasFieldOrPropertyWithValue("metadata.name", "generic-deleted"); + } + + @Test + void deserializesRaw() { + assertThat(watchEvents) + .element(3) + .extracting(WatchEvent::getObject) + .isInstanceOf(RawExtension.class) + .hasFieldOrPropertyWithValue("value.name", "raw-error"); + } + + @Test + void deserializesPrimitiveString() { + assertThat(watchEvents) + .element(4) + .extracting(WatchEvent::getObject) + .asInstanceOf(InstanceOfAssertFactories.type(RawExtension.class)) + .extracting(AnyType::getValue) + .isEqualTo("primitive-string-bookmark"); + } + + @Test + void deserializesPrimitiveInt() { + assertThat(watchEvents) + .element(5) + .extracting(WatchEvent::getObject) + .asInstanceOf(InstanceOfAssertFactories.type(RawExtension.class)) + .extracting(AnyType::getValue) + .isEqualTo(1337); + } + } + + @Nested + class Builder { + + @Test + void shouldBuildWatchEvent() { + final WatchEvent result = new WatchEventBuilder() + .withType("ADDED") + .withObject(new PodBuilder().withNewMetadata().withName("pod").endMetadata().build()) + .build(); + assertThat(result) + .hasFieldOrPropertyWithValue("type", "ADDED") + .extracting(WatchEvent::getObject) + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "pod"); + + } + + @Test + // We need to ensure that Sundrio won't generate withNewXxx methods for the raw typed object field + void doesNotContainWithNew() { + assertThat(WatchEventBuilder.class.getMethods()) + .filteredOn(method -> method.getName().startsWith("with")) + .extracting(Method::getName) + .containsExactlyInAnyOrder("withObject", "withType", "withAdditionalProperties"); + } + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForListTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForListTest.java new file mode 100644 index 00000000000..930f94cd9ce --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForListTest.java @@ -0,0 +1,158 @@ +/* + * 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.internal; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.KubernetesList; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.runtime.RawExtension; +import io.fabric8.kubernetes.model.util.Helper; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +public class KubernetesDeserializerForListTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } + + @Test + void invalid() { + assertThatExceptionOfType(JsonProcessingException.class) + .isThrownBy(() -> mapper.readValue("{\"aList\":{}, \"aListWithRaw\": {}}", ListWrapperForList.class)) + .withMessageContaining("Expected array but found OBJECT"); + } + + @Nested + class AsKubernetesResource { + + private ListWrapperForKubernetesResource listWrapper; + + @BeforeEach + void setUp() throws IOException { + listWrapper = mapper.readValue(Helper.loadJson("/kubernetes-deserializer-for-list.json"), + ListWrapperForKubernetesResource.class); + } + + @Test + void deserializesKubernetesList() { + assertThat(listWrapper.aList).isInstanceOf(KubernetesList.class); + } + + @Test + void deserializesPod() { + assertThat(listWrapper.aList) + .asInstanceOf(InstanceOfAssertFactories.type(KubernetesList.class)) + .extracting(KubernetesList::getItems) + .asInstanceOf(InstanceOfAssertFactories.list(KubernetesResource.class)) + .element(0) + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "pod"); + } + + @Test + void deserializesGeneric() { + assertThat(listWrapper.aList) + .asInstanceOf(InstanceOfAssertFactories.type(KubernetesList.class)) + .extracting(KubernetesList::getItems) + .asInstanceOf(InstanceOfAssertFactories.list(KubernetesResource.class)) + .element(1) + .isInstanceOf(GenericKubernetesResource.class) + .hasFieldOrPropertyWithValue("kind", "Generic") + .hasFieldOrPropertyWithValue("apiVersion", "generic.example.com") + .hasFieldOrPropertyWithValue("metadata.name", "generic"); + } + } + + @Nested + class AsList { + + private ListWrapperForList listWrapper; + + @BeforeEach + void setUp() throws IOException { + listWrapper = mapper.readValue(Helper.loadJson("/kubernetes-deserializer-for-list.json"), ListWrapperForList.class); + } + + @Test + void deserializesPod() { + assertThat(listWrapper.aList) + .element(0) + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "pod"); + } + + @Test + void deserializesGeneric() { + assertThat(listWrapper.aList) + .element(1) + .isInstanceOf(GenericKubernetesResource.class) + .hasFieldOrPropertyWithValue("kind", "Generic") + .hasFieldOrPropertyWithValue("apiVersion", "generic.example.com") + .hasFieldOrPropertyWithValue("metadata.name", "generic"); + } + + @Test + void deserializesRaw() { + assertThat(listWrapper.aListWithRaw) + .element(0) + .isInstanceOf(RawExtension.class) + .hasFieldOrPropertyWithValue("value.name", "raw-extension"); + } + + @Test + void deserializesNestedPod() { + assertThat(listWrapper.aListWithRaw) + .element(1) + .asInstanceOf(InstanceOfAssertFactories.type(KubernetesList.class)) + .extracting(KubernetesList::getItems) + .asInstanceOf(InstanceOfAssertFactories.list(KubernetesResource.class)) + .element(0) + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "nested-pod"); + } + + } + + @JsonIgnoreProperties(ignoreUnknown = true) + private static final class ListWrapperForKubernetesResource { + @JsonDeserialize(using = KubernetesDeserializer.class) + public KubernetesResource aList; + } + + private static final class ListWrapperForList { + @JsonDeserialize(using = KubernetesDeserializerForList.class) + public List aList; + @JsonDeserialize(using = KubernetesDeserializerForList.class) + public List aListWithRaw; + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMapTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMapTest.java new file mode 100644 index 00000000000..f4ef096412b --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerForMapTest.java @@ -0,0 +1,111 @@ + +/* + * 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.internal; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.KubernetesList; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.runtime.RawExtension; +import io.fabric8.kubernetes.model.util.Helper; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.tuple; + +public class KubernetesDeserializerForMapTest { + + private ObjectMapper mapper; + + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + } + + @Test + void invalid() { + assertThatExceptionOfType(JsonProcessingException.class) + .isThrownBy(() -> mapper.readValue("{\"aMap\":[]}", MapWrapper.class)) + .withMessageContaining("Expected map but found ARRAY"); + } + + @Nested + class AsMap { + + private MapWrapper mapWrapper; + + @BeforeEach + void setUp() throws IOException { + mapWrapper = mapper.readValue(Helper.loadJson("/kubernetes-deserializer-for-map.json"), MapWrapper.class); + } + + @Test + void deserializesList() { + assertThat(mapWrapper.aMap) + .extracting("aList") + .asInstanceOf(InstanceOfAssertFactories.type(KubernetesList.class)) + .extracting(KubernetesList::getItems) + .asInstanceOf(InstanceOfAssertFactories.list(HasMetadata.class)) + .extracting("class", "metadata.name") + .contains( + tuple(Pod.class, "pod-in-list"), + tuple(GenericKubernetesResource.class, "generic-in-list")); + } + + @Test + void deserializesPod() { + assertThat(mapWrapper.aMap) + .extracting("aPod") + .isInstanceOf(Pod.class) + .hasFieldOrPropertyWithValue("metadata.name", "pod"); + } + + @Test + void deserializesGeneric() { + assertThat(mapWrapper.aMap) + .extracting("aGeneric") + .isInstanceOf(GenericKubernetesResource.class) + .hasFieldOrPropertyWithValue("kind", "Generic") + .hasFieldOrPropertyWithValue("apiVersion", "generic.example.com") + .hasFieldOrPropertyWithValue("metadata.name", "generic"); + } + + @Test + void deserializesRaw() { + assertThat(mapWrapper.aMap) + .extracting("aRaw") + .isInstanceOf(RawExtension.class) + .hasFieldOrPropertyWithValue("value.name", "raw-extension"); + } + + } + + private static final class MapWrapper { + @JsonDeserialize(using = KubernetesDeserializerForMap.class) + public Map aMap; + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerTest.java b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerTest.java index c6d6f258ad9..02bc66cbed7 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerTest.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/java/io/fabric8/kubernetes/internal/KubernetesDeserializerTest.java @@ -54,11 +54,10 @@ void shouldRegisterKind() { @Test void shouldNotRegisterKindWithoutVersionIfNullVersion() { // given - String version = null; String kind = "kind1"; - TypeKey key = mapping.createKey(version, kind); + TypeKey key = mapping.createKey(null, kind); // when - mapping.registerKind(version, kind, SmurfResource.class); + mapping.registerKind(null, kind, SmurfResource.class); // then Class clazz = mapping.getForKey(key); assertThat(clazz).isNull(); diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-list.json b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-list.json new file mode 100644 index 00000000000..c678475e874 --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-list.json @@ -0,0 +1,32 @@ +{ + "aList": [ + { + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "pod" + } + }, + { + "kind": "Generic", + "apiVersion": "generic.example.com", + "metadata": { + "name": "generic" + } + } + ], + "aListWithRaw": [ + { + "name": "raw-extension" + }, + [ + { + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "nested-pod" + } + } + ] + ] +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-map.json b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-map.json new file mode 100644 index 00000000000..ec97008ce91 --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/kubernetes-deserializer-for-map.json @@ -0,0 +1,37 @@ +{ + "aMap": { + "aList": [ + { + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "pod-in-list" + } + }, + { + "kind": "Generic", + "apiVersion": "generic.example.com", + "metadata": { + "name": "generic-in-list" + } + } + ], + "aPod": { + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "pod" + } + }, + "aGeneric": { + "kind": "Generic", + "apiVersion": "generic.example.com", + "metadata": { + "name": "generic" + } + }, + "aRaw": { + "name": "raw-extension" + } + } +} diff --git a/kubernetes-model-generator/kubernetes-model-core/src/test/resources/watch-events.json b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/watch-events.json new file mode 100644 index 00000000000..919ffae2930 --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-core/src/test/resources/watch-events.json @@ -0,0 +1,40 @@ +[ + { + "type": "ADDED", + "object": null + }, + { + "type": "MODIFIED", + "object": { + "kind": "Pod", + "apiVersion": "v1", + "metadata": { + "name": "pod-modified" + } + } + }, + { + "type": "DELETED", + "object": { + "kind": "UnknownKind", + "apiVersion": "unknown.example.com/v1", + "metadata": { + "name": "generic-deleted" + } + } + }, + { + "type": "ERROR", + "object": { + "name": "raw-error" + } + }, + { + "type": "BOOKMARK", + "object": "primitive-string-bookmark" + }, + { + "type": "BOOKMARK", + "object": 1337 + } +] diff --git a/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChart.java b/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChart.java index 3a65740b076..6f3786f5a76 100644 --- a/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChart.java +++ b/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChart.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -25,7 +24,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -66,9 +64,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class HelmChart implements Editable , KubernetesResource @@ -101,8 +97,9 @@ public class HelmChart implements Editable , KubernetesResourc @JsonProperty("valuesFile") private String valuesFile; @JsonProperty("valuesInline") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForMap.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map valuesInline = new LinkedHashMap<>(); + private Map valuesInline = new LinkedHashMap<>(); @JsonProperty("valuesMerge") private String valuesMerge; @JsonProperty("version") @@ -117,7 +114,7 @@ public class HelmChart implements Editable , KubernetesResourc public HelmChart() { } - public HelmChart(List additionalValuesFiles, List apiVersions, Boolean includeCRDs, String kubeVersion, String name, String nameTemplate, String namespace, String releaseName, String repo, Boolean skipHooks, Boolean skipTests, String valuesFile, Map valuesInline, String valuesMerge, String version) { + public HelmChart(List additionalValuesFiles, List apiVersions, Boolean includeCRDs, String kubeVersion, String name, String nameTemplate, String namespace, String releaseName, String repo, Boolean skipHooks, Boolean skipTests, String valuesFile, Map valuesInline, String valuesMerge, String version) { super(); this.additionalValuesFiles = additionalValuesFiles; this.apiVersions = apiVersions; @@ -260,12 +257,13 @@ public void setValuesFile(String valuesFile) { @JsonProperty("valuesInline") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getValuesInline() { + public Map getValuesInline() { return valuesInline; } @JsonProperty("valuesInline") - public void setValuesInline(Map valuesInline) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForMap.class) + public void setValuesInline(Map valuesInline) { this.valuesInline = valuesInline; } diff --git a/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChartArgs.java b/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChartArgs.java index 95a972fcac1..60477f7450d 100644 --- a/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChartArgs.java +++ b/kubernetes-model-generator/kubernetes-model-kustomize/src/generated/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/HelmChartArgs.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -25,7 +24,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -64,9 +62,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class HelmChartArgs implements Editable , KubernetesResource @@ -96,8 +92,9 @@ public class HelmChartArgs implements Editable , Kubernete @JsonProperty("values") private String values; @JsonProperty("valuesLocal") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForMap.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map valuesLocal = new LinkedHashMap<>(); + private Map valuesLocal = new LinkedHashMap<>(); @JsonProperty("valuesMerge") private String valuesMerge; @JsonIgnore @@ -110,7 +107,7 @@ public class HelmChartArgs implements Editable , Kubernete public HelmChartArgs() { } - public HelmChartArgs(String chartHome, String chartName, String chartRepoName, String chartRepoUrl, String chartVersion, List extraArgs, String helmBin, String helmHome, String releaseName, String releaseNamespace, String values, Map valuesLocal, String valuesMerge) { + public HelmChartArgs(String chartHome, String chartName, String chartRepoName, String chartRepoUrl, String chartVersion, List extraArgs, String helmBin, String helmHome, String releaseName, String releaseNamespace, String values, Map valuesLocal, String valuesMerge) { super(); this.chartHome = chartHome; this.chartName = chartName; @@ -240,12 +237,13 @@ public void setValues(String values) { @JsonProperty("valuesLocal") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getValuesLocal() { + public Map getValuesLocal() { return valuesLocal; } @JsonProperty("valuesLocal") - public void setValuesLocal(Map valuesLocal) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializerForMap.class) + public void setValuesLocal(Map valuesLocal) { this.valuesLocal = valuesLocal; } diff --git a/kubernetes-model-generator/kubernetes-model-kustomize/src/test/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/TestDeserialization.java b/kubernetes-model-generator/kubernetes-model-kustomize/src/test/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/TestDeserialization.java index 3cebb96fcdb..1ff1a477b6a 100644 --- a/kubernetes-model-generator/kubernetes-model-kustomize/src/test/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/TestDeserialization.java +++ b/kubernetes-model-generator/kubernetes-model-kustomize/src/test/java/io/fabric8/kubernetes/api/model/kustomize/v1beta1/TestDeserialization.java @@ -18,21 +18,52 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import org.junit.jupiter.api.Assertions; +import io.fabric8.kubernetes.api.model.runtime.RawExtension; +import io.fabric8.kubernetes.model.util.Helper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TestDeserialization { +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +class TestDeserialization { + + private ObjectMapper objectMapper; + + @BeforeEach + void setUp() { + objectMapper = new ObjectMapper(new YAMLFactory() + .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) + .disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)); + } @Test - public void kustomizeDeserializationTest() throws Exception { - ObjectMapper mapper = new ObjectMapper( - new YAMLFactory().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)); - final Kustomization kustomization = mapper.readValue(this.getClass().getResourceAsStream("/kustomization.yaml"), + void kustomizeDeserializationTest() throws Exception { + final Kustomization kustomization = objectMapper.readValue(this.getClass().getResourceAsStream("/kustomization.yaml"), Kustomization.class); - Assertions.assertEquals(1, kustomization.getReplacements().size()); - Assertions.assertEquals(1, kustomization.getReplacements().get(0).getTargets().size()); - Assertions.assertEquals(1, kustomization.getReplacements().get(0).getTargets().get(0).getFieldPaths().size()); - Assertions.assertEquals("spec.volumes.[name=.*].azureFile.shareName", + assertEquals(1, kustomization.getReplacements().size()); + assertEquals(1, kustomization.getReplacements().get(0).getTargets().size()); + assertEquals(1, kustomization.getReplacements().get(0).getTargets().get(0).getFieldPaths().size()); + assertEquals("spec.volumes.[name=.*].azureFile.shareName", kustomization.getReplacements().get(0).getTargets().get(0).getFieldPaths().get(0)); + assertEquals("chart", kustomization.getHelmCharts().get(0).getName()); + assertInstanceOf(RawExtension.class, kustomization.getHelmCharts().get(0).getValuesInline().get("simple")); + assertEquals("simple-value", + ((RawExtension) kustomization.getHelmCharts().get(0).getValuesInline().get("simple")).getValue()); + assertInstanceOf(RawExtension.class, kustomization.getHelmCharts().get(0).getValuesInline().get("complex")); + assertInstanceOf(Map.class, + ((RawExtension) kustomization.getHelmCharts().get(0).getValuesInline().get("complex")).getValue()); + } + + @Test + void deserializeSerialize() throws Exception { + final String originalWithComments = Helper.loadJson("/kustomization.yaml"); + final String original = "---\n" + originalWithComments.substring(originalWithComments.indexOf("apiVersion")).trim() + .replace("\r\n", "\n"); + final String processed = objectMapper.writeValueAsString(objectMapper.readValue(original, Kustomization.class)).trim() + .replace("\r\n", "\n"); + assertEquals(original, processed); } } diff --git a/kubernetes-model-generator/kubernetes-model-kustomize/src/test/resources/kustomization.yaml b/kubernetes-model-generator/kubernetes-model-kustomize/src/test/resources/kustomization.yaml index 8572e86e0bd..92aef71dbfa 100644 --- a/kubernetes-model-generator/kubernetes-model-kustomize/src/test/resources/kustomization.yaml +++ b/kubernetes-model-generator/kubernetes-model-kustomize/src/test/resources/kustomization.yaml @@ -16,21 +16,29 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -resources: - - pod.yaml +helmCharts: +- name: chart + valuesInline: + simple: simple-value + complex: + name: complex-value + nested: + name: nested patches: - - path: patch.yaml - target: - kind: Pod +- path: patch.yaml + target: + kind: Pod replacements: - - source: +- source: + kind: Pod + fieldPath: metadata.name + targets: + - fieldPaths: + - "spec.volumes.[name=.*].azureFile.shareName" + options: + delimiter: / + index: 3 + select: kind: Pod - fieldPath: metadata.name - targets: - - select: - kind: Pod - fieldPaths: - - spec.volumes.[name=.*].azureFile.shareName - options: - delimiter: '/' - index: 3 +resources: +- pod.yaml diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/DriverAllocationResult.java b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/DriverAllocationResult.java index 32f0db77c84..794b485d617 100644 --- a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/DriverAllocationResult.java +++ b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/DriverAllocationResult.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -23,7 +22,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -51,9 +49,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class DriverAllocationResult implements Editable , KubernetesResource @@ -62,7 +58,8 @@ public class DriverAllocationResult implements Editable additionalProperties = new LinkedHashMap(); @@ -73,7 +70,7 @@ public class DriverAllocationResult implements Editable , KubernetesResource @@ -68,7 +64,8 @@ public class DriverRequests implements Editable , Kuberne @JsonInclude(JsonInclude.Include.NON_EMPTY) private List requests = new ArrayList<>(); @JsonProperty("vendorParameters") - private KubernetesResource vendorParameters; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object vendorParameters; @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -79,7 +76,7 @@ public class DriverRequests implements Editable , Kuberne public DriverRequests() { } - public DriverRequests(String driverName, List requests, KubernetesResource vendorParameters) { + public DriverRequests(String driverName, List requests, Object vendorParameters) { super(); this.driverName = driverName; this.requests = requests; @@ -108,12 +105,13 @@ public void setRequests(List requests) { } @JsonProperty("vendorParameters") - public KubernetesResource getVendorParameters() { + public Object getVendorParameters() { return vendorParameters; } @JsonProperty("vendorParameters") - public void setVendorParameters(KubernetesResource vendorParameters) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setVendorParameters(Object vendorParameters) { this.vendorParameters = vendorParameters; } diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceRequest.java b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceRequest.java index e7a8b5d5f06..e653eb206b6 100644 --- a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceRequest.java +++ b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceRequest.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -23,7 +22,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -51,9 +49,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class ResourceRequest implements Editable , KubernetesResource @@ -62,7 +58,8 @@ public class ResourceRequest implements Editable , Kuber @JsonProperty("namedResources") private NamedResourcesRequest namedResources; @JsonProperty("vendorParameters") - private KubernetesResource vendorParameters; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object vendorParameters; @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -73,7 +70,7 @@ public class ResourceRequest implements Editable , Kuber public ResourceRequest() { } - public ResourceRequest(NamedResourcesRequest namedResources, KubernetesResource vendorParameters) { + public ResourceRequest(NamedResourcesRequest namedResources, Object vendorParameters) { super(); this.namedResources = namedResources; this.vendorParameters = vendorParameters; @@ -90,12 +87,13 @@ public void setNamedResources(NamedResourcesRequest namedResources) { } @JsonProperty("vendorParameters") - public KubernetesResource getVendorParameters() { + public Object getVendorParameters() { return vendorParameters; } @JsonProperty("vendorParameters") - public void setVendorParameters(KubernetesResource vendorParameters) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setVendorParameters(Object vendorParameters) { this.vendorParameters = vendorParameters; } diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/StructuredResourceHandle.java b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/StructuredResourceHandle.java index ea7ca40976f..4a57e59dc8a 100644 --- a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/StructuredResourceHandle.java +++ b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/StructuredResourceHandle.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; import io.fabric8.kubernetes.api.model.LabelSelector; @@ -25,7 +24,6 @@ import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.runtime.RawExtension; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; import lombok.EqualsAndHashCode; @@ -55,9 +53,7 @@ @BuildableReference(IntOrString.class), @BuildableReference(ObjectReference.class), @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class), - @BuildableReference(GenericKubernetesResource.class), - @BuildableReference(RawExtension.class) + @BuildableReference(PersistentVolumeClaim.class) }) @Generated("jsonschema2pojo") public class StructuredResourceHandle implements Editable , KubernetesResource @@ -69,9 +65,11 @@ public class StructuredResourceHandle implements Editable results = new ArrayList<>(); @JsonProperty("vendorClaimParameters") - private KubernetesResource vendorClaimParameters; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object vendorClaimParameters; @JsonProperty("vendorClassParameters") - private KubernetesResource vendorClassParameters; + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object vendorClassParameters; @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -82,7 +80,7 @@ public class StructuredResourceHandle implements Editable results, KubernetesResource vendorClaimParameters, KubernetesResource vendorClassParameters) { + public StructuredResourceHandle(String nodeName, List results, Object vendorClaimParameters, Object vendorClassParameters) { super(); this.nodeName = nodeName; this.results = results; @@ -112,22 +110,24 @@ public void setResults(List results) { } @JsonProperty("vendorClaimParameters") - public KubernetesResource getVendorClaimParameters() { + public Object getVendorClaimParameters() { return vendorClaimParameters; } @JsonProperty("vendorClaimParameters") - public void setVendorClaimParameters(KubernetesResource vendorClaimParameters) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setVendorClaimParameters(Object vendorClaimParameters) { this.vendorClaimParameters = vendorClaimParameters; } @JsonProperty("vendorClassParameters") - public KubernetesResource getVendorClassParameters() { + public Object getVendorClassParameters() { return vendorClassParameters; } @JsonProperty("vendorClassParameters") - public void setVendorClassParameters(KubernetesResource vendorClassParameters) { + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setVendorClassParameters(Object vendorClassParameters) { this.vendorClassParameters = vendorClassParameters; } diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java new file mode 100644 index 00000000000..f78afd6d2fb --- /dev/null +++ b/kubernetes-model-generator/kubernetes-model-resource/src/generated/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java @@ -0,0 +1,124 @@ + +package io.fabric8.kubernetes.api.model.resource.v1alpha2; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.Generated; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.builder.Editable; +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.IntOrString; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.LabelSelector; +import io.fabric8.kubernetes.api.model.LocalObjectReference; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.ObjectReference; +import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; +import io.fabric8.kubernetes.api.model.PodTemplateSpec; +import io.fabric8.kubernetes.api.model.ResourceRequirements; +import io.sundr.builder.annotations.Buildable; +import io.sundr.builder.annotations.BuildableReference; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "driverName", + "parameters" +}) +@ToString +@EqualsAndHashCode +@Accessors(prefix = { + "_", + "" +}) +@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { + @BuildableReference(ObjectMeta.class), + @BuildableReference(LabelSelector.class), + @BuildableReference(Container.class), + @BuildableReference(PodTemplateSpec.class), + @BuildableReference(ResourceRequirements.class), + @BuildableReference(IntOrString.class), + @BuildableReference(ObjectReference.class), + @BuildableReference(LocalObjectReference.class), + @BuildableReference(PersistentVolumeClaim.class) +}) +@Generated("jsonschema2pojo") +public class VendorParameters implements Editable , KubernetesResource +{ + + @JsonProperty("driverName") + private String driverName; + @JsonProperty("parameters") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object parameters; + @JsonIgnore + private Map additionalProperties = new LinkedHashMap(); + + /** + * No args constructor for use in serialization + * + */ + public VendorParameters() { + } + + public VendorParameters(String driverName, Object parameters) { + super(); + this.driverName = driverName; + this.parameters = parameters; + } + + @JsonProperty("driverName") + public String getDriverName() { + return driverName; + } + + @JsonProperty("driverName") + public void setDriverName(String driverName) { + this.driverName = driverName; + } + + @JsonProperty("parameters") + public Object getParameters() { + return parameters; + } + + @JsonProperty("parameters") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setParameters(Object parameters) { + this.parameters = parameters; + } + + @JsonIgnore + public VendorParametersBuilder edit() { + return new VendorParametersBuilder(this); + } + + @JsonIgnore + public VendorParametersBuilder toBuilder() { + return edit(); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/main/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java b/kubernetes-model-generator/kubernetes-model-resource/src/main/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java deleted file mode 100644 index ddeefe752a9..00000000000 --- a/kubernetes-model-generator/kubernetes-model-resource/src/main/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/VendorParameters.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.api.model.resource.v1alpha2; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import io.fabric8.kubernetes.api.builder.Editable; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.IntOrString; -import io.fabric8.kubernetes.api.model.KubernetesResource; -import io.fabric8.kubernetes.api.model.LabelSelector; -import io.fabric8.kubernetes.api.model.LocalObjectReference; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.ObjectReference; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.PodTemplateSpec; -import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.sundr.builder.annotations.Buildable; -import io.sundr.builder.annotations.BuildableReference; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import lombok.experimental.Accessors; - -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.annotation.Generated; - -@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "driverName", - "parameters" -}) -@ToString -@EqualsAndHashCode -@Accessors(prefix = { - "_", - "" -}) -@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { - @BuildableReference(ObjectMeta.class), - @BuildableReference(LabelSelector.class), - @BuildableReference(Container.class), - @BuildableReference(PodTemplateSpec.class), - @BuildableReference(ResourceRequirements.class), - @BuildableReference(IntOrString.class), - @BuildableReference(ObjectReference.class), - @BuildableReference(LocalObjectReference.class), - @BuildableReference(PersistentVolumeClaim.class) -}) -@Generated("jsonschema2pojo") -public class VendorParameters implements Editable, KubernetesResource { - - @JsonProperty("driverName") - private java.lang.String driverName; - @JsonProperty("parameters") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map parameters = new LinkedHashMap<>(); - @JsonIgnore - private Map additionalProperties = new LinkedHashMap(); - - /** - * No args constructor for use in serialization - * - */ - public VendorParameters() { - } - - public VendorParameters(java.lang.String driverName, Map parameters) { - super(); - this.driverName = driverName; - this.parameters = parameters; - } - - @JsonProperty("driverName") - public java.lang.String getDriverName() { - return driverName; - } - - @JsonProperty("driverName") - public void setDriverName(java.lang.String driverName) { - this.driverName = driverName; - } - - @JsonProperty("parameters") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getParameters() { - return parameters; - } - - @JsonProperty("parameters") - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - @JsonIgnore - public VendorParametersBuilder edit() { - return new VendorParametersBuilder(this); - } - - @JsonIgnore - public VendorParametersBuilder toBuilder() { - return edit(); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(java.lang.String name, java.lang.Object value) { - this.additionalProperties.put(name, value); - } - - public void setAdditionalProperties(Map additionalProperties) { - this.additionalProperties = additionalProperties; - } - -} diff --git a/kubernetes-model-generator/kubernetes-model-resource/src/test/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceClassParametersTest.java b/kubernetes-model-generator/kubernetes-model-resource/src/test/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceClassParametersTest.java index 96bba769196..f965d100a99 100644 --- a/kubernetes-model-generator/kubernetes-model-resource/src/test/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceClassParametersTest.java +++ b/kubernetes-model-generator/kubernetes-model-resource/src/test/java/io/fabric8/kubernetes/api/model/resource/v1alpha2/ResourceClassParametersTest.java @@ -16,13 +16,14 @@ package io.fabric8.kubernetes.api.model.resource.v1alpha2; import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder; import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.model.util.Helper; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collections; -import java.util.Scanner; import static org.assertj.core.api.Assertions.assertThat; @@ -42,9 +43,7 @@ void apiGroup() { @Test void deserializationAndSerializationShouldWorkAsExpected() throws IOException { // Given - String originalJson = new Scanner(getClass().getResourceAsStream("/valid-resourceclassparameters.json")) - .useDelimiter("\\A") - .next(); + final String originalJson = Helper.loadJson("/valid-resourceclassparameters.json"); // When final ResourceClassParameters resourceClassParameters = mapper.readValue(originalJson, ResourceClassParameters.class); @@ -64,8 +63,8 @@ void deserializationAndSerializationShouldWorkAsExpected() throws IOException { .hasFieldOrPropertyWithValue("driverName", "driverNameValue") .hasFieldOrPropertyWithValue("parameters.apiVersion", "example.com/v1") .hasFieldOrPropertyWithValue("parameters.kind", "CustomType") - .hasFieldOrPropertyWithValue("parameters.spec.replicas", 1) - .hasFieldOrPropertyWithValue("parameters.status.available", 1)) + .hasFieldOrPropertyWithValue("parameters.additionalProperties.spec.replicas", 1) + .hasFieldOrPropertyWithValue("parameters.additionalProperties.status.available", 1)) .satisfies(r -> assertThat(r.getFilters()) .asInstanceOf(InstanceOfAssertFactories.LIST) .singleElement(InstanceOfAssertFactories.type(ResourceFilter.class)) @@ -85,10 +84,12 @@ void builderShouldCreateObject() { .endGeneratedFrom() .addNewVendorParameter() .withDriverName("driverNameValue") - .addToParameters("apiVersion", "example.com/v1") - .addToParameters("kind", "CustomType") - .addToParameters("spec", Collections.singletonMap("replicas", 1)) - .addToParameters("status", Collections.singletonMap("available", 1)) + .withParameters(new GenericKubernetesResourceBuilder() + .withApiVersion("example.com/v1") + .withKind("CustomType") + .addToAdditionalProperties("spec", Collections.singletonMap("replicas", 1)) + .addToAdditionalProperties("status", Collections.singletonMap("available", 1)) + .build()) .endVendorParameter() .addNewFilter() .withDriverName("driverNameValue") @@ -111,8 +112,8 @@ void builderShouldCreateObject() { .hasFieldOrPropertyWithValue("driverName", "driverNameValue") .hasFieldOrPropertyWithValue("parameters.apiVersion", "example.com/v1") .hasFieldOrPropertyWithValue("parameters.kind", "CustomType") - .hasFieldOrPropertyWithValue("parameters.spec.replicas", 1) - .hasFieldOrPropertyWithValue("parameters.status.available", 1)) + .hasFieldOrPropertyWithValue("parameters.additionalProperties.spec.replicas", 1) + .hasFieldOrPropertyWithValue("parameters.additionalProperties.status.available", 1)) .satisfies(r -> assertThat(r.getFilters()) .asInstanceOf(InstanceOfAssertFactories.LIST) .singleElement(InstanceOfAssertFactories.type(ResourceFilter.class)) diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/expected/WatchEvent.expected b/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/expected/WatchEvent.expected new file mode 100644 index 00000000000..77e0a6c0fd6 --- /dev/null +++ b/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/expected/WatchEvent.expected @@ -0,0 +1,103 @@ + +package io.fabric8.kubernetes.api.model; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.Generated; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.fabric8.kubernetes.api.builder.Editable; +import io.sundr.builder.annotations.Buildable; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "object", + "type" +}) +@ToString +@EqualsAndHashCode +@Accessors(prefix = { + "_", + "" +}) +@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder") +@Generated("jsonschema2pojo") +public class WatchEvent implements Editable , KubernetesResource +{ + + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + private Object object; + @JsonProperty("type") + private String type; + @JsonIgnore + private Map additionalProperties = new LinkedHashMap(); + + /** + * No args constructor for use in serialization + * + */ + public WatchEvent() { + } + + public WatchEvent(Object object, String type) { + super(); + this.object = object; + this.type = type; + } + + @JsonProperty("object") + public Object getObject() { + return object; + } + + @JsonProperty("object") + @JsonDeserialize(using = io.fabric8.kubernetes.internal.KubernetesDeserializer.class) + public void setObject(Object object) { + this.object = object; + } + + @JsonProperty("type") + public String getType() { + return type; + } + + @JsonProperty("type") + public void setType(String type) { + this.type = type; + } + + @JsonIgnore + public WatchEventBuilder edit() { + return new WatchEventBuilder(this); + } + + @JsonIgnore + public WatchEventBuilder toBuilder() { + return edit(); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/verify.groovy b/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/verify.groovy index ce1f8283971..2126eae2da7 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/verify.groovy +++ b/kubernetes-model-generator/openapi/maven-plugin/src/it/kubernetes-model-core/verify.groovy @@ -21,17 +21,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue "Pod", "PodSpec", "PodStatus", - "PodTemplate" + "PodTemplate", + "WatchEvent" ].each { var file = new File(basedir, sprintf("/src/generated/java/io/fabric8/kubernetes/api/model/%s.java", it)) - assertTrue(file.exists()) + assertTrue(file.exists(), sprintf("File %s does not exist", it)) assertEquals( new File(basedir, sprintf("/expected/%s.expected", it)) .getText("UTF-8") .replace("\r\n", "\n") .replaceAll(" +\n", "\n") .trim(), - file.getText("UTF-8").replace("\r\n", "\n").replaceAll(" +\n", "\n").trim() + file.getText("UTF-8").replace("\r\n", "\n").replaceAll(" +\n", "\n").trim(), + sprintf("File %s does not match expected content", it) ) } diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/model/ModelGenerator.java b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/model/ModelGenerator.java index c97eb481b51..0e87c087d2c 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/model/ModelGenerator.java +++ b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/model/ModelGenerator.java @@ -47,6 +47,7 @@ import static io.fabric8.kubernetes.schema.generator.GeneratorUtils.cleanSourceDirectory; import static io.fabric8.kubernetes.schema.generator.schema.SchemaUtils.deserializerForJavaClass; +import static io.fabric8.kubernetes.schema.generator.schema.SchemaUtils.deserializerForType; import static io.fabric8.kubernetes.schema.generator.schema.SchemaUtils.getterName; import static io.fabric8.kubernetes.schema.generator.schema.SchemaUtils.isArray; import static io.fabric8.kubernetes.schema.generator.schema.SchemaUtils.isMap; @@ -174,6 +175,11 @@ private List> templateFields(TemplateContext templateContext templateContext.addImport("com.fasterxml.jackson.databind.annotation.JsonSerialize"); templateProp.put("serializeUsing", serializeUsing); } + final String deserializeUsing = deserializerForType(type); + if (deserializeUsing != null) { + templateContext.addImport("com.fasterxml.jackson.databind.annotation.JsonDeserialize"); + templateProp.put("deserializeUsing", deserializeUsing); + } // Default values if (isArray(propertySchema)) { templateContext.addImport("com.fasterxml.jackson.annotation.JsonInclude"); diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/schema/SchemaUtils.java b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/schema/SchemaUtils.java index 4bdb06e23b9..fb1ec411a12 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/schema/SchemaUtils.java +++ b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/schema/SchemaUtils.java @@ -62,8 +62,6 @@ public class SchemaUtils { "io.fabric8.kubernetes.api.model.ObjectMeta"); REF_TO_JAVA_TYPE_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2", "io.fabric8.kubernetes.api.model.ObjectMeta"); - REF_TO_JAVA_TYPE_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.runtime.RawExtension", - "io.fabric8.kubernetes.api.model.KubernetesResource"); REF_TO_JAVA_TYPE_MAP.put("#/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSON", "com.fasterxml.jackson.databind.JsonNode"); REF_TO_JAVA_TYPE_MAP.put("#/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSON", @@ -72,7 +70,8 @@ public class SchemaUtils { private static final Map REF_TO_JAVA_PRIMITIVE_MAP = new LinkedHashMap<>(); static { - REF_TO_JAVA_PRIMITIVE_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Time", "String"); + REF_TO_JAVA_PRIMITIVE_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Time", STRING_PRIMITIVE); + REF_TO_JAVA_PRIMITIVE_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.runtime.RawExtension", OBJECT_PRIMITIVE); } private static final Map JAVA_CLASS_SERIALIZER_MAP = new LinkedHashMap<>(); @@ -116,6 +115,13 @@ public class SchemaUtils { // REF_SERIALIZER_MAP.put("#/components/schemas/io.k8s.apimachinery.pkg.util.intstr.IntOrString", "com.marcnuri.yakc.model.serialization.IntOrStringSerializer.class"); // } + private static final Map TYPE_DESERIALIZER_MAP = new LinkedHashMap<>(); + static { + TYPE_DESERIALIZER_MAP.put(OBJECT_PRIMITIVE, "io.fabric8.kubernetes.internal.KubernetesDeserializer.class"); + TYPE_DESERIALIZER_MAP.put("List", "io.fabric8.kubernetes.internal.KubernetesDeserializerForList.class"); + TYPE_DESERIALIZER_MAP.put("Map", "io.fabric8.kubernetes.internal.KubernetesDeserializerForMap.class"); + } + private static final Map TYPE_MAP = new LinkedHashMap<>(); static { TYPE_MAP.put("boolean", "Boolean"); @@ -222,10 +228,9 @@ public String schemaToClassName(ImportManager imports, Schema schema) { return refToClassName(ref); } } - // Plain OpenAPI object map to KubernetesResource (deserializer will take care of the rest) + // Plain OpenAPI object map to Object (Model generator will need to annotate field with deserializer to take care of the rest) if (isObject(schema)) { - imports.addImport(settings.getKubernetesResourceClass()); - return settings.getKubernetesResourceClassSimpleName(); + return OBJECT_PRIMITIVE; } return schemaTypeToJavaPrimitive(schema); } @@ -267,7 +272,7 @@ public static boolean isRef(Schema schema) { } public static boolean isObject(Schema schema) { - return Optional.ofNullable(schema.getType()).orElse("").equals("object"); + return schema != null && Objects.equals("object", schema.getType()); } public boolean isString(Schema schema) { @@ -288,7 +293,7 @@ public boolean isRefInstanceOf(String ref, Class clazz) { } public String kubernetesListType(ImportManager imports, Schema schema) { - if (schema == null || !isObject(schema)) { + if (!isObject(schema)) { return null; } return Optional.ofNullable(schema.getProperties()) @@ -370,6 +375,13 @@ public static String serializerForSchema(Schema schema) { .orElse(null); } + public static String deserializerForType(String type) { + if (TYPE_DESERIALIZER_MAP.containsKey(type)) { + return TYPE_DESERIALIZER_MAP.get(type); + } + return null; + } + public static String serializerForJavaClass(String java) { return JAVA_CLASS_SERIALIZER_MAP.get(java); } diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_fields.mustache b/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_fields.mustache index 59ad3409aca..2846ffd062e 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_fields.mustache +++ b/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_fields.mustache @@ -31,6 +31,9 @@ {{#serializeUsing}} @JsonSerialize(using = {{.}}) {{/serializeUsing}} +{{#deserializeUsing}} + @JsonDeserialize(using = {{.}}) +{{/deserializeUsing}} {{#jsonInclude}} @JsonInclude(JsonInclude.Include.{{.}}) {{/jsonInclude}} diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_methods.mustache b/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_methods.mustache index eb6844d2e65..d40ec3f4ad8 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_methods.mustache +++ b/kubernetes-model-generator/openapi/maven-plugin/src/main/resources/templates/model_methods.mustache @@ -37,6 +37,9 @@ */ {{/legacyRequired}} @JsonProperty("{{propertyName}}") +{{#deserializeUsing}} + @JsonDeserialize(using = {{.}}) +{{/deserializeUsing}} public void {{setterName}}({{type}} {{name}}) { this.{{name}} = {{name}}; } diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/test/java/io/fabric8/kubernetes/schema/generator/SchemaUtilsTest.java b/kubernetes-model-generator/openapi/maven-plugin/src/test/java/io/fabric8/kubernetes/schema/generator/SchemaUtilsTest.java index de873432ff0..72a1ccbbbf9 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/test/java/io/fabric8/kubernetes/schema/generator/SchemaUtilsTest.java +++ b/kubernetes-model-generator/openapi/maven-plugin/src/test/java/io/fabric8/kubernetes/schema/generator/SchemaUtilsTest.java @@ -306,8 +306,8 @@ void jsonNode() { void plainObject() { final ObjectSchema schema = new ObjectSchema(); final String result = schemaUtils.schemaToClassName(importManager, schema); - assertEquals("KubernetesResource", result); - assertEquals("io.fabric8.kubernetes.api.model.KubernetesResource", importManager.getImports().iterator().next()); + assertEquals("Object", result); + assertTrue(importManager.getImports().isEmpty()); } @Test diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ControllerRevisionTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ControllerRevisionTest.java index 37e0cebb115..b50986d651c 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ControllerRevisionTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ControllerRevisionTest.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.apps.ControllerRevisionBuilder; import io.fabric8.kubernetes.api.model.apps.ControllerRevisionList; import io.fabric8.kubernetes.api.model.apps.ControllerRevisionListBuilder; +import io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; @@ -108,10 +109,7 @@ void delete() { private ControllerRevision getMockControllerRevision(String name) { return new ControllerRevisionBuilder() .withNewMetadata().withName(name).endMetadata() - .withNewDaemonSetData() - .withApiVersion("apps/v1") - .withKind("DaemonSet") - .endDaemonSetData() + .withData(new DaemonSetBuilder().build()) .build(); } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java index 63b33018190..65704494d86 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StatefulSetTest.java @@ -412,30 +412,29 @@ void testRolloutUndo() throws InterruptedException { .withName("rs1") .endMetadata() .withRevision(1L) - .withNewStatefulSetData() - .withNewSpec() - .withReplicas(0) - .withNewSelector() - .addToMatchLabels("app", "nginx") - .endSelector() - .withNewTemplate() - .withNewMetadata() - .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") - .addToAnnotations("app", "rs1") - .addToLabels("app", "nginx") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("nginx") - .withImage("nginx:perl") - .addNewPort() - .withContainerPort(80) - .endPort() - .endContainer() - .endSpec() - .endTemplate() - .endSpec() - .endStatefulSetData() + .withData(new StatefulSetBuilder().withNewSpec() + .withReplicas(0) + .withNewSelector() + .addToMatchLabels("app", "nginx") + .endSelector() + .withNewTemplate() + .withNewMetadata() + .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") + .addToAnnotations("app", "rs1") + .addToLabels("app", "nginx") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("nginx") + .withImage("nginx:perl") + .addNewPort() + .withContainerPort(80) + .endPort() + .endContainer() + .endSpec() + .endTemplate() + .endSpec() + .build()) .build(); ControllerRevision controllerRevision2 = new ControllerRevisionBuilder() .withNewMetadata() @@ -443,30 +442,30 @@ void testRolloutUndo() throws InterruptedException { .withName("rs2") .endMetadata() .withRevision(2L) - .withNewStatefulSetData() - .withNewSpec() - .withReplicas(1) - .withNewSelector() - .addToMatchLabels("app", "nginx") - .endSelector() - .withNewTemplate() - .withNewMetadata() - .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") - .addToAnnotations("app", "rs2") - .addToLabels("app", "nginx") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("nginx") - .withImage("nginx:1.19") - .addNewPort() - .withContainerPort(80) - .endPort() - .endContainer() - .endSpec() - .endTemplate() - .endSpec() - .endStatefulSetData() + .withData(new StatefulSetBuilder() + .withNewSpec() + .withReplicas(1) + .withNewSelector() + .addToMatchLabels("app", "nginx") + .endSelector() + .withNewTemplate() + .withNewMetadata() + .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") + .addToAnnotations("app", "rs2") + .addToLabels("app", "nginx") + .endMetadata() + .withNewSpec() + .addNewContainer() + .withName("nginx") + .withImage("nginx:1.19") + .addNewPort() + .withContainerPort(80) + .endPort() + .endContainer() + .endSpec() + .endTemplate() + .endSpec() + .build()) .build(); server.expect() diff --git a/pom.xml b/pom.xml index 65445ee4abd..f027bde9a92 100644 --- a/pom.xml +++ b/pom.xml @@ -138,7 +138,6 @@ 1.2.1 4.7.6 1.0.0 - 1.1.4 3.2.1 @@ -973,13 +972,6 @@ ${approvaltests.version} test - - - io.javaoperatorsdk - kubernetes-webhooks-framework-core - ${kubernetes.webhooks.framework.version} - test -