2018-10-24 23:21:28 +00:00
|
|
|
// +build k8s
|
2018-10-22 17:52:52 +00:00
|
|
|
|
|
|
|
package k8s
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/rancher/norman/pkg/kwrapper/etcd"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
"k8s.io/kubernetes/pkg/wrapper/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getEmbedded(ctx context.Context) (bool, context.Context, *rest.Config, error) {
|
2018-10-24 23:21:28 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2018-10-22 17:52:52 +00:00
|
|
|
sc, ok := ctx.Value(serverConfig).(*server.ServerConfig)
|
|
|
|
if !ok {
|
2018-10-24 23:21:28 +00:00
|
|
|
ctx, sc, _, err = NewK3sConfig(ctx, "./management-state", nil)
|
2018-10-22 17:52:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, ctx, nil, err
|
|
|
|
}
|
|
|
|
sc.NoScheduler = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(sc.ETCDEndpoints) == 0 {
|
2018-10-24 23:21:28 +00:00
|
|
|
etcdEndpoints, err := etcd.RunETCD(ctx, sc.DataDir)
|
2018-10-22 17:52:52 +00:00
|
|
|
if err != nil {
|
2018-10-24 23:21:28 +00:00
|
|
|
return false, ctx, nil, err
|
2018-10-22 17:52:52 +00:00
|
|
|
}
|
|
|
|
sc.ETCDEndpoints = etcdEndpoints
|
|
|
|
}
|
|
|
|
|
2018-10-24 23:21:28 +00:00
|
|
|
if err = server.Server(ctx, sc); err != nil {
|
2018-10-22 17:52:52 +00:00
|
|
|
return false, ctx, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("KUBECONFIG", sc.KubeConfig)
|
|
|
|
restConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
|
|
|
&clientcmd.ClientConfigLoadingRules{ExplicitPath: sc.KubeConfig}, &clientcmd.ConfigOverrides{}).ClientConfig()
|
|
|
|
|
|
|
|
return true, ctx, restConfig, err
|
|
|
|
}
|