@@ -135,12 +135,21 @@ func connectToCluster(connection *pkgConnection.Connection) {
135135 }
136136 }
137137
138+ kafkaCfg := clicfg .Services .Kafka
139+
140+ managedservices := connection .NewMASClient ()
141+ kafkaInstance , _ , err := managedservices .DefaultApi .GetKafkaById (context .TODO (), kafkaCfg .ClusterID )
142+
143+ if err != nil {
144+ fmt .Fprintf (os .Stderr , "Could not get Kafka cluster with ID '%v': %w" , kafkaCfg .ClusterID )
145+ }
146+
138147 if err != nil {
139148 fmt .Fprint (os .Stderr , "\n Invalid configuration file" , err )
140149 return
141150 }
142151
143- fmt .Fprintf (os .Stderr , statusMsg , color .HiGreenString (clicfg . Services . Kafka . ClusterName ), color .HiGreenString (currentNamespace ), color .HiGreenString (secretName ))
152+ fmt .Fprintf (os .Stderr , statusMsg , color .HiGreenString (kafkaInstance . Name ), color .HiGreenString (currentNamespace ), color .HiGreenString (secretName ))
144153 if shouldContinue := showQuestion ("Do you want to continue?" ); shouldContinue == false {
145154 return
146155 }
@@ -150,7 +159,7 @@ func connectToCluster(connection *pkgConnection.Connection) {
150159 return
151160 }
152161 createSecret (credentials , currentNamespace , clientset )
153- createCR (clicfg , clientset , currentNamespace )
162+ createCR (clientset , & kafkaInstance , currentNamespace )
154163}
155164
156165func fileExists (path string ) bool {
@@ -241,8 +250,8 @@ func createSecret(credentials *managedservices.TokenResponse, currentNamespace s
241250 return secret
242251}
243252
244- func createCR (clicfg * config. Config , clientset * kubernetes. Clientset , namespace string ) {
245- crName := secretName + "-" + clicfg . Services . Kafka . ClusterName
253+ func createCR (clientset * kubernetes. Clientset , kafkaInstance * managedservices. KafkaRequest , namespace string ) {
254+ crName := secretName + "-" + kafkaInstance . Name
246255 crInstance := & connection.ManagedKafkaConnection {
247256 ObjectMeta : metav1.ObjectMeta {
248257 Name : crName ,
@@ -254,7 +263,7 @@ func createCR(clicfg *config.Config, clientset *kubernetes.Clientset, namespace
254263 },
255264 Spec : connection.ManagedKafkaConnectionSpec {
256265 BootstrapServer : connection.BootstrapServerSpec {
257- Host : clicfg . Services . Kafka . ClusterHost ,
266+ Host : kafkaInstance . BootstrapServerHost ,
258267 },
259268 Credentials : connection.CredentialsSpec {
260269 Kind : connection .ClientCredentials ,
@@ -313,7 +322,7 @@ func useKafka(cliconfig *config.Config, connection *pkgConnection.Connection) *c
313322 index , _ , err := prompt .Run ()
314323 if err == nil {
315324 selectedKafka := response .Items [index ]
316- var kafkaConfig config.KafkaConfig = config.KafkaConfig {ClusterID : selectedKafka .Id , ClusterName : selectedKafka . Name , ClusterHost : selectedKafka . BootstrapServerHost }
325+ var kafkaConfig config.KafkaConfig = config.KafkaConfig {ClusterID : selectedKafka .Id }
317326 cliconfig .Services .SetKafka (& kafkaConfig )
318327
319328 return cliconfig
0 commit comments