Skip to content

Commit 1d02a27

Browse files
committed
OCPBUGS-43792: Follow-on fix. Add new "plugins-order" flag to bridge cli args since "plugins" is an
undordered map. We need a way to persist plugin order from console operator config to the frontend server flag.
1 parent cb0532c commit 1d02a27

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

cmd/bridge/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func main() {
128128

129129
consolePluginsFlags := serverconfig.MultiKeyValue{}
130130
fs.Var(&consolePluginsFlags, "plugins", "List of plugin entries that are enabled for the console. Each entry consist of plugin-name as a key and plugin-endpoint as a value.")
131+
fPluginsOrder := fs.String("plugins-order", "", "List of plugin names which determines the order in which plugin extensions will be resolved.")
131132
fPluginProxy := fs.String("plugin-proxy", "", "Defines various service types to which will console proxy plugins requests. (JSON as string)")
132133
fI18NamespacesFlags := fs.String("i18n-namespaces", "", "List of namespaces separated by comma. Example --i18n-namespaces=plugin__acm,plugin__kubevirt")
133134
fContentSecurityPolicyEnabled := fs.Bool("content-security-policy-enabled", false, "Flag to indicate if Content Secrity Policy features should be enabled.")
@@ -229,6 +230,20 @@ func main() {
229230
}
230231
}
231232

233+
pluginsOrder := []string{}
234+
if *fPluginsOrder != "" {
235+
for _, str := range strings.Split(*fPluginsOrder, ",") {
236+
str = strings.TrimSpace(str)
237+
if str == "" {
238+
flags.FatalIfFailed(flags.NewInvalidFlagError("plugins-order", "list must contain names of plugins separated by comma"))
239+
}
240+
if consolePluginsFlags[str] == "" {
241+
flags.FatalIfFailed(flags.NewInvalidFlagError("plugins-order", "list must only contain currently enabled plugins"))
242+
}
243+
pluginsOrder = append(pluginsOrder, str)
244+
}
245+
}
246+
232247
nodeArchitectures := []string{}
233248
if *fNodeArchitectures != "" {
234249
for _, str := range strings.Split(*fNodeArchitectures, ",") {
@@ -295,6 +310,7 @@ func main() {
295310
K8sMode: *fK8sMode,
296311
CopiedCSVsDisabled: *fCopiedCSVsDisabled,
297312
Capabilities: capabilities,
313+
PluginsOrder: pluginsOrder,
298314
}
299315

300316
completedAuthnOptions, err := authOptions.Complete()

pkg/server/server.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ type Server struct {
209209
ThanosTenancyProxyConfig *proxy.Config
210210
ThanosTenancyProxyForRulesConfig *proxy.Config
211211
UserSettingsLocation string
212+
PluginsOrder []string
212213
}
213214

214215
func disableDirectoryListing(handler http.Handler) http.Handler {
@@ -712,19 +713,14 @@ func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
712713
w.Header().Set("Content-Security-Policy-Report-Only", strings.Join(cspDirectives, "; "))
713714
}
714715

715-
plugins := make([]string, 0, len(s.EnabledConsolePlugins))
716-
for plugin := range s.EnabledConsolePlugins {
717-
plugins = append(plugins, plugin)
718-
}
719-
720716
jsg := &jsGlobals{
721717
AddPage: s.AddPage,
722718
AlertManagerPublicURL: s.AlertManagerPublicURL.String(),
723719
AuthDisabled: s.Authenticator.IsStatic(),
724720
BasePath: s.BaseURL.Path,
725721
Branding: s.Branding,
726722
Capabilities: s.Capabilities,
727-
ConsolePlugins: plugins,
723+
ConsolePlugins: s.PluginsOrder,
728724
ConsoleVersion: version.Version,
729725
ControlPlaneTopology: s.ControlPlaneTopology,
730726
CopiedCSVsDisabled: s.CopiedCSVsDisabled,

pkg/serverconfig/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func SetFlagsFromConfig(fs *flag.FlagSet, config *Config) (err error) {
171171
addMonitoringInfo(fs, &config.MonitoringInfo)
172172
addHelmConfig(fs, &config.Helm)
173173
addPlugins(fs, config.Plugins)
174+
addPluginsOrder(fs, config.PluginsOrder)
174175
addI18nNamespaces(fs, config.I18nNamespaces)
175176
err = addProxy(fs, &config.Proxy)
176177
if err != nil {
@@ -424,6 +425,10 @@ func addPlugins(fs *flag.FlagSet, plugins MultiKeyValue) {
424425
}
425426
}
426427

428+
func addPluginsOrder(fs *flag.FlagSet, pluginsOrder []string) {
429+
fs.Set("plugins-order", strings.Join(pluginsOrder, ","))
430+
}
431+
427432
func addTelemetry(fs *flag.FlagSet, telemetry MultiKeyValue) {
428433
for key, value := range telemetry {
429434
fs.Set("telemetry", fmt.Sprintf("%s=%s", key, value))

pkg/serverconfig/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Config struct {
2424
Helm `yaml:"helm"`
2525
MonitoringInfo `yaml:"monitoringInfo,omitempty"`
2626
Plugins MultiKeyValue `yaml:"plugins,omitempty"`
27+
PluginsOrder []string `yaml:"pluginsOrder,omitempty"`
2728
I18nNamespaces []string `yaml:"i18nNamespaces,omitempty"`
2829
Proxy Proxy `yaml:"proxy,omitempty"`
2930
ContentSecurityPolicyEnabled bool `yaml:"contentSecurityPolicyEnabled,omitempty"`

0 commit comments

Comments
 (0)