Skip to content

Commit

Permalink
fix: order printer columns by json path for consistent ordering
Browse files Browse the repository at this point in the history
Fixes #3040
  • Loading branch information
metacosm committed Apr 30, 2021
1 parent bfc3170 commit 9403d16
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 5.4-SNAPSHOT

#### Bugs
* Fix #3040: Consistently order printer columns by JSON path to prevent undue changes in generated CRDs
* Fix #3038: Upgrade TLS versions in mock servers to 1.2.
* Fix #3014: Resync Future is canceled and resync executor is shutdown on informer stop
* Fix #2978: Fix SharedInformer NPE on initial requests while syncing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import io.sundr.codegen.model.TypeDef;
import io.sundr.codegen.model.TypeDefBuilder;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ public void handle(CustomResourceInfo config) {
addDecorators(config, def, specReplicasPathDetector.getPath(),
statusReplicasPathDetector.getPath(), labelSelectorPathDetector.getPath());

Map<String, Property> additionalPrinterColumns = new HashMap<>();
Map<String, Property> additionalPrinterColumns = new TreeMap<>();
additionalPrinterColumns.putAll(additionalPrinterColumnDetector.getProperties());
additionalPrinterColumns.forEach((path, property) -> {
Map<String, Object> parameters = property.getAnnotations().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,53 @@

public class JokeRequestSpec {

public enum Category {
Any,
Misc,
Programming,
Dark,
Pun,
Spooky,
Christmas
}
public enum Category {
Any,
Misc,
Programming,
Dark,
Pun,
Spooky,
Christmas
}

public enum ExcludedTopic {
nsfw,
religious,
political,
racist,
sexist,
explicit
}
public enum ExcludedTopic {
nsfw,
religious,
political,
racist,
sexist,
explicit
}

@PrinterColumn(name = "jokeCategory")
private Category category = Category.Any;
private ExcludedTopic[] excluded = new ExcludedTopic[] { ExcludedTopic.nsfw, ExcludedTopic.racist, ExcludedTopic.sexist };
private boolean safe;
private Category category = Category.Any;
@PrinterColumn(name = "excludedTopics")
private ExcludedTopic[] excluded = new ExcludedTopic[]{ExcludedTopic.nsfw, ExcludedTopic.racist,
ExcludedTopic.sexist};
private boolean safe;

public Category getCategory() {
return category;
}
public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}
public void setCategory(Category category) {
this.category = category;
}

public ExcludedTopic[] getExcluded() {
return excluded;
}
public ExcludedTopic[] getExcluded() {
return excluded;
}

public void setExcluded(ExcludedTopic[] excluded) {
this.excluded = excluded;
}
public void setExcluded(ExcludedTopic[] excluded) {
this.excluded = excluded;
}

public boolean isSafe() {
return safe;
}
public boolean isSafe() {
return safe;
}

public void setSafe(boolean safe) {
this.safe = safe;
}
public void setSafe(boolean safe) {
this.safe = safe;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class Address {
private Type type;

public enum Type {
home, work;
home, work
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public class Person {
private Type type;

public enum Type {
crazy, crazier;
crazy, crazier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,18 @@ void jokerequestCRDShouldWork() {

final CustomResourceDefinitionVersion version = checkVersion(spec);
assertNotNull(version.getSubresources());
// printer columns should be ordered in the alphabetical order of their json path
final List<CustomResourceColumnDefinition> printerColumns = version
.getAdditionalPrinterColumns();
assertEquals(1, printerColumns.size());
final CustomResourceColumnDefinition columnDefinition = printerColumns.get(0);
assertEquals(2, printerColumns.size());
CustomResourceColumnDefinition columnDefinition = printerColumns.get(0);
assertEquals("string", columnDefinition.getType());
assertEquals(".spec.category", columnDefinition.getJsonPath());
assertEquals("jokeCategory", columnDefinition.getName());
columnDefinition = printerColumns.get(1);
assertEquals("string", columnDefinition.getType());
assertEquals(".spec.excluded", columnDefinition.getJsonPath());
assertEquals("excludedTopics", columnDefinition.getName());
CustomResourceValidation schema = version.getSchema();
assertNotNull(schema);
Map<String, JSONSchemaProps> properties = schema.getOpenAPIV3Schema().getProperties();
Expand Down

0 comments on commit 9403d16

Please sign in to comment.