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

Expose error handling services #519

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/bases/dataplane.openstack.org_openstackdataplaneservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ spec:
type: object
spec:
properties:
ansibleExtraVars:
properties:
ansibleAnyErrorsFatal:
default: false
type: boolean
ansibleMaxFailPercentage:
maximum: 100
minimum: 1
type: integer
type: object
configMaps:
items:
type: string
Expand Down
18 changes: 18 additions & 0 deletions api/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,29 @@ type OpenStackDataPlaneServiceSpec struct {
// +kubebuilder:validation:Optional
Secrets []string `json:"secrets,omitempty"`

// AnsibleExtraVars are error handling variables provided via the --extra-vars interface
// +kubebuilder:validation:Optional
AnsibleExtraVars AnsibleExtraVars `json:"ansibleExtraVars,omitempty"`

// OpenStackAnsibleEERunnerImage image to use as the ansibleEE runner image
// +kubebuilder:validation:Optional
OpenStackAnsibleEERunnerImage string `json:"openStackAnsibleEERunnerImage,omitempty" yaml:"openStackAnsibleEERunnerImage,omitempty"`
}

// AnsibleExtraVars are error handling variables provided via the --extra-vars interface
type AnsibleExtraVars 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
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=100
AnsibleMaxFailPercentage int `json:"ansibleMaxFailPercentage,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned safe defaults in the commit message but I don't see those defaults here. Where are they set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I need to update my wording there. We'll just fallback to what Ansible would do without these arguments provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


// AnsibleAnyErrorsFatal is used to tune service specific, any_errors_fatal
// +kubebuilder:default=false
AnsibleAnyErrorsFatal *bool `json:"ansibleAnyErrorsFatal,omitempty"`
}

// OpenStackDataPlaneServiceStatus defines the observed state of OpenStackDataPlaneService
type OpenStackDataPlaneServiceStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
Expand Down
21 changes: 21 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ spec:
type: object
spec:
properties:
ansibleExtraVars:
properties:
ansibleAnyErrorsFatal:
default: false
type: boolean
ansibleMaxFailPercentage:
maximum: 100
minimum: 1
type: integer
type: object
configMaps:
items:
type: string
Expand Down
13 changes: 13 additions & 0 deletions docs/openstack_dataplaneservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [AnsibleOpts](#ansibleopts)
* [NodeSection](#nodesection)
* [NodeTemplate](#nodetemplate)
* [AnsibleExtraVars](#ansibleextravars)
* [KubeService](#kubeservice)
* [OpenStackDataPlaneServiceList](#openstackdataplaneservicelist)
* [OpenStackDataPlaneServiceSpec](#openstackdataplaneservicespec)
Expand Down Expand Up @@ -76,6 +77,17 @@ NodeTemplate is a specification of the node attributes that override top level a

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

#### AnsibleExtraVars

AnsibleExtraVars are error handling variables provided via the --extra-vars interface

| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| 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)

#### KubeService

KubeService represents a Kubernetes Service. It is called like this to avoid the extreme overloading of the Service term in this context
Expand Down Expand Up @@ -124,6 +136,7 @@ OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneSer
| playbook | Playbook is a path to the playbook that ansible will run on this execution | string | false |
| 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 |
| ansibleExtraVars | AnsibleExtraVars are error handling variables provided via the --extra-vars interface | [AnsibleExtraVars](#ansibleextravars) | false |
| openStackAnsibleEERunnerImage | OpenStackAnsibleEERunnerImage image to use as the ansibleEE runner image | string | 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet!

if err != nil {
helper.GetLogger().Error(err, fmt.Sprintf("Unable to execute Ansible for %s", foundService.Name))
return err
Expand Down
32 changes: 17 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 @@ -90,15 +87,23 @@ func AnsibleExecution(
if len(aeeSpec.AnsibleSkipTags) > 0 {
fmt.Fprintf(&cmdLineArguments, "--skip-tags %s ", aeeSpec.AnsibleSkipTags)
}
if service.Spec.AnsibleExtraVars != (dataplanev1.AnsibleExtraVars{}) {
if service.Spec.AnsibleExtraVars.AnsibleMaxFailPercentage != 0 {
fmt.Fprintf(&cmdLineArguments, "--extra-vars edpm_max_fail_percentage=%d ", service.Spec.AnsibleExtraVars.AnsibleMaxFailPercentage)
}
if service.Spec.AnsibleExtraVars.AnsibleAnyErrorsFatal != nil && !*service.Spec.AnsibleExtraVars.AnsibleAnyErrorsFatal {
fmt.Fprintf(&cmdLineArguments, "--extra-vars edpm_any_errors_fatal=%t ", *service.Spec.AnsibleExtraVars.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 Expand Up @@ -156,7 +161,6 @@ func AnsibleExecution(
}

return nil

})

if err != nil {
Expand All @@ -171,7 +175,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 +203,4 @@ func GetAnsibleExecution(ctx context.Context, helper *helper.Helper, obj client.
}

return ansibleEE, nil

}
Loading