<commit_before>package app

import (
	"context"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	alicloud "k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/utils/metric"
	componentbaseconfig "k8s.io/component-base/config"
	"k8s.io/klog"
	ccfg "k8s.io/kubernetes/cmd/cloud-controller-manager/app/apis/config"
	genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app"
	kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
	serviceconfig "k8s.io/kubernetes/pkg/controller/service/config"
	"k8s.io/kubernetes/pkg/master/ports"
	"runtime"
	"time"

	"fmt"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/apiserver/pkg/server/healthz"
	"k8s.io/client-go/informers"
	"k8s.io/client-go/kubernetes"
	v1c "k8s.io/client-go/kubernetes/typed/core/v1"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
	"k8s.io/client-go/tools/leaderelection"
	"k8s.io/client-go/tools/leaderelection/resourcelock"
	"k8s.io/client-go/tools/record"
	"k8s.io/cloud-provider"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/route"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/service"
	"k8s.io/kubernetes/pkg/api/legacyscheme"
	"k8s.io/kubernetes/pkg/controller"
	"k8s.io/kubernetes/pkg/util/configz"
	"math/rand"
	"net"
	"net/http"
	"net/http/pprof"
	"os"
	"strconv"
)

const (
	// ControllerStartJitter is the jitter value used when starting controller managers.
	ControllerStartJitter = 1.0
)

// ServerCCM is the main context object for the controller manager.
type ServerCCM struct {
	ccfg.CloudControllerManagerConfiguration
	restConfig *rest.Config
	election   *kubernetes.Clientset
	client     *kubernetes.Clientset
	recorder   record.EventRecorder
	Master     string
	Kubeconfig string
	cloud      cloudprovider.Interface

	// NodeStatusUpdateFrequency is the frequency at which the controller
	// updates nodes' status
	NodeStatusUpdateFrequency metav1.Duration
}

// NewServerCCM creates a new ExternalCMServer with a default config.
func NewServerCCM() *ServerCCM {
	ccm := ServerCCM{
		// Part of these default values also present in 'cmd/kube-controller-manager/app/options/options.go'.
		// Please keep them in sync when doing update.
		CloudControllerManagerConfiguration: ccfg.CloudControllerManagerConfiguration{
			Generic: kubectrlmgrconfig.GenericControllerManagerConfiguration{
				Port:            ports.CloudControllerManagerPort,
				Address:         "0.0.0.0",
				MinResyncPeriod: metav1.Duration{Duration: 5 * time.Minute},
				ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
					ContentType: "application/vnd.kubernetes.protobuf",
					QPS:         20.0,
					Burst:       30,
				},
				LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
					LeaderElect:   false,
					LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
					RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
					RetryPeriod:   metav1.Duration{Duration: 2 * time.Second},
					ResourceLock:  resourcelock.EndpointsResourceLock,
				},
				ControllerStartInterval: metav1.Duration{Duration: 0 * time.Second},
			},
			KubeCloudShared: kubectrlmgrconfig.KubeCloudSharedConfiguration{
				NodeMonitorPeriod:         metav1.Duration{Duration: 5 * time.Second},
				ClusterName:               "kubernetes",
				ConfigureCloudRoutes:      true,
				RouteReconciliationPeriod: metav1.Duration{Duration: 10 * time.Second},
			},
			ServiceController: serviceconfig.ServiceControllerConfiguration{
				ConcurrentServiceSyncs: 3,
			},
		},
		NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute},
	}
	ccm.Generic.LeaderElection.LeaderElect = true
	return &ccm
}

func createRecorder(client *kubernetes.Clientset) record.EventRecorder {
	cast := record.NewBroadcaster()
	cast.StartLogging(klog.Infof)
	cast.StartRecordingToSink(
		&v1c.EventSinkImpl{
			Interface: v1c.New(client.CoreV1().RESTClient()).Events(""),
		},
	)
	return cast.NewRecorder(
		legacyscheme.Scheme,
		v1.EventSource{Component: "cloud-controller-manager"},<commit_msg>change resource lock to leaseLock<commit_after>package app

import (
	"context"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	alicloud "k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/utils/metric"
	componentbaseconfig "k8s.io/component-base/config"
	"k8s.io/klog"
	ccfg "k8s.io/kubernetes/cmd/cloud-controller-manager/app/apis/config"
	genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app"
	kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
	serviceconfig "k8s.io/kubernetes/pkg/controller/service/config"
	"k8s.io/kubernetes/pkg/master/ports"
	"runtime"
	"time"

	"fmt"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/apiserver/pkg/server/healthz"
	"k8s.io/client-go/informers"
	"k8s.io/client-go/kubernetes"
	v1c "k8s.io/client-go/kubernetes/typed/core/v1"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
	"k8s.io/client-go/tools/leaderelection"
	"k8s.io/client-go/tools/leaderelection/resourcelock"
	"k8s.io/client-go/tools/record"
	"k8s.io/cloud-provider"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/route"
	"k8s.io/cloud-provider-alibaba-cloud/cloud-controller-manager/controller/service"
	"k8s.io/kubernetes/pkg/api/legacyscheme"
	"k8s.io/kubernetes/pkg/controller"
	"k8s.io/kubernetes/pkg/util/configz"
	"math/rand"
	"net"
	"net/http"
	"net/http/pprof"
	"os"
	"strconv"
)

const (
	// ControllerStartJitter is the jitter value used when starting controller managers.
	ControllerStartJitter = 1.0
)

// ServerCCM is the main context object for the controller manager.
type ServerCCM struct {
	ccfg.CloudControllerManagerConfiguration
	restConfig *rest.Config
	election   *kubernetes.Clientset
	client     *kubernetes.Clientset
	recorder   record.EventRecorder
	Master     string
	Kubeconfig string
	cloud      cloudprovider.Interface

	// NodeStatusUpdateFrequency is the frequency at which the controller
	// updates nodes' status
	NodeStatusUpdateFrequency metav1.Duration
}

// NewServerCCM creates a new ExternalCMServer with a default config.
func NewServerCCM() *ServerCCM {
	ccm := ServerCCM{
		// Part of these default values also present in 'cmd/kube-controller-manager/app/options/options.go'.
		// Please keep them in sync when doing update.
		CloudControllerManagerConfiguration: ccfg.CloudControllerManagerConfiguration{
			Generic: kubectrlmgrconfig.GenericControllerManagerConfiguration{
				Port:            ports.CloudControllerManagerPort,
				Address:         "0.0.0.0",
				MinResyncPeriod: metav1.Duration{Duration: 5 * time.Minute},
				ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
					ContentType: "application/vnd.kubernetes.protobuf",
					QPS:         20.0,
					Burst:       30,
				},
				LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
					LeaderElect:   false,
					LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
					RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
					RetryPeriod:   metav1.Duration{Duration: 2 * time.Second},
					ResourceLock:  resourcelock.LeasesResourceLock,
				},
				ControllerStartInterval: metav1.Duration{Duration: 0 * time.Second},
			},
			KubeCloudShared: kubectrlmgrconfig.KubeCloudSharedConfiguration{
				NodeMonitorPeriod:         metav1.Duration{Duration: 5 * time.Second},
				ClusterName:               "kubernetes",
				ConfigureCloudRoutes:      true,
				RouteReconciliationPeriod: metav1.Duration{Duration: 10 * time.Second},
			},
			ServiceController: serviceconfig.ServiceControllerConfiguration{
				ConcurrentServiceSyncs: 3,
			},
		},
		NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute},
	}
	ccm.Generic.LeaderElection.LeaderElect = true
	return &ccm
}

func createRecorder(client *kubernetes.Clientset) record.EventRecorder {
	cast := record.NewBroadcaster()
	cast.StartLogging(klog.Infof)
	cast.StartRecordingToSink(
		&v1c.EventSinkImpl{
			Interface: v1c.New(client.CoreV1().RESTClient()).Events(""),
		},
	)
	return cast.NewRecorder(
		legacyscheme.Scheme,
		v1.EventSource{Component: "cloud-controller-manager"},
{'fraction_non_alphanumeric': 0.11446853892641308, 'fraction_numerical': 0.01611565351344946, 'mean_word_length': 4.39297124600639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4011494', 'n_tokens_mistral': 3170, 'n_tokens_neox': 2897, 'n_words': 439}