From 8084e563c8c864f317e1ee2205a2b93ddf9ffba3 Mon Sep 17 00:00:00 2001 From: Raihan Khan Date: Thu, 22 Feb 2024 16:28:56 +0600 Subject: [PATCH] Set default spec for RabbitMQ monitoring (#1159) Signed-off-by: raihankhan --- apis/kubedb/v1alpha2/rabbitmq_helpers.go | 3 ++ go.mod | 2 +- go.sum | 4 +- .../client-go/apiextensions/v1/crd.go | 7 ++- .../client-go/core/v1/kubernetes.go | 47 +++++++++++++++++++ vendor/modules.txt | 2 +- 6 files changed, 60 insertions(+), 5 deletions(-) diff --git a/apis/kubedb/v1alpha2/rabbitmq_helpers.go b/apis/kubedb/v1alpha2/rabbitmq_helpers.go index 205271986e..b6e77e2220 100644 --- a/apis/kubedb/v1alpha2/rabbitmq_helpers.go +++ b/apis/kubedb/v1alpha2/rabbitmq_helpers.go @@ -304,6 +304,9 @@ func (r *RabbitMQ) SetDefaults() { } r.SetHealthCheckerDefaults() + if r.Spec.Monitor != nil { + r.Spec.Monitor.SetDefaults() + } } func (r *RabbitMQ) setDefaultContainerSecurityContext(rmVersion *catalog.RabbitMQVersion, podTemplate *ofst.PodTemplateSpec) { diff --git a/go.mod b/go.mod index ebc1c92ea2..f8a2b6600c 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( k8s.io/kube-aggregator v0.29.0 k8s.io/kube-openapi v0.0.0-20231129212854-f0671cc7e66a k8s.io/metrics v0.25.1 - kmodules.xyz/client-go v0.29.8 + kmodules.xyz/client-go v0.29.9 kmodules.xyz/crd-schema-fuzz v0.29.1 kmodules.xyz/custom-resources v0.29.1 kmodules.xyz/monitoring-agent-api v0.29.0 diff --git a/go.sum b/go.sum index 8d7a116974..8b3f09e793 100644 --- a/go.sum +++ b/go.sum @@ -653,8 +653,8 @@ k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6R k8s.io/utils v0.0.0-20231127182322-b307cd553661/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.29.8 h1:8Uw7zoaye0ZaY47fBVTLjDOOn6cXzLPYBNnzHj7pgH4= -kmodules.xyz/client-go v0.29.8/go.mod h1:WYM/ZC3I5/AUGHYyYYEzYHFhnSwK+tEZyGld6KpLoxI= +kmodules.xyz/client-go v0.29.9 h1:nZcKM4YzmHAAQ62EYLep1NQdhARA9uOnYOiHMRf2VVg= +kmodules.xyz/client-go v0.29.9/go.mod h1:WYM/ZC3I5/AUGHYyYYEzYHFhnSwK+tEZyGld6KpLoxI= 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.29.1 h1:xiNylhs3ILRbcUhxxy306AOy9GMA4Mq7xFIptZKgal4= diff --git a/vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go b/vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go index d49713a2ca..28156ee2a4 100644 --- a/vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go +++ b/vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go @@ -18,6 +18,7 @@ package v1 import ( "context" + "time" "github.com/pkg/errors" api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -29,6 +30,10 @@ import ( kutil "kmodules.xyz/client-go" ) +const ( + RetryTimeout = 10 * time.Minute +) + func CreateOrUpdateCustomResourceDefinition( ctx context.Context, c cs.Interface, @@ -70,7 +75,7 @@ func TryUpdateCustomResourceDefinition( opts metav1.UpdateOptions, ) (result *api.CustomResourceDefinition, err error) { attempt := 0 - err = wait.PollUntilContextTimeout(ctx, kutil.RetryInterval, kutil.RetryTimeout, true, func(ctx context.Context) (bool, error) { + err = wait.PollUntilContextTimeout(ctx, kutil.RetryInterval, RetryTimeout, true, func(ctx context.Context) (bool, error) { attempt++ cur, e2 := c.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, name, metav1.GetOptions{}) if kerr.IsNotFound(e2) { diff --git a/vendor/kmodules.xyz/client-go/core/v1/kubernetes.go b/vendor/kmodules.xyz/client-go/core/v1/kubernetes.go index 7c8f60dcf4..6354737390 100644 --- a/vendor/kmodules.xyz/client-go/core/v1/kubernetes.go +++ b/vendor/kmodules.xyz/client-go/core/v1/kubernetes.go @@ -19,6 +19,8 @@ package v1 import ( "sort" + "kmodules.xyz/client-go/meta" + jsoniter "github.com/json-iterator/go" "gomodules.xyz/mergo" core "k8s.io/api/core/v1" @@ -108,6 +110,31 @@ func UpsertContainer(containers []core.Container, upsert core.Container) []core. return append(containers, upsert) } +func MergeContainer(container core.Container, containerTemplate core.Container) core.Container { + container.Command = containerTemplate.Command + container.Args = meta.UpsertArgumentList(container.Args, containerTemplate.Args) + container.WorkingDir = containerTemplate.WorkingDir + container.EnvFrom = containerTemplate.EnvFrom + container.Env = UpsertEnvVars(container.Env, containerTemplate.Env...) + container.Ports = UpsertContainerPorts(container.Ports, containerTemplate.Ports...) + container.Resources = containerTemplate.Resources + container.ResizePolicy = containerTemplate.ResizePolicy + container.RestartPolicy = containerTemplate.RestartPolicy + container.VolumeMounts = UpsertVolumeMount(container.VolumeMounts, containerTemplate.VolumeMounts...) + container.VolumeDevices = containerTemplate.VolumeDevices + container.LivenessProbe = containerTemplate.LivenessProbe + container.ReadinessProbe = containerTemplate.ReadinessProbe + container.StartupProbe = containerTemplate.StartupProbe + container.Lifecycle = containerTemplate.Lifecycle + container.TerminationMessagePath = containerTemplate.TerminationMessagePath + container.TerminationMessagePolicy = containerTemplate.TerminationMessagePolicy + container.ImagePullPolicy = containerTemplate.ImagePullPolicy + container.SecurityContext = containerTemplate.SecurityContext + container.StdinOnce = containerTemplate.StdinOnce + container.TTY = containerTemplate.TTY + return container +} + func UpsertContainers(containers []core.Container, addons []core.Container) []core.Container { out := containers for _, c := range addons { @@ -264,6 +291,26 @@ func EnsureVolumeMountDeletedByPath(mounts []core.VolumeMount, mountPath string) return mounts } +func UpsertContainerPorts(ports []core.ContainerPort, np ...core.ContainerPort) []core.ContainerPort { + upsert := func(p core.ContainerPort) { + for i, port := range ports { + if port.Name == p.Name { + err := mergo.Merge(&ports[i], p, mergo.WithOverride) + if err != nil { + panic(err) + } + return + } + } + ports = append(ports, p) + } + + for _, port := range np { + upsert(port) + } + return ports +} + func GetEnvByName(envs []core.EnvVar, name string) *core.EnvVar { for i := range envs { if envs[i].Name == name { diff --git a/vendor/modules.txt b/vendor/modules.txt index 902c8a01d2..88dfddc967 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1571,7 +1571,7 @@ k8s.io/utils/trace # kmodules.xyz/apiversion v0.2.0 ## explicit; go 1.14 kmodules.xyz/apiversion -# kmodules.xyz/client-go v0.29.8 +# kmodules.xyz/client-go v0.29.9 ## explicit; go 1.21.5 kmodules.xyz/client-go kmodules.xyz/client-go/api/v1