Skip to content

Commit b6cce2d

Browse files
authored
fix: Ensure ca-certs-merged CM is resynced when annotations updated (#2041)
Signed-off-by: Anatolii Bazko <[email protected]>
1 parent 5778fa5 commit b6cce2d

File tree

12 files changed

+217
-342
lines changed

12 files changed

+217
-342
lines changed

controllers/usernamespace/usernamespace_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"strconv"
2020
"strings"
2121

22+
"github.com/eclipse-che/che-operator/pkg/common/diffs"
23+
2224
"github.com/eclipse-che/che-operator/controllers/namespacecache"
2325
"k8s.io/utils/pointer"
2426
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -410,7 +412,7 @@ func (r *CheUserNamespaceReconciler) reconcileUserSettings(
410412
Data: data,
411413
}
412414

413-
_, err := deploy.Sync(deployContext, cm, deploy.ConfigMapDiffOpts)
415+
_, err := deploy.Sync(deployContext, cm, diffs.ConfigMapAllLabels)
414416
return err
415417
}
416418

@@ -464,7 +466,7 @@ func (r *CheUserNamespaceReconciler) reconcileGitTlsCertificate(ctx context.Cont
464466
target.Data["host"] = gitCert.Data["githost"]
465467
}
466468

467-
_, err := deploy.Sync(deployContext, &target, deploy.ConfigMapDiffOpts)
469+
_, err := deploy.Sync(deployContext, &target, diffs.ConfigMapAllLabels)
468470
return err
469471
}
470472

pkg/common/diffs/diffs.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright (c) 2019-2025 Red Hat, Inc.
3+
// This program and the accompanying materials are made
4+
// available under the terms of the Eclipse Public License 2.0
5+
// which is available at https://www.eclipse.org/legal/epl-2.0/
6+
//
7+
// SPDX-License-Identifier: EPL-2.0
8+
//
9+
// Contributors:
10+
// Red Hat, Inc. - initial API and implementation
11+
//
12+
13+
package diffs
14+
15+
import (
16+
"reflect"
17+
18+
"github.com/google/go-cmp/cmp"
19+
"github.com/google/go-cmp/cmp/cmpopts"
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
var ConfigMapAllLabels = cmp.Options{
25+
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
26+
cmp.Comparer(func(x, y metav1.ObjectMeta) bool {
27+
return reflect.DeepEqual(x.Labels, y.Labels)
28+
}),
29+
}
30+
31+
func ConfigMap(labels []string, annotations []string) cmp.Options {
32+
return cmp.Options{
33+
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
34+
objectMetaComparator(labels, annotations),
35+
}
36+
}
37+
38+
func ConfigMapIgnoreData(labels []string, annotations []string) cmp.Options {
39+
return cmp.Options{
40+
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
41+
cmpopts.IgnoreFields(corev1.ConfigMap{}, "Data"),
42+
objectMetaComparator(labels, annotations),
43+
}
44+
}
45+
46+
func objectMetaComparator(labels []string, annotations []string) cmp.Option {
47+
return cmp.Comparer(func(x, y metav1.ObjectMeta) bool {
48+
if labels != nil {
49+
for _, label := range labels {
50+
if x.Labels[label] != y.Labels[label] {
51+
return false
52+
}
53+
}
54+
}
55+
56+
if annotations != nil {
57+
for _, annotation := range annotations {
58+
if x.Annotations[annotation] != y.Annotations[annotation] {
59+
return false
60+
}
61+
}
62+
}
63+
64+
return true
65+
})
66+
}

pkg/deploy/configmap.go

Lines changed: 0 additions & 100 deletions
This file was deleted.

pkg/deploy/configmap_test.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

pkg/deploy/editors-definitions/editors_definitions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"path/filepath"
1919
"regexp"
2020

21+
"github.com/eclipse-che/che-operator/pkg/common/diffs"
22+
2123
"github.com/eclipse-che/che-operator/pkg/common/utils"
2224
corev1 "k8s.io/api/core/v1"
2325
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -159,5 +161,5 @@ func syncEditorDefinitions(ctx *chetypes.DeployContext, editorDefinitions map[st
159161
cm.Data[fileName] = string(content)
160162
}
161163

162-
return deploy.Sync(ctx, cm, deploy.ConfigMapDiffOpts)
164+
return deploy.Sync(ctx, cm, diffs.ConfigMapAllLabels)
163165
}

pkg/deploy/expose/expose.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ package expose
1515
import (
1616
"strings"
1717

18+
"github.com/eclipse-che/che-operator/pkg/common/diffs"
19+
1820
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
1921
routev1 "github.com/openshift/api/route/v1"
2022

@@ -74,7 +76,7 @@ func exposeWithGateway(deployContext *chetypes.DeployContext,
7476
if err != nil {
7577
return "", false, err
7678
}
77-
done, err = deploy.SyncConfigMapSpecToCluster(deployContext, &cfg)
79+
done, err = deploy.Sync(deployContext, &cfg, diffs.ConfigMapAllLabels)
7880
if !done {
7981
if err != nil {
8082
logrus.Error(err)

pkg/deploy/labels.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ import (
1717
defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
1818
)
1919

20+
var (
21+
DefaultsLabelKeys = []string{
22+
constants.KubernetesNameLabelKey,
23+
constants.KubernetesInstanceLabelKey,
24+
constants.KubernetesPartOfLabelKey,
25+
constants.KubernetesComponentLabelKey,
26+
constants.KubernetesManagedByLabelKey,
27+
}
28+
)
29+
2030
func GetLabels(component string) map[string]string {
2131
return map[string]string{
2232
constants.KubernetesNameLabelKey: defaults.GetCheFlavor(),
@@ -27,19 +37,6 @@ func GetLabels(component string) map[string]string {
2737
}
2838
}
2939

30-
func GetDefaultKubernetesLabelsWith(labels ...string) []string {
31-
defaultK8sLabels := append(
32-
[]string{
33-
constants.KubernetesNameLabelKey,
34-
constants.KubernetesInstanceLabelKey,
35-
constants.KubernetesPartOfLabelKey,
36-
constants.KubernetesComponentLabelKey,
37-
constants.KubernetesManagedByLabelKey,
38-
}, labels...)
39-
40-
return defaultK8sLabels
41-
}
42-
4340
func GetManagedByLabel() string {
4441
return defaults.GetCheFlavor() + "-operator"
4542
}

pkg/deploy/pluginregistry/pluginregistry.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"fmt"
1717
"strings"
1818

19+
"github.com/eclipse-che/che-operator/pkg/common/diffs"
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
1922
appsv1 "k8s.io/api/apps/v1"
2023
corev1 "k8s.io/api/core/v1"
2124

@@ -98,7 +101,22 @@ func (p *PluginRegistryReconciler) syncConfigMap(ctx *chetypes.DeployContext) (b
98101
if err != nil {
99102
return false, err
100103
}
101-
return deploy.SyncConfigMapDataToCluster(ctx, constants.PluginRegistryName, data, constants.PluginRegistryName)
104+
105+
cm := &corev1.ConfigMap{
106+
TypeMeta: metav1.TypeMeta{
107+
Kind: "ConfigMap",
108+
APIVersion: "v1",
109+
},
110+
ObjectMeta: metav1.ObjectMeta{
111+
Name: constants.PluginRegistryName,
112+
Namespace: ctx.CheCluster.Namespace,
113+
Labels: deploy.GetLabels(constants.PluginRegistryName),
114+
Annotations: data,
115+
},
116+
Data: data,
117+
}
118+
119+
return deploy.Sync(ctx, cm, diffs.ConfigMapAllLabels)
102120
}
103121

104122
func (p *PluginRegistryReconciler) ExposeEndpoint(ctx *chetypes.DeployContext) (string, bool, error) {

0 commit comments

Comments
 (0)