Skip to content

Commit

Permalink
Add required imports
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Mitchell <[email protected]>
  • Loading branch information
wcmitchell committed Nov 7, 2023
1 parent 98668fe commit ac2971f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions controllers/cloud.redhat.com/providers/kafka/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (

crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers"
"github.com/RedHatInsights/rhc-osdk-utils/utils"

core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

type managedKafkaProvider struct {
Expand All @@ -34,13 +37,12 @@ func (k *managedKafkaProvider) Provide(app *crd.ClowdApp) error {
var secret *core.Secret
var brokers []config.BrokerConfig

secret, err = getSecret(k)
secret, err = k.getSecret()
if err != nil {
return err
}

brokers, err = k.getBrokerConfig(secret)

if err != nil {
return err
}
Expand Down Expand Up @@ -139,3 +141,30 @@ func (k *managedKafkaProvider) getKafkaConfig(brokers []config.BrokerConfig, app
return kafkaConfig

}

func (k *managedKafkaProvider) getSecret() (*core.Secret, error) {
secretRef, err := k.getSecretRef()
if err != nil {
return nil, err
}

secret := &core.Secret{}

if err = k.Client.Get(k.Ctx, secretRef, secret); err != nil {
return nil, err
}

return secret, nil
}

func (k *managedKafkaProvider) getSecretRef() (types.NamespacedName, error) {
secretRef := types.NamespacedName{
Name: k.Env.Spec.Providers.Kafka.ManagedSecretRef.Name,
Namespace: k.Env.Spec.Providers.Kafka.ManagedSecretRef.Namespace,
}
nullName := types.NamespacedName{}
if secretRef == nullName {
return nullName, errors.NewClowderError("no secret ref defined for managed Kafka")
}
return secretRef, nil
}

0 comments on commit ac2971f

Please sign in to comment.