Skip to content

Commit

Permalink
Use ansibleEE library instead of AnsibleEE v1 CR
Browse files Browse the repository at this point in the history
This change swaps out the use of the AnsibleEE custom resource for
a generic Go library implementation. This enables us to stop using the unnecessary
OpenStackAnsibleEE abstraction that we currently have around Kubernetes Jobs for
AnsibleEE executions.

Jira: https://issues.redhat.com/browse/OSPRH-8926
Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Jul 25, 2024
1 parent d5a74fd commit 696c586
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/go-playground/validator/v10"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -35,7 +36,6 @@ import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
deployment "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane"
dataplaneutil "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane/util"
Expand Down Expand Up @@ -427,6 +427,6 @@ func (r *OpenStackDataPlaneDeploymentReconciler) setHashes(
func (r *OpenStackDataPlaneDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&dataplanev1.OpenStackDataPlaneDeployment{}).
Owns(&ansibleeev1.OpenStackAnsibleEE{}).
Owns(&batchv1.Job{}).
Complete(r)
}
7 changes: 4 additions & 3 deletions controllers/dataplane/openstackdataplanenodeset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/go-playground/validator/v10"
"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -48,7 +49,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/serviceaccount"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
Expand Down Expand Up @@ -576,7 +576,8 @@ func checkDeployment(ctx context.Context, helper *helper.Helper,

// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackDataPlaneNodeSetReconciler) SetupWithManager(
ctx context.Context, mgr ctrl.Manager) error {
ctx context.Context, mgr ctrl.Manager,
) error {
// index for ConfigMaps listed on ansibleVarsFrom
if err := mgr.GetFieldIndexer().IndexField(ctx,
&dataplanev1.OpenStackDataPlaneNodeSet{}, "spec.ansibleVarsFrom.ansible.configMaps",
Expand Down Expand Up @@ -629,7 +630,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) SetupWithManager(
}
return ctrl.NewControllerManagedBy(mgr).
For(&dataplanev1.OpenStackDataPlaneNodeSet{}).
Owns(&ansibleeev1.OpenStackAnsibleEE{}).
Owns(&batchv1.Job{}).
Owns(&baremetalv1.OpenStackBaremetalSet{}).
Owns(&infranetworkv1.IPSet{}).
Owns(&infranetworkv1.DNSData{}).
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202304141430

// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.6.0_patches_tag)
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20240719064129-c0201810c8f5 //allow-merging

replace github.com/openstack-k8s-operators/lib-common/modules/ansible => github.com/bshephar/lib-common/modules/ansible v0.0.0-20240724052033-e8fa85ebec00
30 changes: 18 additions & 12 deletions pkg/dataplane/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"sort"
"strconv"

batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"

slices "golang.org/x/exp/slices"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -35,11 +38,9 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/lib-common/modules/storage"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
dataplaneutil "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane/util"
corev1 "k8s.io/api/core/v1"
)

// Deployer defines a data structure with all of the relevant objects required for a full deployment.
Expand Down Expand Up @@ -195,7 +196,7 @@ func (d *Deployer) ConditionalDeploy(
}

if nsConditions.IsFalse(readyCondition) {
var ansibleEE *ansibleeev1.OpenStackAnsibleEE
var ansibleEE *batchv1.Job
_, labelSelector := dataplaneutil.GetAnsibleExecutionNameAndLabels(&foundService, d.Deployment.Name, d.NodeSet.Name)
ansibleEE, err = dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, labelSelector)
if err != nil {
Expand All @@ -213,34 +214,39 @@ func (d *Deployer) ConditionalDeploy(
err.Error()))
}

if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusSucceeded {
if ansibleEE.Status.Succeeded != 0 {
log.Info(fmt.Sprintf("Condition %s ready", readyCondition))
nsConditions.Set(condition.TrueCondition(
readyCondition,
readyMessage))
}

if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusRunning || ansibleEE.Status.JobStatus == ansibleeev1.JobStatusPending {
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Status: %s", ansibleEE.Name, ansibleEE.Status.JobStatus))
if ansibleEE.Status.Succeeded == 0 || ansibleEE.Status.Active != 0 && ansibleEE.Status.Failed != 0 {
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Active pods: %d", ansibleEE.Name, ansibleEE.Status.Active))
nsConditions.Set(condition.FalseCondition(
readyCondition,
condition.RequestedReason,
condition.SeverityInfo,
readyWaitingMessage))
}

if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusFailed {
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s execution.status.jobstatus: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.JobStatus)
ansibleCondition := ansibleEE.Status.Conditions.Get(condition.ReadyCondition)
var ansibleCondition *batchv1.JobCondition
if ansibleEE.Status.Failed != 0 {
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s failed pods: %d", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.Failed)
for _, condition := range ansibleEE.Status.Conditions {
if condition.Type == batchv1.JobFailed {
ansibleCondition = &condition
}
}
if ansibleCondition.Reason == condition.JobReasonBackoffLimitExceeded {
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.status.jobstatus: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.JobStatus)
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.condition.message: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleCondition.Message)
}
log.Info(fmt.Sprintf("Condition %s error", readyCondition))
err = fmt.Errorf(errorMsg)
nsConditions.Set(condition.FalseCondition(
readyCondition,
ansibleCondition.Reason,
ansibleCondition.Severity,
condition.Reason(ansibleCondition.Reason),
condition.SeverityError,
readyErrorMessage,
err.Error()))
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/dataplane/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ type ServiceYAML struct {
// DeployService service deployment
func (d *Deployer) DeployService(foundService dataplanev1.OpenStackDataPlaneService) error {
err := dataplaneutil.AnsibleExecution(
d.Ctx,
d.Helper,
d.Deployment,
&foundService,
d.AnsibleSSHPrivateKeySecrets,
d.InventorySecrets,
d.AeeSpec,
d.NodeSet)

if err != nil {
d.Helper.GetLogger().Error(err, fmt.Sprintf("Unable to execute Ansible for %s", foundService.Name))
return err
Expand Down Expand Up @@ -160,8 +158,9 @@ func EnsureServices(ctx context.Context, helper *helper.Helper, instance *datapl
// Global Services in multiple NodeSets for a deployment
func DedupeServices(ctx context.Context, helper *helper.Helper,
nodesets []dataplanev1.OpenStackDataPlaneNodeSet,
serviceOverride []string) (map[string][]string, error) {
var nodeSetServiceMap = make(map[string][]string, 0)
serviceOverride []string,
) (map[string][]string, error) {
nodeSetServiceMap := make(map[string][]string, 0)
var globalServices []string
if len(serviceOverride) != 0 {
services, err := dedupe(ctx, helper, serviceOverride, globalServices)
Expand All @@ -182,7 +181,8 @@ func DedupeServices(ctx context.Context, helper *helper.Helper,
}

func dedupe(ctx context.Context, helper *helper.Helper,
services []string, globalServices []string) ([]string, error) {
services []string, globalServices []string,
) ([]string, error) {
var dedupedServices []string
var nodeSetServiceTypes []string
for _, svc := range services {
Expand Down
Loading

0 comments on commit 696c586

Please sign in to comment.