2020-04-27 17:09:58 +00:00
|
|
|
// +build !no_embedded_executor
|
|
|
|
|
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2021-05-11 19:50:08 +00:00
|
|
|
"github.com/rancher/k3s/pkg/cli/cmds"
|
|
|
|
daemonconfig "github.com/rancher/k3s/pkg/daemons/config"
|
2021-06-29 14:28:38 +00:00
|
|
|
"github.com/rancher/k3s/pkg/version"
|
2020-04-27 17:09:58 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-06-29 14:28:38 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
"k8s.io/apiserver/pkg/authentication/authenticator"
|
|
|
|
ccm "k8s.io/cloud-provider"
|
|
|
|
cloudprovider "k8s.io/cloud-provider"
|
|
|
|
ccmapp "k8s.io/cloud-provider/app"
|
|
|
|
cloudcontrollerconfig "k8s.io/cloud-provider/app/config"
|
|
|
|
ccmopt "k8s.io/cloud-provider/options"
|
|
|
|
cliflag "k8s.io/component-base/cli/flag"
|
2020-04-27 17:09:58 +00:00
|
|
|
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
|
|
|
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
2021-06-29 14:28:38 +00:00
|
|
|
proxy "k8s.io/kubernetes/cmd/kube-proxy/app"
|
2020-04-27 17:09:58 +00:00
|
|
|
sapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
|
2021-06-29 14:28:38 +00:00
|
|
|
kubelet "k8s.io/kubernetes/cmd/kubelet/app"
|
|
|
|
|
|
|
|
// registering k3s cloud provider
|
|
|
|
_ "github.com/rancher/k3s/pkg/cloudprovider"
|
2020-04-27 17:09:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
executor = Embedded{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Embedded struct{}
|
|
|
|
|
2021-05-11 19:50:08 +00:00
|
|
|
func (Embedded) Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node, cfg cmds.Agent) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-27 17:09:58 +00:00
|
|
|
func (Embedded) Kubelet(args []string) error {
|
2020-08-05 16:26:36 +00:00
|
|
|
command := kubelet.NewKubeletCommand(context.Background())
|
2020-04-27 17:09:58 +00:00
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
logrus.Fatalf("kubelet exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Embedded) KubeProxy(args []string) error {
|
|
|
|
command := proxy.NewProxyCommand()
|
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
logrus.Fatalf("kube-proxy exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:02:16 +00:00
|
|
|
func (Embedded) APIServer(ctx context.Context, etcdReady <-chan struct{}, args []string) (authenticator.Request, http.Handler, error) {
|
|
|
|
<-etcdReady
|
2020-04-27 17:09:58 +00:00
|
|
|
command := app.NewAPIServerCommand(ctx.Done())
|
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
logrus.Fatalf("apiserver exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
startupConfig := <-app.StartupConfig
|
|
|
|
return startupConfig.Authenticator, startupConfig.Handler, nil
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:44:05 +00:00
|
|
|
func (Embedded) Scheduler(apiReady <-chan struct{}, args []string) error {
|
2020-04-27 17:09:58 +00:00
|
|
|
command := sapp.NewSchedulerCommand()
|
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
2020-04-28 22:44:05 +00:00
|
|
|
<-apiReady
|
2020-04-27 17:09:58 +00:00
|
|
|
logrus.Fatalf("scheduler exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:44:05 +00:00
|
|
|
func (Embedded) ControllerManager(apiReady <-chan struct{}, args []string) error {
|
2020-04-27 17:09:58 +00:00
|
|
|
command := cmapp.NewControllerManagerCommand()
|
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
2020-04-28 22:44:05 +00:00
|
|
|
<-apiReady
|
2020-04-27 17:09:58 +00:00
|
|
|
logrus.Fatalf("controller-manager exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-29 14:28:38 +00:00
|
|
|
|
|
|
|
func (Embedded) CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error {
|
|
|
|
ccmOptions, err := ccmopt.NewCloudControllerManagerOptions()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("unable to initialize command options: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cloudInitializer := func(config *cloudcontrollerconfig.CompletedConfig) cloudprovider.Interface {
|
|
|
|
cloud, err := ccm.InitCloudProvider(version.Program, "")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Cloud provider could not be initialized: %v", err)
|
|
|
|
}
|
|
|
|
if cloud == nil {
|
|
|
|
logrus.Fatalf("Cloud provider is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
cloud.Initialize(config.ClientBuilder, make(chan struct{}))
|
|
|
|
if informerUserCloud, ok := cloud.(ccm.InformerUser); ok {
|
|
|
|
informerUserCloud.SetInformers(config.SharedInformers)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloud
|
|
|
|
}
|
|
|
|
|
|
|
|
controllerInitializers := ccmapp.DefaultInitFuncConstructors
|
|
|
|
delete(controllerInitializers, "service")
|
|
|
|
delete(controllerInitializers, "route")
|
|
|
|
|
|
|
|
command := ccmapp.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, cliflag.NamedFlagSets{}, wait.NeverStop)
|
|
|
|
command.SetArgs(args)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-ccmRBACReady
|
|
|
|
logrus.Fatalf("cloud-controller-manager exited: %v", command.Execute())
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|