Skip to content
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

Add support for merging GO* variables when existing ones are present in the manifest. #3368

Open
wants to merge 1 commit 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
31 changes: 22 additions & 9 deletions internal/manifests/collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,28 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme
}

if featuregate.SetGolangFlags.IsEnabled() {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.Container(),
skipGoMemLimit, skipGoMaxprocs := false, false
for _, v := range envVars {
if v.Name == "GOMEMLIMIT" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does happen when the golangFlags fg is enabled and the env variable is set in the CR?

skipGoMemLimit = true
} else if v.Name == "GOMAXPROCS" {
skipGoMaxprocs = true
}
}
if !skipGoMemLimit {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.Container(),
},
},
},
},
corev1.EnvVar{
)
}
if !skipGoMaxprocs {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMAXPROCS",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Expand All @@ -174,7 +186,8 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme
},
},
},
)
)
}
}

envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...)
Expand Down
31 changes: 22 additions & 9 deletions internal/manifests/opampbridge/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,28 @@ func Container(cfg config.Config, logger logr.Logger, opampBridge v1alpha1.OpAMP
}

if featuregate.SetGolangFlags.IsEnabled() {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.OpAMPBridgeContainer(),
skipGoMemLimit, skipGoMaxprocs := false, false
for _, v := range envVars {
if v.Name == "GOMEMLIMIT" {
skipGoMemLimit = true
} else if v.Name == "GOMAXPROCS" {
skipGoMaxprocs = true
}
}
if !skipGoMemLimit {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.OpAMPBridgeContainer(),
},
},
},
},
corev1.EnvVar{
)
}
if !skipGoMaxprocs {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMAXPROCS",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Expand All @@ -82,7 +94,8 @@ func Container(cfg config.Config, logger logr.Logger, opampBridge v1alpha1.OpAMP
},
},
},
)
)
}
}

envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...)
Expand Down
31 changes: 22 additions & 9 deletions internal/manifests/targetallocator/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,28 @@ func Container(cfg config.Config, logger logr.Logger, instance v1alpha1.TargetAl
}

if featuregate.SetGolangFlags.IsEnabled() {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.TAContainer(),
skipGoMemLimit, skipGoMaxprocs := false, false
for _, v := range envVars {
if v.Name == "GOMEMLIMIT" {
skipGoMemLimit = true
} else if v.Name == "GOMAXPROCS" {
skipGoMaxprocs = true
}
}
if !skipGoMemLimit {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMEMLIMIT",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Resource: "limits.memory",
ContainerName: naming.TAContainer(),
},
},
},
},
corev1.EnvVar{
)
}
if !skipGoMaxprocs {
envVars = append(envVars, corev1.EnvVar{
Name: "GOMAXPROCS",
ValueFrom: &corev1.EnvVarSource{
ResourceFieldRef: &corev1.ResourceFieldSelector{
Expand All @@ -100,7 +112,8 @@ func Container(cfg config.Config, logger logr.Logger, instance v1alpha1.TargetAl
},
},
},
)
)
}
}

var args []string
Expand Down
Loading