Skip to content

Commit

Permalink
fix(#2596) Add buildable ref for container, port and volume
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel authored and manusa committed Jan 20, 2021
1 parent d9c84fb commit 4c988ae
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
@@ -0,0 +1,40 @@
/**
* 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.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,53 @@
/**
* 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.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 @@ -22,9 +22,9 @@
import com.sun.codemodel.*;
import io.fabric8.kubernetes.model.annotation.ApiGroup;
import io.fabric8.kubernetes.model.annotation.ApiVersion;
import io.sundr.builder.annotations.Inline;
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,7 +53,7 @@ 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");
Expand All @@ -63,8 +63,14 @@ public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) {
.param("prefix", "Doneable")
.param("value", "done");

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 4c988ae

Please sign in to comment.