Skip to content

Commit

Permalink
Bump CAPI to v1.8.4
Browse files Browse the repository at this point in the history
Signed-off-by: Furkat Gofurov <furkat.gofurov@suse.com>
  • Loading branch information
furkatgofurov7 committed Oct 22, 2024
1 parent c42dfc8 commit dfe91b4
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 328 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4

SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9
# This is a commit from CR main (22.05.2024).
# Intentionally using a commit from main to use a setup-envtest version
# that uses binaries from controller-tools, not GCS.
# CR PR: https://github.com/kubernetes-sigs/controller-runtime/pull/2811
SETUP_ENVTEST_VER := v0.0.0-20240522175850-2e9781e9fc60
SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
Expand Down Expand Up @@ -101,7 +105,7 @@ GOLANGCI_LINT_VER := v1.55.1
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))

GINKGO_VER := v2.17.1
GINKGO_VER := v2.20.1
GINKGO_BIN := ginkgo
GINKGO := $(abspath $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER))
GINKGO_PKG := github.com/onsi/ginkgo/v2/ginkgo
Expand Down
3 changes: 0 additions & 3 deletions bootstrap/config/crd/patches/webhook_in_rke2configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
strategy: Webhook
webhook:
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
strategy: Webhook
webhook:
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
- ALL
privileged: false
runAsUser: 65532
runAsGroup: 65532
terminationMessagePolicy: FallbackToLogsOnError
terminationGracePeriodSeconds: 10
serviceAccountName: manager
tolerations:
Expand Down
146 changes: 101 additions & 45 deletions bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"net/http"
"os"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/controller"

"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
Expand All @@ -39,35 +40,41 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/remote"
"sigs.k8s.io/cluster-api/util/flags"
"sigs.k8s.io/cluster-api/webhooks"

bootstrapv1alpha1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
bootstrapv1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta1"
"github.com/rancher/cluster-api-provider-rke2/bootstrap/internal/controllers"
controlplanev1alpha1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1alpha1"
controlplanev1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1beta1"
"github.com/rancher/cluster-api-provider-rke2/pkg/consts"
"github.com/rancher/cluster-api-provider-rke2/version"
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
controllerName = "rke2-bootstrap-controller"

// flags.
enableLeaderElection bool
leaderElectionLeaseDuration time.Duration
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
profilerAddress string
concurrencyNumber int
syncPeriod time.Duration
watchNamespace string
webhookPort int
webhookCertDir string
healthAddr string

diagnosticsOptions = flags.DiagnosticsOptions{}
enableLeaderElection bool
leaderElectionLeaseDuration time.Duration
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
profilerAddress string
concurrencyNumber int
clusterCacheTrackerConcurrency int
syncPeriod time.Duration
clusterCacheTrackerClientQPS float32
clusterCacheTrackerClientBurst int
watchNamespace string
webhookPort int
webhookCertDir string
healthAddr string
managerOptions = flags.ManagerOptions{}
)

func init() {
Expand Down Expand Up @@ -105,9 +112,18 @@ func InitFlags(fs *pflag.FlagSet) {
fs.IntVar(&concurrencyNumber, "concurrency", 1,
"Number of core resources to process simultaneously")

fs.IntVar(&clusterCacheTrackerConcurrency, "clustercachetracker-concurrency", 10,
"Number of clusters to process simultaneously")

fs.DurationVar(&syncPeriod, "sync-period", consts.DefaultSyncPeriod,
"The minimum interval at which watched resources are reconciled (e.g. 15m)")

fs.Float32Var(&clusterCacheTrackerClientQPS, "clustercachetracker-client-qps", 20,
"Maximum queries per second from the cluster cache tracker clients to the Kubernetes API server of workload clusters.")

fs.IntVar(&clusterCacheTrackerClientBurst, "clustercachetracker-client-burst", 30,
"Maximum number of queries that should be allowed in one burst from the cluster cache tracker clients to the Kubernetes API server of workload clusters.")

fs.StringVar(&watchNamespace, "namespace", "",
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") //nolint:lll

Expand All @@ -119,7 +135,7 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddManagerOptions(fs, &managerOptions)
}

// Add RBAC for the authorized diagnostics endpoint.
Expand All @@ -133,7 +149,13 @@ func main() {

ctrl.SetLogger(klog.Background())

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)
restConfig := ctrl.GetConfigOrDie()

tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

var watchNamespaces map[string]cache.Config

Expand All @@ -144,23 +166,16 @@ func main() {
}
}

if profilerAddress != "" {
klog.Infof("Profiler listening for requests at %s", profilerAddress)

go func() {
klog.Info(http.ListenAndServe(profilerAddress, nil))
}()
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "rke2-bootstrap-manager-leader-election-capi",
PprofBindAddress: profilerAddress,
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
Metrics: diagnosticsOpts,
ctrlOptions := ctrl.Options{
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "rke2-bootstrap-manager-leader-election-capi",
PprofBindAddress: profilerAddress,
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
HealthProbeBindAddress: healthAddr,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand All @@ -177,23 +192,26 @@ func main() {
webhook.Options{
Port: webhookPort,
CertDir: webhookCertDir,
TLSOpts: tlsOptions,
},
),
HealthProbeBindAddress: healthAddr,
})
}

mgr, err := ctrl.NewManager(restConfig, ctrlOptions)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

ctx := ctrl.SetupSignalHandler()

setupChecks(mgr)
setupReconcilers(mgr)
setupWebhooks(mgr)
//+kubebuilder:scaffold:builder
tracker := setupReconcilers(ctx, mgr, watchNamespaces, &syncPeriod)
setupWebhooks(mgr, tracker)

setupLog.Info("starting manager")
setupLog.Info("Starting manager", "version", version.Get().String())

if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
Expand All @@ -211,17 +229,51 @@ func setupChecks(mgr ctrl.Manager) {
}
}

func setupReconcilers(mgr ctrl.Manager) {
func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchNamespaces map[string]cache.Config, syncPeriod *time.Duration) webhooks.ClusterCacheTrackerReader {
if err := (&controllers.RKE2ConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Rke2Config")
os.Exit(1)
}

// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
ControllerName: controllerName,
Log: &ctrl.Log,
Indexes: []remote.Index{},
ClientUncachedObjects: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
ClientQPS: clusterCacheTrackerClientQPS,
ClientBurst: clusterCacheTrackerClientBurst,
},
)

if err != nil {
setupLog.Error(err, "Unable to create cluster cache tracker")
os.Exit(1)
}

if err := (&remote.ClusterCacheReconciler{
Client: mgr.GetClient(),
Tracker: tracker,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, concurrency(clusterCacheTrackerConcurrency)); err != nil {
setupLog.Error(err, "Unable to create controller", "controller", "ClusterCacheReconciler")
os.Exit(1)
}

return tracker

}

func setupWebhooks(mgr ctrl.Manager) {
func setupWebhooks(mgr ctrl.Manager, tracker webhooks.ClusterCacheTrackerReader) {
if err := (&bootstrapv1.RKE2Config{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Rke2Config")
os.Exit(1)
Expand All @@ -232,3 +284,7 @@ func setupWebhooks(mgr ctrl.Manager) {
os.Exit(1)
}
}

func concurrency(c int) controller.Options {
return controller.Options{MaxConcurrentReconciles: c}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
strategy: Webhook
webhook:
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
strategy: Webhook
webhook:
clientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
Expand Down
1 change: 1 addition & 0 deletions controlplane/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ spec:
privileged: false
runAsUser: 65532
runAsGroup: 65532
terminationMessagePolicy: FallbackToLogsOnError
# TODO(user): Configure the resources accordingly based on the project requirements.
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resources:
Expand Down
Loading

0 comments on commit dfe91b4

Please sign in to comment.