Skip to content

Commit 0a73ed0

Browse files
authored
fix: Remove plugin registry pod if openVSX configured (#1913) (#1914)
* fix: Remove plugin registry pod if openVSX configured Signed-off-by: Anatolii Bazko <[email protected]>
1 parent 4c435d8 commit 0a73ed0

9 files changed

+144
-16
lines changed

api/v2/checluster_types.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1034,11 +1034,14 @@ func (c *CheCluster) IsCheFlavor() bool {
10341034
// IsEmbeddedOpenVSXRegistryConfigured returns true if the Open VSX Registry is configured to be embedded
10351035
// only if only the `Spec.Components.PluginRegistry.OpenVSXURL` is empty.
10361036
func (c *CheCluster) IsEmbeddedOpenVSXRegistryConfigured() bool {
1037-
openVSXURL := defaults.GetPluginRegistryOpenVSXURL()
10381037
if c.Spec.Components.PluginRegistry.OpenVSXURL != nil {
1039-
openVSXURL = *c.Spec.Components.PluginRegistry.OpenVSXURL
1038+
return *c.Spec.Components.PluginRegistry.OpenVSXURL == ""
10401039
}
1041-
return openVSXURL == ""
1040+
return defaults.GetPluginRegistryOpenVSXURL() == ""
1041+
}
1042+
1043+
func (c *CheCluster) IsInternalPluginRegistryDisabled() bool {
1044+
return c.Spec.Components.PluginRegistry.DisableInternalRegistry || !c.IsEmbeddedOpenVSXRegistryConfigured()
10421045
}
10431046

10441047
// IsCheBeingInstalled returns true if the Che version is not set in the status.

pkg/deploy/dashboard/dashboard_deployment_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,6 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
224224
Name: "CHE_DASHBOARD_INTERNAL_URL",
225225
Value: fmt.Sprintf("http://%s-dashboard.eclipse-che.svc:8080", defaults.GetCheFlavor()),
226226
})
227-
assert.Contains(
228-
t,
229-
deployment.Spec.Template.Spec.Containers[0].Env,
230-
corev1.EnvVar{
231-
Name: "CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL",
232-
Value: "http://plugin-registry.eclipse-che.svc:8080/v3",
233-
})
234227
assert.Contains(
235228
t,
236229
deployment.Spec.Template.Spec.Containers[0].Env,

pkg/deploy/dashboard/deployment_dashboard.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (d *DashboardReconciler) getDashboardDeploymentSpec(ctx *chetypes.DeployCon
8383
Value: fmt.Sprintf("http://%s.%s.svc:8080/api", deploy.CheServiceName, ctx.CheCluster.Namespace)},
8484
)
8585

86-
if !ctx.CheCluster.Spec.Components.PluginRegistry.DisableInternalRegistry {
86+
if !ctx.CheCluster.IsInternalPluginRegistryDisabled() {
8787
envVars = append(envVars,
8888
corev1.EnvVar{
8989
Name: "CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL",

pkg/deploy/gateway/gateway_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"strings"
1919
"testing"
2020

21+
"k8s.io/utils/pointer"
22+
2123
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
2224
chev2 "github.com/eclipse-che/che-operator/api/v2"
2325
"github.com/eclipse-che/che-operator/pkg/common/chetypes"
@@ -170,6 +172,7 @@ func TestOauthProxyConfigUnauthorizedPaths(t *testing.T) {
170172
Components: chev2.CheClusterComponents{
171173
PluginRegistry: chev2.PluginRegistry{
172174
DisableInternalRegistry: false,
175+
OpenVSXURL: pointer.String(""),
173176
},
174177
}},
175178
}, nil)

pkg/deploy/gateway/oauth_proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ cookie_domains = "%s"
160160

161161
func skipAuthConfig(instance *chev2.CheCluster) string {
162162
var skipAuthPaths []string
163-
if !instance.Spec.Components.PluginRegistry.DisableInternalRegistry {
163+
if !instance.IsInternalPluginRegistryDisabled() {
164164
skipAuthPaths = append(skipAuthPaths, "^/"+constants.PluginRegistryName)
165165
}
166166
skipAuthPaths = append(skipAuthPaths, "^/$")

pkg/deploy/pluginregistry/pluginregistry.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"fmt"
1717
"strings"
1818

19+
appsv1 "k8s.io/api/apps/v1"
20+
corev1 "k8s.io/api/core/v1"
21+
1922
"github.com/eclipse-che/che-operator/pkg/common/chetypes"
2023
"github.com/eclipse-che/che-operator/pkg/common/constants"
2124
"github.com/eclipse-che/che-operator/pkg/deploy/gateway"
@@ -34,7 +37,12 @@ func NewPluginRegistryReconciler() *PluginRegistryReconciler {
3437
}
3538

3639
func (p *PluginRegistryReconciler) Reconcile(ctx *chetypes.DeployContext) (reconcile.Result, bool, error) {
37-
if ctx.CheCluster.Spec.Components.PluginRegistry.DisableInternalRegistry {
40+
if ctx.CheCluster.IsInternalPluginRegistryDisabled() {
41+
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &corev1.Service{})
42+
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &corev1.ConfigMap{})
43+
_, _ = deploy.DeleteNamespacedObject(ctx, gateway.GatewayConfigMapNamePrefix+constants.PluginRegistryName, &corev1.ConfigMap{})
44+
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &appsv1.Deployment{})
45+
3846
if ctx.CheCluster.Status.PluginRegistryURL != "" {
3947
ctx.CheCluster.Status.PluginRegistryURL = ""
4048
err := deploy.UpdateCheCRStatus(ctx, "PluginRegistryURL", "")

pkg/deploy/pluginregistry/pluginregistry_test.go

+113-2
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,39 @@
1313
package pluginregistry
1414

1515
import (
16+
"os"
17+
1618
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
19+
chev2 "github.com/eclipse-che/che-operator/api/v2"
20+
defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
1721
"github.com/eclipse-che/che-operator/pkg/common/test"
1822
"github.com/stretchr/testify/assert"
1923
appsv1 "k8s.io/api/apps/v1"
2024
corev1 "k8s.io/api/core/v1"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2126
"k8s.io/apimachinery/pkg/runtime"
2227
"k8s.io/apimachinery/pkg/types"
28+
"k8s.io/utils/pointer"
2329

2430
"testing"
2531
)
2632

27-
func TestPluginRegistryReconcile(t *testing.T) {
33+
func TestShouldDeployPluginRegistryIfOpenVSXIsEmpty(t *testing.T) {
2834
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
2935

30-
ctx := test.GetDeployContext(nil, []runtime.Object{})
36+
ctx := test.GetDeployContext(&chev2.CheCluster{
37+
ObjectMeta: metav1.ObjectMeta{
38+
Name: "eclipse-che",
39+
Namespace: "eclipse-che",
40+
},
41+
Spec: chev2.CheClusterSpec{
42+
Components: chev2.CheClusterComponents{
43+
PluginRegistry: chev2.PluginRegistry{
44+
OpenVSXURL: pointer.String(""),
45+
},
46+
},
47+
},
48+
}, []runtime.Object{})
3149

3250
pluginregistry := NewPluginRegistryReconciler()
3351
_, done, err := pluginregistry.Reconcile(ctx)
@@ -39,3 +57,96 @@ func TestPluginRegistryReconcile(t *testing.T) {
3957
assert.True(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
4058
assert.NotEmpty(t, ctx.CheCluster.Status.PluginRegistryURL)
4159
}
60+
61+
func TestShouldDeployPluginRegistryIfOpenVSXIsEmptyByDefault(t *testing.T) {
62+
defaultOpenVSXURL := os.Getenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL")
63+
64+
err := os.Unsetenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL")
65+
assert.NoError(t, err)
66+
67+
defer func() {
68+
_ = os.Setenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL", defaultOpenVSXURL)
69+
}()
70+
71+
// re initialize defaults with new env var
72+
defaults.Initialize()
73+
74+
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
75+
76+
ctx := test.GetDeployContext(&chev2.CheCluster{
77+
ObjectMeta: metav1.ObjectMeta{
78+
Name: "eclipse-che",
79+
Namespace: "eclipse-che",
80+
},
81+
}, []runtime.Object{})
82+
83+
pluginregistry := NewPluginRegistryReconciler()
84+
_, done, err := pluginregistry.Reconcile(ctx)
85+
assert.True(t, done)
86+
assert.Nil(t, err)
87+
88+
assert.True(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.Service{}))
89+
assert.True(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.ConfigMap{}))
90+
assert.True(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
91+
assert.NotEmpty(t, ctx.CheCluster.Status.PluginRegistryURL)
92+
}
93+
94+
func TestShouldNotDeployPluginRegistryIfOpenVSXConfigured(t *testing.T) {
95+
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
96+
97+
ctx := test.GetDeployContext(&chev2.CheCluster{
98+
ObjectMeta: metav1.ObjectMeta{
99+
Name: "eclipse-che",
100+
Namespace: "eclipse-che",
101+
},
102+
Spec: chev2.CheClusterSpec{
103+
Components: chev2.CheClusterComponents{
104+
PluginRegistry: chev2.PluginRegistry{
105+
OpenVSXURL: pointer.String("https://openvsx.org"),
106+
},
107+
},
108+
},
109+
}, []runtime.Object{})
110+
111+
pluginregistry := NewPluginRegistryReconciler()
112+
_, done, err := pluginregistry.Reconcile(ctx)
113+
assert.True(t, done)
114+
assert.Nil(t, err)
115+
116+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.Service{}))
117+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.ConfigMap{}))
118+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
119+
assert.Empty(t, ctx.CheCluster.Status.PluginRegistryURL)
120+
}
121+
122+
func TestShouldNotDeployPluginRegistryIfOpenVSXConfiguredByDefault(t *testing.T) {
123+
defaultOpenVSXURL := os.Getenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL")
124+
err := os.Setenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL", "https://openvsx.org")
125+
assert.NoError(t, err)
126+
127+
defer func() {
128+
_ = os.Setenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL", defaultOpenVSXURL)
129+
}()
130+
131+
// re initialize defaults with new env var
132+
defaults.Initialize()
133+
134+
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
135+
136+
ctx := test.GetDeployContext(&chev2.CheCluster{
137+
ObjectMeta: metav1.ObjectMeta{
138+
Name: "eclipse-che",
139+
Namespace: "eclipse-che",
140+
},
141+
}, []runtime.Object{})
142+
143+
pluginregistry := NewPluginRegistryReconciler()
144+
_, done, err := pluginregistry.Reconcile(ctx)
145+
assert.True(t, done)
146+
assert.Nil(t, err)
147+
148+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.Service{}))
149+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.ConfigMap{}))
150+
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
151+
assert.Empty(t, ctx.CheCluster.Status.PluginRegistryURL)
152+
}

pkg/deploy/server/server_configmap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (s *CheServerReconciler) getCheConfigMapData(ctx *chetypes.DeployContext) (
142142
cheAPI := "https://" + ctx.CheHost + "/api"
143143
var pluginRegistryInternalURL string
144144

145-
if !ctx.CheCluster.Spec.Components.PluginRegistry.DisableInternalRegistry {
145+
if !ctx.CheCluster.IsInternalPluginRegistryDisabled() {
146146
pluginRegistryInternalURL = fmt.Sprintf("http://%s.%s.svc:8080/v3", constants.PluginRegistryName, ctx.CheCluster.Namespace)
147147
}
148148

pkg/deploy/server/server_configmap_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ package server
1515
import (
1616
"testing"
1717

18+
"k8s.io/utils/pointer"
19+
1820
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
1921
"github.com/eclipse-che/che-operator/pkg/common/test"
2022
"github.com/stretchr/testify/assert"
@@ -349,6 +351,14 @@ func TestShouldSetUpCorrectlyPluginRegistryURL(t *testing.T) {
349351
ObjectMeta: metav1.ObjectMeta{
350352
Namespace: "eclipse-che",
351353
},
354+
Spec: chev2.CheClusterSpec{
355+
Components: chev2.CheClusterComponents{
356+
PluginRegistry: chev2.PluginRegistry{
357+
DisableInternalRegistry: false,
358+
OpenVSXURL: pointer.String(""),
359+
},
360+
},
361+
},
352362
Status: chev2.CheClusterStatus{
353363
PluginRegistryURL: "internal-plugin-registry",
354364
},

0 commit comments

Comments
 (0)