Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"testing"

"github.com/eclipse-che/che-operator/controllers/namespacecache"
"github.com/eclipse-che/che-operator/pkg/common/diffs"
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/errors"

rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -84,10 +82,9 @@ func TestCreate(t *testing.T) {
assert.NoError(t, err)

dstCm := &corev1.ConfigMap{}
exists, err := deploy.Get(ctx, types.NamespacedName{Namespace: "user-che", Name: "test"}, dstCm)
err = ctx.ClusterAPI.Client.Get(context.TODO(), types.NamespacedName{Namespace: "user-che", Name: "test"}, dstCm)

assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, 1, len(dstCm.Data))
assert.Equal(t, "new-value", dstCm.Data["key"])
}
Expand Down Expand Up @@ -141,7 +138,8 @@ func TestUpdate(t *testing.T) {
err = ctx.ClusterAPI.Client.Get(context.TODO(), types.NamespacedName{Name: "test", Namespace: "eclipse-che"}, srcCm)

assert.NoError(t, err)
assert.True(t, cmp.Equal(dstCm, srcCm, diffs.ConfigMap([]string{constants.KubernetesPartOfLabelKey, constants.KubernetesComponentLabelKey}, nil)))
assert.Equal(t, srcCm.Labels[constants.KubernetesPartOfLabelKey], dstCm.Labels[constants.KubernetesPartOfLabelKey])
assert.Equal(t, srcCm.Labels[constants.KubernetesComponentLabelKey], dstCm.Labels[constants.KubernetesComponentLabelKey])

// update source and destination config maps

Expand Down
7 changes: 4 additions & 3 deletions pkg/common/diffs/diffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ var ConfigMapEnsureLabels = cmp.Options{
}),
}

func ConfigMap(labels []string, annotations []string) cmp.Options {
// ConfigMap respects existed labels and annotations
func ConfigMap(labelKeys []string, annotationKeys []string) cmp.Options {
return cmp.Options{
cmpopts.IgnoreFields(corev1.ConfigMap{}, "TypeMeta"),
objectMetaComparator(labels, annotations),
cmpMetadata(labelKeys, annotationKeys),
}
}

var ServiceMonitor = cmp.Options{
cmpopts.IgnoreFields(monitoringv1.ServiceMonitor{}, "TypeMeta", "ObjectMeta"),
}

func objectMetaComparator(labels []string, annotations []string) cmp.Option {
func cmpMetadata(labels []string, annotations []string) cmp.Option {
return cmp.Comparer(func(x, y metav1.ObjectMeta) bool {
for _, label := range labels {
if x.Labels[label] != y.Labels[label] {
Expand Down
40 changes: 40 additions & 0 deletions pkg/deploy/devworkspace/dev_workspace_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package devworkspace

import (
"context"
"encoding/json"
"fmt"
"maps"
Expand All @@ -26,10 +27,12 @@ import (
"github.com/eclipse-che/che-operator/pkg/common/reconciler"
"github.com/eclipse-che/che-operator/pkg/common/utils"
"github.com/eclipse-che/che-operator/pkg/deploy"
"github.com/eclipse-che/che-operator/pkg/deploy/tls"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -123,6 +126,10 @@ func updateWorkspaceConfig(ctx *chetypes.DeployContext, operatorConfig *controll

updateInitContainers(devEnvironments, operatorConfig.Workspace)

if err := updateTLSCertificateConfigmapRef(ctx, operatorConfig); err != nil {
return err
}

// If the CheCluster has a configured proxy, or if the Che Operator has detected a proxy configuration,
// we need to disable automatic proxy handling in the DevWorkspace Operator as its implementation collides
// with ours -- they set environment variables the deployment spec explicitly, which overrides the proxy-settings
Expand Down Expand Up @@ -301,6 +308,39 @@ func updateInitContainers(devEnvironments *chev2.CheClusterDevEnvironments, work
workspaceConfig.InitContainers = devEnvironments.InitContainers
}

func updateTLSCertificateConfigmapRef(ctx *chetypes.DeployContext, operatorConfig *controllerv1alpha1.OperatorConfiguration) error {
cm := &corev1.ConfigMap{}
exists, err := ctx.ClusterAPI.ClientWrapper.GetIgnoreNotFound(
context.TODO(),
types.NamespacedName{
Name: tls.CheMergedCABundleCertsCMName,
Namespace: ctx.CheCluster.Namespace,
},
cm,
)

if err != nil {
return fmt.Errorf("failed to get ConfigMap %s: %w", tls.CheMergedCABundleCertsCMName, err)
}

if exists && len(cm.Data) > 0 {
if operatorConfig.Routing == nil {
operatorConfig.Routing = &controllerv1alpha1.RoutingConfig{}
}

operatorConfig.Routing.TLSCertificateConfigmapRef = &controllerv1alpha1.ConfigmapReference{
Name: tls.CheMergedCABundleCertsCMName,
Namespace: ctx.CheCluster.Namespace,
}
} else {
if operatorConfig.Routing != nil {
operatorConfig.Routing.TLSCertificateConfigmapRef = nil
}
}

return nil
}

func disableDWOProxy(routingConfig *controllerv1alpha1.RoutingConfig) {
// Since we create proxy configmaps to mount proxy settings, we want to disable
// proxy handling in DWO; otherwise the env vars added by DWO will override the env
Expand Down
Loading
Loading