Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-606][FEATURE] Add config mode for ModeWithIRSA to support using d… #682

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions translator/config/envconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const (
RUN_IN_CONTAINER_TRUE = "True"
RUN_IN_AWS = "RUN_IN_AWS"
RUN_IN_AWS_TRUE = "True"
RUN_WITH_IRSA = "RUN_WITH_IRSA"
RUN_WITH_IRSA_TRUE = "True"
USE_DEFAULT_CONFIG = "USE_DEFAULT_CONFIG"
USE_DEFAULT_CONFIG_TRUE = "True"
HOST_NAME = "HOST_NAME"
Expand Down
3 changes: 2 additions & 1 deletion translator/config/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ package config
const (
ModeEC2 = "ec2"
ModeOnPrem = "onPrem"
ModeOnPremise = "onPremise"
ModeOnPremise = "onPremise"
ModeWithIRSA = "withIRSA"
)
6 changes: 4 additions & 2 deletions translator/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func CurrentContext() *Context {
return ctx
}

//Testing only
// Testing only
func ResetContext() {
ctx = nil
}
Expand Down Expand Up @@ -114,8 +114,10 @@ func (ctx *Context) SetMode(mode string) {
ctx.mode = config.ModeOnPrem
case config.ModeOnPremise:
ctx.mode = config.ModeOnPremise
case config.ModeWithIRSA:
ctx.mode = config.ModeWithIRSA
default:
log.Panicf("Invalid mode %s. Valid mode values are %s, %s and %s.", mode, config.ModeEC2, config.ModeOnPrem, config.ModeOnPremise)
log.Panicf("Invalid mode %s. Valid mode values are %s, %s, %s and %s.", mode, config.ModeEC2, config.ModeOnPrem, config.ModeOnPremise, config.ModeWithIRSA)
}
}

Expand Down
7 changes: 7 additions & 0 deletions translator/util/sdkutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var DetectCredentialsPath = detectCredentialsPath
var DefaultEC2Region = defaultEC2Region
var DefaultECSRegion = defaultECSRegion
var runInAws = os.Getenv(config.RUN_IN_AWS)
var runWithIrsa = os.Getenv(config.RUN_WITH_IRSA)

func DetectAgentMode(configuredMode string) string {
if configuredMode != "auto" {
Expand All @@ -38,6 +39,11 @@ func DetectAgentMode(configuredMode string) string {
return config.ModeEC2
}

if runWithIrsa == config.RUN_WITH_IRSA_TRUE {
khanhntd marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println("I! Detected from ENV RUN_WITH_IRSA is True")
return config.ModeWithIRSA
}

if DefaultEC2Region() != "" {
fmt.Println("I! Detected the instance is EC2")
return config.ModeEC2
Expand All @@ -47,6 +53,7 @@ func DetectAgentMode(configuredMode string) string {
fmt.Println("I! Detected the instance is ECS")
return config.ModeEC2
}

fmt.Println("I! Detected the instance is OnPremise")
return config.ModeOnPrem
}
Expand Down