From fb62f3bcf3ce1aae29463a10b493511647458dfa Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Thu, 12 Nov 2020 17:13:01 +0200 Subject: [PATCH] fix(#2596) Add buildable ref for container, port and volume --- CHANGELOG.md | 3 +- .../java/io/fabric8/knative/ModelTest.java | 42 ++++++++++++++ .../java/io/fabric8/tekton/ModelTest.java | 55 +++++++++++++++++++ .../io/fabric8/kubernetes/ModelAnnotator.java | 13 +++-- 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 extensions/knative/model/src/test/java/io/fabric8/knative/ModelTest.java create mode 100644 extensions/tekton/model-v1beta1/src/test/java/io/fabric8/tekton/ModelTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 693f8748057..8408b44dc9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,10 @@ ### 5.0-SNAPSHOT #### Bugs +* Fix #2596: Add buildable references for Container, Port and Volume #### Improvements +* Eliminated the use of Doneables and simplified the internal DSL implementation. #### Dependency Upgrade @@ -22,7 +24,6 @@ * Fix #2507: Add a test for creating a Job with generateName * Fix #2509: Reversed order + Add Kubernetes 1.16.0 + OpenShift 4.5.14 to Compatibility matrix * Add cache in github actions for integration tests -* Eliminated the use of Doneables and simplified the internal DSL implementation. #### Dependency Upgrade * Fix #2513: Update Kubernetes Model to v1.19.1 diff --git a/extensions/knative/model/src/test/java/io/fabric8/knative/ModelTest.java b/extensions/knative/model/src/test/java/io/fabric8/knative/ModelTest.java new file mode 100644 index 00000000000..b45449ef14f --- /dev/null +++ b/extensions/knative/model/src/test/java/io/fabric8/knative/ModelTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) ${project.inceptionYear} ${owner} + * + * 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.knative; + +import org.junit.jupiter.api.Test; + +import io.fabric8.knative.serving.v1.*; + +class ModelTest { + + @Test + void shouldHaveBuildableContainer() { + Service service = new ServiceBuilder() + .withNewSpec() + .withNewTemplate() + .withNewSpec() + .addNewContainer() + .withNewImage("my-image") + .endContainer() + .endSpec() + .endTemplate() + .endSpec() + .build(); + + } +} + diff --git a/extensions/tekton/model-v1beta1/src/test/java/io/fabric8/tekton/ModelTest.java b/extensions/tekton/model-v1beta1/src/test/java/io/fabric8/tekton/ModelTest.java new file mode 100644 index 00000000000..a52074e991a --- /dev/null +++ b/extensions/tekton/model-v1beta1/src/test/java/io/fabric8/tekton/ModelTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) ${project.inceptionYear} ${owner} + * + * 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.tekton; + +import org.junit.jupiter.api.Test; + +import io.fabric8.tekton.pipeline.v1beta1.*; + +class ModelTest { + + @Test + void shouldHaveBuildableContainer() { + Task service = new TaskBuilder() + .withNewSpec() + .addNewVolume() + .withName("m2-cache") + .withNewNfs() + .withPath("my.nfs-server.com") + .withNewPath("/m2") + .endNfs() + .endVolume() + .addNewStep() + .withName("maven-build") + .withCommand("mvn") + .withArgs("clean", "install") + .withImage("maven:3.6.3-jdk11") + .addNewVolumeMount() + .withName("m2-cache") + .withMountPath("/m2-cache") + .endVolumeMount() + .addNewEnv() + .withName("FOO") + .withValue("BAR") + .endEnv() + .endStep() + .endSpec() + .build(); + } +} + diff --git a/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java b/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java index 14cf15b4f03..880cf78e1ce 100755 --- a/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java +++ b/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java @@ -24,7 +24,6 @@ import io.fabric8.kubernetes.model.annotation.ApiVersion; import io.sundr.builder.annotations.Buildable; import io.sundr.builder.annotations.BuildableReference; -import io.sundr.builder.annotations.Inline; import io.sundr.transform.annotations.VelocityTransformation; import io.sundr.transform.annotations.VelocityTransformations; import lombok.EqualsAndHashCode; @@ -53,13 +52,19 @@ public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { clazz.annotate(EqualsAndHashCode.class); JAnnotationUse buildable = clazz.annotate(Buildable.class) - .param("editableEnabled", false) + .param("editableEnabled", true) .param("validationEnabled", false) .param("generateBuilderPackage", false) .param("builderPackage", "io.fabric8.kubernetes.api.builder"); - buildable.paramArray("refs").annotate(BuildableReference.class) - .param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.ObjectMeta")); + JAnnotationArrayMember refs = buildable.paramArray("refs"); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.ObjectMeta")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.LabelSelector")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.Container")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.EnvVar")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.ContainerPort")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.Volume")); + refs.annotate(BuildableReference.class).param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.VolumeMount")); if (isCRD(clazz, propertiesNode) || isCRDList(clazz, propertiesNode)) { // add CRD-specific annotations String apiVersion = getApiVersion(propertiesNode);