From 3952a53188d2bc2ae704ff576733ed8b6ecd75fa Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Fri, 1 Oct 2021 19:35:53 +0300 Subject: [PATCH] Propagate plugin registry URL to plugin registry configmap (#1118) Signed-off-by: Mykola Morhun --- controllers/che/checluster_controller_test.go | 50 +++++++++---------- pkg/deploy/pluginregistry/pluginregistry.go | 14 ++---- .../pluginregistry_configmap.go | 2 + .../pluginregistry/pluginregistry_test.go | 7 +++ 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/controllers/che/checluster_controller_test.go b/controllers/che/checluster_controller_test.go index cac559052..cd7ae30f9 100644 --- a/controllers/che/checluster_controller_test.go +++ b/controllers/che/checluster_controller_test.go @@ -231,6 +231,7 @@ func TestNativeUserModeEnabled(t *testing.T) { orgv1.SchemeBuilder.AddToScheme(scheme) scheme.AddKnownTypes(routev1.GroupVersion, route) scheme.AddKnownTypes(oauth.SchemeGroupVersion, oAuthClient) + scheme.AddKnownTypes(configv1.SchemeGroupVersion, &configv1.Proxy{}) initCR := InitCheWithSimpleCR().DeepCopy() testCase.initObjects = append(testCase.initObjects, initCR) @@ -1095,6 +1096,8 @@ func TestImagePullerConfiguration(t *testing.T) { } func TestCheController(t *testing.T) { + var err error + util.IsOpenShift = true util.IsOpenShift4 = false @@ -1124,21 +1127,12 @@ func TestCheController(t *testing.T) { }, } - _, err := r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) - } - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) - } - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) - } - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) + reconcileLoops := 4 + for i := 0; i < reconcileLoops; i++ { + _, err = r.Reconcile(context.TODO(), req) + if err != nil { + t.Fatalf("reconcile: (%v)", err) + } } // get devfile-registry configmap @@ -1147,6 +1141,12 @@ func TestCheController(t *testing.T) { t.Errorf("ConfigMap %s not found: %s", devfilecm.Name, err) } + // get plugin-registry configmap + pluginRegistrycm := &corev1.ConfigMap{} + if err := cl.Get(context.TODO(), types.NamespacedName{Name: deploy.DevfileRegistryName, Namespace: cheCR.Namespace}, pluginRegistrycm); err != nil { + t.Errorf("ConfigMap %s not found: %s", pluginRegistrycm.Name, err) + } + // get CR if err := cl.Get(context.TODO(), types.NamespacedName{Name: os.Getenv("CHE_FLAVOR"), Namespace: namespace}, cheCR); err != nil { t.Errorf("CR not found") @@ -1159,17 +1159,11 @@ func TestCheController(t *testing.T) { } // reconcile again - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) - } - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) - } - _, err = r.Reconcile(context.TODO(), req) - if err != nil { - t.Fatalf("reconcile: (%v)", err) + for i := 0; i < reconcileLoops; i++ { + _, err = r.Reconcile(context.TODO(), req) + if err != nil { + t.Fatalf("reconcile: (%v)", err) + } } // get configmap @@ -1194,7 +1188,9 @@ func TestCheController(t *testing.T) { // run a few checks to make sure the operator reconciled tls routes and updated configmap if cm.Data["CHE_INFRA_OPENSHIFT_TLS__ENABLED"] != "true" { - t.Errorf("ConfigMap wasn't updated. Extecting true, got: %s", cm.Data["CHE_INFRA_OPENSHIFT_TLS__ENABLED"]) + // If the test fails here without obvious reason, it could mean that there was not enought reconcile loops before. + // To fix the above problem, just increase reconcileLoops variable above. + t.Errorf("ConfigMap wasn't updated. Expecting true, but got: %s", cm.Data["CHE_INFRA_OPENSHIFT_TLS__ENABLED"]) } route := &routev1.Route{} if err := cl.Get(context.TODO(), types.NamespacedName{Name: deploy.DefaultCheFlavor(cheCR), Namespace: cheCR.Namespace}, route); err != nil { diff --git a/pkg/deploy/pluginregistry/pluginregistry.go b/pkg/deploy/pluginregistry/pluginregistry.go index 9ec702a7d..5447d9e01 100644 --- a/pkg/deploy/pluginregistry/pluginregistry.go +++ b/pkg/deploy/pluginregistry/pluginregistry.go @@ -19,7 +19,6 @@ import ( "github.com/eclipse-che/che-operator/pkg/deploy" "github.com/eclipse-che/che-operator/pkg/deploy/expose" - corev1 "k8s.io/api/core/v1" ) type PluginRegistry struct { @@ -48,16 +47,9 @@ func (p *PluginRegistry) SyncAll() (bool, error) { return false, err } - if p.deployContext.CheCluster.IsAirGapMode() { - done, err := p.SyncConfigMap() - if !done { - return false, err - } - } else { - done, err := deploy.DeleteNamespacedObject(p.deployContext, deploy.PluginRegistryName, &corev1.ConfigMap{}) - if !done { - return false, err - } + done, err = p.SyncConfigMap() + if !done { + return false, err } done, err = p.SyncDeployment() diff --git a/pkg/deploy/pluginregistry/pluginregistry_configmap.go b/pkg/deploy/pluginregistry/pluginregistry_configmap.go index f47415ae6..c1b65878b 100644 --- a/pkg/deploy/pluginregistry/pluginregistry_configmap.go +++ b/pkg/deploy/pluginregistry/pluginregistry_configmap.go @@ -18,6 +18,7 @@ import ( type PluginRegistryConfigMap struct { CheSidecarContainersRegistryURL string `json:"CHE_SIDECAR_CONTAINERS_REGISTRY_URL"` CheSidecarContainersRegistryOrganization string `json:"CHE_SIDECAR_CONTAINERS_REGISTRY_ORGANIZATION"` + ChePluginRegistryURL string `json:"CHE_PLUGIN_REGISTRY_URL"` } func (p *PluginRegistry) GetConfigMapData() (map[string]string, error) { @@ -25,6 +26,7 @@ func (p *PluginRegistry) GetConfigMapData() (map[string]string, error) { data := &PluginRegistryConfigMap{ CheSidecarContainersRegistryURL: p.deployContext.CheCluster.Spec.Server.AirGapContainerRegistryHostname, CheSidecarContainersRegistryOrganization: p.deployContext.CheCluster.Spec.Server.AirGapContainerRegistryOrganization, + ChePluginRegistryURL: p.deployContext.CheCluster.Status.PluginRegistryURL, } out, err := json.Marshal(data) diff --git a/pkg/deploy/pluginregistry/pluginregistry_test.go b/pkg/deploy/pluginregistry/pluginregistry_test.go index 79056ddb7..0a6aedeaa 100644 --- a/pkg/deploy/pluginregistry/pluginregistry_test.go +++ b/pkg/deploy/pluginregistry/pluginregistry_test.go @@ -72,6 +72,13 @@ func TestPluginRegistrySyncAll(t *testing.T) { t.Fatalf("Route not found: %v", err) } + // check configmap + cm := &corev1.ConfigMap{} + err = cli.Get(context.TODO(), types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, cm) + if err != nil { + t.Fatalf("Config Map not found: %v", err) + } + // check deployment deployment := &appsv1.Deployment{} err = cli.Get(context.TODO(), types.NamespacedName{Name: "plugin-registry", Namespace: "eclipse-che"}, deployment)