Skip to content

Commit

Permalink
Remove usage of clone
Browse files Browse the repository at this point in the history
  • Loading branch information
azorej committed Apr 23, 2024
1 parent d0ca463 commit 147f247
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* the "<EMPTY>" literal to represent an empty string.
*/
@EachProperty("airbyte.worker.kube-job-configs")
public final class KubeResourceConfig implements Cloneable {
public final class KubeResourceConfig {

public static final String EMPTY_VALUE = "<EMPTY>";

Expand All @@ -34,25 +34,18 @@ public KubeResourceConfig(@Parameter final String name) {
this.name = name;
}

public KubeResourceConfig clone() {
try {
return (KubeResourceConfig) super.clone();
} catch (final CloneNotSupportedException e) {
// Unlikely, but in the worst case, we will get this error when running tests.
throw new RuntimeException(e);
}
}
public KubeResourceConfig merge(KubeResourceConfig other) {
var merged = new KubeResourceConfig(name);

public KubeResourceConfig update(KubeResourceConfig other) {
annotations = useOtherIfEmpty(other.annotations, annotations);
labels = useOtherIfEmpty(other.labels, labels);
nodeSelectors = useOtherIfEmpty(other.nodeSelectors, nodeSelectors);
cpuLimit = useOtherIfEmpty(other.cpuLimit, cpuLimit);
cpuRequest = useOtherIfEmpty(other.cpuRequest, cpuRequest);
memoryLimit = useOtherIfEmpty(other.memoryLimit, memoryLimit);
memoryRequest = useOtherIfEmpty(other.memoryRequest, memoryRequest);
merged.setAnnotations(useOtherIfEmpty(annotations, other.annotations));
merged.setLabels(useOtherIfEmpty(labels, other.labels));
merged.setNodeSelectors(useOtherIfEmpty(nodeSelectors, other.nodeSelectors));
merged.setCpuLimit(useOtherIfEmpty(cpuLimit, other.cpuLimit));
merged.setCpuRequest(useOtherIfEmpty(cpuRequest, other.cpuRequest));
merged.setMemoryLimit(useOtherIfEmpty(memoryLimit, other.memoryLimit));
merged.setMemoryRequest(useOtherIfEmpty(memoryRequest, other.memoryRequest));

return this;
return merged;
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private Optional<KubeResourceConfig> getKubeResourceConfig(final KubeResourceKey
if (defaultConfig.isEmpty()) {
return variantConfig;
}
return variantConfig.map(kubeResourceConfig -> defaultConfig.get().clone().update(kubeResourceConfig)).or(() -> defaultConfig);
return variantConfig.map(kubeResourceConfig -> kubeResourceConfig.merge(defaultConfig.get())).or(() -> defaultConfig);
}

private static Optional<KubeResourceConfig> getKubeResourceConfigByType(
Expand All @@ -301,7 +301,7 @@ private static Optional<KubeResourceConfig> getKubeResourceConfigByType(
if (defaultConfig.isEmpty()) {
return typeConfig;
}
return typeConfig.map(kubeResourceConfig -> defaultConfig.get().clone().update(kubeResourceConfig)).or(() -> defaultConfig);
return typeConfig.map(kubeResourceConfig -> kubeResourceConfig.merge(defaultConfig.get())).or(() -> defaultConfig);
}

private static Optional<KubeResourceConfig> getKubeResourceConfigBySubType(final Map<ResourceSubType, KubeResourceConfig> configBySubType,
Expand All @@ -319,7 +319,7 @@ private static Optional<KubeResourceConfig> getKubeResourceConfigBySubType(final
if (defaultConfig.isEmpty()) {
return subTypeConfig;
}
return subTypeConfig.map(kubeResourceConfig -> defaultConfig.get().clone().update(kubeResourceConfig)).or(() -> defaultConfig);
return subTypeConfig.map(kubeResourceConfig -> kubeResourceConfig.merge(defaultConfig.get())).or(() -> defaultConfig);
}

private void validateIsolatedPoolConfigInitialization(final boolean useCustomNodeSelector, final Map<String, String> isolatedNodeSelectors) {
Expand Down

0 comments on commit 147f247

Please sign in to comment.