Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - Cloud Resources Reconciles on Plan Changes #856

Merged
merged 1 commit into from
Jun 21, 2023
Merged
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
35 changes: 35 additions & 0 deletions pkg/controller/cloudresource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cloudresource

import (
"context"
"fmt"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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 {
Expand Down