Skip to content

Commit

Permalink
- only include CRDs (not Lists) in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian-K committed Apr 22, 2020
1 parent d785e03 commit f629b9c
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
* <p>
*
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* 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.
Expand Down Expand Up @@ -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)
Expand All @@ -87,17 +87,25 @@ 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;
}
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];
}
Expand Down

0 comments on commit f629b9c

Please sign in to comment.