Skip to content

Switch operator to code-first#5038

Merged
jsenko merged 4 commits into
Apicurio:mainfrom
andreaTP:switch-to-code-first
Sep 3, 2024
Merged

Switch operator to code-first#5038
jsenko merged 4 commits into
Apicurio:mainfrom
andreaTP:switch-to-code-first

Conversation

@andreaTP
Copy link
Copy Markdown
Member

No description provided.

package io.apicurio.registry.operator;

import io.apicur.registry.v1.ApicurioRegistry;
import io.apicurio.registry.operator.api.v3.ApicurioRegistry3;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ApicurioRegistry3 kind has version v1, even though it is intended for Registry v3. Either use io.apicurio.registry.operator.api.v1 or what I did io.apicurio.registry.operator.api.v3.v1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍

@Plural("ApicurioRegistries3")
public class ApicurioRegistry3 extends CustomResource<ApicurioRegistry3Spec, ApicurioRegistry3Status>
implements Namespaced {
} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

newline missing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "conditions", "info" })
@JsonDeserialize(using = JsonDeserializer.None.class)
public class ApicurioRegistry3Status implements KubernetesResource {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use io.javaoperatorsdk.operator.api.ObservedGenerationAwareStatus. The framework then updates the observed generation automatically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this adds the dependency on the JOSDK to the model package ... but ok ..

@JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "env" })
@JsonDeserialize(using = JsonDeserializer.None.class)
public class Configuration implements KubernetesResource {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not use builder:

@Buildable(editableEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder")

@JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "env" })
@JsonDeserialize(using = JsonDeserializer.None.class)
public class Configuration implements KubernetesResource {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not use Lombok? (Also elsewhere). All fabric8 models use Lombok and it's far more readable.

@Required()
@JsonPropertyDescription("lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.")
@JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
private ZonedDateTime lastTransitionTime;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not Instant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no super strong opinions here, ok

return lastTransitionTime;
}

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[XXX][VV]")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why there are two different formats for getter and setter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A long long story here, basically:
fabric8io/kubernetes-client#5384 (comment)

happy to share the full story when needed XD

this.reason = reason;
}

public enum Status {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move these to a separate class please for better readability.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok


// Assert
assertEquals("test", registry.getMetadata().getName());
assertEquals("test-namespace", registry.getMetadata().getNamespace());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to see a comparison with a manually (with code) created instance (with status, since spec is empty). Builders help here.

assertEquals("test", registry.getMetadata().getName());
assertEquals("test-namespace", registry.getMetadata().getNamespace());
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is explicit ApicurioRegistry3List unnecessary? I'd like to see a test that reads a list of CRDs to see an example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added an example on how to deserialize a List of Registries

@paoloantinori
Copy link
Copy Markdown
Member

Hey guys, wtf is this?

What I'm sure I've asked was:

Andrea: code reviews
Jakub: opening PR

Can anyone help me to understand how we ended up with the exact opposite?

@jsenko
Copy link
Copy Markdown
Member

jsenko commented Aug 22, 2024

Hey guys, wtf is this?

What I'm sure I've asked was:

Andrea: code reviews Jakub: opening PR

Can anyone help me to understand how we ended up with the exact opposite?

This was opened last week. We can close it, but I didn't want to close someone else's PR.

@paoloantinori
Copy link
Copy Markdown
Member

np with not closing it, but why the Code review has been done today?

@andreaTP
Copy link
Copy Markdown
Member Author

Done everything, but the changes related to sundrio and lombok.
I think we can descope those changes from this PR to a follow-up after we discuss with the group about the tradeoffs.

@andreaTP
Copy link
Copy Markdown
Member Author

added lombok, @jsenko ready for next round.

@jsenko jsenko force-pushed the switch-to-code-first branch from 81c2989 to 99c5193 Compare September 3, 2024 12:33
@jsenko jsenko merged commit 82f3a1d into Apicurio:main Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants