Skip to content

Commit

Permalink
feat: add equals and hashCode implementations for CustomResource
Browse files Browse the repository at this point in the history
Fixes #3414
  • Loading branch information
metacosm authored and manusa committed Aug 30, 2021
1 parent 269db16 commit 523ec58
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Bugs

#### Improvements
* Fix #3414: Add equals and hashCode implementations for CustomResource

#### Dependency Upgrade

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package io.fabric8.kubernetes.client;

import static io.fabric8.kubernetes.client.utils.Utils.isNullOrEmpty;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -34,11 +32,14 @@
import io.fabric8.kubernetes.model.annotation.Version;
import io.sundr.builder.annotations.Buildable;
import io.sundr.builder.annotations.BuildableReference;

import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.Optional;

import static io.fabric8.kubernetes.client.utils.Utils.isNullOrEmpty;

/**
* A base class for implementing a custom resource kind. Implementations must be annotated with
* {@link io.fabric8.kubernetes.model.annotation.Group} and {@link io.fabric8.kubernetes.model.annotation.Version}.
Expand Down Expand Up @@ -280,4 +281,40 @@ public T getStatus() {
public void setStatus(T status) {
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CustomResource)) return false;

CustomResource<?, ?> that = (CustomResource<?, ?>) o;

if (served != that.served) return false;
if (storage != that.storage) return false;
if (!metadata.equals(that.metadata)) return false;
if (!Objects.equals(spec, that.spec)) return false;
if (!Objects.equals(status, that.status)) return false;
if (!singular.equals(that.singular)) return false;
if (!crdName.equals(that.crdName)) return false;
if (!kind.equals(that.kind)) return false;
if (!apiVersion.equals(that.apiVersion)) return false;
if (!scope.equals(that.scope)) return false;
return plural.equals(that.plural);
}

@Override
public int hashCode() {
int result = metadata.hashCode();
result = 31 * result + (spec != null ? spec.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + singular.hashCode();
result = 31 * result + crdName.hashCode();
result = 31 * result + kind.hashCode();
result = 31 * result + apiVersion.hashCode();
result = 31 * result + scope.hashCode();
result = 31 * result + plural.hashCode();
result = 31 * result + (served ? 1 : 0);
result = 31 * result + (storage ? 1 : 0);
return result;
}
}

0 comments on commit 523ec58

Please sign in to comment.