From 93bf79e8fe42ccd1c71340d0cfd6c8de560c281d Mon Sep 17 00:00:00 2001 From: Paolo Chila Date: Thu, 5 Oct 2023 18:07:43 +0200 Subject: [PATCH] add tags to created deployments --- pkg/testing/ess/deployment.go | 16 +++++++++++++--- pkg/testing/ess/provisioner.go | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pkg/testing/ess/deployment.go b/pkg/testing/ess/deployment.go index 9d9469036b0..caacb25dcd7 100644 --- a/pkg/testing/ess/deployment.go +++ b/pkg/testing/ess/deployment.go @@ -16,10 +16,20 @@ import ( "time" ) +type MetadataItem struct { + Key string `json:"key"` + Value string `json:"value"` +} + +type DeploymentCreateMetadata struct { + Tags []MetadataItem `json:"tags,omitempty"` +} + type CreateDeploymentRequest struct { - Name string `json:"name"` - Region string `json:"region"` - Version string `json:"version"` + Name string `json:"name"` + Region string `json:"region"` + Version string `json:"version"` + Metadata DeploymentCreateMetadata `json:"metadata,omitempty"` } type CreateDeploymentResponse struct { diff --git a/pkg/testing/ess/provisioner.go b/pkg/testing/ess/provisioner.go index 941cf5bcaf7..da918aa37d7 100644 --- a/pkg/testing/ess/provisioner.go +++ b/pkg/testing/ess/provisioner.go @@ -67,7 +67,7 @@ func (p *provisioner) Provision(ctx context.Context, requests []runner.StackRequ for _, r := range requests { // allow up to 2 minutes for each create request createCtx, createCancel := context.WithTimeout(ctx, 2*time.Minute) - resp, err := p.createDeployment(createCtx, r) + resp, err := p.createDeployment(createCtx, r, map[string]string{"elastic-agent-integration-tests": "true"}) createCancel() if err != nil { return nil, err @@ -131,17 +131,30 @@ func (p *provisioner) Clean(ctx context.Context, stacks []runner.Stack) error { return nil } -func (p *provisioner) createDeployment(ctx context.Context, r runner.StackRequest) (*CreateDeploymentResponse, error) { +func (p *provisioner) createDeployment(ctx context.Context, r runner.StackRequest, tags map[string]string) (*CreateDeploymentResponse, error) { ctx, cancel := context.WithTimeout(ctx, 1*time.Minute) defer cancel() p.logger.Logf("Creating stack %s (%s)", r.Version, r.ID) name := fmt.Sprintf("%s-%s", strings.Replace(p.cfg.Identifier, ".", "-", -1), r.ID) - resp, err := p.client.CreateDeployment(ctx, CreateDeploymentRequest{ + createDeploymentRequest := CreateDeploymentRequest{ Name: name, Region: p.cfg.Region, Version: r.Version, - }) + } + + if len(tags) > 0 { + requestTags := make([]MetadataItem, 0, len(tags)) + for k, v := range tags { + requestTags = append(requestTags, MetadataItem{ + Key: k, + Value: v, + }) + } + createDeploymentRequest.Metadata.Tags = requestTags + } + + resp, err := p.client.CreateDeployment(ctx, createDeploymentRequest) if err != nil { p.logger.Logf("Failed to create ESS cloud %s: %s", r.Version, err) return nil, fmt.Errorf("failed to create ESS cloud for version %s: %w", r.Version, err)