Skip to content

Commit

Permalink
Merge pull request #152 from gianlucam76/selector
Browse files Browse the repository at this point in the history
Return an error if clusterSelector is not parsable
  • Loading branch information
gianlucam76 authored Jan 11, 2024
2 parents 96fe79e + 229d989 commit ffad4da
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ARCH ?= amd64
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 ?= main
TAG ?= dev

## Tool Binaries
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
Expand Down
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: projectsveltos/event-manager-amd64:main
- image: projectsveltos/event-manager-amd64:dev
name: manager
6 changes: 5 additions & 1 deletion controllers/eventtrigger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ func (r *EventTriggerReconciler) reconcileNormal(
}
}

parsedSelector, _ := labels.Parse(eventTriggerScope.GetSelector())
parsedSelector, err := labels.Parse(eventTriggerScope.GetSelector())
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to parse clusterSelector: %v", err))
return reconcile.Result{}, err
}
matchingCluster, err := clusterproxy.GetMatchingClusters(ctx, r.Client, parsedSelector, "",
eventTriggerScope.Logger)
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions controllers/transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ func (r *EventTriggerReconciler) requeueEventTriggerForCluster(
// matching the Cluster
for k := range r.EventTriggers {
eventTriggerSelector := r.EventTriggers[k]
parsedSelector, _ := labels.Parse(string(eventTriggerSelector))
parsedSelector, err := labels.Parse(string(eventTriggerSelector))
if err != nil {
// When clusterSelector is fixed, this EventTrigger instance will
// be reconciled
continue
}
if parsedSelector.Matches(labels.Set(cluster.GetLabels())) {
l := logger.WithValues("eventTrigger", k.Name)
l.V(logs.LogDebug).Info("queuing EventTrigger")
Expand Down Expand Up @@ -195,7 +200,12 @@ func (r *EventTriggerReconciler) requeueEventTriggerForMachine(
// matching the Cluster
for k := range r.EventTriggers {
eventTriggerSelector := r.EventTriggers[k]
parsedSelector, _ := labels.Parse(string(eventTriggerSelector))
parsedSelector, err := labels.Parse(string(eventTriggerSelector))
if err != nil {
// When clusterSelector is fixed, this EventTrigger instance will
// be reconciled
continue
}
if parsedSelector.Matches(labels.Set(clusterLabels)) {
l := logger.WithValues("eventTrigger", k.Name)
l.V(logs.LogDebug).Info("queuing EventTrigger")
Expand Down
2 changes: 1 addition & 1 deletion manifest/deployment-shard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
- --v=5
command:
- /manager
image: projectsveltos/event-manager-amd64:main
image: projectsveltos/event-manager-amd64:dev
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ spec:
- --v=5
command:
- /manager
image: projectsveltos/event-manager-amd64:main
image: projectsveltos/event-manager-amd64:dev
livenessProbe:
httpGet:
path: /healthz
Expand Down

0 comments on commit ffad4da

Please sign in to comment.