2020-04-27 17:09:58 +00:00
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-05 22:02:16 +00:00
|
|
|
"io/ioutil"
|
2020-04-27 17:09:58 +00:00
|
|
|
"net/http"
|
2020-05-05 22:02:16 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"sigs.k8s.io/yaml"
|
2020-04-27 17:09:58 +00:00
|
|
|
|
2021-05-11 19:50:08 +00:00
|
|
|
"github.com/rancher/k3s/pkg/cli/cmds"
|
|
|
|
daemonconfig "github.com/rancher/k3s/pkg/daemons/config"
|
2020-04-27 17:09:58 +00:00
|
|
|
"k8s.io/apiserver/pkg/authentication/authenticator"
|
|
|
|
)
|
|
|
|
|
2020-05-05 22:02:16 +00:00
|
|
|
var (
|
|
|
|
executor Executor
|
|
|
|
)
|
|
|
|
|
2020-04-27 17:09:58 +00:00
|
|
|
type Executor interface {
|
2021-05-11 19:50:08 +00:00
|
|
|
Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node, cfg cmds.Agent) error
|
2020-04-27 17:09:58 +00:00
|
|
|
Kubelet(args []string) error
|
|
|
|
KubeProxy(args []string) error
|
2020-05-05 22:02:16 +00:00
|
|
|
APIServer(ctx context.Context, etcdReady <-chan struct{}, args []string) (authenticator.Request, http.Handler, error)
|
2020-04-28 22:44:05 +00:00
|
|
|
Scheduler(apiReady <-chan struct{}, args []string) error
|
|
|
|
ControllerManager(apiReady <-chan struct{}, args []string) error
|
2020-05-05 22:02:16 +00:00
|
|
|
CurrentETCDOptions() (InitialOptions, error)
|
|
|
|
ETCD(args ETCDConfig) error
|
2021-06-29 14:28:38 +00:00
|
|
|
CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error
|
2020-04-27 17:09:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:02:16 +00:00
|
|
|
type ETCDConfig struct {
|
|
|
|
InitialOptions `json:",inline"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
ListenClientURLs string `json:"listen-client-urls,omitempty"`
|
|
|
|
ListenMetricsURLs string `json:"listen-metrics-urls,omitempty"`
|
|
|
|
ListenPeerURLs string `json:"listen-peer-urls,omitempty"`
|
|
|
|
AdvertiseClientURLs string `json:"advertise-client-urls,omitempty"`
|
|
|
|
DataDir string `json:"data-dir,omitempty"`
|
|
|
|
SnapshotCount int `json:"snapshot-count,omitempty"`
|
|
|
|
ServerTrust ServerTrust `json:"client-transport-security"`
|
|
|
|
PeerTrust PeerTrust `json:"peer-transport-security"`
|
|
|
|
ForceNewCluster bool `json:"force-new-cluster,omitempty"`
|
2020-05-27 19:10:24 +00:00
|
|
|
HeartbeatInterval int `json:"heartbeat-interval"`
|
|
|
|
ElectionTimeout int `json:"election-timeout"`
|
2020-10-27 18:06:26 +00:00
|
|
|
Logger string `json:"logger"`
|
|
|
|
LogOutputs []string `json:"log-outputs"`
|
2020-05-05 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ServerTrust struct {
|
|
|
|
CertFile string `json:"cert-file"`
|
|
|
|
KeyFile string `json:"key-file"`
|
|
|
|
ClientCertAuth bool `json:"client-cert-auth"`
|
|
|
|
TrustedCAFile string `json:"trusted-ca-file"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PeerTrust struct {
|
|
|
|
CertFile string `json:"cert-file"`
|
|
|
|
KeyFile string `json:"key-file"`
|
|
|
|
ClientCertAuth bool `json:"client-cert-auth"`
|
|
|
|
TrustedCAFile string `json:"trusted-ca-file"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InitialOptions struct {
|
|
|
|
AdvertisePeerURL string `json:"initial-advertise-peer-urls,omitempty"`
|
|
|
|
Cluster string `json:"initial-cluster,omitempty"`
|
|
|
|
State string `json:"initial-cluster-state,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e ETCDConfig) ToConfigFile() (string, error) {
|
|
|
|
confFile := filepath.Join(e.DataDir, "config")
|
|
|
|
bytes, err := yaml.Marshal(&e)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(e.DataDir, 0700); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return confFile, ioutil.WriteFile(confFile, bytes, 0600)
|
|
|
|
}
|
2020-04-27 17:09:58 +00:00
|
|
|
|
|
|
|
func Set(driver Executor) {
|
|
|
|
executor = driver
|
|
|
|
}
|
|
|
|
|
2021-05-11 19:50:08 +00:00
|
|
|
func Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node, cfg cmds.Agent) error {
|
|
|
|
return executor.Bootstrap(ctx, nodeConfig, cfg)
|
|
|
|
}
|
|
|
|
|
2020-04-27 17:09:58 +00:00
|
|
|
func Kubelet(args []string) error {
|
|
|
|
return executor.Kubelet(args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func KubeProxy(args []string) error {
|
|
|
|
return executor.KubeProxy(args)
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:02:16 +00:00
|
|
|
func APIServer(ctx context.Context, etcdReady <-chan struct{}, args []string) (authenticator.Request, http.Handler, error) {
|
|
|
|
return executor.APIServer(ctx, etcdReady, args)
|
2020-04-27 17:09:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:44:05 +00:00
|
|
|
func Scheduler(apiReady <-chan struct{}, args []string) error {
|
|
|
|
return executor.Scheduler(apiReady, args)
|
2020-04-27 17:09:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:44:05 +00:00
|
|
|
func ControllerManager(apiReady <-chan struct{}, args []string) error {
|
|
|
|
return executor.ControllerManager(apiReady, args)
|
2020-04-27 17:09:58 +00:00
|
|
|
}
|
2020-05-05 22:02:16 +00:00
|
|
|
|
|
|
|
func CurrentETCDOptions() (InitialOptions, error) {
|
|
|
|
return executor.CurrentETCDOptions()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ETCD(args ETCDConfig) error {
|
|
|
|
return executor.ETCD(args)
|
|
|
|
}
|
2021-06-29 14:28:38 +00:00
|
|
|
|
|
|
|
func CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error {
|
|
|
|
return executor.CloudControllerManager(ccmRBACReady, args)
|
|
|
|
}
|