From 2198d91098dcd7d93b9ddd454cb8dfc267264b64 Mon Sep 17 00:00:00 2001 From: Arnob Kumar Saha Date: Fri, 29 Nov 2024 12:10:24 +0600 Subject: [PATCH] Add helpers to use different labels in sidekick (#1357) Signed-off-by: Arnob kumar saha --- apis/kubedb/constants.go | 16 ++++++++++++++++ apis/kubedb/v1/mariadb_helpers.go | 8 ++++++++ apis/kubedb/v1/mongodb_helpers.go | 8 ++++++++ apis/kubedb/v1/mysql_helpers.go | 8 ++++++++ apis/kubedb/v1/postgres_helpers.go | 8 ++++++++ apis/kubedb/v1alpha2/mssqlserver_helpers.go | 9 +++++++++ go.mod | 4 ++-- go.sum | 12 ++++++------ vendor/kmodules.xyz/client-go/api/v1/cluster.go | 1 + vendor/modules.txt | 4 ++-- 10 files changed, 68 insertions(+), 10 deletions(-) diff --git a/apis/kubedb/constants.go b/apis/kubedb/constants.go index e216ca6ea2..a6d334fd35 100644 --- a/apis/kubedb/constants.go +++ b/apis/kubedb/constants.go @@ -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 ( @@ -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{ diff --git a/apis/kubedb/v1/mariadb_helpers.go b/apis/kubedb/v1/mariadb_helpers.go index 5ca57402de..54b6b64bad 100644 --- a/apis/kubedb/v1/mariadb_helpers.go +++ b/apis/kubedb/v1/mariadb_helpers.go @@ -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)) diff --git a/apis/kubedb/v1/mongodb_helpers.go b/apis/kubedb/v1/mongodb_helpers.go index 4422cccafe..60fc7f8c8f 100644 --- a/apis/kubedb/v1/mongodb_helpers.go +++ b/apis/kubedb/v1/mongodb_helpers.go @@ -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) diff --git a/apis/kubedb/v1/mysql_helpers.go b/apis/kubedb/v1/mysql_helpers.go index 611674987c..a9af4b3c50 100644 --- a/apis/kubedb/v1/mysql_helpers.go +++ b/apis/kubedb/v1/mysql_helpers.go @@ -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) } diff --git a/apis/kubedb/v1/postgres_helpers.go b/apis/kubedb/v1/postgres_helpers.go index 3b1f9afe85..956de9e547 100644 --- a/apis/kubedb/v1/postgres_helpers.go +++ b/apis/kubedb/v1/postgres_helpers.go @@ -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) diff --git a/apis/kubedb/v1alpha2/mssqlserver_helpers.go b/apis/kubedb/v1alpha2/mssqlserver_helpers.go index 415e49f43e..16194974eb 100644 --- a/apis/kubedb/v1alpha2/mssqlserver_helpers.go +++ b/apis/kubedb/v1alpha2/mssqlserver_helpers.go @@ -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" @@ -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) } diff --git a/go.mod b/go.mod index f81c0f9cb4..62c036dd9b 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index a475f9fcfb..654f35489c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/vendor/kmodules.xyz/client-go/api/v1/cluster.go b/vendor/kmodules.xyz/client-go/api/v1/cluster.go index b40cd8d1ef..c8a0a104bd 100644 --- a/vendor/kmodules.xyz/client-go/api/v1/cluster.go +++ b/vendor/kmodules.xyz/client-go/api/v1/cluster.go @@ -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" diff --git a/vendor/modules.txt b/vendor/modules.txt index 3872ac1449..53c916e6a7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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 @@ -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