Skip to content

Commit

Permalink
*: do not print SSHCommands when total nodes >10
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Jul 10, 2020
1 parent fe3ba89 commit 464f1bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
39 changes: 21 additions & 18 deletions ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ func (ts *Tester) Up() (err error) {

if err == nil {
if ts.cfg.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))

ts.lg.Sugar().Infof("SSH (%s)", ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}

ts.lg.Info("Up succeeded",
zap.String("started", humanize.RelTime(now, time.Now(), "ago", "from now")),
Expand All @@ -194,10 +195,11 @@ func (ts *Tester) Up() (err error) {

if !ts.cfg.OnFailureDelete {
if ts.cfg.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))

ts.lg.Sugar().Infof("SSH (%s)", ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}
}

ts.lg.Warn("Up failed",
Expand All @@ -213,10 +215,11 @@ func (ts *Tester) Up() (err error) {
}

if ts.cfg.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))

ts.lg.Sugar().Infof("SSH (%s)", ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}
}
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("🔥 💀 👽 😱 😡 (-_-) [light_magenta]UP FAIL\n"))
Expand Down Expand Up @@ -254,9 +257,9 @@ func (ts *Tester) Up() (err error) {
zap.String("name", ts.cfg.Name),
)
defer ts.cfg.Sync()

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createS3 [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand All @@ -266,9 +269,9 @@ func (ts *Tester) Up() (err error) {
); err != nil {
return err
}

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createRole [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand All @@ -278,9 +281,9 @@ func (ts *Tester) Up() (err error) {
); err != nil {
return err
}

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createVPC [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand All @@ -290,9 +293,9 @@ func (ts *Tester) Up() (err error) {
); err != nil {
return err
}

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createKeyPair [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand All @@ -302,9 +305,9 @@ func (ts *Tester) Up() (err error) {
); err != nil {
return err
}

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createASGs [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand All @@ -314,9 +317,9 @@ func (ts *Tester) Up() (err error) {
); err != nil {
return err
}

fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]createSSM [default](%q)\n"), ts.cfg.ConfigPath)

if err := catchInterrupt(
ts.lg,
ts.stopCreationCh,
Expand Down
3 changes: 3 additions & 0 deletions ec2config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ type Config struct {
ASGsLogsDir string `json:"asgs-logs-dir,omitempty"`
// ASGs is a map from each ASG name to EC2 ASG.
ASGs map[string]ASG `json:"asgs"`

// TotalNodes is the total number of nodes from all ASGs.
TotalNodes int64 `json:"total-nodes" read-only:"true"`
}

func (c Config) Colorize(input string) string {
Expand Down
3 changes: 3 additions & 0 deletions ec2config/validate-defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func (cfg *Config) validateASGs() error {
return fmt.Errorf("ASGs %d exceeds maximum number of ASGs which is %d", n, ASGsMaxLimit)
}
names, processed := make(map[string]struct{}), make(map[string]ASG)
total := int64(0)
for k, cur := range cfg.ASGs {
k = strings.ReplaceAll(k, "GetRef.Name", cfg.Name)
cur.Name = strings.ReplaceAll(cur.Name, "GetRef.Name", cfg.Name)
Expand Down Expand Up @@ -453,10 +454,12 @@ func (cfg *Config) validateASGs() error {
case false: // use existing one, or don't run any SSM
}

total += cur.ASGDesiredCapacity
processed[k] = cur
}

cfg.ASGs = processed
cfg.TotalNodes = total
return nil
}

Expand Down
27 changes: 15 additions & 12 deletions eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,11 @@ func (ts *Tester) Up() (err error) {

if err == nil {
if ts.cfg.Status.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())

if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]kubectl [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.KubectlCommands())
Expand All @@ -819,10 +820,11 @@ func (ts *Tester) Up() (err error) {

if !ts.cfg.OnFailureDelete {
if ts.cfg.Status.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())

if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]kubectl [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.KubectlCommands())
Expand All @@ -844,10 +846,11 @@ func (ts *Tester) Up() (err error) {
}

if ts.cfg.Status.Up {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())

if ts.cfg.TotalNodes < 10 {
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]SSH [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.SSHCommands())
}
fmt.Fprintf(ts.logWriter, ts.color("\n\n[yellow]*********************************\n"))
fmt.Fprintf(ts.logWriter, ts.color("[light_green]kubectl [default](%q)\n"), ts.cfg.ConfigPath)
fmt.Fprintln(ts.logWriter, ts.cfg.KubectlCommands())
Expand Down

0 comments on commit 464f1bf

Please sign in to comment.