crossplane-contrib / provider-kafka

Crossplane provider for Kafka
Apache License 2.0
30 stars 32 forks source link

Topic controller Observe function doesn't distinguish between non-existing topics and errors from the client in retrieving the topic #46

Open adarmiento opened 2 years ago

adarmiento commented 2 years ago

From controller/topic/topic.go Observe() function:

    tpc, err := topic.Get(ctx, c.kafkaClient, meta.GetExternalName(cr))
        if tpc == nil {
        return managed.ExternalObservation{ResourceExists: false}, nil
    }
    if err != nil {
        return managed.ExternalObservation{}, errors.Wrapf(err, "cannot get topic spec from topic client")
    }

topic.Get either returns a topic or an error. In case of errors, the topic will always be nil and the function will return on the first error check. If the topic is not nil err will always be nil, therefore the code in that if block is unreachable.

This code was probably developed because topic.Get() returns an error in both cases when a topic does not exist of when something went wrong, and it is not possible with just the error itself to discern which of the two happened.

As a result, errors from the client performing a Get are interpreted as "Topic does not exist" issuing a topic creation when not necessary