Add an internal env var for managed cluster config in the ui (#12796)

This commit is contained in:
Kyle Havlovitz 2022-04-15 09:55:52 -07:00 committed by GitHub
parent 78c346cbb3
commit e162db7ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 0 deletions

View File

@ -1827,6 +1827,7 @@ func (b *builder) uiConfigVal(v RawUIConfig) UIConfig {
MetricsProviderOptionsJSON: stringVal(v.MetricsProviderOptionsJSON),
MetricsProxy: b.uiMetricsProxyVal(v.MetricsProxy),
DashboardURLTemplates: v.DashboardURLTemplates,
HCPEnabled: os.Getenv("CONSUL_HCP_ENABLED") == "true",
}
}

View File

@ -1433,6 +1433,7 @@ type UIConfig struct {
MetricsProviderOptionsJSON string
MetricsProxy UIMetricsProxy
DashboardURLTemplates map[string]string
HCPEnabled bool
}
type UIMetricsProxy struct {

View File

@ -438,6 +438,7 @@
"DashboardURLTemplates": {},
"Dir": "",
"Enabled": false,
"HCPEnabled": false,
"MetricsProvider": "",
"MetricsProviderFiles": [],
"MetricsProviderOptionsJSON": "",

View File

@ -19,6 +19,7 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
// browser.
"metrics_proxy_enabled": cfg.UIConfig.MetricsProxy.BaseURL != "",
"dashboard_url_templates": cfg.UIConfig.DashboardURLTemplates,
"hcp_enabled": cfg.UIConfig.HCPEnabled,
}
// Only set this if there is some actual JSON or we'll cause a JSON

View File

@ -43,6 +43,7 @@ func TestUIServerIndex(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
@ -76,6 +77,7 @@ func TestUIServerIndex(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "foo",
"metrics_provider_options": {
"a-very-unlikely-string":1
@ -97,6 +99,26 @@ func TestUIServerIndex(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
}`,
},
{
name: "hcp enabled",
cfg: basicUIEnabledConfig(withHCPEnabled()),
path: "/",
wantStatus: http.StatusOK,
wantContains: []string{"<!-- CONSUL_VERSION:"},
wantUICfgJSON: `{
"ACLsEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": true,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
@ -126,6 +148,7 @@ func TestUIServerIndex(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "bar",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
@ -255,6 +278,12 @@ func withMetricsProviderOptions(jsonStr string) cfgFunc {
}
}
func withHCPEnabled() cfgFunc {
return func(cfg *config.RuntimeConfig) {
cfg.UIConfig.HCPEnabled = true
}
}
// TestMultipleIndexRequests validates that the buffered file mechanism works
// beyond the first request. The initial implementation did not as it shared an
// bytes.Reader between callers.
@ -388,6 +417,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
@ -411,6 +441,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null