Skip to content

Commit 2e6cf12

Browse files
committed
OCPBUGS-60782: pluginOrder field should only contain available plugins
1 parent 9aa65fe commit 2e6cf12

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

pkg/console/subresource/configmap/configmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func DefaultConfigMap(
8484
TopologyMode(infrastructureConfig.Status.ControlPlaneTopology).
8585
Monitoring(monitoringSharedConfig).
8686
Plugins(getPluginsEndpointMap(availablePlugins)).
87-
PluginsOrder(operatorConfig).
87+
PluginsOrder(availablePlugins, operatorConfig).
8888
I18nNamespaces(pluginsWithI18nNamespace(availablePlugins)).
8989
ContentSecurityPolicies(aggregateCSPDirectives(availablePlugins)).
9090
ContentSecurityPolicyEnabled(contentSecurityPolicyEnabled).

pkg/console/subresource/consoleserver/config_builder.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,26 @@ func (b *ConsoleServerCLIConfigBuilder) Plugins(plugins map[string]string) *Cons
243243
return b
244244
}
245245

246-
func (b *ConsoleServerCLIConfigBuilder) PluginsOrder(consoleConfig *operatorv1.Console) *ConsoleServerCLIConfigBuilder {
247-
b.pluginsOrder = consoleConfig.Spec.Plugins
246+
func (b *ConsoleServerCLIConfigBuilder) PluginsOrder(availablePlugins []*v1.ConsolePlugin, consoleConfig *operatorv1.Console) *ConsoleServerCLIConfigBuilder {
247+
// Build a fast lookup set of available plugin names
248+
availableSet := map[string]struct{}{}
249+
for _, plugin := range availablePlugins {
250+
if plugin == nil {
251+
continue
252+
}
253+
availableSet[plugin.ObjectMeta.Name] = struct{}{}
254+
}
255+
256+
// Preserve the order from consoleConfig.Spec.Plugins, but include only those
257+
// plugins that are actually available on the cluster.
258+
ordered := []string{}
259+
for _, name := range consoleConfig.Spec.Plugins {
260+
if _, ok := availableSet[name]; ok {
261+
ordered = append(ordered, name)
262+
}
263+
}
264+
265+
b.pluginsOrder = ordered
248266
return b
249267
}
250268

pkg/console/subresource/consoleserver/config_builder_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"github.com/go-test/deep"
88
"github.com/google/go-cmp/cmp"
99
configv1 "github.com/openshift/api/config/v1"
10+
consolev1 "github.com/openshift/api/console/v1"
1011
v1 "github.com/openshift/api/operator/v1"
1112
"github.com/openshift/console-operator/pkg/api"
1213
authorizationv1 "k8s.io/api/authorization/v1"
1314
corev1 "k8s.io/api/core/v1"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1416
)
1517

1618
// defaultTestCapabilities represents the default capabilities as defined in the operator manifest
@@ -907,6 +909,56 @@ func TestConsoleServerCLIConfigBuilder(t *testing.T) {
907909
I18nNamespaces: []string{"plugin__plugin1"},
908910
},
909911
},
912+
{
913+
name: "Config builder should set plugins order from available plugins",
914+
input: func() Config {
915+
b := &ConsoleServerCLIConfigBuilder{}
916+
b.Plugins(map[string]string{
917+
"plugin1": "plugin1_url",
918+
"plugin2": "plugin2_url",
919+
}).
920+
PluginsOrder([]*consolev1.ConsolePlugin{
921+
{ObjectMeta: metav1.ObjectMeta{Name: "plugin1"}},
922+
{ObjectMeta: metav1.ObjectMeta{Name: "plugin2"}},
923+
}, &v1.Console{
924+
Spec: v1.ConsoleSpec{
925+
Plugins: []string{"plugin1", "plugin2", "plugin3"},
926+
},
927+
})
928+
return b.Config()
929+
},
930+
output: Config{
931+
Kind: "ConsoleConfig",
932+
APIVersion: "console.openshift.io/v1",
933+
ServingInfo: ServingInfo{
934+
BindAddress: "https://[::]:8443",
935+
CertFile: certFilePath,
936+
KeyFile: keyFilePath,
937+
},
938+
ClusterInfo: ClusterInfo{
939+
ConsoleBasePath: "",
940+
},
941+
Auth: Auth{
942+
ClientID: api.OpenShiftConsoleName,
943+
ClientSecretFile: clientSecretFilePath,
944+
},
945+
Session: Session{},
946+
Customization: Customization{
947+
Perspectives: []Perspective{
948+
{
949+
ID: "dev",
950+
Visibility: PerspectiveVisibility{State: PerspectiveDisabled},
951+
},
952+
},
953+
},
954+
Providers: Providers{},
955+
Plugins: map[string]string{
956+
"plugin1": "plugin1_url",
957+
"plugin2": "plugin2_url",
958+
},
959+
PluginsOrder: []string{"plugin1", "plugin2"},
960+
},
961+
},
910962
{
911963
name: "Config builder should pass telemetry configuration",
912964
input: func() Config {

0 commit comments

Comments
 (0)