dev-v2.0.0: fix api cluster.kubesphere.io not found bug

Signed-off-by: 24sama <leo@kubesphere.io>
This commit is contained in:
24sama 2021-10-27 13:54:43 +08:00
parent c9773712a5
commit 160b4cdbae
7 changed files with 24 additions and 25 deletions

View File

@ -288,7 +288,7 @@ func (cfg *ClusterSpec) GroupHosts() (*HostGroups, error) {
logger.Log.Fatal(errors.New("The number of etcd cannot be 0"))
}
if len(masterGroup) != len(cfg.Hosts) {
if len(masterGroup) != len(clusterHostsGroups.Master) {
return nil, errors.New("Incorrect nodeName under roleGroups/master in the configuration file")
}
if len(etcdGroup) != len(clusterHostsGroups.Etcd) {

View File

@ -258,10 +258,8 @@ func getClusterClientSet(runtime *common.KubeRuntime) (*kube.Clientset, error) {
}
obj, err := clientset.RESTClient().Get().AbsPath("/apis/cluster.kubesphere.io/v1alpha1/clusters").Name(runtime.ClusterName).Do(context.TODO()).Raw()
if err != nil && !kubeErr.IsNotFound(err) {
if err != nil {
return nil, err
} else if kubeErr.IsNotFound(err) {
return nil, nil
}
result := make(map[string]interface{})
@ -305,11 +303,13 @@ func nodeForCluster(name string, labels map[string]string) *corev1.Node {
// CreateNodeForCluster is used to create new nodes for the cluster to be add nodes.
func CreateNodeForCluster(runtime *common.KubeRuntime) error {
clientsetForCluster, err := getClusterClientSet(runtime)
if err != nil && !kubeErr.IsNotFound(err) {
if err != nil {
if kubeErr.IsNotFound(err) {
return nil
}
return err
} else if kubeErr.IsNotFound(err) {
return nil
}
nodeInfo := make(map[string]string)
nodeList, _ := clientsetForCluster.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
for _, node := range nodeList.Items {
@ -339,10 +339,11 @@ func CreateNodeForCluster(runtime *common.KubeRuntime) error {
// PatchNodeImportStatus is used to update new node's status.
func PatchNodeImportStatus(runtime *common.KubeRuntime, status string) error {
clientsetForCluster, err := getClusterClientSet(runtime)
if err != nil && !kubeErr.IsNotFound(err) {
if err != nil {
if kubeErr.IsNotFound(err) {
return nil
}
return err
} else if kubeErr.IsNotFound(err) {
return nil
}
patchStr := fmt.Sprintf(`{"metadata": {"labels": {"kubekey.kubesphere.io/import-status": "%s"}}}`, status)

View File

@ -19,7 +19,7 @@ Explanation of parameters:
```
example:
```yaml
apiVersion: kubekey.kubesphere.io/v1alpha1
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: example

View File

@ -1,5 +1,5 @@
```yaml
apiVersion: kubekey.kubesphere.io/v1alpha1
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample

View File

@ -3,7 +3,6 @@ package binaries
import (
"crypto/sha256"
"fmt"
kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha2"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/cache"
@ -29,14 +28,14 @@ func K8sFilesDownloadHTTP(kubeConf *common.KubeConf, filepath, version, arch str
docker := files.KubeBinary{Name: "docker", Arch: arch, Version: kubekeyapiv1alpha2.DefaultDockerVersion}
crictl := files.KubeBinary{Name: "crictl", Arch: arch, Version: kubekeyapiv1alpha2.DefaultCrictlVersion}
etcd.Path = fmt.Sprintf("%s/etcd-%s-linux-%s.tar.gz", filepath, kubekeyapiv1alpha1.DefaultEtcdVersion, arch)
etcd.Path = fmt.Sprintf("%s/etcd-%s-linux-%s.tar.gz", filepath, kubekeyapiv1alpha2.DefaultEtcdVersion, arch)
kubeadm.Path = fmt.Sprintf("%s/kubeadm", filepath)
kubelet.Path = fmt.Sprintf("%s/kubelet", filepath)
kubectl.Path = fmt.Sprintf("%s/kubectl", filepath)
kubecni.Path = fmt.Sprintf("%s/cni-plugins-linux-%s-%s.tgz", filepath, arch, kubekeyapiv1alpha1.DefaultCniVersion)
kubecni.Path = fmt.Sprintf("%s/cni-plugins-linux-%s-%s.tgz", filepath, arch, kubekeyapiv1alpha2.DefaultCniVersion)
helm.Path = fmt.Sprintf("%s/helm", filepath)
docker.Path = fmt.Sprintf("%s/docker-%s.tgz", filepath, kubekeyapiv1alpha1.DefaultDockerVersion)
crictl.Path = fmt.Sprintf("%s/crictl-%s-linux-%s.tar.gz", filepath, kubekeyapiv1alpha1.DefaultCrictlVersion, arch)
docker.Path = fmt.Sprintf("%s/docker-%s.tgz", filepath, kubekeyapiv1alpha2.DefaultDockerVersion)
crictl.Path = fmt.Sprintf("%s/crictl-%s-linux-%s.tar.gz", filepath, kubekeyapiv1alpha2.DefaultCrictlVersion, arch)
if kkzone == "cn" {
etcd.Url = fmt.Sprintf("https://kubernetes-release.pek3b.qingstor.com/etcd/release/download/%s/etcd-%s-linux-%s.tar.gz", etcd.Version, etcd.Version, etcd.Arch)
@ -47,7 +46,7 @@ func K8sFilesDownloadHTTP(kubeConf *common.KubeConf, filepath, version, arch str
helm.Url = fmt.Sprintf("https://kubernetes-helm.pek3b.qingstor.com/linux-%s/%s/helm", helm.Arch, helm.Version)
helm.GetCmd = kubeConf.Arg.DownloadCommand(helm.Path, helm.Url)
docker.Url = fmt.Sprintf("https://mirrors.aliyun.com/docker-ce/linux/static/stable/%s/docker-%s.tgz", util.ArchAlias(docker.Arch), docker.Version)
crictl.Url = fmt.Sprintf("https://kubernetes-release.pek3b.qingstor.com/cri-tools/releases/download/%s/crictl-%s-linux-%s.tar.gz", kubekeyapiv1alpha1.DefaultCrictlVersion, kubekeyapiv1alpha1.DefaultCrictlVersion, arch)
crictl.Url = fmt.Sprintf("https://kubernetes-release.pek3b.qingstor.com/cri-tools/releases/download/%s/crictl-%s-linux-%s.tar.gz", kubekeyapiv1alpha2.DefaultCrictlVersion, kubekeyapiv1alpha2.DefaultCrictlVersion, arch)
} else {
etcd.Url = fmt.Sprintf("https://github.com/coreos/etcd/releases/download/%s/etcd-%s-linux-%s.tar.gz", etcd.Version, etcd.Version, etcd.Arch)
kubeadm.Url = fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/kubeadm", kubeadm.Version, kubeadm.Arch)
@ -58,7 +57,7 @@ func K8sFilesDownloadHTTP(kubeConf *common.KubeConf, filepath, version, arch str
getCmd := kubeConf.Arg.DownloadCommand(fmt.Sprintf("%s/helm-%s-linux-%s.tar.gz", filepath, helm.Version, helm.Arch), helm.Url)
helm.GetCmd = fmt.Sprintf("%s && cd %s && tar -zxf helm-%s-linux-%s.tar.gz && mv linux-%s/helm . && rm -rf *linux-%s*", getCmd, filepath, helm.Version, helm.Arch, helm.Arch, helm.Arch)
docker.Url = fmt.Sprintf("https://download.docker.com/linux/static/stable/%s/docker-%s.tgz", util.ArchAlias(docker.Arch), docker.Version)
crictl.Url = fmt.Sprintf("https://github.com/kubernetes-sigs/cri-tools/releases/download/%s/crictl-%s-linux-%s.tar.gz", kubekeyapiv1alpha1.DefaultCrictlVersion, kubekeyapiv1alpha1.DefaultCrictlVersion, arch)
crictl.Url = fmt.Sprintf("https://github.com/kubernetes-sigs/cri-tools/releases/download/%s/crictl-%s-linux-%s.tar.gz", kubekeyapiv1alpha2.DefaultCrictlVersion, kubekeyapiv1alpha2.DefaultCrictlVersion, arch)
}
kubeadm.GetCmd = kubeConf.Arg.DownloadCommand(kubeadm.Path, kubeadm.Url)
@ -128,7 +127,7 @@ func SHA256Check(binary files.KubeBinary) error {
}
if strings.TrimSpace(binary.GetSha256()) == "" {
return errors.New(fmt.Sprintf("No SHA256 found for %s. %s is not supported.", binary.Version, binary.Version))
return errors.New(fmt.Sprintf("No SHA256 found for %s. %s is not supported.", binary.Name, binary.Version))
}
if output != binary.GetSha256() {
return errors.New(fmt.Sprintf("SHA256 no match. %s not equal %s", binary.GetSha256(), output))

View File

@ -2,7 +2,6 @@ package binaries
import (
"fmt"
kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha2"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/connector"
@ -59,7 +58,7 @@ func (k *K3sDownload) Execute(runtime connector.Runtime) error {
var kubeVersion string
if cfg.Kubernetes.Version == "" {
kubeVersion = kubekeyapiv1alpha1.DefaultKubeVersion
kubeVersion = kubekeyapiv1alpha2.DefaultKubeVersion
} else {
kubeVersion = cfg.Kubernetes.Version
}

View File

@ -2,7 +2,7 @@ package k3s
import (
"fmt"
kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha2"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/action"
"github.com/kubesphere/kubekey/pkg/core/connector"
@ -215,13 +215,13 @@ func (g *GenerateK3sServiceEnv) Execute(runtime connector.Runtime) error {
}
cluster := clusterStatus.(*K3sStatus)
var externalEtcd kubekeyapiv1alpha1.ExternalEtcd
var externalEtcd kubekeyapiv1alpha2.ExternalEtcd
var endpointsList []string
var caFile, certFile, keyFile string
var token string
for _, node := range runtime.GetHostsByRole(common.ETCD) {
endpoint := fmt.Sprintf("https://%s:%s", node.GetInternalAddress(), kubekeyapiv1alpha1.DefaultEtcdPort)
endpoint := fmt.Sprintf("https://%s:%s", node.GetInternalAddress(), kubekeyapiv1alpha2.DefaultEtcdPort)
endpointsList = append(endpointsList, endpoint)
}
externalEtcd.Endpoints = endpointsList