Skip to content

Commit

Permalink
Add GetAuthSecretName() helper (#986)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Sep 30, 2022
1 parent b48d011 commit 9f60ebb
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 15 deletions.
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/elasticsearch_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ func (e Elasticsearch) ResourcePlural() string {
return ResourcePluralElasticsearch
}

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

func (e Elasticsearch) ServiceName() string {
return e.OffshootName()
}
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/etcd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func (e Etcd) ResourcePlural() string {
return ResourcePluralEtcd
}

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

func (e Etcd) ClientServiceName() string {
return e.OffshootName() + "-client"
}
Expand Down
9 changes: 4 additions & 5 deletions apis/kubedb/v1alpha2/mariadb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ func (m MariaDB) PeerName(idx int) string {
}

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

func (m MariaDB) ClusterName() string {
Expand Down Expand Up @@ -295,10 +298,6 @@ func (m *MariaDB) GetCertSecretName(alias MariaDBCertificateAlias) string {
return m.CertificateName(alias)
}

func (m *MariaDB) AuthSecretName() string {
return meta_util.NameWithSuffix(m.Name, "auth")
}

func (m *MariaDB) ReplicasAreReady(lister appslister.StatefulSetLister) (bool, string, error) {
// Desire number of statefulSets
expectedItems := 1
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func (m MongoDB) ResourcePlural() string {
return ResourcePluralMongoDB
}

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

func (m MongoDB) ServiceName() string {
return m.OffshootName()
}
Expand Down
4 changes: 2 additions & 2 deletions apis/kubedb/v1alpha2/mysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func (m MySQL) PeerName(idx int) string {
}

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

type mysqlApp struct {
Expand Down
9 changes: 4 additions & 5 deletions apis/kubedb/v1alpha2/perconaxtradb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func (p PerconaXtraDB) PeerName(idx int) string {
}

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

func (p PerconaXtraDB) ClusterName() string {
Expand Down Expand Up @@ -309,10 +312,6 @@ func (p *PerconaXtraDB) GetCertSecretName(alias PerconaXtraDBCertificateAlias) s
return p.CertificateName(alias)
}

func (p *PerconaXtraDB) AuthSecretName() string {
return meta_util.NameWithSuffix(p.Name, "auth")
}

func (p *PerconaXtraDB) ReplicationSecretName() string {
return meta_util.NameWithSuffix(p.Name, "replication")
}
Expand Down
6 changes: 3 additions & 3 deletions apis/kubedb/v1alpha2/pgbouncer_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (p PgBouncer) GoverningServiceName() string {
return meta_util.NameWithSuffix(p.ServiceName(), "pods")
}

func (p PgBouncer) AuthSecretName() string {
return meta_util.NameWithSuffix(p.ServiceName(), "auth")
func (p PgBouncer) GetAuthSecretName() string {
return meta_util.NameWithSuffix(p.OffshootName(), "auth")
}

func (p PgBouncer) ConfigSecretName() string {
Expand Down Expand Up @@ -217,7 +217,7 @@ func (p *PgBouncer) GetPersistentSecrets() []string {
return nil
}
var secrets []string
secrets = append(secrets, p.AuthSecretName())
secrets = append(secrets, p.GetAuthSecretName())
secrets = append(secrets, p.ConfigSecretName())

return secrets
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/postgres_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ func (p Postgres) ResourcePlural() string {
return ResourcePluralPostgres
}

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

func (p Postgres) ServiceName() string {
return p.OffshootName()
}
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/proxysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func (p ProxySQL) ResourcePlural() string {
return ResourcePluralProxySQL
}

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

func (p ProxySQL) ServiceName() string {
return p.OffshootName()
}
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/redis_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ func (r Redis) ResourcePlural() string {
return ResourcePluralRedis
}

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

func (r Redis) ServiceName() string {
return r.OffshootName()
}
Expand Down
7 changes: 7 additions & 0 deletions apis/kubedb/v1alpha2/redis_sentinel_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (rs RedisSentinel) ResourcePlural() string {
return ResourcePluralRedisSentinel
}

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

func (rs RedisSentinel) GoverningServiceName() string {
return meta_util.NameWithSuffix(rs.OffshootName(), "pods")
}
Expand Down

0 comments on commit 9f60ebb

Please sign in to comment.