Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crd-generator] Fix inconsistent additionalPrinterColumns jsonPath #4614

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AddAdditionPrinterColumnDecorator(String name, String version, String typ
@Override
public void andThenVisit(CustomResourceDefinitionVersionFluent<?> spec) {
Predicate<CustomResourceColumnDefinitionBuilder> matchingColumn = col -> col.getName() != null
&& col.getName().equals(columnName);
&& col.getName().equals(columnName) && col.getJsonPath() != null && col.getJsonPath().equals(path);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just highlighting the "real change" in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should issue a warning when we encounter such a situation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the behavior, and it looks consistent to me without the need for a warning.
Using the "Joke" CRD used in the tests and created a corresponding "Joke" CR:

apiVersion: "samples.javaoperatorsdk.io/v1alpha1"
kind: JokeRequest
metadata:
  name: jr-any
spec:
  category: Any
status:
  category: Pun

the output of kubectl get seems fine to me:
Screenshot 2022-11-29 at 10 47 21

spec.removeMatchingFromAdditionalPrinterColumns(matchingColumn);

spec.addNewAdditionalPrinterColumn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AddAdditionPrinterColumnDecorator(String resourceName, String resourceVer
@Override
public void andThenVisit(CustomResourceDefinitionVersionFluent<?> spec) {
Predicate<CustomResourceColumnDefinitionBuilder> matchingColumn = col -> col.getName() != null
&& col.getName().equals(columnName);
&& col.getName().equals(columnName) && col.getJSONPath() != null && col.getJSONPath().equals(path);
spec.removeMatchingFromAdditionalPrinterColumns(matchingColumn);

spec.addNewAdditionalPrinterColumn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.fabric8.crd.example.joke;

import io.fabric8.kubernetes.model.annotation.PrinterColumn;

public class JokeRequestStatus {
public enum State {
CREATED,
Expand All @@ -28,6 +30,9 @@ public enum State {
private boolean error;
private String message;

@PrinterColumn(name = "jokeCategory")
private JokeRequestSpec.Category category = JokeRequestSpec.Category.Any;

public State getState() {
return state;
}
Expand All @@ -51,4 +56,12 @@ public String getMessage() {
public void setMessage(String message) {
this.message = message;
}

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

public void setCategory(JokeRequestSpec.Category category) {
this.category = category;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void jokerequestCRDShouldWork() {
// printer columns should be ordered in the alphabetical order of their json path
final List<CustomResourceColumnDefinition> printerColumns = version
.getAdditionalPrinterColumns();
assertEquals(2, printerColumns.size());
assertEquals(3, printerColumns.size());
CustomResourceColumnDefinition columnDefinition = printerColumns.get(0);
assertEquals("string", columnDefinition.getType());
assertEquals(".spec.category", columnDefinition.getJsonPath());
Expand All @@ -356,6 +356,10 @@ void jokerequestCRDShouldWork() {
assertEquals("string", columnDefinition.getType());
assertEquals(".spec.excluded", columnDefinition.getJsonPath());
assertEquals("excludedTopics", columnDefinition.getName());
columnDefinition = printerColumns.get(2);
assertEquals("string", columnDefinition.getType());
assertEquals(".status.category", columnDefinition.getJsonPath());
assertEquals("jokeCategory", columnDefinition.getName());
CustomResourceValidation schema = version.getSchema();
assertNotNull(schema);
Map<String, JSONSchemaProps> properties = schema.getOpenAPIV3Schema().getProperties();
Expand Down