Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Feb 27, 2024
1 parent f7f8f9e commit afaf8c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2282,15 +2282,14 @@ func makeFilebeatContainer(volumeMounts []corev1.VolumeMount, envVar []corev1.En
}

func MergeGlobalAndNamespacedEnv(ctx context.Context, r client.Reader, namespace string, statefulSet *appsv1.StatefulSet) {
var globalEnvs []corev1.EnvVar
var envData map[string]string
envData := make(map[string]string)
if utils.GlobalConfigMap != "" {
globalCM := &corev1.ConfigMap{}
err := r.Get(ctx, types.NamespacedName{Namespace: utils.GlobalConfigMapNamespace, Name: utils.GlobalConfigMap}, globalCM)
if err != nil && !k8serrors.IsNotFound(err) {
return
}
if globalCM != nil {
if globalCM.Data != nil {
for key, val := range globalCM.Data {
envData[key] = val
}
Expand All @@ -2302,13 +2301,18 @@ func MergeGlobalAndNamespacedEnv(ctx context.Context, r client.Reader, namespace
if err != nil && !k8serrors.IsNotFound(err) {
return
}
if namespacedCM != nil {
if namespacedCM.Data != nil {
for key, val := range namespacedCM.Data {
envData[key] = val
}
}
}

if len(envData) == 0 {
return
}

globalEnvs := make([]corev1.EnvVar, 0, len(envData))
for key, val := range envData {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
Expand Down

0 comments on commit afaf8c6

Please sign in to comment.