mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
feat: add localhost cluster. it will use default kubeconfig(.kube/config).
Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
d1894b1e3e
commit
c09106c6b3
|
|
@ -158,8 +158,8 @@ linters-settings:
|
|||
- wrapperFunc
|
||||
- commentFormatting
|
||||
- filepathJoin
|
||||
- rangeValCopy
|
||||
- hugeParam
|
||||
# - rangeValCopy
|
||||
# - hugeParam
|
||||
stylecheck:
|
||||
checks:
|
||||
- -ST1000 # ignore package comment
|
||||
|
|
@ -251,4 +251,7 @@ run:
|
|||
go: "1.22"
|
||||
build-tags:
|
||||
- builtin
|
||||
executor-dirs:
|
||||
- .git
|
||||
- vendor
|
||||
allow-parallel-runners: true
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func NewConnector(host string, vars map[string]any) (Connector, error) {
|
|||
}, nil
|
||||
case "kubernetes":
|
||||
kubeconfig, err := variable.StringVar(nil, vars, "kubeconfig")
|
||||
if err != nil {
|
||||
if err != nil && host != _const.LocalHostName {
|
||||
return nil, err
|
||||
}
|
||||
return &kubernetesConnector{Cmd: exec.New(), clusterName: host, kubeconfig: kubeconfig}, nil
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ type kubernetesConnector struct {
|
|||
}
|
||||
|
||||
func (c *kubernetesConnector) Init(ctx context.Context) error {
|
||||
if c.clusterName == _const.LocalHostName && c.kubeconfig == "" {
|
||||
// use default kubeconfig. skip
|
||||
klog.V(4).InfoS("kubeconfig is not set, using local kubeconfig")
|
||||
return nil
|
||||
}
|
||||
c.kubeconfigPath = filepath.Join(_const.GetWorkDir(), "kubernetes", c.clusterName, "kubeconfig")
|
||||
if _, err := os.Stat(c.kubeconfigPath); err == nil || !os.IsNotExist(err) {
|
||||
klog.V(4).InfoS("kubeconfig file already exists", "cluster", c.clusterName)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/flosch/pongo2/v6"
|
||||
"gopkg.in/yaml.v3"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
)
|
||||
|
|
@ -38,6 +39,7 @@ func init() {
|
|||
utilruntime.Must(pongo2.RegisterFilter("to_yaml", filterToYaml))
|
||||
utilruntime.Must(pongo2.RegisterFilter("ip_range", filterIpRange))
|
||||
utilruntime.Must(pongo2.RegisterFilter("get", filterGet))
|
||||
utilruntime.Must(pongo2.RegisterFilter("rand", filterRand))
|
||||
}
|
||||
|
||||
func filterDefined(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||
|
|
@ -174,7 +176,6 @@ func filterIpRange(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo
|
|||
for _, s := range strings.Split(in.String(), ",") {
|
||||
ipRange = append(ipRange, ParseIp(s)...)
|
||||
}
|
||||
|
||||
return pongo2.AsValue(ipRange), nil
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +195,15 @@ func filterGet(in *pongo2.Value, param *pongo2.Value) (out *pongo2.Value, err *p
|
|||
}, func() {
|
||||
result = pongo2.AsValue(nil)
|
||||
})
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func filterRand(in *pongo2.Value, param *pongo2.Value) (out *pongo2.Value, err *pongo2.Error) {
|
||||
if !param.IsInteger() {
|
||||
return pongo2.AsValue(nil), &pongo2.Error{
|
||||
Sender: "rand",
|
||||
OrigError: fmt.Errorf("param is not format int"),
|
||||
}
|
||||
}
|
||||
return pongo2.AsValue(rand.String(param.Integer())), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue