Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Common AuthSecret Name #1333

Merged
merged 8 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions apis/kafka/v1alpha1/connect_cluster_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,6 @@ func (k *ConnectCluster) KafkaClientCredentialsSecretName() string {
return meta_util.NameWithSuffix(k.Name, "kafka-client-cred")
}

func (k *ConnectCluster) DefaultUserCredSecretName(username string) string {
return meta_util.NameWithSuffix(k.Name, strings.ReplaceAll(fmt.Sprintf("%s-cred", username), "_", "-"))
}

func (k *ConnectCluster) DefaultKeystoreCredSecretName() string {
return meta_util.NameWithSuffix(k.Name, strings.ReplaceAll("connect-keystore-cred", "_", "-"))
}

// CertificateName returns the default certificate name and/or certificate secret name for a certificate alias
func (k *ConnectCluster) CertificateName(alias ConnectClusterCertificateAlias) string {
return meta_util.NameWithSuffix(k.Name, fmt.Sprintf("%s-connect-cert", string(alias)))
Expand All @@ -213,7 +205,14 @@ func (k *ConnectCluster) GetAuthSecretName() string {
if k.Spec.AuthSecret != nil && k.Spec.AuthSecret.Name != "" {
return k.Spec.AuthSecret.Name
}
return k.DefaultUserCredSecretName("admin")
return meta_util.NameWithSuffix(k.OffshootName(), "auth")
}

func (k *ConnectCluster) GetKeystoreSecretName() string {
if k.Spec.KeystoreCredSecret != nil && k.Spec.KeystoreCredSecret.Name != "" {
return k.Spec.KeystoreCredSecret.Name
}
return meta_util.NameWithSuffix(k.OffshootName(), "keystore-cred")
}

// GetCertSecretName returns the secret name for a certificate alias if any,
Expand Down
17 changes: 8 additions & 9 deletions apis/kubedb/v1/kafka_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ func (k *Kafka) GetAuthSecretName() string {
if k.Spec.AuthSecret != nil && k.Spec.AuthSecret.Name != "" {
return k.Spec.AuthSecret.Name
}
return k.DefaultUserCredSecretName("admin")
return meta_util.NameWithSuffix(k.OffshootName(), "auth")
}

func (k *Kafka) GetKeystoreSecretName() string {
if k.Spec.KeystoreCredSecret != nil && k.Spec.KeystoreCredSecret.Name != "" {
return k.Spec.KeystoreCredSecret.Name
}
return meta_util.NameWithSuffix(k.OffshootName(), "keystore-cred")
}

func (k *Kafka) GetPersistentSecrets() []string {
Expand All @@ -249,14 +256,6 @@ func (k *Kafka) CruiseControlConfigSecretName() string {
return meta_util.NameWithSuffix(k.OffshootName(), "cruise-control-config")
}

func (k *Kafka) DefaultUserCredSecretName(username string) string {
return meta_util.NameWithSuffix(k.Name, strings.ReplaceAll(fmt.Sprintf("%s-cred", username), "_", "-"))
}

func (k *Kafka) DefaultKeystoreCredSecretName() string {
return meta_util.NameWithSuffix(k.Name, strings.ReplaceAll("keystore-cred", "_", "-"))
}

// CertificateName returns the default certificate name and/or certificate secret name for a certificate alias
func (k *Kafka) CertificateName(alias KafkaCertificateAlias) string {
return meta_util.NameWithSuffix(k.Name, fmt.Sprintf("%s-cert", string(alias)))
Expand Down
2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/cassandra_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r *Cassandra) GetAuthSecretName() string {
if r.Spec.AuthSecret != nil && r.Spec.AuthSecret.Name != "" {
return r.Spec.AuthSecret.Name
}
return r.DefaultUserCredSecretName("admin")
return meta_util.NameWithSuffix(r.OffshootName(), "auth")
}

func (r *Cassandra) ConfigSecretName() string {
Expand Down
2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/clickhouse_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (c *ClickHouse) GetAuthSecretName() string {
if c.Spec.AuthSecret != nil && c.Spec.AuthSecret.Name != "" {
return c.Spec.AuthSecret.Name
}
return c.DefaultUserCredSecretName("admin")
return meta_util.NameWithSuffix(c.OffshootName(), "auth")
}

func (r *ClickHouse) ConfigSecretName() string {
Expand Down
13 changes: 10 additions & 3 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ func (d *Druid) GoverningServiceName() string {
return meta_util.NameWithSuffix(d.ServiceName(), "pods")
}

func (d *Druid) GetAuthSecretName() string {
if d.Spec.AuthSecret != nil && d.Spec.AuthSecret.Name != "" {
return d.Spec.AuthSecret.Name
}
return meta_util.NameWithSuffix(d.OffShootName(), "auth")
}

func (d *Druid) OffShootSelectors(extraSelectors ...map[string]string) map[string]string {
selector := map[string]string{
meta_util.NameLabelKey: d.ResourceFQN(),
Expand Down Expand Up @@ -310,9 +317,9 @@ func (d *Druid) AppBindingMeta() appcat.AppBindingMeta {

func (d *Druid) GetConnectionScheme() string {
scheme := "http"
//if d.Spec.EnableSSL {
// scheme = "https"
//}
if d.Spec.EnableSSL {
scheme = "https"
}
return scheme
}

Expand Down
4 changes: 2 additions & 2 deletions apis/kubedb/v1alpha2/kafka_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ func (k *Kafka) CruiseControlConfigSecretName() string {
return meta_util.NameWithSuffix(k.OffshootName(), "cruise-control-config")
}

func (k *Kafka) DefaultUserCredSecretName(username string) string {
return meta_util.NameWithSuffix(k.Name, strings.ReplaceAll(fmt.Sprintf("%s-cred", username), "_", "-"))
func (k *Kafka) DefaultUserCredSecretName() string {
return meta_util.NameWithSuffix(k.OffshootName(), "auth")
}

func (k *Kafka) DefaultKeystoreCredSecretName() string {
Expand Down
2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/rabbitmq_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *RabbitMQ) GetAuthSecretName() string {
if r.Spec.AuthSecret != nil && r.Spec.AuthSecret.Name != "" {
return r.Spec.AuthSecret.Name
}
return r.DefaultUserCredSecretName("admin")
return meta_util.NameWithSuffix(r.OffshootName(), "auth")
}

func (r *RabbitMQ) GetPersistentSecrets() []string {
Expand Down
18 changes: 9 additions & 9 deletions apis/kubedb/v1alpha2/solr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (s *Solr) SolrSecretName(suffix string) string {
return strings.Join([]string{s.Name, suffix}, "-")
}

func (s *Solr) GetAuthSecretName() string {
if s.Spec.AuthSecret != nil && s.Spec.AuthSecret.Name != "" {
return s.Spec.AuthSecret.Name
}
return meta_util.NameWithSuffix(s.OffshootName(), "auth")
}

func (s *Solr) SolrSecretKey() string {
return kubedb.SolrSecretKey
}
Expand Down Expand Up @@ -262,12 +269,6 @@ func (s *Solr) SetDefaults() {
s.Spec.StorageType = StorageTypeDurable
}

if s.Spec.AuthSecret == nil {
s.Spec.AuthSecret = &v1.LocalObjectReference{
Name: s.SolrSecretName("admin-cred"),
}
Comment on lines -265 to -268
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont need the authSecret defaulting ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no
a method is added to retrieve the name of auth secret.

}

if s.Spec.ZookeeperDigestSecret == nil {
s.Spec.ZookeeperDigestSecret = &v1.LocalObjectReference{
Name: s.SolrSecretName("zk-digest"),
Expand Down Expand Up @@ -442,9 +443,8 @@ func (s *Solr) GetPersistentSecrets() []string {

var secrets []string
// Add Admin/Elastic user secret name
if s.Spec.AuthSecret != nil {
secrets = append(secrets, s.Spec.AuthSecret.Name)
}

secrets = append(secrets, s.GetAuthSecretName())

if s.Spec.AuthConfigSecret != nil {
secrets = append(secrets, s.Spec.AuthConfigSecret.Name)
Expand Down
Loading