Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#2596) Add buildable ref for container, port and volume #2734

Merged
merged 1 commit into from Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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