mirror of https://github.com/k3s-io/k3s.git
Remove unnecessary copies of runtime struct
Several types contained redundant references to ControlRuntime data. Switch to consistently accessing this via config.Runtime instead. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/5032/head
parent
54bb65064e
commit
2989b8b2c5
|
@ -77,7 +77,7 @@ func rotate(app *cli.Context, cfg *cmds.Server) error {
|
||||||
|
|
||||||
serverConfig.ControlConfig.DataDir = serverDataDir
|
serverConfig.ControlConfig.DataDir = serverDataDir
|
||||||
serverConfig.ControlConfig.Runtime = &config.ControlRuntime{}
|
serverConfig.ControlConfig.Runtime = &config.ControlRuntime{}
|
||||||
deps.CreateRuntimeCertFiles(&serverConfig.ControlConfig, serverConfig.ControlConfig.Runtime)
|
deps.CreateRuntimeCertFiles(&serverConfig.ControlConfig)
|
||||||
|
|
||||||
if err := validateCertConfig(); err != nil {
|
if err := validateCertConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -196,7 +196,7 @@ func createTmpDataDir(src, dst string) error {
|
||||||
func (c *Cluster) shouldBootstrapLoad(ctx context.Context) (bool, bool, error) {
|
func (c *Cluster) shouldBootstrapLoad(ctx context.Context) (bool, bool, error) {
|
||||||
// Non-nil managedDB indicates that the database is either initialized, initializing, or joining
|
// Non-nil managedDB indicates that the database is either initialized, initializing, or joining
|
||||||
if c.managedDB != nil {
|
if c.managedDB != nil {
|
||||||
c.runtime.HTTPBootstrap = true
|
c.config.Runtime.HTTPBootstrap = true
|
||||||
|
|
||||||
isInitialized, err := c.managedDB.IsInitialized(ctx, c.config)
|
isInitialized, err := c.managedDB.IsInitialized(ctx, c.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -363,7 +363,7 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker,
|
||||||
if c.managedDB != nil && !isHTTP {
|
if c.managedDB != nil && !isHTTP {
|
||||||
token := c.config.Token
|
token := c.config.Token
|
||||||
if token == "" {
|
if token == "" {
|
||||||
tokenFromFile, err := readTokenFromFile(c.runtime.ServerToken, c.runtime.ServerCA, c.config.DataDir)
|
tokenFromFile, err := readTokenFromFile(c.config.Runtime.ServerToken, c.config.Runtime.ServerCA, c.config.DataDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -600,7 +600,7 @@ func (c *Cluster) httpBootstrap(ctx context.Context) error {
|
||||||
|
|
||||||
func (c *Cluster) retrieveInitializedDBdata(ctx context.Context) (*bytes.Buffer, error) {
|
func (c *Cluster) retrieveInitializedDBdata(ctx context.Context) (*bytes.Buffer, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := bootstrap.ReadFromDisk(&buf, &c.runtime.ControlRuntimeBootstrap); err != nil {
|
if err := bootstrap.ReadFromDisk(&buf, &c.config.Runtime.ControlRuntimeBootstrap); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ func (c *Cluster) bootstrap(ctx context.Context) error {
|
||||||
c.joining = true
|
c.joining = true
|
||||||
|
|
||||||
// bootstrap managed database via HTTPS
|
// bootstrap managed database via HTTPS
|
||||||
if c.runtime.HTTPBootstrap {
|
if c.config.Runtime.HTTPBootstrap {
|
||||||
// Assuming we should just compare on managed databases
|
// Assuming we should just compare on managed databases
|
||||||
if err := c.compareConfig(); err != nil {
|
if err := c.compareConfig(); err != nil {
|
||||||
return errors.Wrap(err, "failed to validate server configuration")
|
return errors.Wrap(err, "failed to validate server configuration")
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
clientAccessInfo *clientaccess.Info
|
clientAccessInfo *clientaccess.Info
|
||||||
config *config.Control
|
config *config.Control
|
||||||
runtime *config.ControlRuntime
|
|
||||||
managedDB managed.Driver
|
managedDB managed.Driver
|
||||||
EtcdConfig endpoint.ETCDConfig
|
EtcdConfig endpoint.ETCDConfig
|
||||||
joining bool
|
joining bool
|
||||||
|
@ -149,7 +148,6 @@ func (c *Cluster) startStorage(ctx context.Context) error {
|
||||||
// New creates an initial cluster using the provided configuration.
|
// New creates an initial cluster using the provided configuration.
|
||||||
func New(config *config.Control) *Cluster {
|
func New(config *config.Control) *Cluster {
|
||||||
return &Cluster{
|
return &Cluster{
|
||||||
config: config,
|
config: config,
|
||||||
runtime: config.Runtime,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,11 @@ func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
cert, key, err := factory.LoadCerts(c.runtime.ServerCA, c.runtime.ServerCAKey)
|
cert, key, err := factory.LoadCerts(c.config.Runtime.ServerCA, c.config.Runtime.ServerCAKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
storage := tlsStorage(ctx, c.config.DataDir, c.runtime)
|
storage := tlsStorage(ctx, c.config.DataDir, c.config.Runtime)
|
||||||
return dynamiclistener.NewListener(tcp, storage, cert, key, dynamiclistener.Config{
|
return dynamiclistener.NewListener(tcp, storage, cert, key, dynamiclistener.Config{
|
||||||
ExpirationDaysCheck: config.CertificateRenewDays,
|
ExpirationDaysCheck: config.CertificateRenewDays,
|
||||||
Organization: []string{version.Program},
|
Organization: []string{version.Program},
|
||||||
|
|
|
@ -184,11 +184,11 @@ func (c *Cluster) deleteNodePasswdSecret(ctx context.Context) {
|
||||||
}
|
}
|
||||||
// the core factory may not yet be initialized so we
|
// the core factory may not yet be initialized so we
|
||||||
// want to wait until it is so not to evoke a panic.
|
// want to wait until it is so not to evoke a panic.
|
||||||
if c.runtime.Core == nil {
|
if c.config.Runtime.Core == nil {
|
||||||
logrus.Infof("runtime is not yet initialized")
|
logrus.Infof("runtime is not yet initialized")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
secretsClient := c.runtime.Core.Core().V1().Secret()
|
secretsClient := c.config.Runtime.Core.Core().V1().Secret()
|
||||||
if err := nodepassword.Delete(secretsClient, nodeName); err != nil {
|
if err := nodepassword.Delete(secretsClient, nodeName); err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
logrus.Debugf("node password secret is not found for node %s", nodeName)
|
logrus.Debugf("node password secret is not found for node %s", nodeName)
|
||||||
|
|
|
@ -19,11 +19,11 @@ func (c *Cluster) getHandler(handler http.Handler) (http.Handler, error) {
|
||||||
// if no additional handlers are available.
|
// if no additional handlers are available.
|
||||||
func (c *Cluster) router() http.Handler {
|
func (c *Cluster) router() http.Handler {
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
if c.runtime.Handler == nil {
|
if c.config.Runtime.Handler == nil {
|
||||||
http.Error(rw, "starting", http.StatusServiceUnavailable)
|
http.Error(rw, "starting", http.StatusServiceUnavailable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.runtime.Handler.ServeHTTP(rw, req)
|
c.config.Runtime.Handler.ServeHTTP(rw, req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
|
||||||
|
|
||||||
token := c.config.Token
|
token := c.config.Token
|
||||||
if token == "" {
|
if token == "" {
|
||||||
tokenFromFile, err := readTokenFromFile(c.runtime.ServerToken, c.runtime.ServerCA, c.config.DataDir)
|
tokenFromFile, err := readTokenFromFile(c.config.Runtime.ServerToken, c.config.Runtime.ServerCA, c.config.DataDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,8 @@ func KubeConfig(dest, url, caCert, clientCert, clientKey string) error {
|
||||||
|
|
||||||
// CreateRuntimeCertFiles is responsible for filling out all the
|
// CreateRuntimeCertFiles is responsible for filling out all the
|
||||||
// .crt and .key filenames for a ControlRuntime.
|
// .crt and .key filenames for a ControlRuntime.
|
||||||
func CreateRuntimeCertFiles(config *config.Control, runtime *config.ControlRuntime) {
|
func CreateRuntimeCertFiles(config *config.Control) {
|
||||||
|
runtime := config.Runtime
|
||||||
runtime.ClientCA = filepath.Join(config.DataDir, "tls", "client-ca.crt")
|
runtime.ClientCA = filepath.Join(config.DataDir, "tls", "client-ca.crt")
|
||||||
runtime.ClientCAKey = filepath.Join(config.DataDir, "tls", "client-ca.key")
|
runtime.ClientCAKey = filepath.Join(config.DataDir, "tls", "client-ca.key")
|
||||||
runtime.ServerCA = filepath.Join(config.DataDir, "tls", "server-ca.crt")
|
runtime.ServerCA = filepath.Join(config.DataDir, "tls", "server-ca.crt")
|
||||||
|
@ -156,8 +157,9 @@ func CreateRuntimeCertFiles(config *config.Control, runtime *config.ControlRunti
|
||||||
|
|
||||||
// GenServerDeps is responsible for generating the cluster dependencies
|
// GenServerDeps is responsible for generating the cluster dependencies
|
||||||
// needed to successfully bootstrap a cluster.
|
// needed to successfully bootstrap a cluster.
|
||||||
func GenServerDeps(config *config.Control, runtime *config.ControlRuntime) error {
|
func GenServerDeps(config *config.Control) error {
|
||||||
if err := genCerts(config, runtime); err != nil {
|
runtime := config.Runtime
|
||||||
|
if err := genCerts(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,15 +167,15 @@ func GenServerDeps(config *config.Control, runtime *config.ControlRuntime) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genUsers(config, runtime); err != nil {
|
if err := genUsers(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genEncryptedNetworkInfo(config, runtime); err != nil {
|
if err := genEncryptedNetworkInfo(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genEncryptionConfigAndState(config, runtime); err != nil {
|
if err := genEncryptionConfigAndState(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +208,8 @@ func getNodePass(config *config.Control, serverPass string) string {
|
||||||
return config.AgentToken
|
return config.AgentToken
|
||||||
}
|
}
|
||||||
|
|
||||||
func genUsers(config *config.Control, runtime *config.ControlRuntime) error {
|
func genUsers(config *config.Control) error {
|
||||||
|
runtime := config.Runtime
|
||||||
passwd, err := passwd.Read(runtime.PasswdFile)
|
passwd, err := passwd.Read(runtime.PasswdFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -234,7 +237,8 @@ func genUsers(config *config.Control, runtime *config.ControlRuntime) error {
|
||||||
return passwd.Write(runtime.PasswdFile)
|
return passwd.Write(runtime.PasswdFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func genEncryptedNetworkInfo(controlConfig *config.Control, runtime *config.ControlRuntime) error {
|
func genEncryptedNetworkInfo(controlConfig *config.Control) error {
|
||||||
|
runtime := controlConfig.Runtime
|
||||||
if s, err := os.Stat(runtime.IPSECKey); err == nil && s.Size() > 0 {
|
if s, err := os.Stat(runtime.IPSECKey); err == nil && s.Size() > 0 {
|
||||||
psk, err := ioutil.ReadFile(runtime.IPSECKey)
|
psk, err := ioutil.ReadFile(runtime.IPSECKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -272,17 +276,17 @@ func getServerPass(passwd *passwd.Passwd, config *config.Control) (string, error
|
||||||
return serverPass, nil
|
return serverPass, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genCerts(config *config.Control, runtime *config.ControlRuntime) error {
|
func genCerts(config *config.Control) error {
|
||||||
if err := genClientCerts(config, runtime); err != nil {
|
if err := genClientCerts(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := genServerCerts(config, runtime); err != nil {
|
if err := genServerCerts(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := genRequestHeaderCerts(config, runtime); err != nil {
|
if err := genRequestHeaderCerts(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return genETCDCerts(config, runtime)
|
return genETCDCerts(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSigningCertFactory(regen bool, altNames *certutil.AltNames, extKeyUsage []x509.ExtKeyUsage, caCertFile, caKeyFile string) signedCertFactory {
|
func getSigningCertFactory(regen bool, altNames *certutil.AltNames, extKeyUsage []x509.ExtKeyUsage, caCertFile, caKeyFile string) signedCertFactory {
|
||||||
|
@ -291,7 +295,8 @@ func getSigningCertFactory(regen bool, altNames *certutil.AltNames, extKeyUsage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func genClientCerts(config *config.Control, runtime *config.ControlRuntime) error {
|
func genClientCerts(config *config.Control) error {
|
||||||
|
runtime := config.Runtime
|
||||||
regen, err := createSigningCertKey(version.Program+"-client", runtime.ClientCA, runtime.ClientCAKey)
|
regen, err := createSigningCertKey(version.Program+"-client", runtime.ClientCA, runtime.ClientCAKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -367,8 +372,9 @@ func genClientCerts(config *config.Control, runtime *config.ControlRuntime) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genServerCerts(config *config.Control, runtime *config.ControlRuntime) error {
|
func genServerCerts(config *config.Control) error {
|
||||||
regen, err := createServerSigningCertKey(config, runtime)
|
runtime := config.Runtime
|
||||||
|
regen, err := createServerSigningCertKey(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -393,7 +399,8 @@ func genServerCerts(config *config.Control, runtime *config.ControlRuntime) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genETCDCerts(config *config.Control, runtime *config.ControlRuntime) error {
|
func genETCDCerts(config *config.Control) error {
|
||||||
|
runtime := config.Runtime
|
||||||
regen, err := createSigningCertKey("etcd-server", runtime.ETCDServerCA, runtime.ETCDServerCAKey)
|
regen, err := createSigningCertKey("etcd-server", runtime.ETCDServerCA, runtime.ETCDServerCAKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -431,7 +438,8 @@ func genETCDCerts(config *config.Control, runtime *config.ControlRuntime) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genRequestHeaderCerts(config *config.Control, runtime *config.ControlRuntime) error {
|
func genRequestHeaderCerts(config *config.Control) error {
|
||||||
|
runtime := config.Runtime
|
||||||
regen, err := createSigningCertKey(version.Program+"-request-header", runtime.RequestHeaderCA, runtime.RequestHeaderCAKey)
|
regen, err := createSigningCertKey(version.Program+"-request-header", runtime.RequestHeaderCA, runtime.RequestHeaderCAKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -449,7 +457,8 @@ func genRequestHeaderCerts(config *config.Control, runtime *config.ControlRuntim
|
||||||
|
|
||||||
type signedCertFactory = func(commonName string, organization []string, certFile, keyFile string) (bool, error)
|
type signedCertFactory = func(commonName string, organization []string, certFile, keyFile string) (bool, error)
|
||||||
|
|
||||||
func createServerSigningCertKey(config *config.Control, runtime *config.ControlRuntime) (bool, error) {
|
func createServerSigningCertKey(config *config.Control) (bool, error) {
|
||||||
|
runtime := config.Runtime
|
||||||
TokenCA := filepath.Join(config.DataDir, "tls", "token-ca.crt")
|
TokenCA := filepath.Join(config.DataDir, "tls", "token-ca.crt")
|
||||||
TokenCAKey := filepath.Join(config.DataDir, "tls", "token-ca.key")
|
TokenCAKey := filepath.Join(config.DataDir, "tls", "token-ca.key")
|
||||||
|
|
||||||
|
@ -653,7 +662,8 @@ func expired(certFile string, pool *x509.CertPool) bool {
|
||||||
return certutil.IsCertExpired(certificates[0], config.CertificateRenewDays)
|
return certutil.IsCertExpired(certificates[0], config.CertificateRenewDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
func genEncryptionConfigAndState(controlConfig *config.Control, runtime *config.ControlRuntime) error {
|
func genEncryptionConfigAndState(controlConfig *config.Control) error {
|
||||||
|
runtime := controlConfig.Runtime
|
||||||
if !controlConfig.EncryptSecrets {
|
if !controlConfig.EncryptSecrets {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,46 +35,45 @@ var localhostIP = net.ParseIP("127.0.0.1")
|
||||||
|
|
||||||
func Server(ctx context.Context, cfg *config.Control) error {
|
func Server(ctx context.Context, cfg *config.Control) error {
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
runtime := cfg.Runtime
|
|
||||||
|
|
||||||
if err := prepare(ctx, cfg, runtime); err != nil {
|
if err := prepare(ctx, cfg); err != nil {
|
||||||
return errors.Wrap(err, "preparing server")
|
return errors.Wrap(err, "preparing server")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Runtime.Tunnel = setupTunnel()
|
cfg.Runtime.Tunnel = setupTunnel()
|
||||||
proxyutil.DisableProxyHostnameCheck = true
|
proxyutil.DisableProxyHostnameCheck = true
|
||||||
|
|
||||||
basicAuth, err := basicAuthenticator(runtime.PasswdFile)
|
basicAuth, err := basicAuthenticator(cfg.Runtime.PasswdFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
runtime.Authenticator = basicAuth
|
cfg.Runtime.Authenticator = basicAuth
|
||||||
|
|
||||||
if !cfg.DisableAPIServer {
|
if !cfg.DisableAPIServer {
|
||||||
go waitForAPIServerHandlers(ctx, runtime)
|
go waitForAPIServerHandlers(ctx, cfg.Runtime)
|
||||||
|
|
||||||
if err := apiServer(ctx, cfg, runtime); err != nil {
|
if err := apiServer(ctx, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := waitForAPIServerInBackground(ctx, runtime); err != nil {
|
if err := waitForAPIServerInBackground(ctx, cfg.Runtime); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.DisableScheduler {
|
if !cfg.DisableScheduler {
|
||||||
if err := scheduler(ctx, cfg, runtime); err != nil {
|
if err := scheduler(ctx, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !cfg.DisableControllerManager {
|
if !cfg.DisableControllerManager {
|
||||||
if err := controllerManager(ctx, cfg, runtime); err != nil {
|
if err := controllerManager(ctx, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.DisableCCM {
|
if !cfg.DisableCCM {
|
||||||
if err := cloudControllerManager(ctx, cfg, runtime); err != nil {
|
if err := cloudControllerManager(ctx, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,8 @@ func Server(ctx context.Context, cfg *config.Control) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func controllerManager(ctx context.Context, cfg *config.Control, runtime *config.ControlRuntime) error {
|
func controllerManager(ctx context.Context, cfg *config.Control) error {
|
||||||
|
runtime := cfg.Runtime
|
||||||
argsMap := map[string]string{
|
argsMap := map[string]string{
|
||||||
"feature-gates": "JobTrackingWithFinalizers=true",
|
"feature-gates": "JobTrackingWithFinalizers=true",
|
||||||
"kubeconfig": runtime.KubeConfigController,
|
"kubeconfig": runtime.KubeConfigController,
|
||||||
|
@ -116,10 +116,11 @@ func controllerManager(ctx context.Context, cfg *config.Control, runtime *config
|
||||||
args := config.GetArgs(argsMap, cfg.ExtraControllerArgs)
|
args := config.GetArgs(argsMap, cfg.ExtraControllerArgs)
|
||||||
logrus.Infof("Running kube-controller-manager %s", config.ArgString(args))
|
logrus.Infof("Running kube-controller-manager %s", config.ArgString(args))
|
||||||
|
|
||||||
return executor.ControllerManager(ctx, runtime.APIServerReady, args)
|
return executor.ControllerManager(ctx, cfg.Runtime.APIServerReady, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func scheduler(ctx context.Context, cfg *config.Control, runtime *config.ControlRuntime) error {
|
func scheduler(ctx context.Context, cfg *config.Control) error {
|
||||||
|
runtime := cfg.Runtime
|
||||||
argsMap := map[string]string{
|
argsMap := map[string]string{
|
||||||
"kubeconfig": runtime.KubeConfigScheduler,
|
"kubeconfig": runtime.KubeConfigScheduler,
|
||||||
"authorization-kubeconfig": runtime.KubeConfigScheduler,
|
"authorization-kubeconfig": runtime.KubeConfigScheduler,
|
||||||
|
@ -134,10 +135,11 @@ func scheduler(ctx context.Context, cfg *config.Control, runtime *config.Control
|
||||||
args := config.GetArgs(argsMap, cfg.ExtraSchedulerAPIArgs)
|
args := config.GetArgs(argsMap, cfg.ExtraSchedulerAPIArgs)
|
||||||
|
|
||||||
logrus.Infof("Running kube-scheduler %s", config.ArgString(args))
|
logrus.Infof("Running kube-scheduler %s", config.ArgString(args))
|
||||||
return executor.Scheduler(ctx, runtime.APIServerReady, args)
|
return executor.Scheduler(ctx, cfg.Runtime.APIServerReady, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiServer(ctx context.Context, cfg *config.Control, runtime *config.ControlRuntime) error {
|
func apiServer(ctx context.Context, cfg *config.Control) error {
|
||||||
|
runtime := cfg.Runtime
|
||||||
argsMap := map[string]string{
|
argsMap := map[string]string{
|
||||||
"feature-gates": "JobTrackingWithFinalizers=true",
|
"feature-gates": "JobTrackingWithFinalizers=true",
|
||||||
}
|
}
|
||||||
|
@ -225,7 +227,7 @@ func defaults(config *config.Control) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepare(ctx context.Context, config *config.Control, runtime *config.ControlRuntime) error {
|
func prepare(ctx context.Context, config *config.Control) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
defaults(config)
|
defaults(config)
|
||||||
|
@ -242,7 +244,7 @@ func prepare(ctx context.Context, config *config.Control, runtime *config.Contro
|
||||||
os.MkdirAll(filepath.Join(config.DataDir, "tls"), 0700)
|
os.MkdirAll(filepath.Join(config.DataDir, "tls"), 0700)
|
||||||
os.MkdirAll(filepath.Join(config.DataDir, "cred"), 0700)
|
os.MkdirAll(filepath.Join(config.DataDir, "cred"), 0700)
|
||||||
|
|
||||||
deps.CreateRuntimeCertFiles(config, runtime)
|
deps.CreateRuntimeCertFiles(config)
|
||||||
|
|
||||||
cluster := cluster.New(config)
|
cluster := cluster.New(config)
|
||||||
|
|
||||||
|
@ -250,7 +252,7 @@ func prepare(ctx context.Context, config *config.Control, runtime *config.Contro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := deps.GenServerDeps(config, runtime); err != nil {
|
if err := deps.GenServerDeps(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,8 +261,8 @@ func prepare(ctx context.Context, config *config.Control, runtime *config.Contro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.ETCDReady = ready
|
config.Runtime.ETCDReady = ready
|
||||||
runtime.EtcdConfig = cluster.EtcdConfig
|
config.Runtime.EtcdConfig = cluster.EtcdConfig
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +284,8 @@ func setupStorageBackend(argsMap map[string]string, cfg *config.Control) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloudControllerManager(ctx context.Context, cfg *config.Control, runtime *config.ControlRuntime) error {
|
func cloudControllerManager(ctx context.Context, cfg *config.Control) error {
|
||||||
|
runtime := cfg.Runtime
|
||||||
argsMap := map[string]string{
|
argsMap := map[string]string{
|
||||||
"profiling": "false",
|
"profiling": "false",
|
||||||
"allocate-node-cidrs": "true",
|
"allocate-node-cidrs": "true",
|
||||||
|
@ -313,7 +316,7 @@ func cloudControllerManager(ctx context.Context, cfg *config.Control, runtime *c
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-runtime.APIServerReady:
|
case <-cfg.Runtime.APIServerReady:
|
||||||
break apiReadyLoop
|
break apiReadyLoop
|
||||||
case <-time.After(30 * time.Second):
|
case <-time.After(30 * time.Second):
|
||||||
logrus.Infof("Waiting for API server to become available")
|
logrus.Infof("Waiting for API server to become available")
|
||||||
|
@ -325,7 +328,7 @@ func cloudControllerManager(ctx context.Context, cfg *config.Control, runtime *c
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case err := <-promise(func() error { return checkForCloudControllerPrivileges(ctx, runtime, 5*time.Second) }):
|
case err := <-promise(func() error { return checkForCloudControllerPrivileges(ctx, cfg.Runtime, 5*time.Second) }):
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infof("Waiting for cloud-controller-manager privileges to become available: %v", err)
|
logrus.Infof("Waiting for cloud-controller-manager privileges to become available: %v", err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -84,7 +84,6 @@ type ETCD struct {
|
||||||
client *clientv3.Client
|
client *clientv3.Client
|
||||||
config *config.Control
|
config *config.Control
|
||||||
name string
|
name string
|
||||||
runtime *config.ControlRuntime
|
|
||||||
address string
|
address string
|
||||||
cron *cron.Cron
|
cron *cron.Cron
|
||||||
s3 *S3
|
s3 *S3
|
||||||
|
@ -196,7 +195,7 @@ func (e *ETCD) IsInitialized(ctx context.Context, config *config.Control) (bool,
|
||||||
func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error {
|
func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error {
|
||||||
// Wait for etcd to come up as a new single-node cluster, then exit
|
// Wait for etcd to come up as a new single-node cluster, then exit
|
||||||
go func() {
|
go func() {
|
||||||
<-e.runtime.AgentReady
|
<-e.config.Runtime.AgentReady
|
||||||
t := time.NewTicker(5 * time.Second)
|
t := time.NewTicker(5 * time.Second)
|
||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
for range t.C {
|
for range t.C {
|
||||||
|
@ -219,7 +218,7 @@ func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// call functions to rewrite them from daemons/control/server.go (prepare())
|
// call functions to rewrite them from daemons/control/server.go (prepare())
|
||||||
if err := deps.GenServerDeps(e.config, e.runtime); err != nil {
|
if err := deps.GenServerDeps(e.config); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +319,7 @@ func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) e
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-e.runtime.AgentReady
|
<-e.config.Runtime.AgentReady
|
||||||
if err := e.join(ctx, clientAccessInfo); err != nil {
|
if err := e.join(ctx, clientAccessInfo); err != nil {
|
||||||
logrus.Fatalf("ETCD join failed: %v", err)
|
logrus.Fatalf("ETCD join failed: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -344,7 +343,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := GetClient(clientCtx, e.runtime, clientURLs...)
|
client, err := GetClient(clientCtx, e.config.Runtime, clientURLs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -420,9 +419,8 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
|
||||||
// Register configures a new etcd client and adds db info routes for the http request handler.
|
// Register configures a new etcd client and adds db info routes for the http request handler.
|
||||||
func (e *ETCD) Register(ctx context.Context, config *config.Control, handler http.Handler) (http.Handler, error) {
|
func (e *ETCD) Register(ctx context.Context, config *config.Control, handler http.Handler) (http.Handler, error) {
|
||||||
e.config = config
|
e.config = config
|
||||||
e.runtime = config.Runtime
|
|
||||||
|
|
||||||
client, err := GetClient(ctx, e.runtime, endpoint)
|
client, err := GetClient(ctx, e.config.Runtime, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -434,9 +432,9 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, handler htt
|
||||||
}
|
}
|
||||||
e.address = address
|
e.address = address
|
||||||
e.config.Datastore.Endpoint = endpoint
|
e.config.Datastore.Endpoint = endpoint
|
||||||
e.config.Datastore.BackendTLSConfig.CAFile = e.runtime.ETCDServerCA
|
e.config.Datastore.BackendTLSConfig.CAFile = e.config.Runtime.ETCDServerCA
|
||||||
e.config.Datastore.BackendTLSConfig.CertFile = e.runtime.ClientETCDCert
|
e.config.Datastore.BackendTLSConfig.CertFile = e.config.Runtime.ClientETCDCert
|
||||||
e.config.Datastore.BackendTLSConfig.KeyFile = e.runtime.ClientETCDKey
|
e.config.Datastore.BackendTLSConfig.KeyFile = e.config.Runtime.ClientETCDKey
|
||||||
|
|
||||||
tombstoneFile := filepath.Join(DBDir(e.config), "tombstone")
|
tombstoneFile := filepath.Join(DBDir(e.config), "tombstone")
|
||||||
if _, err := os.Stat(tombstoneFile); err == nil {
|
if _, err := os.Stat(tombstoneFile); err == nil {
|
||||||
|
@ -623,7 +621,7 @@ func (e *ETCD) migrateFromSQLite(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
defer sqliteClient.Close()
|
defer sqliteClient.Close()
|
||||||
|
|
||||||
etcdClient, err := GetClient(ctx, e.runtime, "https://localhost:2379")
|
etcdClient, err := GetClient(ctx, e.config.Runtime, "https://localhost:2379")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -733,7 +731,7 @@ func (e *ETCD) RemovePeer(ctx context.Context, name, address string, allowSelfRe
|
||||||
// being promoted to full voting member. The checks only run on the cluster member that is
|
// being promoted to full voting member. The checks only run on the cluster member that is
|
||||||
// the etcd leader.
|
// the etcd leader.
|
||||||
func (e *ETCD) manageLearners(ctx context.Context) error {
|
func (e *ETCD) manageLearners(ctx context.Context) error {
|
||||||
<-e.runtime.AgentReady
|
<-e.config.Runtime.AgentReady
|
||||||
t := time.NewTicker(manageTickerTime)
|
t := time.NewTicker(manageTickerTime)
|
||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
|
|
||||||
|
@ -937,9 +935,6 @@ func (e *ETCD) preSnapshotSetup(ctx context.Context, config *config.Control) err
|
||||||
}
|
}
|
||||||
e.client = client
|
e.client = client
|
||||||
}
|
}
|
||||||
if e.runtime == nil {
|
|
||||||
e.runtime = config.Runtime
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1069,7 +1064,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
|
||||||
return errors.Wrap(err, "failed to get the snapshot dir")
|
return errors.Wrap(err, "failed to get the snapshot dir")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := getClientConfig(ctx, e.runtime, endpoint)
|
cfg, err := getClientConfig(ctx, e.config.Runtime, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get config for etcd snapshot")
|
return errors.Wrap(err, "failed to get config for etcd snapshot")
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,8 +244,7 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
ctxInfo.ctx, ctxInfo.cancel = context.WithCancel(context.Background())
|
ctxInfo.ctx, ctxInfo.cancel = context.WithCancel(context.Background())
|
||||||
e.config.EtcdDisableSnapshots = true
|
e.config.EtcdDisableSnapshots = true
|
||||||
testutil.GenerateRuntime(e.config)
|
testutil.GenerateRuntime(e.config)
|
||||||
e.runtime = e.config.Runtime
|
client, err := GetClient(ctxInfo.ctx, e.config.Runtime, endpoint)
|
||||||
client, err := GetClient(ctxInfo.ctx, e.runtime, endpoint)
|
|
||||||
e.client = client
|
e.client = client
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -275,8 +274,7 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
setup: func(e *ETCD, ctxInfo *contextInfo) error {
|
setup: func(e *ETCD, ctxInfo *contextInfo) error {
|
||||||
ctxInfo.ctx, ctxInfo.cancel = context.WithCancel(context.Background())
|
ctxInfo.ctx, ctxInfo.cancel = context.WithCancel(context.Background())
|
||||||
testutil.GenerateRuntime(e.config)
|
testutil.GenerateRuntime(e.config)
|
||||||
e.runtime = e.config.Runtime
|
client, err := GetClient(ctxInfo.ctx, e.config.Runtime, endpoint)
|
||||||
client, err := GetClient(ctxInfo.ctx, e.runtime, endpoint)
|
|
||||||
e.client = client
|
e.client = client
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -308,8 +306,7 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
if err := testutil.GenerateRuntime(e.config); err != nil {
|
if err := testutil.GenerateRuntime(e.config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
e.runtime = e.config.Runtime
|
client, err := GetClient(ctxInfo.ctx, e.config.Runtime, endpoint)
|
||||||
client, err := GetClient(ctxInfo.ctx, e.runtime, endpoint)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -335,7 +332,6 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
client: tt.fields.client,
|
client: tt.fields.client,
|
||||||
config: tt.fields.config,
|
config: tt.fields.config,
|
||||||
name: tt.fields.name,
|
name: tt.fields.name,
|
||||||
runtime: tt.fields.config.Runtime,
|
|
||||||
address: tt.fields.address,
|
address: tt.fields.address,
|
||||||
cron: tt.fields.cron,
|
cron: tt.fields.cron,
|
||||||
s3: tt.fields.s3,
|
s3: tt.fields.s3,
|
||||||
|
|
|
@ -43,7 +43,7 @@ func CleanupDataDir(cnf *config.Control) {
|
||||||
// GenerateRuntime creates a temporary data dir and configures
|
// GenerateRuntime creates a temporary data dir and configures
|
||||||
// config.ControlRuntime with all the appropriate certificate keys.
|
// config.ControlRuntime with all the appropriate certificate keys.
|
||||||
func GenerateRuntime(cnf *config.Control) error {
|
func GenerateRuntime(cnf *config.Control) error {
|
||||||
runtime := &config.ControlRuntime{}
|
cnf.Runtime = &config.ControlRuntime{}
|
||||||
if err := GenerateDataDir(cnf); err != nil {
|
if err := GenerateDataDir(cnf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,9 @@ func GenerateRuntime(cnf *config.Control) error {
|
||||||
os.MkdirAll(filepath.Join(cnf.DataDir, "tls"), 0700)
|
os.MkdirAll(filepath.Join(cnf.DataDir, "tls"), 0700)
|
||||||
os.MkdirAll(filepath.Join(cnf.DataDir, "cred"), 0700)
|
os.MkdirAll(filepath.Join(cnf.DataDir, "cred"), 0700)
|
||||||
|
|
||||||
deps.CreateRuntimeCertFiles(cnf, runtime)
|
deps.CreateRuntimeCertFiles(cnf)
|
||||||
|
|
||||||
if err := deps.GenServerDeps(cnf, runtime); err != nil {
|
return deps.GenServerDeps(cnf)
|
||||||
return err
|
|
||||||
}
|
|
||||||
cnf.Runtime = runtime
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClusterIPNet() *net.IPNet {
|
func ClusterIPNet() *net.IPNet {
|
||||||
|
|
Loading…
Reference in New Issue