Skip to content

Commit

Permalink
Propagate plugin registry URL to plugin registry configmap (#1118)
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun authored Oct 1, 2021
1 parent 89055c9 commit 3952a53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
50 changes: 23 additions & 27 deletions controllers/che/checluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -1095,6 +1096,8 @@ func TestImagePullerConfiguration(t *testing.T) {
}

func TestCheController(t *testing.T) {
var err error

util.IsOpenShift = true
util.IsOpenShift4 = false

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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 {
Expand Down
14 changes: 3 additions & 11 deletions pkg/deploy/pluginregistry/pluginregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions pkg/deploy/pluginregistry/pluginregistry_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ 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) {
pluginRegistryEnv := make(map[string]string)
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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/deploy/pluginregistry/pluginregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3952a53

Please sign in to comment.