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

Add pod and workload controller label support #817

Merged
merged 21 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
16 changes: 16 additions & 0 deletions apis/autoscaling/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions apis/catalog/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions apis/config/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions apis/kubedb/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const (
DatabasePodPrimary = "primary"
DatabasePodStandby = "standby"

ComponentDatabase = "database"
RoleStats = "stats"
DefaultStatsPath = "/metrics"
DefaultPasswordLength = 16
HealthCheckInterval = 10 * time.Second
ComponentDatabase = "database"
ComponentConnectionPooler = "connection-pooler"
RoleStats = "stats"
DefaultStatsPath = "/metrics"
DefaultPasswordLength = 16
HealthCheckInterval = 10 * time.Second

ContainerExporterName = "exporter"
LocalHost = "localhost"
Expand Down
21 changes: 18 additions & 3 deletions apis/kubedb/v1alpha2/elasticsearch_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,24 @@ func (e Elasticsearch) NodeRoleSpecificSelectors(roleType ElasticsearchNodeRoleT
}

func (e Elasticsearch) OffshootLabels() map[string]string {
out := e.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, e.Labels)
return e.offshootLabels(e.OffshootSelectors(), nil)
}

func (e Elasticsearch) PodLabels(overwrites ...map[string]string) map[string]string {
pLabels := e.offshootLabels(e.OffshootSelectors(), e.Spec.PodTemplate.Labels)
for _, overwrite := range overwrites {
pLabels = meta_util.OverwriteKeys(pLabels, overwrite)
}
return pLabels
}

func (e Elasticsearch) PodControllerLabels() map[string]string {
return e.offshootLabels(e.OffshootSelectors(), e.Spec.PodTemplate.Controller.Labels)
}

func (e Elasticsearch) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(e.Labels, overwrite))
}

func (e Elasticsearch) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/etcd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ func (e Etcd) OffshootSelectors() map[string]string {
}

func (e Etcd) OffshootLabels() map[string]string {
out := e.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, e.Labels)
return e.offshootLabels(e.OffshootSelectors(), nil)
}

func (e Etcd) PodLabels() map[string]string {
return e.offshootLabels(e.OffshootSelectors(), e.Spec.PodTemplate.Labels)
}

func (e Etcd) PodControllerLabels() map[string]string {
return e.offshootLabels(e.OffshootSelectors(), e.Spec.PodTemplate.Controller.Labels)
}

func (e Etcd) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(e.Labels, overwrite))
}

func (e Etcd) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/mariadb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ func (m MariaDB) OffshootSelectors() map[string]string {
}

func (m MariaDB) OffshootLabels() map[string]string {
out := m.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, m.Labels)
return m.offshootLabels(m.OffshootSelectors(), nil)
}

func (m MariaDB) PodLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Labels)
}

func (m MariaDB) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MariaDB) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(m.Labels, overwrite))
}

func (m MariaDB) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/memcached_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,20 @@ func (m Memcached) OffshootSelectors() map[string]string {
}

func (m Memcached) OffshootLabels() map[string]string {
out := m.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, m.Labels)
return m.offshootLabels(m.OffshootSelectors(), nil)
}

func (m Memcached) PodLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Labels)
}

func (m Memcached) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m Memcached) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(m.Labels, overwrite))
}

func (m Memcached) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,20 @@ func (m MongoDB) MongosSelectors() map[string]string {
}

func (m MongoDB) OffshootLabels() map[string]string {
out := m.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, m.Labels)
return m.offshootLabels(m.OffshootSelectors(), nil)
}

func (m MongoDB) PodLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Labels)
}

func (m MongoDB) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MongoDB) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(m.Labels, overwrite))
}

func (m MongoDB) ShardLabels(nodeNum int32) map[string]string {
Expand Down
47 changes: 30 additions & 17 deletions apis/kubedb/v1alpha2/mysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,52 @@ func (m MySQL) OffshootName() string {
}

func (m MySQL) OffshootSelectors() map[string]string {
selectors := map[string]string{
meta_util.NameLabelKey: m.ResourceFQN(),
meta_util.InstanceLabelKey: m.Name,
meta_util.ManagedByLabelKey: kubedb.GroupName,
}
if m.IsInnoDBCluster() {
selectors[MySQLComponentKey] = MySQLComponentDB
}
return selectors
return m.offshootSelectors(MySQLComponentDB)
}

func (m MySQL) RouterOffshootSelectors() map[string]string {
return m.offshootSelectors(MySQLComponentRouter)
}

func (m MySQL) offshootSelectors(component string) map[string]string {
selectors := map[string]string{
meta_util.NameLabelKey: m.ResourceFQN(),
meta_util.InstanceLabelKey: m.Name,
meta_util.ManagedByLabelKey: kubedb.GroupName,
}
if m.IsInnoDBCluster() {
selectors[MySQLComponentKey] = MySQLComponentRouter
selectors[MySQLComponentKey] = component
}
return selectors
}

func (m MySQL) OffshootLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), nil)
}

func (m MySQL) PodLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Labels)
}

func (m MySQL) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MySQL) RouterOffshootLabels() map[string]string {
out := m.RouterOffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, m.Labels)
return m.offshootLabels(m.RouterOffshootSelectors(), nil)
}

func (m MySQL) OffshootLabels() map[string]string {
out := m.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, m.Labels)
func (m MySQL) RouterPodLabels() map[string]string {
return m.offshootLabels(m.RouterOffshootLabels(), m.Spec.PodTemplate.Labels)
}

func (m MySQL) RouterPodControllerLabels() map[string]string {
return m.offshootLabels(m.RouterOffshootLabels(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MySQL) offshootLabels(selector, override map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(m.Labels, override))
}

func (m MySQL) ResourceFQN() string {
Expand Down
16 changes: 16 additions & 0 deletions apis/kubedb/v1alpha2/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/perconaxtradb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ func (p PerconaXtraDB) OffshootSelectors() map[string]string {
}

func (p PerconaXtraDB) OffshootLabels() map[string]string {
out := p.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, p.Labels)
return p.offshootLabels(p.OffshootSelectors(), nil)
}

func (p PerconaXtraDB) PodLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Labels)
}

func (p PerconaXtraDB) PodControllerLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Controller.Labels)
}

func (p PerconaXtraDB) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(p.Labels, overwrite))
}

func (p PerconaXtraDB) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/pgbouncer_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ func (p PgBouncer) OffshootSelectors() map[string]string {
}

func (p PgBouncer) OffshootLabels() map[string]string {
out := p.OffshootSelectors()
out[meta_util.ComponentLabelKey] = "connection-pooler"
return meta_util.FilterKeys(kubedb.GroupName, out, p.Labels)
return p.offshootLabels(p.OffshootSelectors(), nil)
}

func (p PgBouncer) PodLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Labels)
}

func (p PgBouncer) PodControllerLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Controller.Labels)
}

func (p PgBouncer) offshootLabels(selector, overwrite map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentConnectionPooler
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(p.Labels, overwrite))
}

func (p PgBouncer) ResourceFQN() string {
Expand Down
18 changes: 15 additions & 3 deletions apis/kubedb/v1alpha2/postgres_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,21 @@ func (p Postgres) OffshootSelectors() map[string]string {
}

func (p Postgres) OffshootLabels() map[string]string {
out := p.OffshootSelectors()
out[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, out, p.Labels)
return p.offshootLabels(p.OffshootSelectors(), nil)
}

func (p Postgres) PodLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Labels)
}

func (p Postgres) PodControllerLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Controller.Labels)
}

func (p Postgres) offshootLabels(selector, overwrite map[string]string) map[string]string {
// out := p.OffshootSelectors()
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(p.Labels, overwrite))
}

func (p Postgres) ResourceFQN() string {
Expand Down
Loading