Skip to content

Commit

Permalink
Set default spec for RabbitMQ monitoring (#1159)
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <[email protected]>
  • Loading branch information
raihankhan authored Feb 22, 2024
1 parent c7516ae commit 8084e56
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apis/kubedb/v1alpha2/rabbitmq_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 6 additions & 1 deletion vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"context"
"time"

"github.com/pkg/errors"
api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -29,6 +30,10 @@ import (
kutil "kmodules.xyz/client-go"
)

const (
RetryTimeout = 10 * time.Minute
)

func CreateOrUpdateCustomResourceDefinition(
ctx context.Context,
c cs.Interface,
Expand Down Expand Up @@ -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) {
Expand Down
47 changes: 47 additions & 0 deletions vendor/kmodules.xyz/client-go/core/v1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8084e56

Please sign in to comment.