Skip to content

Commit bd0c549

Browse files
authored
feat(crd-generator): Deprecation warning for CRD versions (#5787)
* Add deprecation and deprecationWarning to CustomResource and Version annotation * Add deprecation and deprecationWarning support to CRDGenerator
1 parent 2281ae4 commit bd0c549

File tree

15 files changed

+385
-12
lines changed

15 files changed

+385
-12
lines changed

crd-generator/api/src/main/java/io/fabric8/crd/generator/CustomResourceInfo.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class CustomResourceInfo {
4242
private final String[] shortNames;
4343
private final boolean storage;
4444
private final boolean served;
45+
private final boolean deprecated;
46+
private final String deprecationWarning;
4547
private final Scope scope;
4648
private final TypeDef definition;
4749
private final String crClassName;
@@ -54,7 +56,7 @@ public class CustomResourceInfo {
5456
private final String[] labels;
5557

5658
public CustomResourceInfo(String group, String version, String kind, String singular,
57-
String plural, String[] shortNames, boolean storage, boolean served,
59+
String plural, String[] shortNames, boolean storage, boolean served, boolean deprecated, String deprecationWarning,
5860
Scope scope, TypeDef definition, String crClassName,
5961
String specClassName, String statusClassName, String[] annotations, String[] labels) {
6062
this.group = group;
@@ -65,6 +67,8 @@ public CustomResourceInfo(String group, String version, String kind, String sing
6567
this.shortNames = shortNames;
6668
this.storage = storage;
6769
this.served = served;
70+
this.deprecated = deprecated;
71+
this.deprecationWarning = deprecationWarning;
6872
this.scope = scope;
6973
this.definition = definition;
7074
this.crClassName = crClassName;
@@ -84,6 +88,14 @@ public boolean served() {
8488
return served;
8589
}
8690

91+
public boolean deprecated() {
92+
return deprecated;
93+
}
94+
95+
public String deprecationWarning() {
96+
return deprecationWarning;
97+
}
98+
8799
public String key() {
88100
return crdName();
89101
}
@@ -165,8 +177,9 @@ public static CustomResourceInfo fromClass(Class<? extends CustomResource<?, ?>>
165177
}
166178

167179
return new CustomResourceInfo(instance.getGroup(), instance.getVersion(), instance.getKind(),
168-
instance.getSingular(), instance.getPlural(), shortNames, instance.isStorage(), instance.isServed(), scope,
169-
definition,
180+
instance.getSingular(), instance.getPlural(), shortNames, instance.isStorage(), instance.isServed(),
181+
instance.isDeprecated(), instance.getDeprecationWarning(),
182+
scope, definition,
170183
customResource.getCanonicalName(), specAndStatus.getSpecClassName(),
171184
specAndStatus.getStatusClassName(), toStringArray(instance.getMetadata().getAnnotations()),
172185
toStringArray(instance.getMetadata().getLabels()));

crd-generator/api/src/main/java/io/fabric8/crd/generator/v1/CustomResourceHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.fabric8.crd.generator.v1.decorator.AddStatusSubresourceDecorator;
3030
import io.fabric8.crd.generator.v1.decorator.AddSubresourcesDecorator;
3131
import io.fabric8.crd.generator.v1.decorator.EnsureSingleStorageVersionDecorator;
32+
import io.fabric8.crd.generator.v1.decorator.SetDeprecatedVersionDecorator;
3233
import io.fabric8.crd.generator.v1.decorator.SetServedVersionDecorator;
3334
import io.fabric8.crd.generator.v1.decorator.SetStorageVersionDecorator;
3435
import io.fabric8.crd.generator.v1.decorator.SortPrinterColumnsDecorator;
@@ -89,6 +90,7 @@ protected void addDecorators(CustomResourceInfo config, TypeDef def, Optional<St
8990

9091
resources.decorate(new SetServedVersionDecorator(name, version, config.served()));
9192
resources.decorate(new SetStorageVersionDecorator(name, version, config.storage()));
93+
resources.decorate(new SetDeprecatedVersionDecorator(name, version, config.deprecated(), config.deprecationWarning()));
9294
resources.decorate(new EnsureSingleStorageVersionDecorator(name));
9395
resources.decorate(new SortPrinterColumnsDecorator(name, version));
9496
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.generator.v1.decorator;
17+
18+
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersionFluent;
19+
20+
public class SetDeprecatedVersionDecorator
21+
extends CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {
22+
23+
private final boolean deprecated;
24+
private final String deprecationWarning;
25+
26+
public SetDeprecatedVersionDecorator(String name, String version, boolean deprecated, String deprecationWarning) {
27+
super(name, version);
28+
this.deprecated = deprecated;
29+
this.deprecationWarning = deprecationWarning;
30+
}
31+
32+
@Override
33+
public void andThenVisit(CustomResourceDefinitionVersionFluent<?> version) {
34+
if (deprecated) {
35+
version.withDeprecated(true);
36+
version.withDeprecationWarning(deprecationWarning);
37+
}
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return getClass().getName() + " [name:" + getName() + ", version:" + getVersion()
43+
+ ", deprecated:" + deprecated + ", deprecationWarning:" + deprecationWarning + "]";
44+
}
45+
}

crd-generator/api/src/main/java/io/fabric8/crd/generator/v1beta1/CustomResourceHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.fabric8.crd.generator.v1beta1.decorator.AddSubresourcesDecorator;
3131
import io.fabric8.crd.generator.v1beta1.decorator.EnsureSingleStorageVersionDecorator;
3232
import io.fabric8.crd.generator.v1beta1.decorator.PromoteSingleVersionAttributesDecorator;
33+
import io.fabric8.crd.generator.v1beta1.decorator.SetDeprecatedVersionDecorator;
3334
import io.fabric8.crd.generator.v1beta1.decorator.SetServedVersionDecorator;
3435
import io.fabric8.crd.generator.v1beta1.decorator.SetStorageVersionDecorator;
3536
import io.fabric8.crd.generator.v1beta1.decorator.SortPrinterColumnsDecorator;
@@ -90,6 +91,7 @@ protected void addDecorators(CustomResourceInfo config, TypeDef def,
9091

9192
resources.decorate(new SetServedVersionDecorator(name, version, config.served()));
9293
resources.decorate(new SetStorageVersionDecorator(name, version, config.storage()));
94+
resources.decorate(new SetDeprecatedVersionDecorator(name, version, config.deprecated(), config.deprecationWarning()));
9395
resources.decorate(new EnsureSingleStorageVersionDecorator(name));
9496
resources.decorate(new PromoteSingleVersionAttributesDecorator(name));
9597
resources.decorate(new SortPrinterColumnsDecorator(name, version));
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.generator.v1beta1.decorator;
17+
18+
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersionFluent;
19+
20+
public class SetDeprecatedVersionDecorator
21+
extends CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {
22+
23+
private final boolean deprecated;
24+
private final String deprecationWarning;
25+
26+
public SetDeprecatedVersionDecorator(String name, String version, boolean deprecated, String deprecationWarning) {
27+
super(name, version);
28+
this.deprecated = deprecated;
29+
this.deprecationWarning = deprecationWarning;
30+
}
31+
32+
@Override
33+
public void andThenVisit(CustomResourceDefinitionVersionFluent<?> version) {
34+
if (deprecated) {
35+
version.withDeprecated(true);
36+
version.withDeprecationWarning(deprecationWarning);
37+
}
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return getClass().getName() + " [name:" + getName() + ", version:" + getVersion()
43+
+ ", deprecated:" + deprecated + ", deprecationWarning:" + deprecationWarning + "]";
44+
}
45+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.example.deprecated.v1;
17+
18+
import io.fabric8.kubernetes.client.CustomResource;
19+
import io.fabric8.kubernetes.model.annotation.Group;
20+
import io.fabric8.kubernetes.model.annotation.Version;
21+
22+
@Group("sample.fabric8.io")
23+
@Version(value = "v1", storage = false, deprecated = true)
24+
public class DeprecationExample extends CustomResource<DeprecationExampleSpec, Void> {
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.example.deprecated.v1;
17+
18+
public class DeprecationExampleSpec {
19+
private String v1;
20+
21+
public String getV1() {
22+
return v1;
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.example.deprecated.v1beta1;
17+
18+
import io.fabric8.kubernetes.client.CustomResource;
19+
import io.fabric8.kubernetes.model.annotation.Group;
20+
import io.fabric8.kubernetes.model.annotation.Version;
21+
22+
@Group("sample.fabric8.io")
23+
@Version(value = "v1beta1", storage = false, deprecated = true, deprecationWarning = "sample.fabric8.io/v1beta1 DeprecationExample is deprecated; Migrate to sample.fabric8.io/v2")
24+
public class DeprecationExample extends CustomResource<DeprecationExampleSpec, Void> {
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.example.deprecated.v1beta1;
17+
18+
public class DeprecationExampleSpec {
19+
private String v1beta1;
20+
21+
public String getV1() {
22+
return v1beta1;
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.crd.example.deprecated.v2;
17+
18+
import io.fabric8.kubernetes.client.CustomResource;
19+
import io.fabric8.kubernetes.model.annotation.Group;
20+
import io.fabric8.kubernetes.model.annotation.Version;
21+
22+
@Group("sample.fabric8.io")
23+
@Version("v2")
24+
public class DeprecationExample extends CustomResource<DeprecationExampleSpec, Void> {
25+
}

0 commit comments

Comments
 (0)