strimzi-kafka-operator icon indicating copy to clipboard operation
strimzi-kafka-operator copied to clipboard

Config spec field from the CRD need to have validation

Open alinalex1392 opened this issue 3 years ago • 11 comments

We use the CRD from Strimzi for creating Kafka topics, we had a case where the Config object was misconfigured with the wrong parameters type for retention.ms and segment.bytes, but the CR was applied.

Because we want to be in line with the upstream solution, we would benefit from the introduction of validation for this Config object. The fast feedback for creating wrong topics configuration will be improved.

alinalex1392 avatar Nov 10 '21 13:11 alinalex1392

@tombentley @sknot-rh Do we validate .spec.kafka.config in Kafka CRs now? Was there some reason why it was not done also for KafkaTopic CRs?

scholzj avatar Nov 10 '21 13:11 scholzj

I think we are doing some basic validation for Kafka resource (https://github.com/strimzi/strimzi-kafka-operator/blob/main/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java#L384). IIRC there is no validation in the KafkaTopic spec.config.

sknot-rh avatar Nov 10 '21 13:11 sknot-rh

@sknot-rh we also do validation in io.strimzi.operator.common.AbstractOperator#validate. Why are we doing validation in two places? Maybe there's a good reason, but in that case a comment in the code explaining why wouldn't go amiss.

@scholzj I don't recall a good reason, except that the TO doesn't extend AbstractOperator. I guess we could try to reuse the AbstractOperator#validate mechanism.

tombentley avatar Nov 10 '21 14:11 tombentley

I think io.strimzi.operator.common.AbstractOperator#validate does validate the entire spec but not the config (since it is Map<String, Object>). However the spec.config validation is done in io.strimzi.operator.cluster.model.KafkaConfiguration#validate. It reads config model and for each entry it checks the type. Currently we cannot do this for topics as the config model is generated only for brokers.

sknot-rh avatar Nov 10 '21 15:11 sknot-rh

@sknot-rh true, but then why aren't we calling validateIntConfigProperty in validateConfiguration?

We could generate a config model for topics (any maybe one for Kafka Connect workers?)

tombentley avatar Nov 10 '21 16:11 tombentley

Good question. I think it could be refactored. I can take a look at topic config model generation.

sknot-rh avatar Nov 11 '21 08:11 sknot-rh

Does #5960 PR resolve this? There does not seem to be any link.

scholzj avatar Dec 09 '21 16:12 scholzj

5960 seem to resolve this improvement.

alinalex1392 avatar Dec 09 '21 16:12 alinalex1392

Note: The PR #5960 was reverted in #6195 because it didn't support different Kafka versions.

Triaged on 28.4.2022: We need to re-consider if there is some easy way to get the configuration model for given Kafka version. @tombentley will think about it. To be revisited.

scholzj avatar Apr 28 '22 15:04 scholzj

I think this would work to support validation of topic config types, for arbitrary broker versions:

  1. During TO start up use the Admin client to do describeConfigs for the default topic configs (basically use an empty topic name). Use DescribeConfigOptions to include synonyms (IDK off hand whether there are any for topic configs, but in principal if there are any we should allow the user to use them).
  2. Use the ConfigEntrys for the DescribeConfigResult to discover the ConfigEntry.ConfigType
  3. Keep a Map<String, ConfigEntry.ConfigType> for use during the lifetime of the TO.
  4. Use that map whenever we need to validate a KafkaTopic.spec.configs.

It's not quite perfect, since it could go wrong if topic configs were added/removed in broker version X and the TO is running against a cluster in the middle of upgrade. It would then use an incorrect model. But TBH this not solvable, because topic configs get sent to the least loaded broker (i.e. you don't know which), so you could have this problem even manually.

tombentley avatar Apr 28 '22 16:04 tombentley

Triaged on 10.5.2022: Should be worth trying to improve the validation.

scholzj avatar May 10 '22 14:05 scholzj