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
From
controller/topic/topic.go
Observe()
function: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