NET-5398: Update UI server to include if v2 is enabled (#20353)

* Update ui server to include V2 Catalog flag

* Fix typo
This commit is contained in:
Tyler Wendlandt 2024-01-26 14:38:51 -07:00 committed by GitHub
parent e586a4490d
commit 7e08d8988c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 70 additions and 7 deletions

3
.changelog/20353.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:feature
ui: adds V2CatalogEnabled to config that is passed to the ui
```

View File

@ -31,6 +31,14 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
uiCfg["metrics_provider_options"] = json.RawMessage(cfg.UIConfig.MetricsProviderOptionsJSON)
}
v2CatalogEnabled := false
for _, experiment := range cfg.Experiments {
if experiment == "resource-apis" {
v2CatalogEnabled = true
break
}
}
d := map[string]interface{}{
"ContentPath": cfg.UIConfig.ContentPath,
"ACLsEnabled": cfg.ACLsEnabled,
@ -39,6 +47,7 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
"LocalDatacenter": cfg.Datacenter,
"PrimaryDatacenter": cfg.PrimaryDatacenter,
"PeeringEnabled": cfg.PeeringEnabled,
"V2CatalogEnabled": v2CatalogEnabled,
}
// Also inject additional provider scripts if needed, otherwise strip the

View File

@ -51,7 +51,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
@ -90,7 +91,8 @@ func TestUIServerIndex(t *testing.T) {
},
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
@ -111,7 +113,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
@ -132,7 +135,30 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
name: "v2 catalog enabled",
cfg: basicUIEnabledConfig(withV2CatalogEnabled()),
path: "/",
wantStatus: http.StatusOK,
wantContains: []string{"<!-- CONSUL_VERSION:"},
wantUICfgJSON: `{
"ACLsEnabled": false,
"HCPEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"PeeringEnabled": true,
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": true
}`,
},
{
@ -155,7 +181,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
@ -187,7 +214,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "bar",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
@ -320,6 +348,12 @@ func withHCPEnabled() cfgFunc {
}
}
func withV2CatalogEnabled() cfgFunc {
return func(cfg *config.RuntimeConfig) {
cfg.Experiments = append(cfg.Experiments, "resource-apis")
}
}
func withPeeringDisabled() cfgFunc {
return func(cfg *config.RuntimeConfig) {
cfg.PeeringEnabled = false
@ -466,6 +500,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": false,
"apple": "seeds"
}`
require.JSONEq(t, expected, extractUIConfig(t, rec.Body.String()))
@ -492,6 +527,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": false,
"apple": "plant"
}`
require.JSONEq(t, expected, extractUIConfig(t, rec.Body.String()))

View File

@ -197,6 +197,10 @@ export default function (config = {}, win = window, doc = document) {
// reserve 1 for traffic that we can't manage
return 5;
}
case 'CONSUL_V2_CATALOG_ENABLED':
return operatorConfig.V2CatalogEnabled === 'undefined'
? false
: operatorConfig.V2CatalogEnabled;
}
};
const ui = function (key) {
@ -244,6 +248,9 @@ export default function (config = {}, win = window, doc = document) {
case 'TokenSecretID':
prev['CONSUL_HTTP_TOKEN'] = value;
break;
case 'CONSUL_V2_CATALOG_ENABLE':
prev['CONSUL_V2_CATALOG_ENABLED'] = JSON.parse(value);
break;
default:
prev[key] = value;
}
@ -295,6 +302,7 @@ export default function (config = {}, win = window, doc = document) {
case 'CONSUL_METRICS_PROXY_ENABLE':
case 'CONSUL_SERVICE_DASHBOARD_URL':
case 'CONSUL_BASE_UI_URL':
case 'CONSUL_V2_CATALOG_ENABLED':
case 'CONSUL_HTTP_PROTOCOL':
case 'CONSUL_HTTP_MAX_CONNECTIONS': {
// We allow the operator to set these ones via various methods

View File

@ -94,6 +94,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: false,
},
// Static variables used in multiple places throughout the UI
@ -122,6 +123,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: env('CONSUL_V2_CATALOG_ENABLED', false),
},
'@hashicorp/ember-cli-api-double': {
@ -176,6 +178,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: env('CONSUL_V2_CATALOG_ENABLED', false),
},
'@hashicorp/ember-cli-api-double': {

View File

@ -115,7 +115,7 @@ ${
'CONSUL_HCP_ENABLE': {
name: 'consul-hcp',
default: ${config.operatorConfig.HCPEnabled}
}
},
}
);
</script>

View File

@ -31,6 +31,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
@ -49,6 +50,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
@ -67,6 +69,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
@ -82,6 +85,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
].forEach(function (item) {