Skip to content

Commit 5c4214b

Browse files
committed
fix review comments
1 parent 836c5b3 commit 5c4214b

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

pkg/testcase/upgradenodereplacement.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ func validateNodeJoin(ip string) error {
442442
func serverJoin(cluster *shared.Cluster,
443443
awsClient *aws.Client,
444444
serverLeaderIP, token, version, channel, newExternalIP, newPrivateIP string) error {
445+
// All non-slemicro, we do install and enable services in the same step using 'both' keyword
445446
installOrBoth := "both"
446447
if cluster.NodeOS == "slemicro" {
448+
// For slemicro nodes, we perform only 'install' step at this stage.
447449
installOrBoth = "install"
448450
shared.LogLevel("debug", "Running Install on: %s", newExternalIP)
449451
}
@@ -488,7 +490,7 @@ func joinSteps(cluster *shared.Cluster,
488490
} else {
489491
delayTime = false
490492
}
491-
if executeErr := execute(joinCmd, newExternalIP, delayTime); executeErr != nil {
493+
if executeErr := executeJoinCmd(joinCmd, newExternalIP, delayTime); executeErr != nil {
492494
return shared.ReturnLogError("error performing install or enable action on node: %s %w\n",
493495
installEnableOrBoth, executeErr)
494496
}
@@ -588,8 +590,10 @@ func deleteAgents(a *aws.Client, c *shared.Cluster) error {
588590

589591
func joinAgent(cluster *shared.Cluster, awsClient *aws.Client,
590592
serverIp, token, version, channel, selfExternalIp, selfPrivateIp string) error {
593+
// All non-slemicro, we perform install and enable services in the same step with 'both' keyword.
591594
installOrBoth := "both"
592595
if cluster.NodeOS == "slemicro" {
596+
// We do only 'install' first in slemicro case
593597
installOrBoth = "install"
594598
shared.LogLevel("debug", "Running Install step for ip: %s", selfExternalIp)
595599
}
@@ -601,9 +605,9 @@ func joinAgent(cluster *shared.Cluster, awsClient *aws.Client,
601605
}
602606
var joinErr error
603607
if installOrBoth == "both" {
604-
joinErr = execute(cmd, selfExternalIp, true)
608+
joinErr = executeJoinCmd(cmd, selfExternalIp, true)
605609
} else {
606-
joinErr = execute(cmd, selfExternalIp, false)
610+
joinErr = executeJoinCmd(cmd, selfExternalIp, false)
607611
}
608612

609613
if joinErr != nil {
@@ -620,15 +624,15 @@ func joinAgent(cluster *shared.Cluster, awsClient *aws.Client,
620624
return shared.ReturnLogError("error parsing enable commands: %w\n", parseErr)
621625
}
622626

623-
if joinErr := execute(cmd, selfExternalIp, true); joinErr != nil {
627+
if joinErr := executeJoinCmd(cmd, selfExternalIp, true); joinErr != nil {
624628
return shared.ReturnLogError("error enabling services during join of agent node: %w\n", joinErr)
625629
}
626630
}
627631

628632
return nil
629633
}
630634

631-
func execute(cmd, ip string, delayTime bool) error {
635+
func executeJoinCmd(cmd, ip string, delayTime bool) error {
632636
if cmd == "" {
633637
return shared.ReturnLogError("cmd not sent\n")
634638
}

shared/aux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ func SystemCtlCmd(service, action string) (string, error) {
552552
return fmt.Sprintf("%s %s", sysctlPrefix, service), nil
553553
}
554554

555+
// Create a directory if it does not exist.
556+
// Optional: If chmodValue is not empty, Run chmod to change permission of the directory.
555557
func CreateDir(dir, chmodValue, ip string) {
556558
cmdPart1 := fmt.Sprintf("test -d '%s' && echo 'directory exists: %s'", dir, dir)
557559
cmdPart2 := "sudo mkdir -p " + dir
@@ -570,6 +572,8 @@ func CreateDir(dir, chmodValue, ip string) {
570572
}
571573
}
572574

575+
// Wait for SSH to a node ip to be ready.
576+
// Default max wait time: 3 mins. Retry 'SSH is ready' check every 10 seconds.
573577
func WaitForSSHReady(ip string) error {
574578
ticker := time.NewTicker(10 * time.Second)
575579
timeout := time.After(3 * time.Minute)
@@ -591,6 +595,8 @@ func WaitForSSHReady(ip string) error {
591595
}
592596
}
593597

598+
// Grep for a particular text/string from a filename and log the same.
599+
// Ex: Log content:'denied' calls in filename:'/var/log/audit/audit.log' file.
594600
func LogGrepOutput(filename, content, ip string) {
595601
cmd := fmt.Sprintf("sudo cat %s | grep %s", filename, content)
596602
grepData, grepErr := RunCommandOnNode(cmd, ip)

shared/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ func ExtractKubeImageVersion() string {
723723
return version
724724
}
725725

726+
// Runs and logs kubectl describe pod command
726727
func DescribePod(cluster *Cluster, pod *Pod) {
727728
cmd := fmt.Sprintf("%s -n %s", pod.Name, pod.NameSpace)
728729
output, describeErr := KubectlCommand(cluster, "node", "describe", "pod", cmd)
@@ -735,6 +736,7 @@ func DescribePod(cluster *Cluster, pod *Pod) {
735736
}
736737
}
737738

739+
// Runs and logs: kubectl logs command output
738740
func PodLogs(cluster *Cluster, pod *Pod) {
739741
if pod.NameSpace == "" || pod.Name == "" {
740742
LogLevel("warn", "Name or Namespace info in pod data is empty. kubectl logs cmd may not work")
@@ -750,6 +752,9 @@ func PodLogs(cluster *Cluster, pod *Pod) {
750752
}
751753
}
752754

755+
// Given a namespace, this function:
756+
// 1. filters ALL pods in the namespace
757+
// 2. logs both kubectl describe pod and kubectl logs output for each pod in the namespace
753758
func LogAllPodsForNamespace(namespace string) {
754759
LogLevel("debug", "logging pod logs and describe pod output for all pods with namespace: %s", namespace)
755760
filters := map[string]string{
@@ -768,6 +773,9 @@ func LogAllPodsForNamespace(namespace string) {
768773
}
769774
}
770775

776+
// Search and log for a particular pod(s) given its unique name substring and namespace. Ex: coredns, kube-system
777+
// 1. Filter based on the name substring, and find the right pod(s)
778+
// 2. For the pods matching the name, logs: kubectl describe pod and kubectl logs output
771779
func FindPodAndLog(name, namespace string) {
772780
LogLevel("debug",
773781
"find and log(pod logs and describe pod) for pod starting with %s for namespace %s", name, namespace)

0 commit comments

Comments
 (0)