Skip to content

Commit

Permalink
[FEATURE] - Cloud Resources Reconciles on Plan Changes (#856)
Browse files Browse the repository at this point in the history
Given the addition of the available update status, it's useful to reconcile on changes to the plan as it can keep the field in sync. This PR adds to the cloud resource controller the abilty to reconcile all cloud resource which reference a plan X, when plan X has a generational change
gambol99 authored Jun 21, 2023
1 parent be38462 commit 5e0fb3a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/controller/cloudresource/controller.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
package cloudresource

import (
"context"
"fmt"

log "github.com/sirupsen/logrus"
@@ -76,6 +77,40 @@ func (c *Controller) Add(mgr manager.Manager) error {
&predicate.GenerationChangedPredicate{},
&predicate.ResourceVersionChangedPredicate{},
)).
Watches(
&source.Kind{Type: &terraformv1alpha1.Plan{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
list := &terraformv1alpha1.CloudResourceList{}
if err := c.cc.List(context.Background(), list,
client.MatchingLabels(map[string]string{
terraformv1alpha1.CloudResourcePlanNameLabel: o.GetName(),
}),
); err != nil {
log.WithError(err).Error("failed to list cloudresources")

return nil
}
if len(list.Items) == 0 {
return nil
}

var requests []reconcile.Request

for _, x := range list.Items {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: x.Name,
Namespace: x.Namespace,
},
})
}

return requests
}),
builder.WithPredicates(
&predicate.GenerationChangedPredicate{},
),
).
Watches(
&source.Kind{Type: &terraformv1alpha1.Configuration{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {

0 comments on commit 5e0fb3a

Please sign in to comment.