From 747d0b9af44d3b47af27b78c1167e5493322ce7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20=C5=BByli=C5=84ski?= Date: Mon, 6 Nov 2023 12:52:50 +0100 Subject: [PATCH] Cleanup: Remove separate client for k8s events Remove RateLimiting options - replay on APF for apiserver protection. Details: https://github.com/kubernetes/kubernetes/issues/111880 --- cluster-autoscaler/config/autoscaling_options.go | 4 ---- cluster-autoscaler/context/autoscaling_context.go | 6 +++--- cluster-autoscaler/core/autoscaler.go | 3 +-- cluster-autoscaler/main.go | 14 +++----------- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cluster-autoscaler/config/autoscaling_options.go b/cluster-autoscaler/config/autoscaling_options.go index 05e6cc2fb6e8..9e008a11a6f1 100644 --- a/cluster-autoscaler/config/autoscaling_options.go +++ b/cluster-autoscaler/config/autoscaling_options.go @@ -223,10 +223,6 @@ type AutoscalingOptions struct { GCEOptions GCEOptions // Path to kube configuration if available KubeConfigPath string - // Burst setting for kubernetes client - KubeClientBurst int - // QPS setting for kubernetes client - KubeClientQPS float64 // ClusterAPICloudConfigAuthoritative tells the Cluster API provider to treat the CloudConfig option as authoritative and // not use KubeConfigPath as a fallback when it is not provided. ClusterAPICloudConfigAuthoritative bool diff --git a/cluster-autoscaler/context/autoscaling_context.go b/cluster-autoscaler/context/autoscaling_context.go index 3e7a0e119632..4dead12a1a46 100644 --- a/cluster-autoscaler/context/autoscaling_context.go +++ b/cluster-autoscaler/context/autoscaling_context.go @@ -128,15 +128,15 @@ func NewAutoscalingContext( } // NewAutoscalingKubeClients builds AutoscalingKubeClients out of basic client. -func NewAutoscalingKubeClients(opts config.AutoscalingOptions, kubeClient, eventsKubeClient kube_client.Interface, informerFactory informers.SharedInformerFactory) *AutoscalingKubeClients { +func NewAutoscalingKubeClients(opts config.AutoscalingOptions, kubeClient kube_client.Interface, informerFactory informers.SharedInformerFactory) *AutoscalingKubeClients { listerRegistry := kube_util.NewListerRegistryWithDefaultListers(informerFactory) - kubeEventRecorder := kube_util.CreateEventRecorder(eventsKubeClient, opts.RecordDuplicatedEvents) + kubeEventRecorder := kube_util.CreateEventRecorder(kubeClient, opts.RecordDuplicatedEvents) logRecorder, err := utils.NewStatusMapRecorder(kubeClient, opts.ConfigNamespace, kubeEventRecorder, opts.WriteStatusConfigMap, opts.StatusConfigMapName) if err != nil { klog.Error("Failed to initialize status configmap, unable to write status events") // Get a dummy, so we can at least safely call the methods // TODO(maciekpytel): recover from this after successful status configmap update? - logRecorder, _ = utils.NewStatusMapRecorder(eventsKubeClient, opts.ConfigNamespace, kubeEventRecorder, false, opts.StatusConfigMapName) + logRecorder, _ = utils.NewStatusMapRecorder(kubeClient, opts.ConfigNamespace, kubeEventRecorder, false, opts.StatusConfigMapName) } return &AutoscalingKubeClients{ diff --git a/cluster-autoscaler/core/autoscaler.go b/cluster-autoscaler/core/autoscaler.go index f0baf8cc51f7..abca7362a848 100644 --- a/cluster-autoscaler/core/autoscaler.go +++ b/cluster-autoscaler/core/autoscaler.go @@ -45,7 +45,6 @@ import ( type AutoscalerOptions struct { config.AutoscalingOptions KubeClient kube_client.Interface - EventsKubeClient kube_client.Interface InformerFactory informers.SharedInformerFactory AutoscalingKubeClients *context.AutoscalingKubeClients CloudProvider cloudprovider.CloudProvider @@ -103,7 +102,7 @@ func initializeDefaultOptions(opts *AutoscalerOptions) error { opts.Processors = ca_processors.DefaultProcessors(opts.AutoscalingOptions) } if opts.AutoscalingKubeClients == nil { - opts.AutoscalingKubeClients = context.NewAutoscalingKubeClients(opts.AutoscalingOptions, opts.KubeClient, opts.EventsKubeClient, opts.InformerFactory) + opts.AutoscalingKubeClients = context.NewAutoscalingKubeClients(opts.AutoscalingOptions, opts.KubeClient, opts.InformerFactory) } if opts.ClusterSnapshot == nil { opts.ClusterSnapshot = clustersnapshot.NewBasicClusterSnapshot() diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index 5276b97c5658..6e5de43b5c24 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -103,8 +103,8 @@ var ( kubernetes = flag.String("kubernetes", "", "Kubernetes master location. Leave blank for default") kubeConfigFile = flag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information.") kubeAPIContentType = flag.String("kube-api-content-type", "application/vnd.kubernetes.protobuf", "Content type of requests sent to apiserver.") - kubeClientBurst = flag.Int("kube-client-burst", rest.DefaultBurst, "Burst value for kubernetes client.") - kubeClientQPS = flag.Float64("kube-client-qps", float64(rest.DefaultQPS), "QPS value for kubernetes client.") + _ = flag.Int("kube-client-burst", rest.DefaultBurst, "Burst value for kubernetes client. (Deprecated, relay on APF for rate limiting)") + _ = flag.Float64("kube-client-qps", float64(rest.DefaultQPS), "QPS value for kubernetes client. (Deprecated, relay on APF for rate limiting)") cloudConfig = flag.String("cloud-config", "", "The path to the cloud provider configuration file. Empty string for no configuration file.") namespace = flag.String("namespace", "kube-system", "Namespace in which cluster-autoscaler run.") enforceNodeGroupMinSize = flag.Bool("enforce-node-group-min-size", false, "Should CA scale up the node group to the configured min size if needed.") @@ -354,8 +354,6 @@ func createAutoscalingOptions() config.AutoscalingOptions { BalancingExtraIgnoredLabels: *balancingIgnoreLabelsFlag, BalancingLabels: *balancingLabelsFlag, KubeConfigPath: *kubeConfigFile, - KubeClientBurst: *kubeClientBurst, - KubeClientQPS: *kubeClientQPS, NodeDeletionDelayTimeout: *nodeDeletionDelayTimeout, AWSUseStaticInstanceList: *awsUseStaticInstanceList, GCEOptions: config.GCEOptions{ @@ -441,10 +439,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter // Create basic config from flags. autoscalingOptions := createAutoscalingOptions() - kubeClientConfig := getKubeConfig() - kubeClientConfig.Burst = autoscalingOptions.KubeClientBurst - kubeClientConfig.QPS = float32(autoscalingOptions.KubeClientQPS) - kubeClient := createKubeClient(kubeClientConfig) + kubeClient := createKubeClient(getKubeConfig()) // Informer transform to trim ManagedFields for memory efficiency. trim := func(obj interface{}) (interface{}, error) { @@ -455,8 +450,6 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter } informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTransform(trim)) - eventsKubeClient := createKubeClient(getKubeConfig()) - predicateChecker, err := predicatechecker.NewSchedulerBasedPredicateChecker(informerFactory, autoscalingOptions.SchedulerConfig) if err != nil { return nil, err @@ -469,7 +462,6 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter ClusterSnapshot: clustersnapshot.NewDeltaClusterSnapshot(), KubeClient: kubeClient, InformerFactory: informerFactory, - EventsKubeClient: eventsKubeClient, DebuggingSnapshotter: debuggingSnapshotter, PredicateChecker: predicateChecker, DeleteOptions: deleteOptions,