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

marking crd fields as required #345

Merged
merged 1 commit into from
Jun 3, 2021
Merged

marking crd fields as required #345

merged 1 commit into from
Jun 3, 2021

Conversation

shawkins
Copy link
Contributor

This is for https://issues.redhat.com/browse/MGDSTRM-3288

Based upon our usage, this appears the set of fields / objects that are required. In some cases not having the field will produce NPEs - such as when the spec is missing. In other cases there's just no explicit null check and a null value could be used directly, like in the oauth properties.

Please review this so that we can identify which fields should have default handling and/or aren't actually required.

Note that due to fabric8io/kubernetes-client#3096 we can't yet mark the spec as required.

cc @rareddy @ppatierno @k-wall

@MikeEdgar
Copy link
Contributor

Does it make sense to use @NotBlank for fields that require a non-empty, non-whitespace value or would that be a future task?

@shawkins
Copy link
Contributor Author

Does it make sense to use @notblank for fields that require a non-empty, non-whitespace value or would that be a future task?

It could from an api standpoint, but it will have no effect on the generated crd nor the json/yaml parsing I believe.

Copy link
Contributor

@rareddy rareddy left a comment

Choose a reason for hiding this comment

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

lgtm

@shawkins
Copy link
Contributor Author

Keep in mind that if we mark a field as required and a cr already exists that does not have that field, it won't update properly - as it will fail validation.

@shawkins
Copy link
Contributor Author

This next commit has a refinement of the spec and spec capacity handling - where not null is enforced in the api, rather than the crd. This requires no changes in changes in our existing logic which is not appropriately checking for null. That is another route to consider - but without additional logic it does mean some oddities in how things would look when created via the api:

ManagedKafka mk = new ... // without a spec
client...create(mk);

that would actually serialize to

spec:
  capacity: {}

Rather than omitting it.

@shawkins
Copy link
Contributor Author

This next commit further refines things - it removes the not null from most of the oauth fields and converts the config kafkacluster config properties to be based upon the cr instead.

Copy link
Contributor

@MikeEdgar MikeEdgar left a comment

Choose a reason for hiding this comment

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

Looks good to me

@ppatierno ppatierno added this to the 0.5.0 milestone Jun 1, 2021
@shawkins
Copy link
Contributor Author

shawkins commented Jun 1, 2021

Tbh based on the chat conversation I would leave all auth fields not required but fixing the potential NPEs.

Since that now has potential conflicts are you suggesting that we continue to wait on this pr until after you merge. Or can this be merged and then we fix up everything in your pr?

The Auth part has already caused a lot of problems to us and marking them required when they are not (because not clear) could cause more. Wdyt?

I'm fine with any resolution...

@ppatierno
Copy link
Contributor

where do you see conflicts with my PR? I see just a "logical" one about tls trusted cert that is NOT required.

@shawkins
Copy link
Contributor Author

shawkins commented Jun 1, 2021

There is a conflict with SecretSecurityManager.

@ppatierno
Copy link
Contributor

Since that now has potential conflicts are you suggesting that we continue to wait on this pr until after you merge.

No you can merge after approvals, I can fix conflicts on my side but my point was about removing the @NotNull from the tls trusted certs. It's not related to the conflict.

@shawkins
Copy link
Contributor Author

shawkins commented Jun 1, 2021

No you can merge after approvals, I can fix conflicts on my side but my point was about removing the @NotNull from the tls trusted certs. It's not related to the conflict.

I'm not trying to be difficult, but I would leave this pr as self-consistent. If I remove the NotNull from tls, that's based upon a change that has not been merged. If this pr is merged first, you can remove the NotNull. If yours is merged first, I'll remove the NotNull here. There's no need to proactively intermingle the changes even more.

@ppatierno
Copy link
Contributor

I'm not trying to be difficult

Same here :-) ... but why adding a NotNull that hasn't been there since today and that we already know will be removed tomorrow?
Anyway I can remove it of course if this will be merged first.

@ppatierno
Copy link
Contributor

@shawkins I have just merged my PR, I think we now agree we need to remove @NotNull on the TLS trusted certificates. Sorry, I rushed because tomorrow I am on PTO ;-)

@shawkins
Copy link
Contributor Author

shawkins commented Jun 1, 2021

I have just merged my PR, I think we now agree we need to remove @NotNull on the TLS trusted certificates. Sorry, I rushed because tomorrow I am on PTO ;-)

In general we need to make sure that we don't let prs sit like this - it's bad for productivity. I think in the future if concerns aren't actionable within a couple of days, we should assume that we can move forward based upon 2 other approvals.

@ppatierno
Copy link
Contributor

I agree, but we spent more time waiting for the people knowing the oauth business more than us, even if in the end the information wasn't so useful :-(

@shawkins shawkins requested a review from k-wall June 1, 2021 17:38
Copy link
Contributor

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

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

LGTM. Let's just wait for my doubt/question for @tomncooper

generally this guards against unexpected npes

due to a fabric8 bug, we can't mark the specs as requires, so they will
always be there based upon the api

switching kafka.authentication.enabled and
kafka.external.certificate.enabled to be based upon the cr, rather than
the config
@shawkins shawkins merged commit 35d9011 into bf2fc6cc711aee1a0c2a:main Jun 3, 2021
Comment on lines -29 to +34
@ConfigProperty(name = "kafka.authentication.enabled", defaultValue = "false")
private boolean isKafkaAuthenticationEnabled;
public static boolean isKafkaAuthenticationEnabled(ManagedKafka managedKafka) {
return managedKafka.getSpec().getOauth() != null;
}

@ConfigProperty(name = "kafka.external.certificate.enabled", defaultValue = "false")
private boolean isKafkaExternalCertificateEnabled;
public static boolean isKafkaExternalCertificateEnabled(ManagedKafka managedKafka) {
return managedKafka.getSpec().getEndpoint().getTls() != null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@shawkins , @k-wall - it looks like this change is going to give us a short-term headache with the development installer script. Fleet manager always sends the tls entry, but with dummy values in the dev installation process. I was relying on the config property to force TLS to be disabled.

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.

6 participants