// aPod4Attack generates the definition of the attack pod
aPod4Attack generates the definition of the attack pod
// aPod4Attack generates the definition of the attack pod
func (r *VegetaReconciler) aPod4Attack(v *vegetav1alpha1.Vegeta) *corev1.Pod {
	immediate := int64(0)
	volumes, mounts := getAPVolumesAndMounts(v)
	var image string
	if vImg := strings.TrimSpace(v.Spec.Image); vImg != "" {
		image = vImg
	} else {
		image = r.Image
	}
	pod := &corev1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			GenerateName: v.Name + "-",
			Namespace:    v.Namespace,
			Labels: r.Labels.Merge(map[string]string{
				"app.kubernetes.io/name":       "vegeta",
				"app.kubernetes.io/instance":   v.Name,
				"app.kubernetes.io/managed-by": "vegeta-operator",
				"vegeta.testing.io/type":       "attack"}),
		},
		Spec: corev1.PodSpec{
			Containers: []corev1.Container{{
				Image:           image,
				ImagePullPolicy: "Always",
				Name:            containerName,
				Command:         []string{"/bin/sh"},
				Args:            []string{"-c", getAttackCmd(v)},
				Resources:       v.Spec.Resources,
				VolumeMounts:    mounts,
				WorkingDir: resultsPath,
				Env:        getAttackEnv(v),
				EnvFrom:    getEnvFrom(v),
			}},
			RestartPolicy:                 "Never",
			Volumes:                       volumes,
			SecurityContext:               &corev1.PodSecurityContext{},
			TerminationGracePeriodSeconds: &immediate,
		},
	}
	ctrl.SetControllerReference(v, pod, r.Scheme)
	return pod
}
func ( r * VegetaReconciler ) aPod4Attack ( v * vegetav1alpha1 . Vegeta ) * corev1 . Pod { immediate := int64 ( 0 ) volumes , mounts := getAPVolumesAndMounts ( v ) var image string if vImg := strings . TrimSpace ( v . Spec . Image ) ; vImg != " " { image = vImg } else { image = r . Image } pod := & corev1 . Pod { ObjectMeta : metav1 . ObjectMeta { GenerateName : v . Name + " " , Namespace : v . Namespace , Labels : r . Labels . Merge ( map [ string ] string { " " : " " , " " : v . Name , " " : " " , " " : " " } ) , } , Spec : corev1 . PodSpec { Containers : [ ] corev1 . Container { { Image : image , ImagePullPolicy : " " , Name : containerName , Command : [ ] string { " " } , Args : [ ] string { " " , getAttackCmd ( v ) } , Resources : v . Spec . Resources , VolumeMounts : mounts , WorkingDir : resultsPath , Env : getAttackEnv ( v ) , EnvFrom : getEnvFrom ( v ) , } } , RestartPolicy : " " , Volumes : volumes , SecurityContext : & corev1 . PodSecurityContext { } , TerminationGracePeriodSeconds : & immediate , } , } ctrl . SetControllerReference ( v , pod , r . Scheme ) return pod }
aPod4Attack generates the definition of the attack pod
aPod4Attack generates the definition of the attack pod
// TODO: I am not sure this needs to be made configurable. What is defined in the image should be just fine. // Set Vegeta instance as the owner and controller