From 4a6fe32b5bf1d9ae1d17bc11884939327e45b2d4 Mon Sep 17 00:00:00 2001 From: Jason Madigan Date: Tue, 25 Aug 2026 12:24:47 +0100 Subject: [PATCH] feat: deploy console plugin backend proxy Signed-off-by: Jason Madigan --- .../controller/consoleplugin_reconciler.go | 40 ++++++---- .../consoleplugin_reconciler_test.go | 75 +++++++++++++------ internal/controller/state_of_the_world.go | 19 +++-- .../openshift/consoleplugin/consoleplugin.go | 14 ++++ .../consoleplugin/consoleplugin_mutator.go | 6 +- .../openshift/consoleplugin/deployment.go | 20 +---- .../consoleplugin/deployment_mutator.go | 67 +++++++++++++++++ .../consoleplugin/deployment_mutator_test.go | 42 +++++++++++ .../consoleplugin/legacy_nginx_configmap.go | 16 ++++ .../consoleplugin/nginx_configmap.go | 44 ----------- internal/openshift/utils.go | 3 + 11 files changed, 239 insertions(+), 107 deletions(-) create mode 100644 internal/openshift/consoleplugin/deployment_mutator.go create mode 100644 internal/openshift/consoleplugin/deployment_mutator_test.go create mode 100644 internal/openshift/consoleplugin/legacy_nginx_configmap.go delete mode 100644 internal/openshift/consoleplugin/nginx_configmap.go diff --git a/internal/controller/consoleplugin_reconciler.go b/internal/controller/consoleplugin_reconciler.go index 6af035568..f43809f9c 100644 --- a/internal/controller/consoleplugin_reconciler.go +++ b/internal/controller/consoleplugin_reconciler.go @@ -27,17 +27,19 @@ import ( type ConsolePluginReconciler struct { *reconcilers.BaseReconciler - namespace string + namespace string + imageOverride string } -func NewConsolePluginReconciler(mgr ctrlruntime.Manager, namespace string) *ConsolePluginReconciler { +func NewConsolePluginReconciler(mgr ctrlruntime.Manager, namespace, imageOverride string) *ConsolePluginReconciler { return &ConsolePluginReconciler{ BaseReconciler: reconcilers.NewBaseReconciler( mgr.GetClient(), mgr.GetScheme(), mgr.GetAPIReader(), ), - namespace: namespace, + namespace: namespace, + imageOverride: imageOverride, } } @@ -79,10 +81,11 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R }) clusterVersionExists := len(clusterVersions) > 0 + consolePluginSupported := clusterVersionExists || r.imageOverride != "" // Service service := consoleplugin.Service(r.namespace) - if !topologyExists || !clusterVersionExists { + if !topologyExists || !consolePluginSupported { utils.TagObjectToDelete(service) } _, err := r.ReconcileResource(ctx, &corev1.Service{}, service, reconcilers.CreateOnlyMutator) @@ -93,7 +96,9 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R // Deployment var consolePluginImageURL string - if topologyExists && clusterVersionExists { + if topologyExists && r.imageOverride != "" { + consolePluginImageURL = r.imageOverride + } else if topologyExists && clusterVersionExists { clusterVersion := clusterVersions[0].(*controller.RuntimeObject).Object.(*configv1.ClusterVersion) consolePluginImageURL, err = openshift.GetConsolePluginImageForVersion(clusterVersion) @@ -104,9 +109,13 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R } deployment := consoleplugin.Deployment(r.namespace, consolePluginImageURL, TopologyConfigMapName) - deploymentMutators := make([]reconcilers.DeploymentMutateFn, 0, 1) + if r.imageOverride != "" { + deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullIfNotPresent + } + deploymentMutators := make([]reconcilers.DeploymentMutateFn, 0, 2) deploymentMutators = append(deploymentMutators, reconcilers.DeploymentImageMutator) - if !topologyExists || !clusterVersionExists { + deploymentMutators = append(deploymentMutators, consoleplugin.DeploymentConfigMutator) + if !topologyExists || !consolePluginSupported { utils.TagObjectToDelete(deployment) } _, err = r.ReconcileResource(ctx, &appsv1.Deployment{}, deployment, reconcilers.DeploymentMutator(deploymentMutators...)) @@ -115,23 +124,22 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R return err } - // Nginx ConfigMap - nginxConfigMap := consoleplugin.NginxConfigMap(r.namespace) - if !topologyExists || !clusterVersionExists { - utils.TagObjectToDelete(nginxConfigMap) - } - _, err = r.ReconcileResource(ctx, &corev1.ConfigMap{}, nginxConfigMap, reconcilers.CreateOnlyMutator) + // Remove the nginx configuration left behind by older Console plugin + // deployments. The combined asset server/backend no longer mounts it. + legacyNginxConfigMap := consoleplugin.LegacyNginxConfigMap(r.namespace) + utils.TagObjectToDelete(legacyNginxConfigMap) + _, err = r.ReconcileResource(ctx, &corev1.ConfigMap{}, legacyNginxConfigMap, reconcilers.CreateOnlyMutator) if err != nil { - logger.Error(err, "reconciling nginx configmap") + logger.Error(err, "deleting legacy nginx configmap") return err } // ConsolePlugin consolePlugin := consoleplugin.ConsolePlugin(r.namespace) - if !topologyExists || !clusterVersionExists { + if !topologyExists || !consolePluginSupported { utils.TagObjectToDelete(consolePlugin) } - consolePluginMutator := reconcilers.Mutator[*consolev1.ConsolePlugin](consoleplugin.ServiceMutator) + consolePluginMutator := reconcilers.Mutator[*consolev1.ConsolePlugin](consoleplugin.SpecMutator) _, err = r.ReconcileResource(ctx, &consolev1.ConsolePlugin{}, consolePlugin, consolePluginMutator) if err != nil { logger.Error(err, "reconciling consoleplugin") diff --git a/internal/controller/consoleplugin_reconciler_test.go b/internal/controller/consoleplugin_reconciler_test.go index 62fa17362..0e603d95b 100644 --- a/internal/controller/consoleplugin_reconciler_test.go +++ b/internal/controller/consoleplugin_reconciler_test.go @@ -106,7 +106,7 @@ func TestConsolePluginReconciler(t *testing.T) { WithScheme(scheme). Build() - reconciler := NewConsolePluginReconciler(manager, TestNamespace) + reconciler := NewConsolePluginReconciler(manager, TestNamespace, "") assert.Assert(t, reconciler != nil) t.Run("Subscription", func(subT *testing.T) { @@ -163,6 +163,9 @@ func TestConsolePluginReconciler(t *testing.T) { assert.DeepEqual(subT, deployment.Spec.Strategy, consoleplugin.DeploymentStrategy()) assert.Assert(subT, is.Len(deployment.Spec.Template.Spec.Containers, 1)) assert.Assert(subT, deployment.Spec.Template.Spec.Containers[0].Image == ConsolePluginImageURL) + assert.Equal(subT, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy, corev1.PullAlways) + assert.Assert(subT, is.Len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts, 1)) + assert.Assert(subT, is.Len(deployment.Spec.Template.Spec.Volumes, 1)) }) t.Run("Delete deployment", func(subT *testing.T) { @@ -175,27 +178,6 @@ func TestConsolePluginReconciler(t *testing.T) { assert.Assert(subT, apierrors.IsNotFound(err)) }) - t.Run("Create nginx configmap", func(subT *testing.T) { - topology := buildTopologyWithClusterVersion(subT) - assert.NilError(subT, reconciler.Run(context.TODO(), nil, topology, nil, nil)) - configMap := &corev1.ConfigMap{} - cmKey := client.ObjectKey{Name: consoleplugin.NginxConfigMapName(), Namespace: TestNamespace} - assert.NilError(subT, manager.GetClient().Get(context.TODO(), cmKey, configMap)) - assert.DeepEqual(subT, configMap.GetLabels(), consoleplugin.CommonLabels()) - _, ok := configMap.Data["nginx.conf"] - assert.Assert(subT, ok) - }) - - t.Run("Delete nginx configmap", func(subT *testing.T) { - topology, err := machinery.NewTopology() - assert.Assert(subT, err == nil) - assert.NilError(subT, reconciler.Run(context.TODO(), nil, topology, nil, nil)) - configMap := &corev1.ConfigMap{} - cmKey := client.ObjectKey{Name: consoleplugin.NginxConfigMapName(), Namespace: TestNamespace} - err = manager.GetClient().Get(context.TODO(), cmKey, configMap) - assert.Assert(subT, apierrors.IsNotFound(err)) - }) - t.Run("Create consoleplugin", func(subT *testing.T) { topology := buildTopologyWithClusterVersion(subT) assert.NilError(subT, reconciler.Run(context.TODO(), nil, topology, nil, nil)) @@ -206,6 +188,11 @@ func TestConsolePluginReconciler(t *testing.T) { assert.Assert(subT, consolePlugin.Spec.Backend.Service != nil) assert.Assert(subT, consolePlugin.Spec.Backend.Service.Name == consoleplugin.ServiceName()) assert.Assert(subT, consolePlugin.Spec.Backend.Service.Namespace == TestNamespace) + assert.Assert(subT, is.Len(consolePlugin.Spec.Proxy, 1)) + assert.Assert(subT, consolePlugin.Spec.Proxy[0].Alias == "backend") + assert.Assert(subT, consolePlugin.Spec.Proxy[0].Authorization == consolev1.UserToken) + assert.Assert(subT, consolePlugin.Spec.Proxy[0].Endpoint.Service != nil) + assert.Assert(subT, consolePlugin.Spec.Proxy[0].Endpoint.Service.Name == consoleplugin.ServiceName()) }) t.Run("Delete consoleplugin", func(subT *testing.T) { @@ -218,3 +205,47 @@ func TestConsolePluginReconciler(t *testing.T) { assert.Assert(subT, apierrors.IsNotFound(err)) }) } + +func TestConsolePluginReconcilerWithDevelopmentImageOverride(t *testing.T) { + const imageOverride = "localhost/kuadrant/console-plugin:dev" + + scheme := runtime.NewScheme() + _ = corev1.AddToScheme(scheme) + _ = appsv1.AddToScheme(scheme) + _ = consolev1.AddToScheme(scheme) + _ = configv1.AddToScheme(scheme) + + legacyConfigMap := consoleplugin.LegacyNginxConfigMap(TestNamespace) + legacyConfigMap.Data = map[string]string{"nginx.conf": "legacy"} + manager := controllersfake. + NewManagerBuilder(). + WithClient(fake.NewClientBuilder().WithScheme(scheme).WithObjects(legacyConfigMap).Build()). + WithScheme(scheme). + Build() + reconciler := NewConsolePluginReconciler(manager, TestNamespace, imageOverride) + + topologyConfigMap := &controller.RuntimeObject{ + Object: &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{Kind: ConfigMapGroupKind.Kind, APIVersion: "v1"}, + ObjectMeta: metav1.ObjectMeta{ + Name: TopologyConfigMapName, + Namespace: TestNamespace, + Labels: map[string]string{kuadrant.TopologyLabel: "true"}, + }, + }, + } + topology, err := machinery.NewTopology(machinery.WithObjects(topologyConfigMap)) + assert.NilError(t, err) + assert.NilError(t, reconciler.Run(context.TODO(), nil, topology, nil, nil)) + + deployment := &appsv1.Deployment{} + deploymentKey := client.ObjectKey{Name: consoleplugin.DeploymentName(), Namespace: TestNamespace} + assert.NilError(t, manager.GetClient().Get(context.TODO(), deploymentKey, deployment)) + assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Image, imageOverride) + assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy, corev1.PullIfNotPresent) + + consolePlugin := &consolev1.ConsolePlugin{} + assert.NilError(t, manager.GetClient().Get(context.TODO(), client.ObjectKey{Name: consoleplugin.Name()}, consolePlugin)) + err = manager.GetClient().Get(context.TODO(), client.ObjectKeyFromObject(legacyConfigMap), &corev1.ConfigMap{}) + assert.Assert(t, apierrors.IsNotFound(err)) +} diff --git a/internal/controller/state_of_the_world.go b/internal/controller/state_of_the_world.go index 50e6bb0af..51af0a393 100644 --- a/internal/controller/state_of_the_world.go +++ b/internal/controller/state_of_the_world.go @@ -225,6 +225,7 @@ type BootOptionsBuilder struct { isCertManagerInstalled bool isConsolePluginInstalled bool isClusterVersionInstalled bool + consolePluginImageOverride string isDNSOperatorInstalled bool isLimitadorOperatorInstalled bool isAuthorinoOperatorInstalled bool @@ -469,7 +470,9 @@ func (b *BootOptionsBuilder) getConsolePluginOptions() ([]controller.ControllerO return nil, err } - if !b.isConsolePluginInstalled || !b.isClusterVersionInstalled { + b.consolePluginImageOverride = env.GetString(openshift.ConsolePluginImageOverrideEnvVar, "") + + if !b.isConsolePluginInstalled || (!b.isClusterVersionInstalled && b.consolePluginImageOverride == "") { b.logger.Info("console plugin or openshift cluster version is not installed, skipping related watches and reconcilers") return opts, nil } @@ -478,13 +481,15 @@ func (b *BootOptionsBuilder) getConsolePluginOptions() ([]controller.ControllerO controller.WithRunnable("consoleplugin watcher", controller.Watch( &consolev1.ConsolePlugin{}, openshift.ConsolePluginsResource, metav1.NamespaceAll, controller.FilterResourcesByLabel[*consolev1.ConsolePlugin](fmt.Sprintf("%s=%s", consoleplugin.AppLabelKey, consoleplugin.AppLabelValue)))), - controller.WithRunnable("cluster version watcher", controller.Watch( + controller.WithObjectKinds(openshift.ConsolePluginGVK.GroupKind()), + ) + if b.isClusterVersionInstalled { + opts = append(opts, controller.WithRunnable("cluster version watcher", controller.Watch( &configv1.ClusterVersion{}, openshift.ClusterVersionResource, metav1.NamespaceAll, - )), - controller.WithObjectKinds(openshift.ConsolePluginGVK.GroupKind(), openshift.ClusterVersionGroupKind.GroupKind()), - ) + )), controller.WithObjectKinds(openshift.ClusterVersionGroupKind.GroupKind())) + } return opts, nil } @@ -793,9 +798,9 @@ func (b *BootOptionsBuilder) Reconciler() controller.ReconcileFunc { Postcondition: traceReconcileFunc("workflow.finalize", b.finalStepsWorkflow().Run), } - if b.isConsolePluginInstalled && b.isClusterVersionInstalled { + if b.isConsolePluginInstalled && (b.isClusterVersionInstalled || b.consolePluginImageOverride != "") { mainWorkflow.Tasks = append(mainWorkflow.Tasks, - traceReconcileFunc("workflow.console_plugin", NewConsolePluginReconciler(b.manager, operatorNamespace).Subscription().Reconcile), + traceReconcileFunc("workflow.console_plugin", NewConsolePluginReconciler(b.manager, operatorNamespace, b.consolePluginImageOverride).Subscription().Reconcile), ) } diff --git a/internal/openshift/consoleplugin/consoleplugin.go b/internal/openshift/consoleplugin/consoleplugin.go index dd47239d1..e6da1e8ee 100644 --- a/internal/openshift/consoleplugin/consoleplugin.go +++ b/internal/openshift/consoleplugin/consoleplugin.go @@ -30,6 +30,20 @@ func ConsolePlugin(ns string) *consolev1.ConsolePlugin { BasePath: "/", }, }, + Proxy: []consolev1.ConsolePluginProxy{ + { + Alias: "backend", + Authorization: consolev1.UserToken, + Endpoint: consolev1.ConsolePluginProxyEndpoint{ + Type: consolev1.ProxyTypeService, + Service: &consolev1.ConsolePluginProxyServiceConfig{ + Name: ServiceName(), + Namespace: ns, + Port: 9443, + }, + }, + }, + }, }, } } diff --git a/internal/openshift/consoleplugin/consoleplugin_mutator.go b/internal/openshift/consoleplugin/consoleplugin_mutator.go index 5e45b332e..69e0eda6b 100644 --- a/internal/openshift/consoleplugin/consoleplugin_mutator.go +++ b/internal/openshift/consoleplugin/consoleplugin_mutator.go @@ -6,7 +6,7 @@ import ( consolev1 "github.com/openshift/api/console/v1" ) -func ServiceMutator(desired, existing *consolev1.ConsolePlugin) bool { +func SpecMutator(desired, existing *consolev1.ConsolePlugin) bool { if desired.Spec.Backend.Service == nil { panic("coded ConsolePlugin does not specify service") } @@ -17,6 +17,10 @@ func ServiceMutator(desired, existing *consolev1.ConsolePlugin) bool { existing.Spec.Backend.Service = desired.Spec.Backend.Service update = true } + if !reflect.DeepEqual(existing.Spec.Proxy, desired.Spec.Proxy) { + existing.Spec.Proxy = desired.Spec.Proxy + update = true + } return update } diff --git a/internal/openshift/consoleplugin/deployment.go b/internal/openshift/consoleplugin/deployment.go index 39360c7ec..ca6a27f81 100644 --- a/internal/openshift/consoleplugin/deployment.go +++ b/internal/openshift/consoleplugin/deployment.go @@ -36,12 +36,6 @@ func DeploymentVolumeMounts() []corev1.VolumeMount { ReadOnly: true, MountPath: "/var/serving-cert", }, - { - Name: "nginx-conf", - ReadOnly: true, - MountPath: "/etc/nginx/nginx.conf", - SubPath: "nginx.conf", - }, } } @@ -56,17 +50,6 @@ func DeploymentVolumes() []corev1.Volume { }, }, }, - { - Name: "nginx-conf", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: NginxConfigMapName(), - }, - DefaultMode: ptr.To(int32(420)), - }, - }, - }, } } @@ -102,6 +85,7 @@ func Deployment(ns, image, topologyName string) *appsv1.Deployment { Image: image, Ports: []corev1.ContainerPort{ { + Name: "https", ContainerPort: 9443, Protocol: corev1.ProtocolTCP, }, @@ -111,6 +95,8 @@ func Deployment(ns, image, topologyName string) *appsv1.Deployment { Env: []corev1.EnvVar{ {Name: "TOPOLOGY_CONFIGMAP_NAME", Value: topologyName}, {Name: "TOPOLOGY_CONFIGMAP_NAMESPACE", Value: ns}, + {Name: "TLS_CERTIFICATE_FILE", Value: "/var/serving-cert/tls.crt"}, + {Name: "TLS_KEY_FILE", Value: "/var/serving-cert/tls.key"}, }, }, }, diff --git a/internal/openshift/consoleplugin/deployment_mutator.go b/internal/openshift/consoleplugin/deployment_mutator.go new file mode 100644 index 000000000..df3573aae --- /dev/null +++ b/internal/openshift/consoleplugin/deployment_mutator.go @@ -0,0 +1,67 @@ +package consoleplugin + +import ( + "reflect" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" +) + +// DeploymentConfigMutator reconciles the parts of the plugin pod that changed +// when its image became both the asset server and the backend. Environment +// variables not owned by the operator are retained so development overrides +// can still be injected without being removed on every reconcile. +func DeploymentConfigMutator(desired, existing *appsv1.Deployment) bool { + if len(desired.Spec.Template.Spec.Containers) == 0 || len(existing.Spec.Template.Spec.Containers) == 0 { + return false + } + + updated := false + desiredContainer := desired.Spec.Template.Spec.Containers[0] + existingContainer := &existing.Spec.Template.Spec.Containers[0] + + if !reflect.DeepEqual(existingContainer.Ports, desiredContainer.Ports) { + existingContainer.Ports = desiredContainer.Ports + updated = true + } + if existingContainer.ImagePullPolicy != desiredContainer.ImagePullPolicy { + existingContainer.ImagePullPolicy = desiredContainer.ImagePullPolicy + updated = true + } + if !reflect.DeepEqual(existingContainer.VolumeMounts, desiredContainer.VolumeMounts) { + existingContainer.VolumeMounts = desiredContainer.VolumeMounts + updated = true + } + if mergeOwnedEnvironment(existingContainer, desiredContainer.Env) { + updated = true + } + if !reflect.DeepEqual(existing.Spec.Template.Spec.Volumes, desired.Spec.Template.Spec.Volumes) { + existing.Spec.Template.Spec.Volumes = desired.Spec.Template.Spec.Volumes + updated = true + } + + return updated +} + +func mergeOwnedEnvironment(container *corev1.Container, desired []corev1.EnvVar) bool { + updated := false + for _, desiredVariable := range desired { + found := false + for index := range container.Env { + if container.Env[index].Name != desiredVariable.Name { + continue + } + found = true + if !reflect.DeepEqual(container.Env[index], desiredVariable) { + container.Env[index] = desiredVariable + updated = true + } + break + } + if !found { + container.Env = append(container.Env, desiredVariable) + updated = true + } + } + return updated +} diff --git a/internal/openshift/consoleplugin/deployment_mutator_test.go b/internal/openshift/consoleplugin/deployment_mutator_test.go new file mode 100644 index 000000000..3031cba28 --- /dev/null +++ b/internal/openshift/consoleplugin/deployment_mutator_test.go @@ -0,0 +1,42 @@ +//go:build unit + +package consoleplugin + +import ( + "testing" + + "gotest.tools/assert" + "gotest.tools/assert/cmp" + corev1 "k8s.io/api/core/v1" +) + +func TestDeploymentConfigMutatorUpgradesNginxDeployment(t *testing.T) { + desired := Deployment("test-namespace", "example.test/plugin:new", "topology") + desired.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullIfNotPresent + existing := desired.DeepCopy() + existing.Spec.Template.Spec.Containers[0].Ports[0].Name = "" + existing.Spec.Template.Spec.Containers[0].ImagePullPolicy = corev1.PullAlways + existing.Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{ + {Name: "TOPOLOGY_CONFIGMAP_NAME", Value: "old-topology"}, + {Name: "MCP_PROXY_DIAL_ADDRESS", Value: "gateway.example:80"}, + } + existing.Spec.Template.Spec.Containers[0].VolumeMounts = append( + existing.Spec.Template.Spec.Containers[0].VolumeMounts, + corev1.VolumeMount{Name: "nginx-conf", MountPath: "/etc/nginx/nginx.conf"}, + ) + existing.Spec.Template.Spec.Volumes = append( + existing.Spec.Template.Spec.Volumes, + corev1.Volume{Name: "nginx-conf"}, + ) + + assert.Assert(t, DeploymentConfigMutator(desired, existing)) + container := existing.Spec.Template.Spec.Containers[0] + assert.DeepEqual(t, container.Ports, desired.Spec.Template.Spec.Containers[0].Ports) + assert.Equal(t, container.ImagePullPolicy, corev1.PullIfNotPresent) + assert.DeepEqual(t, container.VolumeMounts, desired.Spec.Template.Spec.Containers[0].VolumeMounts) + assert.DeepEqual(t, existing.Spec.Template.Spec.Volumes, desired.Spec.Template.Spec.Volumes) + assert.Assert(t, cmp.Contains(container.Env, corev1.EnvVar{Name: "TLS_CERTIFICATE_FILE", Value: "/var/serving-cert/tls.crt"})) + assert.Assert(t, cmp.Contains(container.Env, corev1.EnvVar{Name: "TLS_KEY_FILE", Value: "/var/serving-cert/tls.key"})) + assert.Assert(t, cmp.Contains(container.Env, corev1.EnvVar{Name: "MCP_PROXY_DIAL_ADDRESS", Value: "gateway.example:80"})) + assert.Assert(t, !DeploymentConfigMutator(desired, existing)) +} diff --git a/internal/openshift/consoleplugin/legacy_nginx_configmap.go b/internal/openshift/consoleplugin/legacy_nginx_configmap.go new file mode 100644 index 000000000..35853e987 --- /dev/null +++ b/internal/openshift/consoleplugin/legacy_nginx_configmap.go @@ -0,0 +1,16 @@ +package consoleplugin + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const legacyNginxConfigMapName = "kuadrant-console-nginx-conf" + +// LegacyNginxConfigMap identifies the ConfigMap used by plugin releases whose +// runtime image was served by nginx. The backend image no longer consumes it. +func LegacyNginxConfigMap(namespace string) *corev1.ConfigMap { + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{Name: legacyNginxConfigMapName, Namespace: namespace}, + } +} diff --git a/internal/openshift/consoleplugin/nginx_configmap.go b/internal/openshift/consoleplugin/nginx_configmap.go deleted file mode 100644 index 90e0b3b8f..000000000 --- a/internal/openshift/consoleplugin/nginx_configmap.go +++ /dev/null @@ -1,44 +0,0 @@ -package consoleplugin - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func NginxConfigMapName() string { - return "kuadrant-console-nginx-conf" -} - -func NginxConfigMap(ns string) *corev1.ConfigMap { - return &corev1.ConfigMap{ - TypeMeta: metav1.TypeMeta{Kind: "ConfigMap", APIVersion: "v1"}, - ObjectMeta: metav1.ObjectMeta{ - Name: NginxConfigMapName(), - Namespace: ns, - Labels: CommonLabels(), - }, - Data: map[string]string{ - "nginx.conf": `error_log /dev/stdout; -events {} -http { - access_log /dev/stdout; - include /etc/nginx/mime.types; - default_type application/octet-stream; - keepalive_timeout 65; - server { - listen 9443 ssl; - listen [::]:9443 ssl; - ssl_certificate /var/serving-cert/tls.crt; - ssl_certificate_key /var/serving-cert/tls.key; - location / { - root /usr/share/nginx/html; - } - location /config.js { - root /tmp; - } - } -} -`, - }, - } -} diff --git a/internal/openshift/utils.go b/internal/openshift/utils.go index 177785663..8906708bb 100644 --- a/internal/openshift/utils.go +++ b/internal/openshift/utils.go @@ -17,6 +17,9 @@ const ( RelatedImageConsolePluginLatestEnvVar = "RELATED_IMAGE_CONSOLE_PLUGIN_LATEST" RelatedImageConsolePluginSDK1EnvVar = "RELATED_IMAGE_CONSOLE_PLUGIN_SDK1" RelatedImageConsolePluginPF5EnvVar = "RELATED_IMAGE_CONSOLE_PLUGIN_PF5" + // ConsolePluginImageOverrideEnvVar allows development clusters without a + // ClusterVersion API (for example OINC) to opt in to the Console plugin. + ConsolePluginImageOverrideEnvVar = "CONSOLE_PLUGIN_IMAGE_OVERRIDE" ) type consolePluginImageRule struct {