@@ -64,21 +64,21 @@ static class CRDContext {
64
64
this .model = createModel ();
65
65
}
66
66
67
- private V1beta1CustomResourceDefinition createModel () {
67
+ static V1beta1CustomResourceDefinition createModel () {
68
68
return new V1beta1CustomResourceDefinition ()
69
69
.apiVersion ("apiextensions.k8s.io/v1beta1" )
70
70
.kind ("CustomResourceDefinition" )
71
71
.metadata (createMetadata ())
72
72
.spec (createSpec ());
73
73
}
74
74
75
- private V1ObjectMeta createMetadata () {
75
+ static V1ObjectMeta createMetadata () {
76
76
return new V1ObjectMeta ()
77
77
.name (KubernetesConstants .CRD_NAME )
78
78
.putLabelsItem (LabelConstants .RESOURCE_VERSION_LABEL , DEFAULT_OPERATOR_VERSION );
79
79
}
80
80
81
- private V1beta1CustomResourceDefinitionSpec createSpec () {
81
+ static V1beta1CustomResourceDefinitionSpec createSpec () {
82
82
return new V1beta1CustomResourceDefinitionSpec ()
83
83
.group (KubernetesConstants .DOMAIN_GROUP )
84
84
.version (KubernetesConstants .DOMAIN_VERSION )
@@ -87,26 +87,26 @@ private V1beta1CustomResourceDefinitionSpec createSpec() {
87
87
.validation (createSchemaValidation ());
88
88
}
89
89
90
- private V1beta1CustomResourceDefinitionNames getCRDNames () {
90
+ static V1beta1CustomResourceDefinitionNames getCRDNames () {
91
91
return new V1beta1CustomResourceDefinitionNames ()
92
92
.plural (KubernetesConstants .DOMAIN_PLURAL )
93
93
.singular (KubernetesConstants .DOMAIN_SINGULAR )
94
94
.kind (KubernetesConstants .DOMAIN )
95
95
.shortNames (Collections .singletonList (KubernetesConstants .DOMAIN_SHORT ));
96
96
}
97
97
98
- private V1beta1CustomResourceValidation createSchemaValidation () {
98
+ static V1beta1CustomResourceValidation createSchemaValidation () {
99
99
return new V1beta1CustomResourceValidation ().openAPIV3Schema (createOpenAPIV3Schema ());
100
100
}
101
101
102
- private V1beta1JSONSchemaProps createOpenAPIV3Schema () {
102
+ static V1beta1JSONSchemaProps createOpenAPIV3Schema () {
103
103
Gson gson = new Gson ();
104
104
JsonElement jsonElement = gson .toJsonTree (createSchemaGenerator ().generate (DomainSpec .class ));
105
105
V1beta1JSONSchemaProps spec = gson .fromJson (jsonElement , V1beta1JSONSchemaProps .class );
106
106
return new V1beta1JSONSchemaProps ().putPropertiesItem ("spec" , spec );
107
107
}
108
108
109
- private SchemaGenerator createSchemaGenerator () {
109
+ static SchemaGenerator createSchemaGenerator () {
110
110
SchemaGenerator generator = new SchemaGenerator ();
111
111
generator .setIncludeAdditionalProperties (false );
112
112
generator .setSupportObjectReferences (false );
@@ -218,9 +218,19 @@ public boolean isOutdatedCRD(
218
218
// For later versions of the product, we will want to do a complete comparison
219
219
// of the version, supporting alpha and beta variants, e.g. v3alpha1 format, but
220
220
// for now we just need to replace v1.
221
- return actual .getSpec ().getVersion ().equals ("v1" );
221
+ return actual .getSpec ().getVersion ().equals ("v1" )
222
+ || (actual .getSpec ().getVersion ().equals ("v2" )
223
+ && (getSchemaValidation (actual ) == null
224
+ || !getSchemaValidation (expected ).equals (getSchemaValidation (actual ))));
222
225
// Similarly, we will later want to check:
223
226
// VersionHelper.matchesResourceVersion(existingCRD.getMetadata(), DEFAULT_OPERATOR_VERSION)
224
227
}
228
+
229
+ private V1beta1JSONSchemaProps getSchemaValidation (V1beta1CustomResourceDefinition crd ) {
230
+ if (crd != null && crd .getSpec () != null && crd .getSpec ().getValidation () != null ) {
231
+ return crd .getSpec ().getValidation ().getOpenAPIV3Schema ();
232
+ }
233
+ return null ;
234
+ }
225
235
}
226
236
}
0 commit comments