Skip to content

Commit 4ba7375

Browse files
authored
udpate configmap (#37)
Signed-off-by: Kim Tsao <[email protected]>
1 parent 3665c9b commit 4ba7375

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

controllers/devfileregistry_controller.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020-2022 Red Hat, Inc.
2+
Copyright 2020-2023 Red Hat, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -162,6 +162,13 @@ func (r *DevfileRegistryReconciler) Reconcile(ctx context.Context, req ctrl.Requ
162162
log.Error(err, "Failed to update DevfileRegistry status")
163163
return ctrl.Result{Requeue: true}, err
164164
}
165+
166+
//update the config map
167+
result, err = r.ensure(ctx, devfileRegistry, &corev1.ConfigMap{}, labels, "")
168+
if result != nil {
169+
return *result, err
170+
}
171+
165172
}
166173

167174
return ctrl.Result{}, nil
@@ -180,7 +187,8 @@ func (r *DevfileRegistryReconciler) SetupWithManager(mgr ctrl.Manager) error {
180187
Owns(&appsv1.Deployment{}).
181188
Owns(&corev1.Service{}).
182189
Owns(&corev1.PersistentVolumeClaim{}).
183-
Owns(&networkingv1.Ingress{})
190+
Owns(&networkingv1.Ingress{}).
191+
Owns(&corev1.ConfigMap{})
184192

185193
// If on OpenShift, mark routes as owned by the controller
186194
if config.ControllerCfg.IsOpenShift() {

controllers/ensure.go

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func (r *DevfileRegistryReconciler) ensure(ctx context.Context, cr *registryv1al
6666
case *networkingv1.Ingress:
6767
ingress, _ := resource.(*networkingv1.Ingress)
6868
err = r.updateIngress(ctx, cr, ingressDomain, ingress)
69+
case *corev1.ConfigMap:
70+
configMap, _ := resource.(*corev1.ConfigMap)
71+
err = r.updateConfigMap(ctx, cr, configMap)
6972
}
7073
if err != nil {
7174
r.Log.Error(err, "Failed to update "+resourceType)

controllers/update.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
2324
"github.com/devfile/registry-operator/pkg/registry"
@@ -182,3 +183,16 @@ func (r *DevfileRegistryReconciler) deleteOldPVCIfNeeded(ctx context.Context, cr
182183
}
183184
return nil
184185
}
186+
187+
func (r *DevfileRegistryReconciler) updateConfigMap(ctx context.Context, cr *registryv1alpha1.DevfileRegistry, configMap *corev1.ConfigMap) error {
188+
189+
viewerEnvfile := fmt.Sprintf(`
190+
NEXT_PUBLIC_ANALYTICS_WRITE_KEY=%s
191+
DEVFILE_REGISTRIES=[{"name":"%s","url":"http://localhost:8080","fqdn":"%s"}]`,
192+
cr.Spec.Telemetry.RegistryViewerWriteKey, cr.ObjectMeta.Name, cr.Status.URL)
193+
194+
configMap.Data[".env.registry-viewer"] = viewerEnvfile
195+
196+
return r.Update(ctx, configMap)
197+
198+
}

0 commit comments

Comments
 (0)