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 7d166edd771..2dc049c9261 100755 --- a/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java +++ b/model-annotator/src/main/java/io/fabric8/kubernetes/ModelAnnotator.java @@ -1,12 +1,12 @@ /** * 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 - *

+ * + * 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. @@ -65,13 +65,13 @@ public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { buildable.paramArray("refs").annotate(BuildableReference.class) .param("value", new JCodeModel()._class("io.fabric8.kubernetes.api.model.ObjectMeta")); - if (isCRD(propertiesNode)) { // add CRD-specific annotations - + if (isCRD(clazz, propertiesNode) || isCRDList(clazz, propertiesNode)) { // add CRD-specific annotations String apiVersion = getApiVersion(propertiesNode); clazz.annotate(ApiVersion.class).param("value", extractVersion(apiVersion)); clazz.annotate(ApiGroup.class).param("value", extractGroup(apiVersion)); + } - // include in model.properties + if (isCRD(clazz, propertiesNode)) { // include in model.properties (only CRDs not Lists!) JAnnotationArrayMember arrayMember = clazz.annotate(VelocityTransformations.class) .paramArray("value"); arrayMember.annotate(VelocityTransformation.class) @@ -87,10 +87,10 @@ public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { } } - private boolean isCRD(JsonNode propertiesNode) { - /** - * all CRDs have apiVersion initialized with a default value - */ + /** + * all CRDs have apiVersion initialized with a default value + */ + private boolean hasApiVersionWithDefault(JsonNode propertiesNode) { final JsonNode apiVersion = propertiesNode.get("apiVersion"); if (apiVersion != null) { return apiVersion.get("default") != null; @@ -98,6 +98,14 @@ private boolean isCRD(JsonNode propertiesNode) { return false; } + private boolean isCRD(JDefinedClass clazz, JsonNode propertiesNode) { + return hasApiVersionWithDefault(propertiesNode) && !clazz.name().endsWith("List"); + } + + private boolean isCRDList(JDefinedClass clazz, JsonNode propertiesNode) { + return hasApiVersionWithDefault(propertiesNode) && clazz.name().endsWith("List"); + } + private String extractGroup(String apiVersion) { return apiVersion.split("/")[0]; }