Skip to content

Commit

Permalink
Merge pull request #261 from gianlucam76/release-0.38
Browse files Browse the repository at this point in the history
Release 0.38.4
  • Loading branch information
gianlucam76 authored Sep 27, 2024
2 parents 009fa09 + 7d154ea commit e5b1ab7
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ARCH ?= $(shell go env GOARCH)
OS ?= $(shell uname -s | tr A-Z a-z)
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v0.38.3
TAG ?= v0.38.4

## Tool Binaries
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ spec:
- "--diagnostics-address=:8443"
- "--shard-key="
- "--v=5"
- "--version=v0.38.3"
- "--version=v0.38.4"
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: docker.io/projectsveltos/event-manager:v0.38.3
- image: docker.io/projectsveltos/event-manager:v0.38.4
name: manager
6 changes: 6 additions & 0 deletions controllers/eventtrigger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ func (r *EventTriggerReconciler) SetupWithManager(mgr ctrl.Manager) (controller.
EventReportPredicates(mgr.GetLogger().WithValues("predicate", "eventreportpredicate")),
),
).
Watches(&libsveltosv1beta1.EventSource{},
handler.EnqueueRequestsFromMapFunc(r.requeueEventTriggerForEventSource),
builder.WithPredicates(
EventSourcePredicates(mgr.GetLogger().WithValues("predicate", "eventsourcepredicate")),
),
).
Build(r)
if err != nil {
return nil, errors.Wrap(err, "error creating controller")
Expand Down
56 changes: 56 additions & 0 deletions controllers/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,62 @@ func EventReportPredicates(logger logr.Logger) predicate.Funcs {
}
}

// EventSourcePredicates predicates for EventSource. EventTriggerReconciler watches sveltos
// EventSource and react to those by reconciling itself based on following predicates
func EventSourcePredicates(logger logr.Logger) predicate.Funcs {
return predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
newES := e.ObjectNew.(*libsveltosv1beta1.EventSource)
oldES := e.ObjectOld.(*libsveltosv1beta1.EventSource)
log := logger.WithValues("predicate", "updateEvent",
"eventSource", newES.Name,
)

if oldES == nil {
log.V(logs.LogVerbose).Info("Old EventSource is nil. Reconcile EventTrigger")
return true
}

// return true if EventSource Spec has changed
if !reflect.DeepEqual(oldES.Spec, newES.Spec) {
log.V(logs.LogVerbose).Info(
"EventSource changed. Will attempt to reconcile associated EventTriggers.")
return true
}

// otherwise, return false
log.V(logs.LogVerbose).Info(
"EventSource did not match expected conditions. Will not attempt to reconcile associated EventTriggers.")
return false
},
CreateFunc: func(e event.CreateEvent) bool {
log := logger.WithValues("predicate", "createEvent",
"eventSource", e.Object.GetName(),
)

log.V(logs.LogVerbose).Info(
"EventSource did match expected conditions. Will attempt to reconcile associated EventTriggers.")
return true
},
DeleteFunc: func(e event.DeleteEvent) bool {
log := logger.WithValues("predicate", "deleteEvent",
"eventSource", e.Object.GetName(),
)
log.V(logs.LogVerbose).Info(
"EventSource deleted. Will attempt to reconcile associated EventTriggers.")
return true
},
GenericFunc: func(e event.GenericEvent) bool {
log := logger.WithValues("predicate", "genericEvent",
"eventSource", e.Object.GetName(),
)
log.V(logs.LogVerbose).Info(
"EventSource did not match expected conditions. Will not attempt to reconcile associated EventTriggers.")
return false
},
}
}

// ClusterSetPredicates predicates for ClusterSet. EventTriggerReconciler watches ClusterSet events
// and react to those by reconciling itself based on following predicates
func ClusterSetPredicates(logger logr.Logger) predicate.Funcs {
Expand Down
94 changes: 94 additions & 0 deletions controllers/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,97 @@ var _ = Describe("EventTrigger Predicates: EventReportPredicates", func() {
Expect(result).To(BeFalse())
})
})

var _ = Describe("EventTrigger Predicates: EventSourcePredicates", func() {
var logger logr.Logger
var eventSource *libsveltosv1beta1.EventSource

const upstreamClusterNamePrefix = "eventsource-predicates-"

BeforeEach(func() {
logger = textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
eventSource = &libsveltosv1beta1.EventSource{
ObjectMeta: metav1.ObjectMeta{
Name: upstreamClusterNamePrefix + randomString(),
Namespace: predicates + randomString(),
},
}
})

It("Create will reprocesses", func() {
esPredicate := controllers.EventSourcePredicates(logger)

e := event.CreateEvent{
Object: eventSource,
}

result := esPredicate.Create(e)
Expect(result).To(BeTrue())
})
It("Delete does reprocess ", func() {
esPredicate := controllers.EventSourcePredicates(logger)

e := event.DeleteEvent{
Object: eventSource,
}

result := esPredicate.Delete(e)
Expect(result).To(BeTrue())
})
It("Update reprocesses when eventSource spec changes", func() {
esPredicate := controllers.EventSourcePredicates(logger)

eventSource.Spec = libsveltosv1beta1.EventSourceSpec{
ResourceSelectors: []libsveltosv1beta1.ResourceSelector{
{
Group: randomString(),
Kind: randomString(),
Namespace: randomString(),
},
},
}

oldEventSource := &libsveltosv1beta1.EventSource{
ObjectMeta: metav1.ObjectMeta{
Name: eventSource.Name,
},
}

e := event.UpdateEvent{
ObjectNew: eventSource,
ObjectOld: oldEventSource,
}

result := esPredicate.Update(e)
Expect(result).To(BeTrue())
})

It("Update does not reprocesses EventSource spec has not changed", func() {
esPredicate := controllers.EventSourcePredicates(logger)

eventSource.Spec = libsveltosv1beta1.EventSourceSpec{
ResourceSelectors: []libsveltosv1beta1.ResourceSelector{
{
Group: randomString(),
Kind: randomString(),
Namespace: randomString(),
},
},
}

oldEventSource := &libsveltosv1beta1.EventSource{
ObjectMeta: metav1.ObjectMeta{
Name: eventSource.Name,
},
Spec: eventSource.Spec,
}

e := event.UpdateEvent{
ObjectNew: eventSource,
ObjectOld: oldEventSource,
}

result := esPredicate.Update(e)
Expect(result).To(BeFalse())
})
})
32 changes: 32 additions & 0 deletions controllers/transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ func (r *EventTriggerReconciler) requeueEventTriggerForEventReport(
return requests
}

func (r *EventTriggerReconciler) requeueEventTriggerForEventSource(
ctx context.Context, o client.Object,
) []reconcile.Request {

eventSource := o.(*libsveltosv1beta1.EventSource)
logger := r.Logger.WithValues("eventSource", eventSource.GetName())

logger.V(logs.LogDebug).Info("reacting to eventSource change")

r.Mux.Lock()
defer r.Mux.Unlock()

eventSourceInfo := corev1.ObjectReference{APIVersion: libsveltosv1beta1.GroupVersion.String(),
Kind: libsveltosv1beta1.EventSourceKind, Name: eventSource.Name}

// Get all EventTriggers referencing this EventSource
requests := make([]ctrl.Request, getConsumersForEntry(r.EventSourceMap, &eventSourceInfo).Len())
consumers := getConsumersForEntry(r.EventSourceMap, &eventSourceInfo).Items()

for i := range consumers {
l := logger.WithValues("eventTrigger", consumers[i].Name)
l.V(logs.LogDebug).Info("queuing EventTrigger")
requests[i] = ctrl.Request{
NamespacedName: client.ObjectKey{
Name: consumers[i].Name,
},
}
}

return requests
}

func (r *EventTriggerReconciler) requeueEventTriggerForSveltosCluster(
ctx context.Context, o client.Object,
) []reconcile.Request {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/pkg/errors v0.9.1
github.com/projectsveltos/addon-controller v0.38.3
github.com/projectsveltos/libsveltos v0.38.3
github.com/projectsveltos/addon-controller v0.38.4
github.com/projectsveltos/libsveltos v0.38.4
github.com/prometheus/client_golang v1.20.4
github.com/spf13/pflag v1.0.5
golang.org/x/text v0.18.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/projectsveltos/addon-controller v0.38.3 h1:Al42YV6vCp1dbbgW2+gL0dCnLtkyhQG+eavjGVNAbb8=
github.com/projectsveltos/addon-controller v0.38.3/go.mod h1:2NH4aH+iHk5nYnePHaBU/9l4XZ1pF9bwOM9iymrvJQ0=
github.com/projectsveltos/libsveltos v0.38.3 h1:LcNeAwEJWuez9CP2Z5D++i9GUJUPQcqBllPLsCTRCCE=
github.com/projectsveltos/libsveltos v0.38.3/go.mod h1:FITu0ZxiB0lfPVfFkIKJ9rk/ZWDup1OTymiIX+uEXtw=
github.com/projectsveltos/addon-controller v0.38.4 h1:EiRy3RJA+DJQhyhJ56+NMB5E+46zU0wcz1KoOuZdDHc=
github.com/projectsveltos/addon-controller v0.38.4/go.mod h1:4Ey8ChJPQd+14402V9yMSO/8ITMWA5R1tlZOaZmrKEw=
github.com/projectsveltos/libsveltos v0.38.4 h1:vOV1mmcUYoNrTyU7Vv8bppvk+5NFOXfzJMgLnVgDNDc=
github.com/projectsveltos/libsveltos v0.38.4/go.mod h1:FITu0ZxiB0lfPVfFkIKJ9rk/ZWDup1OTymiIX+uEXtw=
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand Down
4 changes: 2 additions & 2 deletions manifest/deployment-shard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ spec:
- --diagnostics-address=:8443
- --shard-key={{.SHARD}}
- --v=5
- --version=v0.38.3
- --version=v0.38.4
command:
- /manager
image: docker.io/projectsveltos/event-manager:v0.38.3
image: docker.io/projectsveltos/event-manager:v0.38.4
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2406,10 +2406,10 @@ spec:
- --diagnostics-address=:8443
- --shard-key=
- --v=5
- --version=v0.38.3
- --version=v0.38.4
command:
- /manager
image: docker.io/projectsveltos/event-manager:v0.38.3
image: docker.io/projectsveltos/event-manager:v0.38.4
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down

0 comments on commit e5b1ab7

Please sign in to comment.