func (tc *testContext) runSSHJob(name, command, ip string) (string, error) {
	// Create a job which runs the provided command via SSH
	keyMountDir := "/private-key"
	sshCommand := []string{"bash", "-c", fmt.Sprintf("ssh -o StrictHostKeyChecking=no -i %s %s@%s '%s'",
		filepath.Join(keyMountDir, secrets.PrivateKeySecretKey), tc.vmUsername(), ip, command)}
	keyMode := int32(0600)
	job := &batch.Job{
		ObjectMeta: meta.ObjectMeta{
			GenerateName: name + "-job-",
		},
		Spec: batch.JobSpec{
			Template: core.PodTemplateSpec{
				Spec: core.PodSpec{
					HostNetwork:        true,
					RestartPolicy:      core.RestartPolicyNever,
					ServiceAccountName: tc.workloadNamespace,
					Containers: []core.Container{
						{
							Name:            name,
							Image:           tc.toolsImage,
							ImagePullPolicy: core.PullIfNotPresent,
							Command:         sshCommand,
							VolumeMounts: []core.VolumeMount{{
								Name:      "private-key",
								MountPath: keyMountDir,
							}},
						},
					},
					Volumes: []core.Volume{{Name: "private-key", VolumeSource: core.VolumeSource{
						Secret: &core.SecretVolumeSource{
							SecretName:  secrets.PrivateKeySecret,
							DefaultMode: &keyMode,
						},
					}}},
				},
			},
		},
	}

	jobsClient := tc.client.K8s.BatchV1().Jobs(tc.workloadNamespace)
	job, err := jobsClient.Create(context.TODO(), job, meta.CreateOptions{})
	if err != nil {
		return "", errors.Wrap(err, "error creating job")
	}

	// Wait for the job to complete then gather and return the pod output
	if err = tc.waitUntilJobSucceeds(job.GetName()); err != nil {
		return "", errors.Wrap(err, "error waiting for job to succeed")
	}
	labelSelector := "job-name=" + job.Name
	logs, err := tc.getLogs(labelSelector)
	if err != nil {
		return "", errors.Wrap(err, "error getting logs from job pod")
	}
	return logs, nil
}
// runSSHJob creates and waits for a Kubernetes job to run. The command provided will be executed on the host specified
// by the provided IP.
runSSHJob creates and waits for a Kubernetes job to run. The command provided will be executed on the host specified
by the provided IP.
// runSSHJob creates and waits for a Kubernetes job to run . The command provided will be executed on the host specified // by the provided IP .
func (tc *testContext) runSSHJob(name, command, ip string) (string, error) {
	keyMountDir := "/private-key"
	sshCommand := []string{"bash", "-c", fmt.Sprintf("ssh -o StrictHostKeyChecking=no -i %s %s@%s '%s'",
		filepath.Join(keyMountDir, secrets.PrivateKeySecretKey), tc.vmUsername(), ip, command)}
	keyMode := int32(0600)
	job := &batch.Job{
		ObjectMeta: meta.ObjectMeta{
			GenerateName: name + "-job-",
		},
		Spec: batch.JobSpec{
			Template: core.PodTemplateSpec{
				Spec: core.PodSpec{
					HostNetwork:        true,
					RestartPolicy:      core.RestartPolicyNever,
					ServiceAccountName: tc.workloadNamespace,
					Containers: []core.Container{
						{
							Name:            name,
							Image:           tc.toolsImage,
							ImagePullPolicy: core.PullIfNotPresent,
							Command:         sshCommand,
							VolumeMounts: []core.VolumeMount{{
								Name:      "private-key",
								MountPath: keyMountDir,
							}},
						},
					},
					Volumes: []core.Volume{{Name: "private-key", VolumeSource: core.VolumeSource{
						Secret: &core.SecretVolumeSource{
							SecretName:  secrets.PrivateKeySecret,
							DefaultMode: &keyMode,
						},
					}}},
				},
			},
		},
	}
	jobsClient := tc.client.K8s.BatchV1().Jobs(tc.workloadNamespace)
	job, err := jobsClient.Create(context.TODO(), job, meta.CreateOptions{})
	if err != nil {
		return "", errors.Wrap(err, "error creating job")
	}
	if err = tc.waitUntilJobSucceeds(job.GetName()); err != nil {
		return "", errors.Wrap(err, "error waiting for job to succeed")
	}
	labelSelector := "job-name=" + job.Name
	logs, err := tc.getLogs(labelSelector)
	if err != nil {
		return "", errors.Wrap(err, "error getting logs from job pod")
	}
	return logs, nil
}
func ( tc * testContext ) runSSHJob ( name , command , ip string ) ( string , error ) { keyMountDir := " " sshCommand := [ ] string { " " , " " , fmt . Sprintf ( " " , filepath . Join ( keyMountDir , secrets . PrivateKeySecretKey ) , tc . vmUsername ( ) , ip , command ) } keyMode := int32 ( 0600 ) job := & batch . Job { ObjectMeta : meta . ObjectMeta { GenerateName : name + " " , } , Spec : batch . JobSpec { Template : core . PodTemplateSpec { Spec : core . PodSpec { HostNetwork : true , RestartPolicy : core . RestartPolicyNever , ServiceAccountName : tc . workloadNamespace , Containers : [ ] core . Container { { Name : name , Image : tc . toolsImage , ImagePullPolicy : core . PullIfNotPresent , Command : sshCommand , VolumeMounts : [ ] core . VolumeMount { { Name : " " , MountPath : keyMountDir , } } , } , } , Volumes : [ ] core . Volume { { Name : " " , VolumeSource : core . VolumeSource { Secret : & core . SecretVolumeSource { SecretName : secrets . PrivateKeySecret , DefaultMode : & keyMode , } , } } } , } , } , } , } jobsClient := tc . client . K8s . BatchV1 ( ) . Jobs ( tc . workloadNamespace ) job , err := jobsClient . Create ( context . TODO ( ) , job , meta . CreateOptions { } ) if err != nil { return " " , errors . Wrap ( err , " " ) } if err = tc . waitUntilJobSucceeds ( job . GetName ( ) ) ; err != nil { return " " , errors . Wrap ( err , " " ) } labelSelector := " " + job . Name logs , err := tc . getLogs ( labelSelector ) if err != nil { return " " , errors . Wrap ( err , " " ) } return logs , nil }
runSSHJob creates and waits for a Kubernetes job to run.
runSSHJob creates and waits for a Kubernetes job to run .
// Create a job which runs the provided command via SSH // Wait for the job to complete then gather and return the pod output