Skip to content

Commit

Permalink
fix(fabric8io#2596) Add buildable ref for container, port and volume
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Nov 13, 2020
1 parent c66adbb commit fb62f3b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand All @@ -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
Expand Down
@@ -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();

}
}

@@ -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();
}
}

Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb62f3b

Please sign in to comment.