Skip to content

Commit

Permalink
Update label helper methods
Browse files Browse the repository at this point in the history
Signed-off-by: kamolhasan <kamol@appscode.com>
  • Loading branch information
kamolhasan committed Nov 5, 2021
1 parent 02ce080 commit 300eddd
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 27 deletions.
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/elasticsearch_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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/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
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] = "connection-pooler"
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(p.Labels, overwrite))
}

func (p PgBouncer) ResourceFQN() string {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/proxysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/redis_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions apis/kubedb/v1alpha2/redis_sentinel_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 300eddd

Please sign in to comment.