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

Enabled copying files from cluster provided through kubeconfig file #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/kbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"encoding/json"
"flag"
"fmt"
"k-bench/pkg/prometheus"
//"k-bench/pkg/prometheus"
"k-bench/util"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
//"k8s.io/client-go/dynamic"
//"k8s.io/client-go/kubernetes"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -150,10 +150,10 @@ func main() {
}

if configWithPrometheus != nil {
client, _ := kubernetes.NewForConfig(config)
dynClient, _ := dynamic.NewForConfig(config)
pc := prometheus.NewPrometheusController(client, &dynClient, config, configWithPrometheus)
pc.EnablePrometheus()
// client, _ := kubernetes.NewForConfig(config)
// dynClient, _ := dynamic.NewForConfig(config)
// pc := prometheus.NewPrometheusController(client, &dynClient, config, configWithPrometheus)
// pc.EnablePrometheus()
}

// Sort the config files by the lightness of workload, from light to heavy.
Expand Down Expand Up @@ -192,7 +192,7 @@ func main() {
//Run each workload(specified by its config file) one after another in the sorted order
for _, testConfig := range testConfigs {
fmt.Printf("Running workload, please check kbench log for details... \n")
util.Run(config, testConfig, outDir)
util.Run(config, testConfig, outDir, *kubeconfig)
time.Sleep(time.Duration(testConfig.SleepTimeAfterRun) * time.Millisecond)
}

Expand Down
2 changes: 2 additions & 0 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ type ActionSpec struct {
type RunSpec struct {
RunCommand string
ActionFilter ActionSpec
KubeConfigfile string
}

type CopySpec struct {
ParentOutDir string
LocalPath string
ContainerPath string
Upload bool
KubeConfigfile string
ActionFilter ActionSpec
}

Expand Down
4 changes: 2 additions & 2 deletions manager/pod_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func (mgr *PodManager) Run(n interface{}) error {
return err
}

exec.Stream(remotecommand.StreamOptions{
exec.StreamWithContext(context.Background(), remotecommand.StreamOptions{
Stdin: nil,
Stdout: &mystdout,
Stderr: &mystderr,
Expand Down Expand Up @@ -606,7 +606,7 @@ func (mgr *PodManager) Copy(n interface{}) error {
toPath += mgr.startTimestamp + "/" + pod.Name
fromPath = pod.Namespace + "/" + pod.Name + ":" + s.ContainerPath
}
args := []string{"cp", fromPath, toPath}
args := []string{"cp", fromPath, toPath,"--kubeconfig",s.KubeConfigfile}
copyr, copye := osexec.Command("kubectl", args...).CombinedOutput()
if copye != nil {
log.Errorf("Error copying file(s) for pod: %v", pod.Name)
Expand Down
12 changes: 7 additions & 5 deletions util/driver_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func checkAndRunPod(
kubeConfig *restclient.Config,
op WcpOp,
opIdx int,
maxClients map[string]int) string {
maxClients map[string]int,
kubeConfigfile string) string {
if len(op.Pod.Actions) > 0 {

var podMgr *manager.PodManager
Expand All @@ -57,7 +58,7 @@ func checkAndRunPod(
log.Infof("Performing pod actions in operation %v", opIdx)

for i := 0; i < op.Pod.Count; i++ {
go runPodActions(podMgr, op.Pod, opIdx, i)
go runPodActions(podMgr, op.Pod, opIdx, i, kubeConfigfile)
wg.Add(1)
}

Expand Down Expand Up @@ -313,7 +314,8 @@ func runPodActions(
mgr *manager.PodManager,
podConfig PodConfig,
opNum int,
tid int) {
tid int,
kubeConfigfile string) {

// Get default pod name (used when filtering not specified or applicable)
podName := mgr.GetResourceName(podConfig.PodNamePrefix, opNum, tid)
Expand Down Expand Up @@ -409,7 +411,7 @@ func runPodActions(
podName, tid, opNum, ns, lk, lv,
runSpec.MatchGoroutine, runSpec.MatchOperation, manager.POD}
ae := mgr.ActionFuncs[manager.RUN_ACTION](mgr,
manager.RunSpec{runSpec.Command, as})
manager.RunSpec{runSpec.Command, as, kubeConfigfile})
if ae != nil {
log.Error(ae)
}
Expand All @@ -425,7 +427,7 @@ func runPodActions(
*outDir,
copySpec.LocalPath,
copySpec.ContainerPath,
copySpec.Upload, as})
copySpec.Upload, kubeConfigfile, as})
if ae != nil {
log.Error(ae)
}
Expand Down
4 changes: 2 additions & 2 deletions util/testdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var outDir *string
var mgrs map[string]manager.Manager

func Run(kubeConfig *restclient.Config,
testConfig TestConfig, outputDir *string) error {
testConfig TestConfig, outputDir *string, kubeConfigfile string) error {

outDir = outputDir
wcpOps := testConfig.Operations
Expand Down Expand Up @@ -221,7 +221,7 @@ func Run(kubeConfig *restclient.Config,
opIdx += startIdx

// Check and run if valid pod config is found
lastPodAction := checkAndRunPod(kubeConfig, op, opIdx, maxClients)
lastPodAction := checkAndRunPod(kubeConfig, op, opIdx, maxClients, kubeConfigfile)

// Check and run if valid deployment config is found
lastDepAction := checkAndRunDeployment(kubeConfig, op, opIdx, maxClients)
Expand Down