Skip to content

Commit

Permalink
Add pod and workload controller label support (#817)
Browse files Browse the repository at this point in the history
* Add pod and workload controller label support

Signed-off-by: Tamal Saha <tamal@appscode.com>

* Add Postgres, MySQL, MariaDB label helpers

Signed-off-by: Tamal Saha <tamal@appscode.com>

* Update dependencies

Signed-off-by: Tamal Saha <tamal@appscode.com>

* Update label helper methods

Signed-off-by: kamolhasan <kamol@appscode.com>

* Update constants

Signed-off-by: kamolhasan <kamol@appscode.com>

* Update PodLabels() method for ES

Signed-off-by: kamolhasan <kamol@appscode.com>

* Update PodControllerLabels() method for ES

Signed-off-by: kamolhasan <kamol@appscode.com>

* Update OffshootSelector() method of ES

Signed-off-by: kamolhasan <kamol@appscode.com>

* Add mongodb pod labels

Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>

* Update StatefulSet's PDB selector

Signed-off-by: kamolhasan <kamol@appscode.com>

* Remove mongodb PodControllerLabels method

Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>

* Update mysql router label method

Signed-off-by: Mehedi Hasan <mehedi.hasan@appscode.com>

* Update mongodb shard labels

Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>

* Add mongodb service labels

Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>

* Update labels for services

Signed-off-by: kamolhasan <kamol@appscode.com>

* update service labels for mysql

Signed-off-by: Mehedi Hasan <mehedi.hasan@appscode.com>

* add ServiceLabels method for mariadb

Signed-off-by: Mehedi Hasan <mehedi.hasan@appscode.com>

* Update helper methods for other DBs

Signed-off-by: kamolhasan <kamol@appscode.com>

* Don't overwrite db labels

Signed-off-by: Tamal Saha <tamal@appscode.com>

* Rename parameter: overrides --> extraLabels

Signed-off-by: kamolhasan <kamol@appscode.com>

* Update redis labels

Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>

Co-authored-by: kamolhasan <kamol@appscode.com>
Co-authored-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>
Co-authored-by: Mehedi Hasan <mehedi.hasan@appscode.com>
  • Loading branch information
4 people authored Nov 10, 2021
1 parent 1cef683 commit 1222a1d
Show file tree
Hide file tree
Showing 217 changed files with 8,981 additions and 15,760 deletions.
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
47 changes: 27 additions & 20 deletions apis/kubedb/v1alpha2/elasticsearch_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,55 @@ func (e Elasticsearch) OffshootName() string {
return e.Name
}

func (e Elasticsearch) OffshootSelectors() map[string]string {
return map[string]string{
func (e Elasticsearch) OffshootSelectors(extraSelectors ...map[string]string) map[string]string {
selector := map[string]string{
meta_util.NameLabelKey: e.ResourceFQN(),
meta_util.InstanceLabelKey: e.Name,
meta_util.ManagedByLabelKey: kubedb.GroupName,
}
return meta_util.OverwriteKeys(selector, extraSelectors...)
}

func (e Elasticsearch) NodeRoleSpecificLabelKey(roleType ElasticsearchNodeRoleType) string {
return kubedb.GroupName + "/role-" + string(roleType)
}

func (e Elasticsearch) MasterSelectors() map[string]string {
selectors := e.OffshootSelectors()
selectors[e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeMaster)] = ElasticsearchNodeRoleSet
return selectors
return e.OffshootSelectors(map[string]string{e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeMaster): ElasticsearchNodeRoleSet})
}

func (e Elasticsearch) DataSelectors() map[string]string {
selectors := e.OffshootSelectors()
selectors[e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeData)] = ElasticsearchNodeRoleSet
return selectors
return e.OffshootSelectors(map[string]string{e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeData): ElasticsearchNodeRoleSet})
}

func (e Elasticsearch) IngestSelectors() map[string]string {
selectors := e.OffshootSelectors()
selectors[e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeIngest)] = ElasticsearchNodeRoleSet
return selectors
return e.OffshootSelectors(map[string]string{e.NodeRoleSpecificLabelKey(ElasticsearchNodeRoleTypeIngest): ElasticsearchNodeRoleSet})
}

func (e Elasticsearch) NodeRoleSpecificSelectors(roleType ElasticsearchNodeRoleType) map[string]string {
selectors := e.OffshootSelectors()
selectors[e.NodeRoleSpecificLabelKey(roleType)] = ElasticsearchNodeRoleSet
return selectors
return e.OffshootSelectors(map[string]string{e.NodeRoleSpecificLabelKey(roleType): ElasticsearchNodeRoleSet})
}

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(extraLabels ...map[string]string) map[string]string {
return e.offshootLabels(meta_util.OverwriteKeys(e.OffshootSelectors(), extraLabels...), e.Spec.PodTemplate.Labels)
}

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

func (e Elasticsearch) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(e.Spec.ServiceTemplates, alias)
return e.offshootLabels(meta_util.OverwriteKeys(e.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

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

func (e Elasticsearch) ResourceFQN() string {
Expand Down Expand Up @@ -355,9 +364,7 @@ func (e Elasticsearch) StatsService() mona.StatsAccessor {
}

func (e Elasticsearch) StatsServiceLabels() map[string]string {
lbl := meta_util.FilterKeys(kubedb.GroupName, e.OffshootSelectors(), e.Labels)
lbl[LabelRole] = RoleStats
return lbl
return e.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (e *Elasticsearch) SetDefaults(esVersion *catalog.ElasticsearchVersion, topology *core_util.Topology) {
Expand Down
26 changes: 20 additions & 6 deletions apis/kubedb/v1alpha2/etcd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,25 @@ 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) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(e.Spec.ServiceTemplates, alias)
return e.offshootLabels(meta_util.OverwriteKeys(e.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

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

func (e Etcd) ResourceFQN() string {
Expand Down Expand Up @@ -133,9 +149,7 @@ func (e Etcd) StatsService() mona.StatsAccessor {
}

func (e Etcd) StatsServiceLabels() map[string]string {
lbl := meta_util.FilterKeys(kubedb.GroupName, e.OffshootSelectors(), e.Labels)
lbl[LabelRole] = RoleStats
return lbl
return e.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (e *Etcd) SetDefaults() {
Expand Down
26 changes: 20 additions & 6 deletions apis/kubedb/v1alpha2/mariadb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,25 @@ 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, override map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(nil, m.Labels, override))
}

func (m MariaDB) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(m.Spec.ServiceTemplates, alias)
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

func (m MariaDB) ResourceFQN() string {
Expand Down Expand Up @@ -154,9 +170,7 @@ func (m MariaDB) StatsService() mona.StatsAccessor {
}

func (m MariaDB) StatsServiceLabels() map[string]string {
lbl := meta_util.FilterKeys(kubedb.GroupName, m.OffshootSelectors(), m.Labels)
lbl[LabelRole] = RoleStats
return lbl
return m.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (m MariaDB) PrimaryServiceDNS() string {
Expand Down
26 changes: 20 additions & 6 deletions apis/kubedb/v1alpha2/memcached_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,25 @@ 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) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(m.Spec.ServiceTemplates, alias)
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

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

func (m Memcached) ResourceFQN() string {
Expand Down Expand Up @@ -132,9 +148,7 @@ func (m Memcached) StatsService() mona.StatsAccessor {
}

func (m Memcached) StatsServiceLabels() map[string]string {
lbl := meta_util.FilterKeys(kubedb.GroupName, m.OffshootSelectors(), m.Labels)
lbl[LabelRole] = RoleStats
return lbl
return m.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (m *Memcached) SetDefaults() {
Expand Down
39 changes: 26 additions & 13 deletions apis/kubedb/v1alpha2/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
kmapi "kmodules.xyz/client-go/api/v1"
"kmodules.xyz/client-go/apiextensions"
core_util "kmodules.xyz/client-go/core/v1"
v1 "kmodules.xyz/client-go/core/v1"
meta_util "kmodules.xyz/client-go/meta"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
Expand Down Expand Up @@ -136,39 +135,55 @@ func (m MongoDB) OffshootSelectors() map[string]string {
}

func (m MongoDB) ShardSelectors(nodeNum int32) map[string]string {
return v1.UpsertMap(m.OffshootSelectors(), map[string]string{
return meta_util.OverwriteKeys(m.OffshootSelectors(), map[string]string{
MongoDBShardLabelKey: m.ShardNodeName(nodeNum),
})
}

func (m MongoDB) ConfigSvrSelectors() map[string]string {
return v1.UpsertMap(m.OffshootSelectors(), map[string]string{
return meta_util.OverwriteKeys(m.OffshootSelectors(), map[string]string{
MongoDBConfigLabelKey: m.ConfigSvrNodeName(),
})
}

func (m MongoDB) MongosSelectors() map[string]string {
return v1.UpsertMap(m.OffshootSelectors(), map[string]string{
return meta_util.OverwriteKeys(m.OffshootSelectors(), map[string]string{
MongoDBMongosLabelKey: m.MongosNodeName(),
})
}

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(podTemplateLabels map[string]string, extraLabels ...map[string]string) map[string]string {
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), podTemplateLabels)
}

func (m MongoDB) PodControllerLabels(podControllerLabels map[string]string, extraLabels ...map[string]string) map[string]string {
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), podControllerLabels)
}

func (m MongoDB) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(m.Spec.ServiceTemplates, alias)
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
}

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

func (m MongoDB) ShardLabels(nodeNum int32) map[string]string {
return meta_util.FilterKeys(kubedb.GroupName, m.OffshootLabels(), m.ShardSelectors(nodeNum))
return meta_util.OverwriteKeys(m.OffshootLabels(), m.ShardSelectors(nodeNum))
}

func (m MongoDB) ConfigSvrLabels() map[string]string {
return meta_util.FilterKeys(kubedb.GroupName, m.OffshootLabels(), m.ConfigSvrSelectors())
return meta_util.OverwriteKeys(m.OffshootLabels(), m.ConfigSvrSelectors())
}

func (m MongoDB) MongosLabels() map[string]string {
return meta_util.FilterKeys(kubedb.GroupName, m.OffshootLabels(), m.MongosSelectors())
return meta_util.OverwriteKeys(m.OffshootLabels(), m.MongosSelectors())
}

func (m MongoDB) ResourceFQN() string {
Expand Down Expand Up @@ -332,9 +347,7 @@ func (m MongoDB) StatsService() mona.StatsAccessor {
}

func (m MongoDB) StatsServiceLabels() map[string]string {
lbl := meta_util.FilterKeys(kubedb.GroupName, m.OffshootSelectors(), m.Labels)
lbl[LabelRole] = RoleStats
return lbl
return m.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (m *MongoDB) SetDefaults(mgVersion *v1alpha1.MongoDBVersion, topology *core_util.Topology) {
Expand Down
Loading

0 comments on commit 1222a1d

Please sign in to comment.