Skip to content

Commit a0c78d8

Browse files
committed
fix: hostpath to secret
Signed-off-by: namkyu1999 <[email protected]>
1 parent 3e13d53 commit a0c78d8

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails,
5050

5151
// Wait till the completion of the helper pod
5252
// set an upper limit for the waiting time
53-
log.Info("[Wait]: waiting till the completion of the helper pod")
53+
log.Info("[Wait]: Waiting till the completion of the helper pod")
5454
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, common.GetContainerNames(chaosDetails)...)
5555
if err != nil || podStatus == "Failed" {
5656
common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients)
@@ -90,6 +90,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients
9090
// createHelperPod derive the attributes for helper pod and create the helper pod
9191
func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, runID string) error {
9292
const volumeName = "script-volume"
93+
const mountPath = "/mnt"
9394
helperPod := &corev1.Pod{
9495
ObjectMeta: v1.ObjectMeta{
9596
GenerateName: experimentsDetails.ExperimentName + "-helper-",
@@ -111,14 +112,14 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
111112
"run",
112113
},
113114
Args: []string{
114-
experimentsDetails.ScriptPath,
115+
mountPath + "/" + experimentsDetails.ScriptSecretKey,
115116
"-q",
116117
},
117118
Resources: chaosDetails.Resources,
118119
VolumeMounts: []corev1.VolumeMount{
119120
{
120121
Name: volumeName,
121-
MountPath: experimentsDetails.ScriptPath,
122+
MountPath: "/mnt",
122123
},
123124
},
124125
},
@@ -127,8 +128,8 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
127128
{
128129
Name: volumeName,
129130
VolumeSource: corev1.VolumeSource{
130-
HostPath: &corev1.HostPathVolumeSource{
131-
Path: experimentsDetails.ScriptPath,
131+
Secret: &corev1.SecretVolumeSource{
132+
SecretName: experimentsDetails.ScriptSecretName,
132133
},
133134
},
134135
},

experiments/load/k6-loadgen/experiment/k6-loadgen.go

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package experiment
22

33
import (
4-
"errors"
54
"os"
65

76
"github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1"
@@ -53,13 +52,6 @@ func Experiment(clients clients.ClientSets) {
5352
return
5453
}
5554

56-
// Check if the script path exists
57-
if _, err := os.Stat(experimentsDetails.ScriptPath); errors.Is(err, os.ErrNotExist) {
58-
log.Errorf("The script path %v does not exist", experimentsDetails.ScriptPath)
59-
result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails)
60-
return
61-
}
62-
6355
// Set the chaos result uid
6456
result.SetResultUID(&resultDetails, clients, &chaosDetails)
6557

pkg/load/k6-loadgen/environment/environment.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
3636
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "ghcr.io/grafana/k6-operator:latest-runner")
3737
experimentDetails.SetHelperData = types.Getenv("SET_HELPER_DATA", "true")
3838
experimentDetails.ChaosServiceAccount = types.Getenv("CHAOS_SERVICE_ACCOUNT", "")
39-
experimentDetails.ScriptPath = types.Getenv("SCRIPT_PATH", "/tmp/script.js")
39+
experimentDetails.ScriptSecretName = types.Getenv("SCRIPT_SECRET_NAME", "k6-script")
40+
experimentDetails.ScriptSecretKey = types.Getenv("SCRIPT_SECRET_KEY", "script.js")
4041
}

pkg/load/k6-loadgen/types/types.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
clientTypes "k8s.io/apimachinery/pkg/types"
55
)
66

7-
// ADD THE ATTRIBUTES OF YOUR CHOICE HERE
8-
// FEW MANDATORY ATTRIBUTES ARE ADDED BY DEFAULT
9-
107
// ExperimentDetails is for collecting all the experiment-related details
118
type ExperimentDetails struct {
129
ExperimentName string
@@ -32,5 +29,6 @@ type ExperimentDetails struct {
3229
SetHelperData string
3330
ChaosServiceAccount string
3431
IsTargetContainerProvided bool
35-
ScriptPath string
32+
ScriptSecretName string
33+
ScriptSecretKey string
3634
}

0 commit comments

Comments
 (0)