Skip to content

Commit

Permalink
fix: Remove plugin registry pod if openVSX configured
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Oct 7, 2024
1 parent f2ba5ac commit cb815c4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,13 @@ func (c *CheCluster) IsEmbeddedOpenVSXRegistryConfigured() bool {
return openVSXURL == ""
}

func (c *CheCluster) GetOpenVSXURL() string {
if c.Spec.Components.PluginRegistry.OpenVSXURL != nil {
return *c.Spec.Components.PluginRegistry.OpenVSXURL
}
return defaults.GetPluginRegistryOpenVSXURL()
}

// IsCheBeingInstalled returns true if the Che version is not set in the status.
// Basically it means that the Che is being installed since the Che version is set only after the installation.
func (c *CheCluster) IsCheBeingInstalled() bool {
Expand Down
9 changes: 8 additions & 1 deletion pkg/deploy/pluginregistry/pluginregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package pluginregistry

import (
"fmt"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"strings"

"github.com/eclipse-che/che-operator/pkg/common/chetypes"
Expand All @@ -34,7 +36,12 @@ func NewPluginRegistryReconciler() *PluginRegistryReconciler {
}

func (p *PluginRegistryReconciler) Reconcile(ctx *chetypes.DeployContext) (reconcile.Result, bool, error) {
if ctx.CheCluster.Spec.Components.PluginRegistry.DisableInternalRegistry {
if ctx.CheCluster.Spec.Components.PluginRegistry.DisableInternalRegistry || ctx.CheCluster.GetOpenVSXURL() != "" {
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &corev1.Service{})
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &corev1.ConfigMap{})
_, _ = deploy.DeleteNamespacedObject(ctx, gateway.GatewayConfigMapNamePrefix+constants.PluginRegistryName, &corev1.ConfigMap{})
_, _ = deploy.DeleteNamespacedObject(ctx, constants.PluginRegistryName, &appsv1.Deployment{})

if ctx.CheCluster.Status.PluginRegistryURL != "" {
ctx.CheCluster.Status.PluginRegistryURL = ""
err := deploy.UpdateCheCRStatus(ctx, "PluginRegistryURL", "")
Expand Down
47 changes: 45 additions & 2 deletions pkg/deploy/pluginregistry/pluginregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,35 @@ package pluginregistry

import (
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
chev2 "github.com/eclipse-che/che-operator/api/v2"
"github.com/eclipse-che/che-operator/pkg/common/test"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"

"testing"
)

func TestPluginRegistryReconcile(t *testing.T) {
func TestShouldDeployPluginRegistry(t *testing.T) {
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)

ctx := test.GetDeployContext(nil, []runtime.Object{})
ctx := test.GetDeployContext(&chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "eclipse-che",
Namespace: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
Components: chev2.CheClusterComponents{
PluginRegistry: chev2.PluginRegistry{
OpenVSXURL: pointer.String(""),
},
},
},
}, []runtime.Object{})

pluginregistry := NewPluginRegistryReconciler()
_, done, err := pluginregistry.Reconcile(ctx)
Expand All @@ -39,3 +54,31 @@ func TestPluginRegistryReconcile(t *testing.T) {
assert.True(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
assert.NotEmpty(t, ctx.CheCluster.Status.PluginRegistryURL)
}

func TestShouldNotDeployPluginRegistryIfOpenVSXConfigured(t *testing.T) {
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)

ctx := test.GetDeployContext(&chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "eclipse-che",
Namespace: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
Components: chev2.CheClusterComponents{
PluginRegistry: chev2.PluginRegistry{
OpenVSXURL: pointer.String("https://openvsx.org"),
},
},
},
}, []runtime.Object{})

pluginregistry := NewPluginRegistryReconciler()
_, done, err := pluginregistry.Reconcile(ctx)
assert.True(t, done)
assert.Nil(t, err)

assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.Service{}))
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &corev1.ConfigMap{}))
assert.False(t, test.IsObjectExists(ctx.ClusterAPI.Client, types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, &appsv1.Deployment{}))
assert.Empty(t, ctx.CheCluster.Status.PluginRegistryURL)
}

0 comments on commit cb815c4

Please sign in to comment.