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

Commit

Permalink
Add handling for max_fail_percentage and any_errors_fatal
Browse files Browse the repository at this point in the history
This change adds handling for the max_fail_percentage and
any_errors_fatal arguments. These are provided via --extra-vars as
edpm_max_fail_percentage and edpm_any_errors_fatal when used on the
OpenStackDataPlaneService CR's. Else, they can be provided globally to
all services like any other Ansible variable under ansibleVars on the
OpenStackDataPlaneNodeSet.

If values are not provided, or values are removed. Then we will default
to Ansible default values.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Nov 20, 2023
1 parent a7a5f65 commit b519434
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ spec:
type: object
spec:
properties:
ansibleAnyErrorsFatal:
type: boolean
ansibleMaxFailPercentage:
maximum: 100
minimum: 1
type: integer
configMaps:
items:
type: string
Expand Down
8 changes: 5 additions & 3 deletions api/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ type OpenStackDataPlaneServiceSpec struct {
// AnsibleMaxFailPercentage is used to tune service specific, allowable failure percentages during the Ansible execution
// https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#setting-a-maximum-failure-percentage
// +kubebuilder:validation:Optional
AnsibleMaxFailPercentage int64 `json:"ansibleMaxFailPercentage,omitempty"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=100
AnsibleMaxFailPercentage int `json:"ansibleMaxFailPercentage,omitempty"`

// AnyErrorsFatal is used to tune service specific, any_errors_fatal
// AnsibleAnyErrorsFatal is used to tune service specific, any_errors_fatal
// +kubebuilder:validation:Optional
AnyErrorsFatal bool `json:"anyErrorsFatal,omitempty"`
AnsibleAnyErrorsFatal *bool `json:"ansibleAnyErrorsFatal,omitempty"`
}

// OpenStackDataPlaneServiceStatus defines the observed state of OpenStackDataPlaneService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ spec:
type: object
spec:
properties:
ansibleAnyErrorsFatal:
type: boolean
ansibleMaxFailPercentage:
maximum: 100
minimum: 1
type: integer
configMaps:
items:
type: string
Expand Down
2 changes: 2 additions & 0 deletions docs/openstack_dataplaneservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneSer
| configMaps | ConfigMaps list of ConfigMap names to mount as ExtraMounts for the OpenStackAnsibleEE | []string | false |
| secrets | Secrets list of Secret names to mount as ExtraMounts for the OpenStackAnsibleEE | []string | false |
| openStackAnsibleEERunnerImage | OpenStackAnsibleEERunnerImage image to use as the ansibleEE runner image | string | false |
| ansibleMaxFailPercentage | AnsibleMaxFailPercentage is used to tune service specific, allowable failure percentages during the Ansible execution https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_error_handling.html#setting-a-maximum-failure-percentage | int | false |
| ansibleAnyErrorsFatal | AnsibleAnyErrorsFatal is used to tune service specific, any_errors_fatal | bool | false |

[Back to Custom Resources](#custom-resources)

Expand Down
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
26 changes: 15 additions & 11 deletions pkg/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,23 @@ 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 +65,7 @@ func AnsibleExecution(
Name: executionName,
Namespace: obj.GetNamespace(),
Labels: map[string]string{
label: string(obj.GetUID()),
service.Spec.Label: string(obj.GetUID()),
},
},
}
Expand All @@ -90,15 +88,21 @@ func AnsibleExecution(
if len(aeeSpec.AnsibleSkipTags) > 0 {
fmt.Fprintf(&cmdLineArguments, "--skip-tags %s ", aeeSpec.AnsibleSkipTags)
}
if service.Spec.AnsibleMaxFailPercentage != 0 {
fmt.Fprintf(&cmdLineArguments, "--extra-vars edpm_max_fail_percentage=%d ", service.Spec.AnsibleMaxFailPercentage)
}
if !service.Spec.AnsibleAnyErrorsFatal {

Check failure on line 94 in pkg/util/ansible_execution.go

View workflow job for this annotation

GitHub Actions / github (govet, golint and gotest)

invalid operation: operator ! not defined on service.Spec.AnsibleAnyErrorsFatal (variable of type *bool)
fmt.Fprintf(&cmdLineArguments, "--extra-vars edpm_any_errors_fatal=%t ", service.Spec.AnsibleAnyErrorsFatal)
}
if cmdLineArguments.Len() > 0 {
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

0 comments on commit b519434

Please sign in to comment.