From f752debe6aadaa44ba1d876dc63ad7d8fb7e212c Mon Sep 17 00:00:00 2001 From: Brendan Shephard <bshephar@redhat.com> Date: Fri, 24 Nov 2023 13:33:27 +1000 Subject: [PATCH] Simplify signature of AnsibleExecution The current function definition takes multiple components of the service type resource. This change updates the function definition to instead take a pointer to the OpenStackDataPlaneService where we can then reference the various components. This simplifies the function signature and makes it easier to keep track of where code is coming from. Signed-off-by: Brendan Shephard <bshephar@redhat.com> --- pkg/deployment/service.go | 2 +- pkg/util/ansible_execution.go | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/deployment/service.go b/pkg/deployment/service.go index 2188f6dfd..1eb435a50 100644 --- a/pkg/deployment/service.go +++ b/pkg/deployment/service.go @@ -44,7 +44,7 @@ type ServiceYAML struct { // DeployService service deployment func DeployService(ctx context.Context, helper *helper.Helper, obj client.Object, sshKeySecret string, inventorySecret string, aeeSpec dataplanev1.AnsibleEESpec, foundService dataplanev1.OpenStackDataPlaneService) error { - err := dataplaneutil.AnsibleExecution(ctx, helper, obj, foundService.Spec.Label, sshKeySecret, inventorySecret, foundService.Spec.Play, foundService.Spec.Playbook, aeeSpec) + err := dataplaneutil.AnsibleExecution(ctx, helper, obj, &foundService, sshKeySecret, inventorySecret, aeeSpec) if err != nil { helper.GetLogger().Error(err, fmt.Sprintf("Unable to execute Ansible for %s", foundService.Name)) return err diff --git a/pkg/util/ansible_execution.go b/pkg/util/ansible_execution.go index 5598d57e3..61e24bb87 100644 --- a/pkg/util/ansible_execution.go +++ b/pkg/util/ansible_execution.go @@ -40,25 +40,22 @@ func AnsibleExecution( ctx context.Context, helper *helper.Helper, obj client.Object, - label string, + service *dataplanev1.OpenStackDataPlaneService, sshKeySecret string, inventorySecret string, - play string, - playbook string, aeeSpec dataplanev1.AnsibleEESpec, ) error { - var err error var cmdLineArguments strings.Builder - ansibleEE, err := GetAnsibleExecution(ctx, helper, obj, label) + ansibleEE, err := GetAnsibleExecution(ctx, helper, obj, service.Spec.Label) if err != nil && !k8serrors.IsNotFound(err) { return err } if ansibleEE == nil { var executionName string - if len(label) > 0 { - executionName = fmt.Sprintf("%s-%s", label, obj.GetName()) + if len(service.Spec.Label) > 0 { + executionName = fmt.Sprintf("%s-%s", service.Spec.Label, obj.GetName()) } else { executionName = obj.GetName() } @@ -67,7 +64,7 @@ func AnsibleExecution( Name: executionName, Namespace: obj.GetNamespace(), Labels: map[string]string{ - label: string(obj.GetUID()), + service.Spec.Label: string(obj.GetUID()), }, }, } @@ -94,11 +91,11 @@ func AnsibleExecution( ansibleEE.Spec.CmdLine = strings.TrimSpace(cmdLineArguments.String()) } - if len(play) > 0 { - ansibleEE.Spec.Play = play + if len(service.Spec.Play) > 0 { + ansibleEE.Spec.Play = service.Spec.Play } - if len(playbook) > 0 { - ansibleEE.Spec.Playbook = playbook + if len(service.Spec.Playbook) > 0 { + ansibleEE.Spec.Playbook = service.Spec.Playbook } ansibleEEMounts := storage.VolMounts{} @@ -156,7 +153,6 @@ func AnsibleExecution( } return nil - }) if err != nil { @@ -171,7 +167,6 @@ func AnsibleExecution( // label where <label>=<node UID> // If none is found, return nil func GetAnsibleExecution(ctx context.Context, helper *helper.Helper, obj client.Object, label string) (*ansibleeev1.OpenStackAnsibleEE, error) { - var err error ansibleEEs := &ansibleeev1.OpenStackAnsibleEEList{} @@ -200,5 +195,4 @@ func GetAnsibleExecution(ctx context.Context, helper *helper.Helper, obj client. } return ansibleEE, nil - }