Skip to content

Commit

Permalink
dynamic holodeck ci instance name
Browse files Browse the repository at this point in the history
Signed-off-by: shiva kumar <shivaku@nvidia.com>
  • Loading branch information
shivakunv committed Dec 18, 2024
1 parent f478ba5 commit 971df34
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pkg/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package aws
import (
"context"
"os"
"strings"

"github.com/NVIDIA/holodeck/api/holodeck/v1alpha1"
"github.com/NVIDIA/holodeck/internal/logger"
Expand Down Expand Up @@ -87,6 +88,20 @@ func New(log *logger.FunLogger, env v1alpha1.Environment, cacheFile string) (*Pr
if envRegion := os.Getenv("AWS_REGION"); envRegion != "" {
region = envRegion
}
sha := os.Getenv("GITHUB_SHA")
// short sha
if len(sha) > 8 {
sha = sha[:8]
}
actor := os.Getenv("GITHUB_ACTOR")
branch := os.Getenv("GITHUB_REF_NAME")
repo_name := os.Getenv("GITHUB_REPOSITORY")
parts := strings.Split(repo_name, "/")
repoName := parts[len(parts)-1]
githubRunId := os.Getenv("GITHUB_RUN_ID")
githubRunNumber := os.Getenv("GITHUB_RUN_NUMBER")
githubJob := os.Getenv("GITHUB_JOB")

cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
return nil, err
Expand All @@ -100,6 +115,13 @@ func New(log *logger.FunLogger, env v1alpha1.Environment, cacheFile string) (*Pr
{Key: aws.String("Name"), Value: aws.String(env.Name)},
{Key: aws.String("Project"), Value: aws.String("holodeck")},
{Key: aws.String("Environment"), Value: aws.String("cicd")},
{Key: aws.String("Sha"), Value: aws.String(sha)},
{Key: aws.String("Actor"), Value: aws.String(actor)},
{Key: aws.String("Branch"), Value: aws.String(branch)},
{Key: aws.String("GithubRepository"), Value: aws.String(repoName)},
{Key: aws.String("GithubRunId"), Value: aws.String(githubRunId)},
{Key: aws.String("GithubRunNumber"), Value: aws.String(githubRunNumber)},
{Key: aws.String("GithubJob"), Value: aws.String(githubJob)},
},
client,
r53,
Expand Down
20 changes: 19 additions & 1 deletion pkg/provider/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ func (p *Provider) createInternetGateway(cache *AWS) error {
p.log.Wg.Add(1)
go p.log.Loading("Creating Internet Gateway")

gwInput := &ec2.CreateInternetGatewayInput{}
gwInput := &ec2.CreateInternetGatewayInput{
TagSpecifications: []types.TagSpecification{
{
ResourceType: types.ResourceTypeInternetGateway,
Tags: p.Tags,
},
},
}
gwOutput, err := p.ec2.CreateInternetGateway(context.TODO(), gwInput)
if err != nil {
p.fail()
Expand Down Expand Up @@ -357,6 +364,17 @@ func (p *Provider) createEC2Instance(cache *AWS) error {
}
cache.PublicDnsName = *instanceRunning.Reservations[0].Instances[0].PublicDnsName

// tag network interface
instance := instanceOut.Instances[0]
networkInterfaceId := *instance.NetworkInterfaces[0].NetworkInterfaceId
_, err = p.ec2.CreateTags(context.TODO(), &ec2.CreateTagsInput{
Resources: []string{networkInterfaceId},
Tags: p.Tags,
})
if err != nil {
p.fail()
return fmt.Errorf("Fail to tag network to instance: %v", err)
}
p.done()
return nil
}

0 comments on commit 971df34

Please sign in to comment.