Skip to content

feat: support containers env paramater setting #1987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
462 changes: 462 additions & 0 deletions config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions deploy/bundle.yaml

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions deploy/crd.yaml

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions deploy/cw-bundle.yaml

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions e2e-tests/version-service/conf/crd.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions pkg/apis/psmdb/v1/psmdb_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(ctx context.Context, platform
}
}
}

if cr.CompareVersion("1.21.0") >= 0 && cr.Spec.Sharding.Mongos.ContainerEnv == nil {
cr.Spec.Sharding.Mongos.ContainerEnv = make([]corev1.EnvVar, 0)
}

cr.Spec.Sharding.ConfigsvrReplSet.Name = ConfigReplSetName

for i := range cr.Spec.Replsets {
Expand Down Expand Up @@ -744,6 +749,10 @@ func (rs *ReplsetSpec) SetDefaults(platform version.Platform, cr *PerconaServerM
}
}

if cr.CompareVersion("1.21.0") >= 0 && rs.ContainerEnv == nil {
rs.ContainerEnv = make([]corev1.EnvVar, 0)
}

if len(rs.ExternalNodes) > 0 && !rs.Expose.Enabled {
log.Info("Replset is not exposed. Make sure each pod in the replset can reach each other.", "replset", rs.Name)
}
Expand Down Expand Up @@ -877,6 +886,10 @@ func (nv *NonVotingSpec) SetDefaults(cr *PerconaServerMongoDB, rs *ReplsetSpec)
nv.ContainerSecurityContext = rs.ContainerSecurityContext
}

if cr.CompareVersion("1.21.0") >= 0 && nv.ContainerEnv == nil {
nv.ContainerEnv = rs.ContainerEnv
}

if nv.PodSecurityContext == nil {
nv.PodSecurityContext = rs.PodSecurityContext
}
Expand Down Expand Up @@ -984,6 +997,10 @@ func (h *HiddenSpec) SetDefaults(cr *PerconaServerMongoDB, rs *ReplsetSpec) erro
h.ContainerSecurityContext = rs.ContainerSecurityContext
}

if cr.CompareVersion("1.21.0") >= 0 && h.ContainerEnv == nil {
h.ContainerEnv = rs.ContainerEnv
}

if h.PodSecurityContext == nil {
h.PodSecurityContext = rs.PodSecurityContext
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/psmdb/v1/psmdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ type NonVotingSpec struct {
LivenessProbe *LivenessProbeExtended `json:"livenessProbe,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ContainerEnv []corev1.EnvVar `json:"containerEnv,omitempty"`
Configuration MongoConfiguration `json:"configuration,omitempty"`

MultiAZ `json:",inline"`
Expand All @@ -523,6 +524,7 @@ type HiddenSpec struct {
LivenessProbe *LivenessProbeExtended `json:"livenessProbe,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ContainerEnv []corev1.EnvVar `json:"containerEnv,omitempty"`
Configuration MongoConfiguration `json:"configuration,omitempty"`

MultiAZ `json:",inline"`
Expand Down Expand Up @@ -749,6 +751,7 @@ type ReplsetSpec struct {
Horizons HorizonsSpec `json:"splitHorizons,omitempty"`
ReplsetOverrides ReplsetOverrides `json:"replsetOverrides,omitempty"`
PrimaryPreferTagSelector PrimaryPreferTagSelectorSpec `json:"primaryPreferTagSelector,omitempty"`
ContainerEnv []corev1.EnvVar `json:"containerEnv,omitempty"`
}

func (r *ReplsetSpec) PodName(cr *PerconaServerMongoDB, idx int) string {
Expand Down Expand Up @@ -866,6 +869,7 @@ type MongosSpec struct {
LivenessProbe *LivenessProbeExtended `json:"livenessProbe,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ContainerEnv []corev1.EnvVar `json:"containerEnv,omitempty"`
Configuration MongoConfiguration `json:"configuration,omitempty"`
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/psmdb/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pkg/psmdb/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func container(ctx context.Context, cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec, name string, resources corev1.ResourceRequirements,
ikeyName string, useConfigFile bool, livenessProbe *api.LivenessProbeExtended, readinessProbe *corev1.Probe,
containerSecurityContext *corev1.SecurityContext,
containerSecurityContext *corev1.SecurityContext, containerEnv []corev1.EnvVar,
) (corev1.Container, error) {
fvar := false

Expand Down Expand Up @@ -177,6 +177,13 @@ func container(ctx context.Context, cr *api.PerconaServerMongoDB, replset *api.R
}
}

if cr.CompareVersion("1.21.0") >= 0 {
if containerEnv != nil {
for _, env := range containerEnv {
container.Env = append(container.Env, env)
}
}
}
return container, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/psmdb/mongos.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func mongosContainer(cr *api.PerconaServerMongoDB, useConfigFile bool, cfgInstan
container.ReadinessProbe.Exec.Command[0] = "/opt/percona/mongodb-healthcheck"
}

if cr.CompareVersion("1.21.0") >= 0 {
if cr.Spec.Sharding.Mongos.ContainerEnv != nil {
for _, env := range cr.Spec.Sharding.Mongos.ContainerEnv {
container.Env = append(container.Env, env)
}
}
}

return container, nil
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/psmdb/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func StatefulSpec(ctx context.Context, cr *api.PerconaServerMongoDB, replset *ap
volumeSpec := replset.VolumeSpec
podSecurityContext := replset.PodSecurityContext
containerSecurityContext := replset.ContainerSecurityContext
containerEnv := replset.ContainerEnv
livenessProbe := replset.LivenessProbe
readinessProbe := replset.ReadinessProbe
configName := naming.MongodCustomConfigName(cr, replset)
Expand All @@ -76,6 +77,7 @@ func StatefulSpec(ctx context.Context, cr *api.PerconaServerMongoDB, replset *ap
resources = replset.NonVoting.Resources
podSecurityContext = replset.NonVoting.PodSecurityContext
containerSecurityContext = replset.NonVoting.ContainerSecurityContext
containerEnv = replset.NonVoting.ContainerEnv
configName = naming.NonVotingConfigMapName(cr, replset)
livenessProbe = replset.NonVoting.LivenessProbe
readinessProbe = replset.NonVoting.ReadinessProbe
Expand All @@ -87,6 +89,7 @@ func StatefulSpec(ctx context.Context, cr *api.PerconaServerMongoDB, replset *ap
resources = replset.Hidden.Resources
podSecurityContext = replset.Hidden.PodSecurityContext
containerSecurityContext = replset.Hidden.ContainerSecurityContext
containerEnv = replset.Hidden.ContainerEnv
configName = naming.HiddenConfigMapName(cr, replset)
livenessProbe = replset.Hidden.LivenessProbe
readinessProbe = replset.Hidden.ReadinessProbe
Expand Down Expand Up @@ -176,7 +179,7 @@ func StatefulSpec(ctx context.Context, cr *api.PerconaServerMongoDB, replset *ap
}

c, err := container(ctx, cr, replset, containerName, resources, cr.Spec.Secrets.GetInternalKey(cr), configs.MongoDConf.Type.IsUsable(),
livenessProbe, readinessProbe, containerSecurityContext)
livenessProbe, readinessProbe, containerSecurityContext, containerEnv)
if err != nil {
return appsv1.StatefulSetSpec{}, fmt.Errorf("failed to create container %v", err)
}
Expand Down