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

Fix cluster name label of es scripts config map #7630

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
7 changes: 4 additions & 3 deletions pkg/controller/elasticsearch/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
)

// NewConfigMapWithData constructs a new config map with the given data
func NewConfigMapWithData(es types.NamespacedName, data map[string]string) corev1.ConfigMap {
func NewConfigMapWithData(cm, es types.NamespacedName, data map[string]string) corev1.ConfigMap {
return corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: es.Name,
Namespace: es.Namespace,
Name: cm.Name,
Namespace: cm.Namespace,
Labels: label.NewLabels(es),
},
Data: data,
Expand All @@ -51,6 +51,7 @@ func ReconcileScriptsConfigMap(ctx context.Context, c k8s.Client, es esv1.Elasti

scriptsConfigMap := NewConfigMapWithData(
types.NamespacedName{Namespace: es.Namespace, Name: esv1.ScriptsConfigMap(es.Name)},
k8s.ExtractNamespacedName(&es),
map[string]string{
nodespec.ReadinessProbeScriptConfigKey: nodespec.ReadinessProbeScript,
nodespec.PreStopHookScriptConfigKey: preStopScript,
Expand Down
24 changes: 24 additions & 0 deletions pkg/controller/elasticsearch/configmap/configmap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

package configmap

import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types"
)

func Test_NewConfigMapWithData(t *testing.T) {
cmNsn := types.NamespacedName{Namespace: "ns1", Name: "cm-name"}
esNsn := types.NamespacedName{Namespace: "ns1", Name: "es-name"}
data := map[string]string{"foo": "42"}
cm := NewConfigMapWithData(cmNsn, esNsn, data)

assert.Equal(t, "cm-name", cm.Name)
assert.Equal(t, "es-name", cm.Labels["elasticsearch.k8s.elastic.co/cluster-name"])
assert.Equal(t, "elasticsearch", cm.Labels["common.k8s.elastic.co/type"])
assert.Equal(t, "42", cm.Data["foo"])
}