Skip to content

Commit df03103

Browse files
author
Brendan Shephard
committed
Use ansibleEE library instead of AnsibleEE v1 CR
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 <bshephar@redhat.com>
1 parent a02af25 commit df03103

7 files changed

Lines changed: 187 additions & 191 deletions

File tree

‎config/rbac/role.yaml‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ rules:
8282
- patch
8383
- update
8484
- watch
85-
- apiGroups:
86-
- ansibleee.openstack.org
87-
resources:
88-
- openstackansibleees
89-
verbs:
90-
- create
91-
- delete
92-
- get
93-
- list
94-
- patch
95-
- update
96-
- watch
9785
- apiGroups:
9886
- barbican.openstack.org
9987
resources:

‎controllers/dataplane/openstackdataplanedeployment_controller.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-playground/validator/v10"
25+
batchv1 "k8s.io/api/batch/v1"
2526
corev1 "k8s.io/api/core/v1"
2627
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2728
"k8s.io/apimachinery/pkg/runtime"
@@ -40,7 +41,6 @@ import (
4041
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4142
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4243
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
43-
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
4444
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
4545
deployment "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane"
4646
dataplaneutil "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane/util"
@@ -63,7 +63,6 @@ func (r *OpenStackDataPlaneDeploymentReconciler) GetLogger(ctx context.Context)
6363
// +kubebuilder:rbac:groups=dataplane.openstack.org,resources=openstackdataplanedeployments/finalizers,verbs=update;patch
6464
// +kubebuilder:rbac:groups=dataplane.openstack.org,resources=openstackdataplanenodesets,verbs=get;list;watch
6565
// +kubebuilder:rbac:groups=dataplane.openstack.org,resources=openstackdataplaneservices,verbs=get;list;watch
66-
// +kubebuilder:rbac:groups=ansibleee.openstack.org,resources=openstackansibleees,verbs=get;list;watch;create;update;patch;delete
6766
// +kubebuilder:rbac:groups=discovery.k8s.io,resources=endpointslices,verbs=get;list;watch;create;update;patch;delete;
6867
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;
6968
// +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete;
@@ -494,7 +493,7 @@ func (r *OpenStackDataPlaneDeploymentReconciler) SetupWithManager(mgr ctrl.Manag
494493
predicate.GenerationChangedPredicate{},
495494
predicate.AnnotationChangedPredicate{},
496495
predicate.LabelChangedPredicate{}))).
497-
Owns(&ansibleeev1.OpenStackAnsibleEE{}).
496+
Owns(&batchv1.Job{}).
498497
Watches(&certmgrv1.Certificate{},
499498
handler.EnqueueRequestsFromMapFunc(certFn)).
500499
Complete(r)

‎controllers/dataplane/openstackdataplanenodeset_controller.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/go-playground/validator/v10"
2626
"golang.org/x/exp/slices"
27+
batchv1 "k8s.io/api/batch/v1"
2728
corev1 "k8s.io/api/core/v1"
2829
rbacv1 "k8s.io/api/rbac/v1"
2930
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
@@ -48,7 +49,6 @@ import (
4849
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
4950
"github.com/openstack-k8s-operators/lib-common/modules/common/serviceaccount"
5051
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
51-
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
5252
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
5353
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
5454
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
@@ -622,7 +622,7 @@ func (r *OpenStackDataPlaneNodeSetReconciler) SetupWithManager(
622622
predicate.GenerationChangedPredicate{},
623623
predicate.AnnotationChangedPredicate{},
624624
predicate.LabelChangedPredicate{}))).
625-
Owns(&ansibleeev1.OpenStackAnsibleEE{}).
625+
Owns(&batchv1.Job{}).
626626
Owns(&baremetalv1.OpenStackBaremetalSet{}).
627627
Owns(&infranetworkv1.IPSet{}).
628628
Owns(&infranetworkv1.DNSData{}).

‎pkg/dataplane/deployment.go‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import (
2626
"sort"
2727
"strconv"
2828

29+
batchv1 "k8s.io/api/batch/v1"
30+
corev1 "k8s.io/api/core/v1"
31+
2932
slices "golang.org/x/exp/slices"
3033
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
3134
"k8s.io/apimachinery/pkg/types"
@@ -37,11 +40,9 @@ import (
3740
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3841
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
3942
"github.com/openstack-k8s-operators/lib-common/modules/storage"
40-
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
4143
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
4244
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
4345
dataplaneutil "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane/util"
44-
corev1 "k8s.io/api/core/v1"
4546
)
4647

4748
// Deployer defines a data structure with all of the relevant objects required for a full deployment.
@@ -197,13 +198,13 @@ func (d *Deployer) ConditionalDeploy(
197198
}
198199

199200
if nsConditions.IsFalse(readyCondition) {
200-
var ansibleEE *ansibleeev1.OpenStackAnsibleEE
201+
var ansibleEE *batchv1.Job
201202
_, labelSelector := dataplaneutil.GetAnsibleExecutionNameAndLabels(&foundService, d.Deployment.Name, d.NodeSet.Name)
202203
ansibleEE, err = dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, labelSelector)
203204
if err != nil {
204205
// Return nil if we don't have AnsibleEE available yet
205206
if k8s_errors.IsNotFound(err) {
206-
log.Info(fmt.Sprintf("%s OpenStackAnsibleEE not yet found", readyCondition))
207+
log.Info(fmt.Sprintf("%s AnsibleEE job is not yet found", readyCondition))
207208
return nil
208209
}
209210
log.Error(err, fmt.Sprintf("Error getting ansibleEE job for %s", deployName))
@@ -215,34 +216,39 @@ func (d *Deployer) ConditionalDeploy(
215216
err.Error()))
216217
}
217218

218-
if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusSucceeded {
219+
if ansibleEE.Status.Succeeded > 0 {
219220
log.Info(fmt.Sprintf("Condition %s ready", readyCondition))
220221
nsConditions.Set(condition.TrueCondition(
221222
readyCondition,
222223
readyMessage))
223224
}
224225

225-
if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusRunning || ansibleEE.Status.JobStatus == ansibleeev1.JobStatusPending {
226-
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Status: %s", ansibleEE.Name, ansibleEE.Status.JobStatus))
226+
if ansibleEE.Status.Active > 0 {
227+
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Active pods: %d", ansibleEE.Name, ansibleEE.Status.Active))
227228
nsConditions.Set(condition.FalseCondition(
228229
readyCondition,
229230
condition.RequestedReason,
230231
condition.SeverityInfo,
231232
readyWaitingMessage))
232233
}
233234

234-
if ansibleEE.Status.JobStatus == ansibleeev1.JobStatusFailed {
235-
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s execution.status.jobstatus: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.JobStatus)
236-
ansibleCondition := ansibleEE.Status.Conditions.Get(condition.ReadyCondition)
235+
var ansibleCondition *batchv1.JobCondition
236+
if ansibleEE.Status.Failed > 0 {
237+
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s failed pods: %d", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.Failed)
238+
for _, condition := range ansibleEE.Status.Conditions {
239+
if condition.Type == batchv1.JobFailed {
240+
ansibleCondition = &condition
241+
}
242+
}
237243
if ansibleCondition.Reason == condition.JobReasonBackoffLimitExceeded {
238-
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.status.jobstatus: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.JobStatus)
244+
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.condition.message: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleCondition.Message)
239245
}
240246
log.Info(fmt.Sprintf("Condition %s error", readyCondition))
241247
err = fmt.Errorf(errorMsg)
242248
nsConditions.Set(condition.FalseCondition(
243249
readyCondition,
244-
ansibleCondition.Reason,
245-
ansibleCondition.Severity,
250+
condition.Reason(ansibleCondition.Reason),
251+
condition.SeverityError,
246252
readyErrorMessage,
247253
err.Error()))
248254
}

‎pkg/dataplane/service.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func (d *Deployer) DeployService(foundService dataplanev1.OpenStackDataPlaneServ
5555
d.InventorySecrets,
5656
d.AeeSpec,
5757
d.NodeSet)
58-
5958
if err != nil {
6059
d.Helper.GetLogger().Error(err, fmt.Sprintf("Unable to execute Ansible for %s", foundService.Name))
6160
return err

0 commit comments

Comments
 (0)