From 300eddd992d7c3b44ad399a196869f5001366bd7 Mon Sep 17 00:00:00 2001 From: kamolhasan Date: Fri, 5 Nov 2021 12:00:48 +0600 Subject: [PATCH] Update label helper methods Signed-off-by: kamolhasan --- apis/kubedb/v1alpha2/elasticsearch_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/etcd_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/memcached_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/mongodb_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/perconaxtradb_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/pgbouncer_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/proxysql_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/redis_helpers.go | 17 ++++++++++++++--- apis/kubedb/v1alpha2/redis_sentinel_helpers.go | 17 ++++++++++++++--- 9 files changed, 126 insertions(+), 27 deletions(-) diff --git a/apis/kubedb/v1alpha2/elasticsearch_helpers.go b/apis/kubedb/v1alpha2/elasticsearch_helpers.go index 0db75a5ae0..cee93190ce 100644 --- a/apis/kubedb/v1alpha2/elasticsearch_helpers.go +++ b/apis/kubedb/v1alpha2/elasticsearch_helpers.go @@ -92,9 +92,20 @@ 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() map[string]string { + return e.offshootLabels(e.OffshootSelectors(), e.Spec.PodTemplate.Labels) +} + +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 { diff --git a/apis/kubedb/v1alpha2/etcd_helpers.go b/apis/kubedb/v1alpha2/etcd_helpers.go index 84662b1c00..ea16a3f261 100644 --- a/apis/kubedb/v1alpha2/etcd_helpers.go +++ b/apis/kubedb/v1alpha2/etcd_helpers.go @@ -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 { diff --git a/apis/kubedb/v1alpha2/memcached_helpers.go b/apis/kubedb/v1alpha2/memcached_helpers.go index e82208d25d..10cc6c55df 100644 --- a/apis/kubedb/v1alpha2/memcached_helpers.go +++ b/apis/kubedb/v1alpha2/memcached_helpers.go @@ -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 { diff --git a/apis/kubedb/v1alpha2/mongodb_helpers.go b/apis/kubedb/v1alpha2/mongodb_helpers.go index f21f7f6577..c7b02bf208 100644 --- a/apis/kubedb/v1alpha2/mongodb_helpers.go +++ b/apis/kubedb/v1alpha2/mongodb_helpers.go @@ -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 { diff --git a/apis/kubedb/v1alpha2/perconaxtradb_helpers.go b/apis/kubedb/v1alpha2/perconaxtradb_helpers.go index 7fa13c5db2..58e91c6332 100644 --- a/apis/kubedb/v1alpha2/perconaxtradb_helpers.go +++ b/apis/kubedb/v1alpha2/perconaxtradb_helpers.go @@ -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 { diff --git a/apis/kubedb/v1alpha2/pgbouncer_helpers.go b/apis/kubedb/v1alpha2/pgbouncer_helpers.go index 172f31fd8e..f87dc96215 100644 --- a/apis/kubedb/v1alpha2/pgbouncer_helpers.go +++ b/apis/kubedb/v1alpha2/pgbouncer_helpers.go @@ -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] = "connection-pooler" + return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(p.Labels, overwrite)) } func (p PgBouncer) ResourceFQN() string { diff --git a/apis/kubedb/v1alpha2/proxysql_helpers.go b/apis/kubedb/v1alpha2/proxysql_helpers.go index 5cab5d7af0..156c9458a9 100644 --- a/apis/kubedb/v1alpha2/proxysql_helpers.go +++ b/apis/kubedb/v1alpha2/proxysql_helpers.go @@ -52,9 +52,20 @@ func (p ProxySQL) OffshootSelectors() map[string]string { } func (p ProxySQL) 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 ProxySQL) PodLabels() map[string]string { + return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Labels) +} + +func (p ProxySQL) PodControllerLabels() map[string]string { + return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Controller.Labels) +} + +func (p ProxySQL) 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 ProxySQL) ResourceFQN() string { diff --git a/apis/kubedb/v1alpha2/redis_helpers.go b/apis/kubedb/v1alpha2/redis_helpers.go index a6132ed3cf..5917cac54d 100644 --- a/apis/kubedb/v1alpha2/redis_helpers.go +++ b/apis/kubedb/v1alpha2/redis_helpers.go @@ -60,9 +60,20 @@ func (r Redis) OffshootSelectors() map[string]string { } func (r Redis) OffshootLabels() map[string]string { - out := r.OffshootSelectors() - out[meta_util.ComponentLabelKey] = ComponentDatabase - return meta_util.FilterKeys(kubedb.GroupName, out, r.Labels) + return r.offshootLabels(r.OffshootSelectors(), nil) +} + +func (r Redis) PodLabels() map[string]string { + return r.offshootLabels(r.OffshootSelectors(), r.Spec.PodTemplate.Labels) +} + +func (r Redis) PodControllerLabels() map[string]string { + return r.offshootLabels(r.OffshootSelectors(), r.Spec.PodTemplate.Controller.Labels) +} + +func (r Redis) offshootLabels(selector, overwrite map[string]string) map[string]string { + selector[meta_util.ComponentLabelKey] = ComponentDatabase + return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(r.Labels, overwrite)) } func (r Redis) ResourceFQN() string { diff --git a/apis/kubedb/v1alpha2/redis_sentinel_helpers.go b/apis/kubedb/v1alpha2/redis_sentinel_helpers.go index f0b6ab7c48..07301fefb9 100644 --- a/apis/kubedb/v1alpha2/redis_sentinel_helpers.go +++ b/apis/kubedb/v1alpha2/redis_sentinel_helpers.go @@ -52,9 +52,20 @@ func (rs RedisSentinel) OffshootSelectors() map[string]string { } func (rs RedisSentinel) OffshootLabels() map[string]string { - out := rs.OffshootSelectors() - out[meta_util.ComponentLabelKey] = ComponentDatabase - return meta_util.FilterKeys(kubedb.GroupName, out, rs.Labels) + return rs.offshootLabels(rs.OffshootSelectors(), nil) +} + +func (rs RedisSentinel) PodLabels() map[string]string { + return rs.offshootLabels(rs.OffshootSelectors(), rs.Spec.PodTemplate.Labels) +} + +func (rs RedisSentinel) PodControllerLabels() map[string]string { + return rs.offshootLabels(rs.OffshootSelectors(), rs.Spec.PodTemplate.Controller.Labels) +} + +func (rs RedisSentinel) offshootLabels(selector, overwrite map[string]string) map[string]string { + selector[meta_util.ComponentLabelKey] = ComponentDatabase + return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(rs.Labels, overwrite)) } func (rs RedisSentinel) ResourceFQN() string {