Skip to content

Commit 1cc44ce

Browse files
committed
Refactor AnsibleTest code
By working on AnsibleTest changes I have encountered code that is more complicated than its usage. This patch aims to simplify the code with leaving the functionality as it is.
1 parent 485c390 commit 1cc44ce

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

controllers/ansibletest_controller.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
206206
// Create a new pod
207207
mountCerts := r.CheckSecretExists(ctx, instance, "combined-ca-bundle")
208208
podName := r.GetPodName(instance, nextWorkflowStep)
209-
envVars, workflowOverrideParams := r.PrepareAnsibleEnv(instance)
209+
envVars := r.PrepareAnsibleEnv(instance)
210210
logsPVCName := r.GetPVCLogsName(instance, 0)
211-
containerImage, err := r.GetContainerImage(ctx, workflowOverrideParams["ContainerImage"], instance)
211+
containerImage, err := r.GetContainerImage(ctx, instance.Spec.ContainerImage, instance)
212212
if err != nil {
213213
return ctrl.Result{}, err
214214
}
@@ -220,7 +220,6 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
220220
logsPVCName,
221221
mountCerts,
222222
envVars,
223-
workflowOverrideParams,
224223
nextWorkflowStep,
225224
containerImage,
226225
)
@@ -267,23 +266,12 @@ func (r *AnsibleTestReconciler) SetupWithManager(mgr ctrl.Manager) error {
267266
// This function prepares env variables for a single workflow step.
268267
func (r *AnsibleTestReconciler) PrepareAnsibleEnv(
269268
instance *testv1beta1.AnsibleTest,
270-
) (map[string]env.Setter, map[string]string) {
269+
) map[string]env.Setter {
271270
// Prepare env vars
272271
envVars := make(map[string]env.Setter)
273-
workflowOverrideParams := make(map[string]string)
274-
275-
// volumes workflow override
276-
workflowOverrideParams["WorkloadSSHKeySecretName"] = instance.Spec.WorkloadSSHKeySecretName
277-
workflowOverrideParams["ComputeSSHKeySecretName"] = instance.Spec.ComputeSSHKeySecretName
278-
workflowOverrideParams["ContainerImage"] = instance.Spec.ContainerImage
279272

280273
// bool
281-
debug := instance.Spec.Debug
282-
if debug {
283-
envVars["POD_DEBUG"] = env.SetValue("true")
284-
} else {
285-
envVars["POD_DEBUG"] = env.SetValue("false")
286-
}
274+
envVars["POD_DEBUG"] = env.SetValue(strconv.FormatBool(instance.Spec.Debug))
287275

288276
// strings
289277
envVars["POD_ANSIBLE_EXTRA_VARS"] = env.SetValue(instance.Spec.AnsibleExtraVars)
@@ -293,5 +281,5 @@ func (r *AnsibleTestReconciler) PrepareAnsibleEnv(
293281
envVars["POD_ANSIBLE_PLAYBOOK"] = env.SetValue(instance.Spec.AnsiblePlaybookPath)
294282
envVars["POD_INSTALL_COLLECTIONS"] = env.SetValue(instance.Spec.AnsibleCollections)
295283

296-
return envVars, workflowOverrideParams
284+
return envVars
297285
}

pkg/ansibletest/pod.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func Pod(
1717
logsPVCName string,
1818
mountCerts bool,
1919
envVars map[string]env.Setter,
20-
workflowOverrideParams map[string]string,
2120
externalWorkflowCounter int,
2221
containerImage string,
2322
) *corev1.Pod {
@@ -60,7 +59,6 @@ func Pod(
6059
logsPVCName,
6160
mountCerts,
6261
AnsibleTestPropagation,
63-
workflowOverrideParams,
6462
externalWorkflowCounter,
6563
),
6664
},

pkg/ansibletest/volumes.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ func GetVolumes(
1313
logsPVCName string,
1414
mountCerts bool,
1515
svc []storage.PropagationType,
16-
workflowOverrideParams map[string]string,
1716
externalWorkflowCounter int,
1817
) []corev1.Volume {
1918

@@ -85,20 +84,20 @@ func GetVolumes(
8584
Name: "compute-ssh-secret",
8685
VolumeSource: corev1.VolumeSource{
8786
Secret: &corev1.SecretVolumeSource{
88-
SecretName: workflowOverrideParams["ComputeSSHKeySecretName"],
87+
SecretName: instance.Spec.ComputeSSHKeySecretName,
8988
DefaultMode: &privateKeyMode,
9089
},
9190
},
9291
}
9392

9493
volumes = append(volumes, keysVolume)
9594

96-
if workflowOverrideParams["WorkloadSSHKeySecretName"] != "" {
95+
if instance.Spec.WorkloadSSHKeySecretName != "" {
9796
keysVolume = corev1.Volume{
9897
Name: "workload-ssh-secret",
9998
VolumeSource: corev1.VolumeSource{
10099
Secret: &corev1.SecretVolumeSource{
101-
SecretName: workflowOverrideParams["WorkloadSSHKeySecretName"],
100+
SecretName: instance.Spec.WorkloadSSHKeySecretName,
102101
DefaultMode: &privateKeyMode,
103102
},
104103
},

0 commit comments

Comments
 (0)