Skip to content

Commit 342cda7

Browse files
authored
[Integration Test Framework] Allow creation of deployments in ESS QA Azure region (#3365)
* Create deployments in QA Azure region * Use appropriate deployment template based on CSP * Remove TODO comment * Keep GCP as default
1 parent b21af16 commit 342cda7

File tree

2 files changed

+135
-4
lines changed

2 files changed

+135
-4
lines changed

magefile.go

+3
Original file line numberDiff line numberDiff line change
@@ -1725,10 +1725,13 @@ func createTestRunner(matrix bool, singleTest string, goTestFlags string, batche
17251725
if datacenter == "" {
17261726
datacenter = "us-central1-a"
17271727
}
1728+
1729+
// Valid values are gcp-us-central1 (default), azure-eastus2
17281730
essRegion := os.Getenv("TEST_INTEG_AUTH_ESS_REGION")
17291731
if essRegion == "" {
17301732
essRegion = "gcp-us-central1"
17311733
}
1734+
17321735
instanceProvisionerMode := os.Getenv("INSTANCE_PROVISIONER")
17331736
if instanceProvisionerMode == "" {
17341737
instanceProvisionerMode = "ogc"

pkg/testing/ess/deployment.go

+132-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"html/template"
1313
"net/http"
1414
"net/url"
15+
"strings"
1516
"time"
1617
)
1718

@@ -84,9 +85,9 @@ type DeploymentStatusResponse struct {
8485

8586
// CreateDeployment creates the deployment with the specified configuration.
8687
func (c *Client) CreateDeployment(ctx context.Context, req CreateDeploymentRequest) (*CreateDeploymentResponse, error) {
87-
tpl, err := template.New("create_deployment_request").Parse(createDeploymentRequestTemplate)
88+
tpl, err := deploymentTemplateFactory(req)
8889
if err != nil {
89-
return nil, fmt.Errorf("unable to parse deployment creation template: %w", err)
90+
return nil, err
9091
}
9192

9293
var buf bytes.Buffer
@@ -307,8 +308,32 @@ func overallStatus(statuses ...DeploymentStatus) DeploymentStatus {
307308
return overallStatus
308309
}
309310

310-
// TODO: make work for cloud other than GCP
311-
const createDeploymentRequestTemplate = `
311+
func deploymentTemplateFactory(req CreateDeploymentRequest) (*template.Template, error) {
312+
regionParts := strings.Split(req.Region, "-")
313+
if len(regionParts) < 2 {
314+
return nil, fmt.Errorf("unable to parse CSP out of region [%s]", req.Region)
315+
}
316+
317+
csp := regionParts[0]
318+
var tplStr string
319+
switch csp {
320+
case "gcp":
321+
tplStr = createDeploymentRequestTemplateGCP
322+
case "azure":
323+
tplStr = createDeploymentRequestTemplateAzure
324+
default:
325+
return nil, fmt.Errorf("unsupported CSP [%s]", csp)
326+
}
327+
328+
tpl, err := template.New("create_deployment_request").Parse(tplStr)
329+
if err != nil {
330+
return nil, fmt.Errorf("unable to parse deployment creation template: %w", err)
331+
}
332+
333+
return tpl, nil
334+
}
335+
336+
const createDeploymentRequestTemplateGCP = `
312337
{
313338
"resources": {
314339
"integrations_server": [
@@ -410,3 +435,106 @@ const createDeploymentRequestTemplate = `
410435
"system_owned": false
411436
}
412437
}`
438+
439+
const createDeploymentRequestTemplateAzure = `
440+
{
441+
"resources": {
442+
"integrations_server": [
443+
{
444+
"elasticsearch_cluster_ref_id": "main-elasticsearch",
445+
"region": "{{ .Region }}",
446+
"plan": {
447+
"cluster_topology": [
448+
{
449+
"instance_configuration_id": "azure.integrationsserver.fsv2.2",
450+
"zone_count": 1,
451+
"size": {
452+
"resource": "memory",
453+
"value": 1024
454+
}
455+
}
456+
],
457+
"integrations_server": {
458+
"version": "{{ .Version }}"
459+
}
460+
},
461+
"ref_id": "main-integrations_server"
462+
}
463+
],
464+
"elasticsearch": [
465+
{
466+
"region": "{{ .Region }}",
467+
"settings": {
468+
"dedicated_masters_threshold": 6
469+
},
470+
"plan": {
471+
"cluster_topology": [
472+
{
473+
"zone_count": 1,
474+
"elasticsearch": {
475+
"node_attributes": {
476+
"data": "hot"
477+
}
478+
},
479+
"instance_configuration_id": "azure.es.datahot.edsv4",
480+
"node_roles": [
481+
"master",
482+
"ingest",
483+
"transform",
484+
"data_hot",
485+
"remote_cluster_client",
486+
"data_content"
487+
],
488+
"id": "hot_content",
489+
"size": {
490+
"resource": "memory",
491+
"value": 8192
492+
}
493+
}
494+
],
495+
"elasticsearch": {
496+
"version": "{{ .Version }}",
497+
"enabled_built_in_plugins": []
498+
},
499+
"deployment_template": {
500+
"id": "azure-storage-optimized-v2"
501+
}
502+
},
503+
"ref_id": "main-elasticsearch"
504+
}
505+
],
506+
"enterprise_search": [],
507+
"kibana": [
508+
{
509+
"elasticsearch_cluster_ref_id": "main-elasticsearch",
510+
"region": "{{ .Region }}",
511+
"plan": {
512+
"cluster_topology": [
513+
{
514+
"instance_configuration_id": "azure.kibana.fsv2",
515+
"zone_count": 1,
516+
"size": {
517+
"resource": "memory",
518+
"value": 1024
519+
}
520+
}
521+
],
522+
"kibana": {
523+
"version": "{{ .Version }}",
524+
"user_settings_json": {
525+
"xpack.fleet.enableExperimental": ["agentTamperProtectionEnabled"]
526+
}
527+
}
528+
},
529+
"ref_id": "main-kibana"
530+
}
531+
]
532+
},
533+
"settings": {
534+
"autoscaling_enabled": false
535+
},
536+
"name": "{{ .Name }}",
537+
"metadata": {
538+
"system_owned": false
539+
}
540+
}`

0 commit comments

Comments
 (0)