Skip to content

Commit

Permalink
Add helpers to use different labels in sidekick (#1357)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha authored Nov 29, 2024
1 parent cfbad6a commit 2198d91
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 10 deletions.
16 changes: 16 additions & 0 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ limitations under the License.
package kubedb

import (
"fmt"
"time"

core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
meta_util "kmodules.xyz/client-go/meta"
skapi "kubeops.dev/sidekick/apis/apps/v1alpha1"
)

const (
Expand Down Expand Up @@ -1567,6 +1570,19 @@ const (
ResourceKindPetSet = "PetSet"
)

var (
SidekickGVR = fmt.Sprintf("%s.%s", skapi.ResourceSidekicks, skapi.SchemeGroupVersion.Group)
SidekickOwnerName = SidekickGVR + "/owner-name"
SidekickOwnerKind = SidekickGVR + "/owner-kind"
)

func CommonSidekickLabels() map[string]string {
return map[string]string{
meta_util.NameLabelKey: SidekickGVR,
meta_util.ManagedByLabelKey: GroupName,
}
}

var (
DefaultInitContainerResource = core.ResourceRequirements{
Requests: core.ResourceList{
Expand Down
8 changes: 8 additions & 0 deletions apis/kubedb/v1/mariadb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func (m MariaDB) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MariaDB) SidekickLabels(skName string) map[string]string {
return meta_util.OverwriteKeys(nil, kubedb.CommonSidekickLabels(), map[string]string{
meta_util.InstanceLabelKey: skName,
kubedb.SidekickOwnerName: m.Name,
kubedb.SidekickOwnerKind: m.ResourceFQN(),
})
}

func (m MariaDB) offshootLabels(selector, override map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = kubedb.ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(nil, m.Labels, override))
Expand Down
8 changes: 8 additions & 0 deletions apis/kubedb/v1/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ func (m MongoDB) PodControllerLabels(podControllerLabels map[string]string, extr
return m.offshootLabels(meta_util.OverwriteKeys(m.OffshootSelectors(), extraLabels...), podControllerLabels)
}

func (m MongoDB) SidekickLabels(skName string) map[string]string {
return meta_util.OverwriteKeys(nil, kubedb.CommonSidekickLabels(), map[string]string{
meta_util.InstanceLabelKey: skName,
kubedb.SidekickOwnerName: m.Name,
kubedb.SidekickOwnerKind: m.ResourceFQN(),
})
}

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)
Expand Down
8 changes: 8 additions & 0 deletions apis/kubedb/v1/mysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func (m MySQL) PodControllerLabels() map[string]string {
return m.offshootLabels(m.OffshootSelectors(), m.Spec.PodTemplate.Controller.Labels)
}

func (m MySQL) SidekickLabels(skName string) map[string]string {
return meta_util.OverwriteKeys(nil, kubedb.CommonSidekickLabels(), map[string]string{
meta_util.InstanceLabelKey: skName,
kubedb.SidekickOwnerName: m.Name,
kubedb.SidekickOwnerKind: m.ResourceFQN(),
})
}

func (m MySQL) RouterOffshootLabels() map[string]string {
return m.offshootLabels(m.RouterOffshootSelectors(), nil)
}
Expand Down
8 changes: 8 additions & 0 deletions apis/kubedb/v1/postgres_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ func (p Postgres) PodControllerLabels() map[string]string {
return p.offshootLabels(p.OffshootSelectors(), p.Spec.PodTemplate.Controller.Labels)
}

func (p Postgres) SidekickLabels(skName string) map[string]string {
return meta_util.OverwriteKeys(nil, kubedb.CommonSidekickLabels(), map[string]string{
meta_util.InstanceLabelKey: skName,
kubedb.SidekickOwnerName: p.Name,
kubedb.SidekickOwnerKind: p.ResourceFQN(),
})
}

func (p Postgres) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]string) map[string]string {
svcTemplate := GetServiceTemplate(p.Spec.ServiceTemplates, alias)
return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), svcTemplate.Labels)
Expand Down
9 changes: 9 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
kmapi "kmodules.xyz/client-go/api/v1"
"kmodules.xyz/client-go/apiextensions"
coreutil "kmodules.xyz/client-go/core/v1"
meta_util "kmodules.xyz/client-go/meta"
metautil "kmodules.xyz/client-go/meta"
"kmodules.xyz/client-go/policy/secomp"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
Expand Down Expand Up @@ -225,6 +226,14 @@ func (m *MSSQLServer) AvailabilityGroupName() string {
return availabilityGroupName
}

func (m MSSQLServer) SidekickLabels(skName string) map[string]string {
return meta_util.OverwriteKeys(nil, kubedb.CommonSidekickLabels(), map[string]string{
meta_util.InstanceLabelKey: skName,
kubedb.SidekickOwnerName: m.Name,
kubedb.SidekickOwnerKind: m.ResourceFQN(),
})
}

func (m *MSSQLServer) PodControllerLabels(extraLabels ...map[string]string) map[string]string {
return m.offshootLabels(metautil.OverwriteKeys(m.OffshootSelectors(), extraLabels...), m.Spec.PodTemplate.Controller.Labels)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
k8s.io/kube-openapi v0.0.0-20240726031636-6f6746feab9c
k8s.io/metrics v0.30.2
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
kmodules.xyz/client-go v0.30.38
kmodules.xyz/client-go v0.30.39
kmodules.xyz/crd-schema-fuzz v0.29.1
kmodules.xyz/custom-resources v0.30.0
kmodules.xyz/monitoring-agent-api v0.30.2
Expand All @@ -46,7 +46,7 @@ require (
kmodules.xyz/webhook-runtime v0.29.1
kubeops.dev/csi-driver-cacerts v0.1.0
kubeops.dev/petset v0.0.7
kubeops.dev/sidekick v0.0.9
kubeops.dev/sidekick v0.0.10-0.20241122131943-163e27e5ef71
kubestash.dev/apimachinery v0.13.0
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/yaml v1.4.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.bytebuilders.dev/audit v0.0.38 h1:4DEYVfBNeAfI9rctVWmpDOvEExh3gIuPsXVAg4Z3FWA=
go.bytebuilders.dev/audit v0.0.38/go.mod h1:6RC3gMMFpAzTzGJuJg8Ghgvebde4vvXkmDtUo11ypQw=
go.bytebuilders.dev/license-proxyserver v0.0.18 h1:Ii8B4yesaKWM7BTIEjsMONy7+gqnBXambMG5m2J1VbI=
go.bytebuilders.dev/license-proxyserver v0.0.18/go.mod h1:7Y8xJwxWuZXHlnETBE9JqMJrSdA+Vw+zTMZVurxSwrA=
go.bytebuilders.dev/license-proxyserver v0.0.18 h1:xBEw3qJoskrgJrzVrLKfBIoC7bQIARUlNwBIpLkPXaw=
go.bytebuilders.dev/license-proxyserver v0.0.18/go.mod h1:7wLFkvqfHwmB6MHcdTHB72M8+b63jApS59efrqZlY1E=
go.bytebuilders.dev/license-verifier v0.14.3 h1:5BTwmFEgCjSlAs2Nzh3/7+u//VoF93xjqywrJiqmZsg=
go.bytebuilders.dev/license-verifier v0.14.3/go.mod h1:bNNaVbry3TZbu54pf57LkhjsFX94T6O62w0roiy1yiE=
go.bytebuilders.dev/license-verifier/kubernetes v0.14.3 h1:PlzARW7Dt/t8WHtuNOxnB7GLhgdq30smRMAPRfyrhh8=
Expand Down Expand Up @@ -654,8 +654,8 @@ k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/client-go v0.30.38 h1:kAQ3FdgX2HbkmfFGEoeKz7fmJYWo1Ndgdum50aaHyI0=
kmodules.xyz/client-go v0.30.38/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.39 h1:/GjcgKLY1WdsHRK+956FXQdqDkJg/voJASo+IFyH0xA=
kmodules.xyz/client-go v0.30.39/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/custom-resources v0.30.0 h1:vR3CbseHMLwR4GvtcJJuRuwIV8voKqFqNii27rMcm1o=
Expand All @@ -680,8 +680,8 @@ kubeops.dev/csi-driver-cacerts v0.1.0 h1:WDgKNo5QAiMoVy4c/4ARWeCXJbqdcXdcn8VLImV
kubeops.dev/csi-driver-cacerts v0.1.0/go.mod h1:5a/ZOn5LFw26PPBpTKvsivBjcvVArOrJX24C+k+przk=
kubeops.dev/petset v0.0.7 h1:F77BTRfUqRVO7kNc8q2oFSSviDmYBqni/osXqu0kgJ4=
kubeops.dev/petset v0.0.7/go.mod h1:lt0SZV4ohRy7RiwLNUnMoauG4lCbcRbSqhMg20rdUQg=
kubeops.dev/sidekick v0.0.9 h1:nd6hcctswmUammKW50x8S+KSSIBTmQIqJuTp+eyRT70=
kubeops.dev/sidekick v0.0.9/go.mod h1:SksBYafOpe8cHeHw9GahNmrkNGsPTxnSUHf7oTXLEVY=
kubeops.dev/sidekick v0.0.10-0.20241122131943-163e27e5ef71 h1:MIrAOBOkxkJuV1mtRTbP1elbLUUp55UmbGrAlFgLO7U=
kubeops.dev/sidekick v0.0.10-0.20241122131943-163e27e5ef71/go.mod h1:KGH6DiNqAfTaVz9bVTvm7e+KPKPN/PkfKkqee89YhW0=
kubestash.dev/apimachinery v0.13.0 h1:c1K5QzUR/x1Og56+oUufPq7cDX3QljPw9CQrEpVnPrI=
kubestash.dev/apimachinery v0.13.0/go.mod h1:OuO8kh4EcAerSpllIXM7JaPQfKDGsQoAm3jAt4m0a1E=
moul.io/http2curl/v2 v2.3.1-0.20221024080105-10c404f653f7 h1:NykkTlRB+X40z86cLHdEmuoTxhNKhQebLT379b1EumA=
Expand Down
1 change: 1 addition & 0 deletions vendor/kmodules.xyz/client-go/api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
ClusterNameKey string = "cluster.appscode.com/name"
ClusterDisplayNameKey string = "cluster.appscode.com/display-name"
ClusterProviderNameKey string = "cluster.appscode.com/provider"
ClusterProfileLabel string = "cluster.appscode.com/profile"

AceOrgIDKey string = "ace.appscode.com/org-id"
ClientOrgKey string = "ace.appscode.com/client-org"
Expand Down
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ k8s.io/utils/trace
# kmodules.xyz/apiversion v0.2.0
## explicit; go 1.14
kmodules.xyz/apiversion
# kmodules.xyz/client-go v0.30.38
# kmodules.xyz/client-go v0.30.39
## explicit; go 1.22.0
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
Expand Down Expand Up @@ -1781,7 +1781,7 @@ kubeops.dev/petset/client/informers/externalversions/internalinterfaces
kubeops.dev/petset/client/listers/apps/v1
kubeops.dev/petset/crds
kubeops.dev/petset/pkg/features
# kubeops.dev/sidekick v0.0.9
# kubeops.dev/sidekick v0.0.10-0.20241122131943-163e27e5ef71
## explicit; go 1.22.1
kubeops.dev/sidekick/apis/apps
kubeops.dev/sidekick/apis/apps/v1alpha1
Expand Down

0 comments on commit 2198d91

Please sign in to comment.