Skip to content
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
6 changes: 4 additions & 2 deletions controllers/usernamespace/usernamespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"strconv"
"strings"

"github.com/eclipse-che/che-operator/pkg/common/diffs"

"github.com/eclipse-che/che-operator/controllers/namespacecache"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -410,7 +412,7 @@ func (r *CheUserNamespaceReconciler) reconcileUserSettings(
Data: data,
}

_, err := deploy.Sync(deployContext, cm, deploy.ConfigMapDiffOpts)
_, err := deploy.Sync(deployContext, cm, diffs.ConfigMapAllLabels)
return err
}

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

_, err := deploy.Sync(deployContext, &target, deploy.ConfigMapDiffOpts)
_, err := deploy.Sync(deployContext, &target, diffs.ConfigMapAllLabels)
return err
}

Expand Down
66 changes: 66 additions & 0 deletions pkg/common/diffs/diffs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//

package diffs

import (
"reflect"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var ConfigMapAllLabels = cmp.Options{
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
cmp.Comparer(func(x, y metav1.ObjectMeta) bool {
return reflect.DeepEqual(x.Labels, y.Labels)
}),
}

func ConfigMap(labels []string, annotations []string) cmp.Options {
return cmp.Options{
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
objectMetaComparator(labels, annotations),
}
}

func ConfigMapIgnoreData(labels []string, annotations []string) cmp.Options {
return cmp.Options{
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
cmpopts.IgnoreFields(corev1.ConfigMap{}, "Data"),
objectMetaComparator(labels, annotations),
}
}

func objectMetaComparator(labels []string, annotations []string) cmp.Option {
return cmp.Comparer(func(x, y metav1.ObjectMeta) bool {
if labels != nil {
for _, label := range labels {
if x.Labels[label] != y.Labels[label] {
return false
}
}
}

if annotations != nil {
for _, annotation := range annotations {
if x.Annotations[annotation] != y.Annotations[annotation] {
return false
}
}
}

return true
})
}
100 changes: 0 additions & 100 deletions pkg/deploy/configmap.go

This file was deleted.

91 changes: 0 additions & 91 deletions pkg/deploy/configmap_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/deploy/editors-definitions/editors_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"path/filepath"
"regexp"

"github.com/eclipse-che/che-operator/pkg/common/diffs"

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

return deploy.Sync(ctx, cm, deploy.ConfigMapDiffOpts)
return deploy.Sync(ctx, cm, diffs.ConfigMapAllLabels)
}
4 changes: 3 additions & 1 deletion pkg/deploy/expose/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package expose
import (
"strings"

"github.com/eclipse-che/che-operator/pkg/common/diffs"

"github.com/devfile/devworkspace-operator/pkg/infrastructure"
routev1 "github.com/openshift/api/route/v1"

Expand Down Expand Up @@ -74,7 +76,7 @@ func exposeWithGateway(deployContext *chetypes.DeployContext,
if err != nil {
return "", false, err
}
done, err = deploy.SyncConfigMapSpecToCluster(deployContext, &cfg)
done, err = deploy.Sync(deployContext, &cfg, diffs.ConfigMapAllLabels)
if !done {
if err != nil {
logrus.Error(err)
Expand Down
23 changes: 10 additions & 13 deletions pkg/deploy/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import (
defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
)

var (
DefaultsLabelKeys = []string{
constants.KubernetesNameLabelKey,
constants.KubernetesInstanceLabelKey,
constants.KubernetesPartOfLabelKey,
constants.KubernetesComponentLabelKey,
constants.KubernetesManagedByLabelKey,
}
)

func GetLabels(component string) map[string]string {
return map[string]string{
constants.KubernetesNameLabelKey: defaults.GetCheFlavor(),
Expand All @@ -27,19 +37,6 @@ func GetLabels(component string) map[string]string {
}
}

func GetDefaultKubernetesLabelsWith(labels ...string) []string {
defaultK8sLabels := append(
[]string{
constants.KubernetesNameLabelKey,
constants.KubernetesInstanceLabelKey,
constants.KubernetesPartOfLabelKey,
constants.KubernetesComponentLabelKey,
constants.KubernetesManagedByLabelKey,
}, labels...)

return defaultK8sLabels
}

func GetManagedByLabel() string {
return defaults.GetCheFlavor() + "-operator"
}
Expand Down
20 changes: 19 additions & 1 deletion pkg/deploy/pluginregistry/pluginregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"fmt"
"strings"

"github.com/eclipse-che/che-operator/pkg/common/diffs"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -98,7 +101,22 @@ func (p *PluginRegistryReconciler) syncConfigMap(ctx *chetypes.DeployContext) (b
if err != nil {
return false, err
}
return deploy.SyncConfigMapDataToCluster(ctx, constants.PluginRegistryName, data, constants.PluginRegistryName)

cm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.PluginRegistryName,
Namespace: ctx.CheCluster.Namespace,
Labels: deploy.GetLabels(constants.PluginRegistryName),
Annotations: data,
},
Data: data,
}

return deploy.Sync(ctx, cm, diffs.ConfigMapAllLabels)
}

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