Skip to content

Commit

Permalink
[crd-generator] Fix inconsistent additionalPrinterColumns jsonPath
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Nov 28, 2022
1 parent 55394f3 commit 7f4916d
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceColumnDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersionFluent;
import io.fabric8.kubernetes.client.utils.Utils;

import java.util.function.Predicate;

public class AddAdditionPrinterColumnDecorator extends
CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {
CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {

private final String type;
private final String columnName;
private final String path;
private final String format;
private final String description;

public AddAdditionPrinterColumnDecorator(String name, String version, String type, String columnName, String path, String format, String description) {
public AddAdditionPrinterColumnDecorator(String name, String version, String type, String columnName, String path,
String format, String description) {
super(name, version);
this.type = type;
this.columnName = columnName;
Expand All @@ -40,41 +42,42 @@ 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);
Predicate<CustomResourceColumnDefinitionBuilder> matchingColumn = col -> col.getName() != null
&& col.getName().equals(columnName) && col.getJsonPath() != null && col.getJsonPath().equals(path);
spec.removeMatchingFromAdditionalPrinterColumns(matchingColumn);

spec.addNewAdditionalPrinterColumn()
.withType(type)
.withName(columnName)
.withJsonPath(path)
.withFormat(Utils.isNotNullOrEmpty(format) ? format : null)
.withDescription(Utils.isNotNullOrEmpty(description) ? description : null)
.endAdditionalPrinterColumn();
.withType(type)
.withName(columnName)
.withJsonPath(path)
.withFormat(Utils.isNotNullOrEmpty(format) ? format : null)
.withDescription(Utils.isNotNullOrEmpty(description) ? description : null)
.endAdditionalPrinterColumn();
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getVersion() == null) ? 0 : getVersion().hashCode());
result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((format == null) ? 0 : format.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
return result;
}
result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((format == null) ? 0 : format.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AddAdditionPrinterColumnDecorator other = (AddAdditionPrinterColumnDecorator) obj;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AddAdditionPrinterColumnDecorator other = (AddAdditionPrinterColumnDecorator) obj;
if (getName() == null) {
if (other.getName() != null)
return false;
Expand All @@ -85,36 +88,36 @@ public boolean equals(Object obj) {
return false;
} else if (!getVersion().equals(other.getVersion()))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (format == null) {
if (other.format != null)
return false;
} else if (!format.equals(other.format))
return false;
if (columnName == null) {
if (other.columnName != null)
return false;
} else if (!columnName.equals(other.columnName))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (format == null) {
if (other.format != null)
return false;
} else if (!format.equals(other.format))
return false;
if (columnName == null) {
if (other.columnName != null)
return false;
} else if (!columnName.equals(other.columnName))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}

@Override
public String toString() {
return getClass().getName() + " [name:"+ getName() + ", version:"+ getVersion() + "column:" + columnName +"]";
}
@Override
public String toString() {
return getClass().getName() + " [name:" + getName() + ", version:" + getVersion() + "column:" + columnName + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceColumnDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersionFluent;
import io.fabric8.kubernetes.client.utils.Utils;

import java.util.function.Predicate;

public class AddAdditionPrinterColumnDecorator extends
CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {
CustomResourceDefinitionVersionDecorator<CustomResourceDefinitionVersionFluent<?>> {

private final String type;
private final String columnName;
Expand All @@ -30,7 +31,7 @@ public class AddAdditionPrinterColumnDecorator extends
private final String description;

public AddAdditionPrinterColumnDecorator(String resourceName, String resourceVersion, String type,
String columnName, String path, String format, String description) {
String columnName, String path, String format, String description) {
super(resourceName, resourceVersion);
this.type = type;
this.columnName = columnName;
Expand All @@ -41,42 +42,42 @@ public AddAdditionPrinterColumnDecorator(String resourceName, String resourceVer

@Override
public void andThenVisit(CustomResourceDefinitionVersionFluent<?> spec) {
Predicate<CustomResourceColumnDefinitionBuilder> matchingColumn = col -> col.getName() != null && col.getName().equals(columnName);
Predicate<CustomResourceColumnDefinitionBuilder> matchingColumn = col -> col.getName() != null
&& col.getName().equals(columnName) && col.getJSONPath() != null && col.getJSONPath().equals(path);
spec.removeMatchingFromAdditionalPrinterColumns(matchingColumn);

spec.addNewAdditionalPrinterColumn()
.withType(type)
.withName(columnName)
.withJSONPath(path)
.withFormat(Utils.isNotNullOrEmpty(format) ? format : null)
.withDescription(Utils.isNotNullOrEmpty(description) ? description : null)
.endAdditionalPrinterColumn();
.withType(type)
.withName(columnName)
.withJSONPath(path)
.withFormat(Utils.isNotNullOrEmpty(format) ? format : null)
.withDescription(Utils.isNotNullOrEmpty(description) ? description : null)
.endAdditionalPrinterColumn();
}


@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getVersion() == null) ? 0 : getVersion().hashCode());
result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((format == null) ? 0 : format.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
return result;
}
result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((format == null) ? 0 : format.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AddAdditionPrinterColumnDecorator other = (AddAdditionPrinterColumnDecorator) obj;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AddAdditionPrinterColumnDecorator other = (AddAdditionPrinterColumnDecorator) obj;
if (getName() == null) {
if (other.getName() != null)
return false;
Expand All @@ -87,36 +88,36 @@ public boolean equals(Object obj) {
return false;
} else if (!getVersion().equals(other.getVersion()))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (format == null) {
if (other.format != null)
return false;
} else if (!format.equals(other.format))
return false;
if (columnName == null) {
if (other.columnName != null)
return false;
} else if (!columnName.equals(other.columnName))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (format == null) {
if (other.format != null)
return false;
} else if (!format.equals(other.format))
return false;
if (columnName == null) {
if (other.columnName != null)
return false;
} else if (!columnName.equals(other.columnName))
return false;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}

@Override
public String toString() {
return getClass().getName() + " [name:"+ getName() + ", version:"+ getVersion() + "column:" + columnName +"]";
}
@Override
public String toString() {
return getClass().getName() + " [name:" + getName() + ", version:" + getVersion() + "column:" + columnName + "]";
}
}

0 comments on commit 7f4916d

Please sign in to comment.