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

Lombok's EqualsAndHashCode for CR should have callSuper=true #4259

Closed
grossws opened this issue Jul 6, 2022 · 1 comment · Fixed by #4308
Closed

Lombok's EqualsAndHashCode for CR should have callSuper=true #4259

grossws opened this issue Jul 6, 2022 · 1 comment · Fixed by #4308

Comments

@grossws
Copy link

grossws commented Jul 6, 2022

Describe the bug

CRD to Java generator with Config#objectExtraAnnotations set should generate @lombok.EqualsAndHashCode(callSuper = true) for CR classes since generated class has no fields and spec is accessible via CustomResource superclass.

Since it doesn't have callSuper = true lombok produces something like this:

package us.containo.traefik.v1alpha1;

import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Version(
  value = "v1alpha1",
  storage = true,
  served = true
)
@Group("traefik.containo.us")
public class IngressRoute extends CustomResource<IngressRouteSpec, Void> implements Namespaced {
  public IngressRoute() {
  }

  public String toString() {
    return "IngressRoute()";
  }

  public boolean equals(final Object o) {
    if (o == this) {
      return true;
    } else if (!(o instanceof IngressRoute)) {
      return false;
    } else {
      IngressRoute other = (IngressRoute)o;
      return other.canEqual(this);
    }
  }

  protected boolean canEqual(final Object other) {
    return other instanceof IngressRoute;
  }

  public int hashCode() {
    int result = true;
    return 1;
  }
}

Fabric8 Kubernetes Client version

6.0.0-RC1

Steps to reproduce

  1. Get some CRD (e.g. kubectl get crd/middlewares.traefik.containo.us -o yaml > crd.yaml)
  2. Run jbang io.fabric8:java-generator-cli:6.0.0-RC1 -t generated -s crd.yaml --add-extra-annotations

Expected behavior

Generated CR class to have @lombok.EqualsAndHashCode(callSuper = true)

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

Linux

Fabric8 Kubernetes Client Logs

No response

Additional context

Kubelet version 1.23.6
Kubernetes flavor k3s v1.23.6+k3s1

@andreaTP
Copy link
Member

I completely missed this one 😓 , looks reasonable, @rohanKanojia let me know if have any trouble picking this up 👍 the relevant line of code is this:

rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
have `@EqualsAndHashCode(callSuper = true)` (fabric8io#4259)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
have `@EqualsAndHashCode(callSuper = true)` (fabric8io#4259)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
have `@EqualsAndHashCode(callSuper = true)` (fabric8io#4259)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jul 28, 2022
have `@EqualsAndHashCode(callSuper = true)` (fabric8io#4259)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@manusa manusa added this to the 6.1.0 milestone Jul 29, 2022
manusa pushed a commit that referenced this issue Jul 29, 2022
have `@EqualsAndHashCode(callSuper = true)` (#4259)

CustomResource classes generated in extra-annotations mode by Java generator
should have `@EqualsAndHashCode` annotation configured with `callSuper = true` in
case class extends another class.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment