-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(crd-generator): Ensure deterministic ordering of CRD versions (#5784
) * Fix CRDGeneratorTest#checkGenerationIsDeterministic and extend to test v1beta1 CRDVersion * Add CRDGeneratorTest#checkGenerationMultipleVersionsOfCRDsIsDeterministic * Fix broken link in JavaDoc for KubernetesVersionFactory * Add sortByPriority for generic lists to KubernetesVersionPriority utility class * Add SortCustomResourceDefinitionVersionDecorator to CRDGenerator The implementation uses a method from KubernetesVersionPriority to sort the versions by priority. The version with the highest priority comes first. This ensures deterministic generation und should fix #5508. * Add changelog for #5508 * Add license headers to SortCustomResourceDefinitionDecorators * Add not-null check to KubernetesVersionPriority#sortByPriority * Add NPE tests to KubernetesVersionPriorityTest * Fix javadoc in KubernetesVersionPriority
- Loading branch information
Showing
12 changed files
with
605 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...a/io/fabric8/crd/generator/v1/decorator/SortCustomResourceDefinitionVersionDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.crd.generator.v1.decorator; | ||
|
||
import io.fabric8.crd.generator.decorator.Decorator; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpecFluent; | ||
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion; | ||
import io.fabric8.kubernetes.client.utils.KubernetesVersionPriority; | ||
|
||
public class SortCustomResourceDefinitionVersionDecorator | ||
extends CustomResourceDefinitionDecorator<CustomResourceDefinitionSpecFluent<?>> { | ||
public SortCustomResourceDefinitionVersionDecorator(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta resourceMeta) { | ||
spec.withVersions(KubernetesVersionPriority.sortByPriority(spec.buildVersions(), CustomResourceDefinitionVersion::getName)); | ||
} | ||
|
||
@Override | ||
public Class<? extends Decorator>[] after() { | ||
return new Class[] { EnsureSingleStorageVersionDecorator.class }; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getName() + " [name:" + getName() + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...fabric8/crd/generator/v1beta1/decorator/SortCustomResourceDefinitionVersionDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.crd.generator.v1beta1.decorator; | ||
|
||
import io.fabric8.crd.generator.decorator.Decorator; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionSpecFluent; | ||
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersion; | ||
import io.fabric8.kubernetes.client.utils.KubernetesVersionPriority; | ||
|
||
public class SortCustomResourceDefinitionVersionDecorator | ||
extends CustomResourceDefinitionDecorator<CustomResourceDefinitionSpecFluent<?>> { | ||
public SortCustomResourceDefinitionVersionDecorator(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta resourceMeta) { | ||
spec.withVersions(KubernetesVersionPriority.sortByPriority(spec.buildVersions(), CustomResourceDefinitionVersion::getName)); | ||
} | ||
|
||
@Override | ||
public Class<? extends Decorator>[] after() { | ||
return new Class[] { EnsureSingleStorageVersionDecorator.class }; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getName() + " [name:" + getName() + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.