Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Simplify signature of AnsibleExecution
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bshephar committed Nov 24, 2023
1 parent 9af0517 commit f752deb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/deployment/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 9 additions & 15 deletions pkg/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()),
},
},
}
Expand All @@ -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{}
Expand Down Expand Up @@ -156,7 +153,6 @@ func AnsibleExecution(
}

return nil

})

if err != nil {
Expand All @@ -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{}

Expand Down Expand Up @@ -200,5 +195,4 @@ func GetAnsibleExecution(ctx context.Context, helper *helper.Helper, obj client.
}

return ansibleEE, nil

}

0 comments on commit f752deb

Please sign in to comment.