Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: Build
run: make build
- name: FMT
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: ut
run: make test
env:
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: fv
run: make create-cluster fv
env:
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: fv-sharding
run: make create-cluster fv-sharding
env:
Expand All @@ -76,7 +76,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: fv-agentless
run: make create-cluster fv-agentless
env:
Expand All @@ -89,7 +89,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: 1.25.5
go-version: 1.25.6
- name: fv-pullmode
run: make create-cluster-pullmode fv-pullmode
env:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.25.5 AS builder
FROM golang:1.25.6 AS builder

ARG BUILDOS
ARG TARGETARCH
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Classifier currently supports the following classification criteria:
1. Kubernetes version
2. Kubernetes resources

For instance, this Classifier instance will match any cluster whose Kubernetes version is greater than or equal to "v1.24.0" and strictly less than "v1.25.5"
For instance, this Classifier instance will match any cluster whose Kubernetes version is greater than or equal to "v1.24.0" and strictly less than "v1.25.6"

```
apiVersion: lib.projectsveltos.io/v1beta1
Expand All @@ -31,7 +31,7 @@ spec:
- comparison: GreaterThanOrEqualTo
version: 1.24.0
- comparison: LessThan
version: 1.25.5
version: 1.25.6
```

When a cluster is a match for a Classifier instances, all classifierLabels will be automatically added to the Cluster instance.
Expand All @@ -45,8 +45,8 @@ Refer to [examples](./examples/) for more complex examples.
## A simple use case: upgrade helm charts automatically when Kubernetes cluster is upgraded
Suppose you are managing several Kubernetes clusters with different versions.
And you want to deploy:
1. OPA Gatekeeper version 3.10.0 in any Kubernetes cluster whose version is >= v1.25.5
2. OPA Gatekeeper version 3.9.0 in any Kubernetes cluster whose version is >= v1.24.0 && < v1.25.5
1. OPA Gatekeeper version 3.10.0 in any Kubernetes cluster whose version is >= v1.25.6
2. OPA Gatekeeper version 3.9.0 in any Kubernetes cluster whose version is >= v1.24.0 && < v1.25.6

You can create following ClusterProfiles and Classifiers in the management cluster:
```
Expand Down Expand Up @@ -102,7 +102,7 @@ spec:
value: v3-10
kubernetesVersionConstraints:
- comparison: GreaterThanOrEqualTo
version: 1.25.5
version: 1.25.6
```

```
Expand All @@ -118,7 +118,7 @@ spec:
- comparison: GreaterThanOrEqualTo
version: 1.24.0
- comparison: LessThan
version: 1.25.5
version: 1.25.6
```

With the above configuration:
Expand Down
5 changes: 3 additions & 2 deletions controllers/classifier_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ type ClassifierReconciler struct {

// List of current existing Classifiers
AllClassifierSet libsveltosset.Set

Logger logr.Logger
}

//+kubebuilder:rbac:groups=lib.projectsveltos.io,resources=classifiers,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -480,7 +482,7 @@ func (r *ClassifierReconciler) getMatchingClusters(ctx context.Context,
for i := range classifierReportList.Items {
report := &classifierReportList.Items[i]

// Only consider reports with ClusterNamespace set (type #2 in your logic)
// Only consider reports with ClusterNamespace set
if report.Spec.ClusterNamespace == "" {
continue
}
Expand Down Expand Up @@ -591,7 +593,6 @@ func (r *ClassifierReconciler) updateLabelsOnMatchingClusters(ctx context.Contex
}

clusterLogger := logger.WithValues("cluster", fmt.Sprintf("%s/%s", cluster.GetNamespace(), cluster.GetName()))

// Attempt to update labels on the physical cluster
if err := r.updateLabelsOnCluster(ctx, classifierScope, cluster, clusterproxy.GetClusterType(ref), clusterLogger); err != nil {
if !apierrors.IsNotFound(err) {
Expand Down
8 changes: 8 additions & 0 deletions controllers/classifier_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

classifierName := client.ObjectKey{
Expand Down Expand Up @@ -144,6 +145,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Deployer: dep,
Logger: logger,
}

// Because Classifier is currently deployed in a Cluster (Status.ClusterInfo is set
Expand Down Expand Up @@ -207,6 +209,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

classifierScope, err := scope.NewClassifierScope(scope.ClassifierScopeParams{
Expand Down Expand Up @@ -275,6 +278,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

classifierScope, err := scope.NewClassifierScope(scope.ClassifierScopeParams{
Expand Down Expand Up @@ -340,6 +344,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

classifierScope, err := scope.NewClassifierScope(scope.ClassifierScopeParams{
Expand Down Expand Up @@ -416,6 +421,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

classifierScope, err := scope.NewClassifierScope(scope.ClassifierScopeParams{
Expand Down Expand Up @@ -483,6 +489,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

oldMatches := map[corev1.ObjectReference]bool{clusterRef: true}
Expand Down Expand Up @@ -553,6 +560,7 @@ var _ = Describe("Classifier: Reconciler", func() {
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}

clusterRef := &corev1.ObjectReference{
Expand Down
6 changes: 6 additions & 0 deletions controllers/classifier_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,12 @@ func deployClassifierInstance(ctx context.Context, remoteClient client.Client,
logger.V(logs.LogDebug).Info("deploy classifier instance")

if !isPullMode {
if getAgentInMgmtCluster() {
// If sveltos-agent is deployed in the management cluster, Classifier instance
// does not need to be deployed in the managed cluster. So return here
return nil
}

currentClassifier := &libsveltosv1beta1.Classifier{}
err := remoteClient.Get(ctx, types.NamespacedName{Name: classifier.Name}, currentClassifier)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions controllers/classifier_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ func ClassifierReportPredicate(logger logr.Logger) predicate.Funcs {
return true
}

// return true if ClassifierReport.Spec.ClusterNamespace has changed
// This happens in agentless mode as sveltos
if oldReport.Spec.ClusterNamespace != newReport.Spec.ClusterNamespace {
log.V(logs.LogVerbose).Info(
"ClassifierReport Spec.ClusterNamespace changed. Will attempt to reconcile associated Classifiers.")
return true
}

// otherwise, return false
log.V(logs.LogVerbose).Info(
"ClassifierReport did not match expected conditions. Will not attempt to reconcile associated Classifiers.")
Expand Down
2 changes: 1 addition & 1 deletion controllers/classifier_transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (r *ClassifierReconciler) requeueClassifierForClassifierReport(
) []reconcile.Request {

report := o.(*libsveltosv1beta1.ClassifierReport)
logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1))).WithValues(
logger := r.Logger.WithValues(
"objectMapper",
"requeueClassifierForClassifierReport",
"namespace",
Expand Down
5 changes: 5 additions & 0 deletions controllers/classifier_transformations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/textlogger"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -90,11 +91,13 @@ var _ = Describe("ClassifierTransformations map functions", func() {
c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).
WithObjects(initObjects...).Build()

logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
reconciler := &controllers.ClassifierReconciler{
Client: c,
Scheme: scheme,
Mux: sync.Mutex{},
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Logger: logger,
}

set := libsveltosset.Set{}
Expand Down Expand Up @@ -143,11 +146,13 @@ var _ = Describe("ClassifierTransformations map functions", func() {
c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).
WithObjects(initObjects...).Build()

logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
reconciler := &controllers.ClassifierReconciler{
Client: c,
Scheme: scheme,
Mux: sync.Mutex{},
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Logger: logger,
}

requests := controllers.RequeueClassifierForClassifierReport(reconciler, context.TODO(), report)
Expand Down
7 changes: 5 additions & 2 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
"k8s.io/klog/v2/textlogger"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -184,15 +185,15 @@ func getClassifierReport(classifierName, clusterNamespace, clusterName string) *
}

func getClassifierInstance(name string) *libsveltosv1beta1.Classifier {
classifierLabels := []libsveltosv1beta1.ClassifierLabel{{Key: "version", Value: "v1.25.5"}}
classifierLabels := []libsveltosv1beta1.ClassifierLabel{{Key: "version", Value: "v1.25.6"}}
return &libsveltosv1beta1.Classifier{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: libsveltosv1beta1.ClassifierSpec{
KubernetesVersionConstraints: []libsveltosv1beta1.KubernetesVersionConstraint{
{
Version: "1.25.5",
Version: "1.25.6",
Comparison: string(libsveltosv1beta1.ComparisonEqual),
},
},
Expand All @@ -202,13 +203,15 @@ func getClassifierInstance(name string) *libsveltosv1beta1.Classifier {
}

func getClassifierReconciler(c client.Client, dep deployer.DeployerInterface) *controllers.ClassifierReconciler {
logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))
return &controllers.ClassifierReconciler{
Client: c,
Scheme: scheme,
Deployer: dep,
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
Mux: sync.Mutex{},
Logger: logger,
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/kubernetes_version.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Following Classifier will match any Cluster whose
# Kubernetes version is >= v1.24.0 and < v1.25.5
# Kubernetes version is >= v1.24.0 and < v1.25.6
apiVersion: lib.projectsveltos.io/v1beta1
kind: Classifier
metadata:
Expand All @@ -12,4 +12,4 @@ spec:
- comparison: GreaterThanOrEqualTo
version: 1.24.0
- comparison: LessThan
version: 1.25.5
version: 1.25.6
4 changes: 2 additions & 2 deletions examples/multiple_constraints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Following Classifier will match any Cluster whose
# Kubernetes version is >= v1.24.0 and < v1.25.5
# Kubernetes version is >= v1.24.0 and < v1.25.6
apiVersion: lib.projectsveltos.io/v1beta1
kind: Classifier
metadata:
Expand All @@ -10,7 +10,7 @@ spec:
value: multiple
kubernetesVersionConstraints:
- comparison: GreaterThanOrEqualTo
version: 1.25.5
version: 1.25.6
deployedResourceConstraint:
- group: ""
version: v1
Expand Down
Loading