Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Return an error if clusterSelector is not parsable
Browse files Browse the repository at this point in the history
  • Loading branch information
mgianluc committed Jan 11, 2024
1 parent 527e905 commit 77be3c7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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

.PHONY: all
all: build
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/addon-compliance-controller-amd64:main
- image: projectsveltos/addon-compliance-controller-amd64:dev
name: manager
8 changes: 6 additions & 2 deletions controllers/addoncompliance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,13 @@ func (r *AddonComplianceReconciler) getMatchingClusters(ctx context.Context,

logger.V(logs.LogDebug).Info("finding matching clusters")
var matchingCluster []corev1.ObjectReference
var err error

if addonConstraintScope.GetSelector() != "" {
parsedSelector, _ := labels.Parse(addonConstraintScope.GetSelector())
parsedSelector, err := labels.Parse(addonConstraintScope.GetSelector())
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to parse clusterSelector: %v", err))
return nil, err
}
matchingCluster, err = clusterproxy.GetMatchingClusters(ctx, r.Client, parsedSelector, "", logger)
if err != nil {
return nil, err
Expand Down
14 changes: 12 additions & 2 deletions controllers/addoncompliance_transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ func (r *AddonComplianceReconciler) requeueAddonComplianceForCluster(
// matching the Cluster
for k := range r.AddonCompliances {
addonConstraintSelector := r.AddonCompliances[k]
parsedSelector, _ := labels.Parse(string(addonConstraintSelector))
parsedSelector, err := labels.Parse(string(addonConstraintSelector))
if err != nil {
// When clusterSelector is fixed, this AddonCompliance instance
// will be reconciled
continue
}
if parsedSelector.Matches(labels.Set(cluster.GetLabels())) {
l := logger.WithValues("addonConstraint", k.Name)
l.V(logs.LogDebug).Info("queuing AddonCompliance")
Expand Down Expand Up @@ -249,7 +254,12 @@ func (r *AddonComplianceReconciler) requeueAddonComplianceForMachine(
// matching the Cluster
for k := range r.AddonCompliances {
addonConstraintSelector := r.AddonCompliances[k]
parsedSelector, _ := labels.Parse(string(addonConstraintSelector))
parsedSelector, err := labels.Parse(string(addonConstraintSelector))
if err != nil {
// When clusterSelector is fixed, this AddonCompliance instance
// will be reconciled
continue
}
if parsedSelector.Matches(labels.Set(clusterLabels)) {
l := logger.WithValues("addonConstraint", k.Name)
l.V(logs.LogDebug).Info("queuing AddonCompliance")
Expand Down
6 changes: 5 additions & 1 deletion controllers/sveltoscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ func addClusterEntry(ctx context.Context, c client.Client,
s := &libsveltosset.Set{}
for i := range addonConstraints.Items {
ac := &addonConstraints.Items[i]
parsedSelector, _ := labels.Parse(string(ac.Spec.ClusterSelector))
parsedSelector, err := labels.Parse(string(ac.Spec.ClusterSelector))
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to parse clusterSelector: %v", err))
return err
}
if parsedSelector.Matches(labels.Set(clusterLabels)) {
s.Insert(getKeyFromObject(c.Scheme(), ac))
}
Expand Down
2 changes: 1 addition & 1 deletion manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ spec:
- --v=5
command:
- /manager
image: projectsveltos/addon-compliance-controller-amd64:main
image: projectsveltos/addon-compliance-controller-amd64:dev
livenessProbe:
httpGet:
path: /healthz
Expand Down

0 comments on commit 77be3c7

Please sign in to comment.