Skip to content

Commit

Permalink
add tags to created deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
pchila committed Oct 5, 2023
1 parent 71de698 commit 93bf79e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
16 changes: 13 additions & 3 deletions pkg/testing/ess/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 17 additions & 4 deletions pkg/testing/ess/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 93bf79e

Please sign in to comment.