yangwwei commented on code in PR #187:
URL: https://github.com/apache/yunikorn-release/pull/187#discussion_r1951744882


##########
soak/setup/initial_setup.sh:
##########
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# create a kind cluster
+kind create cluster --name soak-test-cluster
+
+# install YuniKorn scheduler on kind Cluster
+helm repo add yunikorn https://apache.github.io/yunikorn-release

Review Comment:
   I think we only publish the stable version to helm charts repo.
   Which means this will only test the latest stable version, this is not 
enough. We need a way to test an unreleased version, I am not entirely sure 
about how to do this, maybe one way is to use the release tool in this repo, 
https://yunikorn.apache.org/community/release_procedure/ to create a release 
based on a branch or tag. Lets discuss this. 



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))

Review Comment:
   can `currentContextOutput` be nil when err != nil? 
   I think its better if we find error here, we do not log the 
`currentContextOutput`, the error message should cover enough info for 
debugging.



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))
+
+       return nil
+}
+
+func UpgradeSchedulerPerConfig(scheduler framework.TemplateFields) error {
+    if err := SetK8sContext(); err != nil {
+        logger.Fatal("failed to set kubernetes context", zap.Error(err))
+        return err
+    }
+
+       logger.Info("Scheduler details",
+               zap.String("VcoreRequests", *scheduler.VcoreRequests),
+               zap.String("MemoryRequests", *scheduler.MemoryRequests),
+               zap.String("VcoreLimits", *scheduler.VcoreLimits),
+               zap.String("MemoryLimits", *scheduler.MemoryLimits),
+               zap.String("path", *scheduler.Path))
+
+       if scheduler.VcoreRequests != nil || scheduler.MemoryRequests != nil || 
scheduler.VcoreLimits != nil || scheduler.MemoryLimits != nil {
+               args := []string{
+                       "upgrade",
+                       "yunikorn",
+                       "yunikorn/yunikorn",
+                       "-n", "yunikorn",
+               }
+
+               if scheduler.VcoreRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.cpu=%s", *scheduler.VcoreRequests))
+               }
+               if scheduler.MemoryRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.memory=%s", *scheduler.MemoryRequests))
+               }
+               if scheduler.VcoreLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.cpu=%s", *scheduler.VcoreLimits))
+               }
+               if scheduler.MemoryLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.memory=%s", *scheduler.MemoryLimits))
+               }
+
+               cmd := exec.Command("helm", args...)
+
+               logger.Info("Helm command to be executed",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))))
+
+               output, err := cmd.CombinedOutput()
+               if err != nil {
+                  return fmt.Errorf("helm upgrade failed: %v, output: %s", 
err, string(output))

Review Comment:
   if err != nil, can output be nil?



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))
+
+       return nil
+}
+
+func UpgradeSchedulerPerConfig(scheduler framework.TemplateFields) error {
+    if err := SetK8sContext(); err != nil {
+        logger.Fatal("failed to set kubernetes context", zap.Error(err))
+        return err
+    }
+
+       logger.Info("Scheduler details",
+               zap.String("VcoreRequests", *scheduler.VcoreRequests),
+               zap.String("MemoryRequests", *scheduler.MemoryRequests),
+               zap.String("VcoreLimits", *scheduler.VcoreLimits),
+               zap.String("MemoryLimits", *scheduler.MemoryLimits),
+               zap.String("path", *scheduler.Path))
+
+       if scheduler.VcoreRequests != nil || scheduler.MemoryRequests != nil || 
scheduler.VcoreLimits != nil || scheduler.MemoryLimits != nil {
+               args := []string{
+                       "upgrade",
+                       "yunikorn",
+                       "yunikorn/yunikorn",
+                       "-n", "yunikorn",
+               }
+
+               if scheduler.VcoreRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.cpu=%s", *scheduler.VcoreRequests))
+               }
+               if scheduler.MemoryRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.memory=%s", *scheduler.MemoryRequests))
+               }
+               if scheduler.VcoreLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.cpu=%s", *scheduler.VcoreLimits))
+               }
+               if scheduler.MemoryLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.memory=%s", *scheduler.MemoryLimits))
+               }
+
+               cmd := exec.Command("helm", args...)
+
+               logger.Info("Helm command to be executed",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))))
+
+               output, err := cmd.CombinedOutput()
+               if err != nil {
+                  return fmt.Errorf("helm upgrade failed: %v, output: %s", 
err, string(output))
+               }
+
+               logger.Info("Helm upgrade successful",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))),
+                  zap.String("output", string(output)))
+       }
+
+       if scheduler.Path != nil {
+               kubectlArgs := []string{"apply"}
+               kubectlArgs = append(kubectlArgs, "-f", *scheduler.Path, "-n", 
"yunikorn")
+               kubectlCmd := exec.Command("kubectl", kubectlArgs...)
+               logger.Info("Kubectl command to be executed",
+                       zap.String("command", fmt.Sprintf("kubectl %s", 
strings.Join(kubectlArgs, " "))))
+
+               kubectlOutput, err := kubectlCmd.CombinedOutput()
+               if err != nil {
+                       return fmt.Errorf("kubectl apply failed: %v, output: 
%s", err, string(kubectlOutput))
+               }
+               logger.Info("Kubectl apply successful", zap.String("output", 
strings.TrimSpace(string(kubectlOutput))))
+       }
+
+    return nil
+}
+
+func SetNodeScalePerConfig(node framework.TemplateFields) error {
+       if err := SetK8sContext(); err != nil {
+               logger.Fatal("failed to set kubernetes context", zap.Error(err))
+               return err
+       }
+
+       logger.Info("Node details",
+               zap.String("path", *node.Path),
+               zap.Int("NodesDesiredCount", *node.DesiredCount),
+               zap.Int("maxCount", *node.MaxCount))
+
+       templateContent, err := 
os.ReadFile("soak/templates/kwok-node-template.yaml")
+       if err != nil {
+               return fmt.Errorf("failed to read template file: %v", err)
+       }
+    desiredCount := *node.DesiredCount

Review Comment:
   NIT : seems like there is some format issue here, the space is not aligned 
with previous lines



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {

Review Comment:
   all these function names can start with lower case, I don't think we are 
gonna need them out of this package right?



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))

Review Comment:
   Its better not to log this



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))
+
+       return nil
+}
+
+func UpgradeSchedulerPerConfig(scheduler framework.TemplateFields) error {
+    if err := SetK8sContext(); err != nil {
+        logger.Fatal("failed to set kubernetes context", zap.Error(err))
+        return err
+    }
+
+       logger.Info("Scheduler details",
+               zap.String("VcoreRequests", *scheduler.VcoreRequests),
+               zap.String("MemoryRequests", *scheduler.MemoryRequests),
+               zap.String("VcoreLimits", *scheduler.VcoreLimits),
+               zap.String("MemoryLimits", *scheduler.MemoryLimits),
+               zap.String("path", *scheduler.Path))
+
+       if scheduler.VcoreRequests != nil || scheduler.MemoryRequests != nil || 
scheduler.VcoreLimits != nil || scheduler.MemoryLimits != nil {
+               args := []string{
+                       "upgrade",
+                       "yunikorn",
+                       "yunikorn/yunikorn",
+                       "-n", "yunikorn",
+               }
+
+               if scheduler.VcoreRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.cpu=%s", *scheduler.VcoreRequests))
+               }
+               if scheduler.MemoryRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.memory=%s", *scheduler.MemoryRequests))
+               }
+               if scheduler.VcoreLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.cpu=%s", *scheduler.VcoreLimits))
+               }
+               if scheduler.MemoryLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.memory=%s", *scheduler.MemoryLimits))
+               }
+
+               cmd := exec.Command("helm", args...)
+
+               logger.Info("Helm command to be executed",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))))
+
+               output, err := cmd.CombinedOutput()
+               if err != nil {
+                  return fmt.Errorf("helm upgrade failed: %v, output: %s", 
err, string(output))
+               }
+
+               logger.Info("Helm upgrade successful",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))),
+                  zap.String("output", string(output)))
+       }
+
+       if scheduler.Path != nil {
+               kubectlArgs := []string{"apply"}
+               kubectlArgs = append(kubectlArgs, "-f", *scheduler.Path, "-n", 
"yunikorn")
+               kubectlCmd := exec.Command("kubectl", kubectlArgs...)
+               logger.Info("Kubectl command to be executed",
+                       zap.String("command", fmt.Sprintf("kubectl %s", 
strings.Join(kubectlArgs, " "))))
+
+               kubectlOutput, err := kubectlCmd.CombinedOutput()
+               if err != nil {
+                       return fmt.Errorf("kubectl apply failed: %v, output: 
%s", err, string(kubectlOutput))
+               }
+               logger.Info("Kubectl apply successful", zap.String("output", 
strings.TrimSpace(string(kubectlOutput))))
+       }
+
+    return nil
+}
+
+func SetNodeScalePerConfig(node framework.TemplateFields) error {
+       if err := SetK8sContext(); err != nil {
+               logger.Fatal("failed to set kubernetes context", zap.Error(err))
+               return err
+       }
+
+       logger.Info("Node details",
+               zap.String("path", *node.Path),
+               zap.Int("NodesDesiredCount", *node.DesiredCount),
+               zap.Int("maxCount", *node.MaxCount))
+
+       templateContent, err := 
os.ReadFile("soak/templates/kwok-node-template.yaml")
+       if err != nil {
+               return fmt.Errorf("failed to read template file: %v", err)
+       }
+    desiredCount := *node.DesiredCount
+
+    for i := 0; i < desiredCount; i++ {
+        currentNodeName := fmt.Sprintf("kwok-node-%d", i)
+        nodeContent := strings.ReplaceAll(string(templateContent), 
"kwok-node-i", currentNodeName)
+
+        tmpfile, err := os.CreateTemp("", "node-*.yaml")

Review Comment:
   is this going to create the tmp file in the current working directory? 



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))
+
+       return nil
+}
+
+func UpgradeSchedulerPerConfig(scheduler framework.TemplateFields) error {
+    if err := SetK8sContext(); err != nil {
+        logger.Fatal("failed to set kubernetes context", zap.Error(err))
+        return err
+    }
+
+       logger.Info("Scheduler details",
+               zap.String("VcoreRequests", *scheduler.VcoreRequests),
+               zap.String("MemoryRequests", *scheduler.MemoryRequests),
+               zap.String("VcoreLimits", *scheduler.VcoreLimits),
+               zap.String("MemoryLimits", *scheduler.MemoryLimits),
+               zap.String("path", *scheduler.Path))
+
+       if scheduler.VcoreRequests != nil || scheduler.MemoryRequests != nil || 
scheduler.VcoreLimits != nil || scheduler.MemoryLimits != nil {

Review Comment:
   this check seems to be redundant
   the following section append arguments to a list, if the list is not empty, 
then run the upgrade.



##########
soak/setup/setup.go:
##########
@@ -0,0 +1,171 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+     http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package setup
+
+import (
+       "fmt"
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-release/soak/constants"
+       "github.com/apache/yunikorn-release/soak/framework"
+       "go.uber.org/zap"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strings"
+)
+
+var logger *zap.Logger = log.Log(log.Test)
+
+func SetK8sContext() error {
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               return fmt.Errorf("failed to get home directory: %v", err)
+       }
+       kubeconfigPath := filepath.Join(homeDir, ".kube", "config")
+       os.Setenv("KUBECONFIG", kubeconfigPath)
+       logger.Info("Set KUBECONFIG", zap.String("path", kubeconfigPath))
+
+       contextCmd := exec.Command("kubectl", "config", "use-context", 
constants.KindSoakTestCluster)
+       contextOutput, err := contextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to switch kubectl context: %v, 
output: %s", err, string(contextOutput))
+       }
+       logger.Info("Kubectl context switch output", zap.String("output", 
strings.TrimSpace(string(contextOutput))))
+
+       currentContextCmd := exec.Command("kubectl", "config", 
"current-context")
+       currentContextOutput, err := currentContextCmd.CombinedOutput()
+       if err != nil {
+               return fmt.Errorf("failed to get current context: %v, output: 
%s", err, string(currentContextOutput))
+       }
+       logger.Info("Current kubectl context", zap.String("context", 
strings.TrimSpace(string(currentContextOutput))))
+
+       return nil
+}
+
+func UpgradeSchedulerPerConfig(scheduler framework.TemplateFields) error {
+    if err := SetK8sContext(); err != nil {
+        logger.Fatal("failed to set kubernetes context", zap.Error(err))
+        return err
+    }
+
+       logger.Info("Scheduler details",
+               zap.String("VcoreRequests", *scheduler.VcoreRequests),
+               zap.String("MemoryRequests", *scheduler.MemoryRequests),
+               zap.String("VcoreLimits", *scheduler.VcoreLimits),
+               zap.String("MemoryLimits", *scheduler.MemoryLimits),
+               zap.String("path", *scheduler.Path))
+
+       if scheduler.VcoreRequests != nil || scheduler.MemoryRequests != nil || 
scheduler.VcoreLimits != nil || scheduler.MemoryLimits != nil {
+               args := []string{
+                       "upgrade",
+                       "yunikorn",
+                       "yunikorn/yunikorn",
+                       "-n", "yunikorn",
+               }
+
+               if scheduler.VcoreRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.cpu=%s", *scheduler.VcoreRequests))
+               }
+               if scheduler.MemoryRequests != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.requests.memory=%s", *scheduler.MemoryRequests))
+               }
+               if scheduler.VcoreLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.cpu=%s", *scheduler.VcoreLimits))
+               }
+               if scheduler.MemoryLimits != nil {
+                       args = append(args, "--set", 
fmt.Sprintf("resources.limits.memory=%s", *scheduler.MemoryLimits))
+               }
+
+               cmd := exec.Command("helm", args...)
+
+               logger.Info("Helm command to be executed",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))))
+
+               output, err := cmd.CombinedOutput()
+               if err != nil {
+                  return fmt.Errorf("helm upgrade failed: %v, output: %s", 
err, string(output))
+               }
+
+               logger.Info("Helm upgrade successful",
+                  zap.String("command", fmt.Sprintf("helm %s", 
strings.Join(args, " "))),
+                  zap.String("output", string(output)))
+       }
+
+       if scheduler.Path != nil {
+               kubectlArgs := []string{"apply"}
+               kubectlArgs = append(kubectlArgs, "-f", *scheduler.Path, "-n", 
"yunikorn")
+               kubectlCmd := exec.Command("kubectl", kubectlArgs...)
+               logger.Info("Kubectl command to be executed",
+                       zap.String("command", fmt.Sprintf("kubectl %s", 
strings.Join(kubectlArgs, " "))))
+
+               kubectlOutput, err := kubectlCmd.CombinedOutput()
+               if err != nil {
+                       return fmt.Errorf("kubectl apply failed: %v, output: 
%s", err, string(kubectlOutput))
+               }
+               logger.Info("Kubectl apply successful", zap.String("output", 
strings.TrimSpace(string(kubectlOutput))))
+       }
+
+    return nil
+}
+
+func SetNodeScalePerConfig(node framework.TemplateFields) error {
+       if err := SetK8sContext(); err != nil {
+               logger.Fatal("failed to set kubernetes context", zap.Error(err))
+               return err
+       }
+
+       logger.Info("Node details",
+               zap.String("path", *node.Path),
+               zap.Int("NodesDesiredCount", *node.DesiredCount),
+               zap.Int("maxCount", *node.MaxCount))
+
+       templateContent, err := 
os.ReadFile("soak/templates/kwok-node-template.yaml")
+       if err != nil {
+               return fmt.Errorf("failed to read template file: %v", err)
+       }
+    desiredCount := *node.DesiredCount
+
+    for i := 0; i < desiredCount; i++ {
+        currentNodeName := fmt.Sprintf("kwok-node-%d", i)
+        nodeContent := strings.ReplaceAll(string(templateContent), 
"kwok-node-i", currentNodeName)
+
+        tmpfile, err := os.CreateTemp("", "node-*.yaml")
+        if err != nil {
+            return fmt.Errorf("failed to create temp file: %v", err)
+        }
+        defer os.Remove(tmpfile.Name()) // Clean up
+
+        if _, err := tmpfile.WriteString(nodeContent); err != nil {
+            return fmt.Errorf("failed to write to temp file: %v", err)
+        }
+        if err := tmpfile.Close(); err != nil {
+            return fmt.Errorf("failed to close temp file: %v", err)
+        }
+
+        cmd := exec.Command("kubectl", "apply", "-f", tmpfile.Name())
+        output, err := cmd.CombinedOutput()
+        if err != nil {
+            return fmt.Errorf("failed to apply node configuration: %v, output: 
%s", err, string(output))

Review Comment:
   can output here be nil?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to