Skip to content

Commit

Permalink
🌱 Add option to skip rancher pre-requisites (#705)
Browse files Browse the repository at this point in the history
* Add option to skip rancher pre-requisites

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>

* Pass maxDuration flag to each controller, preventing ctx cancel

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>

---------

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev authored Sep 2, 2024
1 parent fa89da1 commit 911323f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions charts/rancher-turtles/templates/pre-install-job.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if index .Values "rancherTurtles" "features" "embedded-capi" "disabled" }}
{{- if index .Values "rancherTurtles" "rancherInstalled"}}
---
apiVersion: management.cattle.io/v3
kind: Feature
Expand All @@ -10,6 +11,7 @@ metadata:
spec:
value: false
{{- end }}
{{- end }}
{{- if index .Values "rancherTurtles" "features" "rancher-webhook" "cleanup" }}
---
apiVersion: v1
Expand Down
1 change: 1 addition & 0 deletions charts/rancher-turtles/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rancherTurtles:
namespace: rancher-turtles-system
managerArguments: []
imagePullSecrets: []
rancherInstalled: true
features:
cluster-api-operator:
cleanup: true
Expand Down
4 changes: 3 additions & 1 deletion internal/controllers/capiprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -89,8 +90,9 @@ func (r *CAPIProviderReconciler) patchStatus(ctx context.Context, capiProvider *
}

// SetupWithManager sets up the controller with the Manager.
func (r *CAPIProviderReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager) (err error) {
func (r *CAPIProviderReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager, options controller.Options) (err error) {
b := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&turtlesv1.CAPIProvider{})

resources := []client.Object{
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/capiprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
)

Expand All @@ -53,7 +54,7 @@ var _ = Describe("Reconcile CAPIProvider", func() {
Scheme: testEnv.GetScheme(),
}

Expect(r.SetupWithManager(ctx, testEnv.Manager)).ToNot(HaveOccurred())
Expect(r.SetupWithManager(ctx, testEnv.Manager, controller.Options{})).ToNot(HaveOccurred())
})

It("Should create infrastructure docker provider and secret", func() {
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
RancherClient: rancherClient,
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create rancher management v3 cleanup controller")
os.Exit(1)
Expand All @@ -272,7 +273,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.RancherKubeconfigSecretReconciler{
Client: mgr.GetClient(),
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: concurrencyNumber}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create Rancher kubeconfig secret controller")
os.Exit(1)
}
Expand All @@ -283,7 +287,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.CAPIProviderReconciler{
Client: mgr.GetClient(),
Scheme: scheme,
}).SetupWithManager(ctx, mgr); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create CAPI Provider controller")
os.Exit(1)
}
Expand Down

0 comments on commit 911323f

Please sign in to comment.