Skip to content

Commit

Permalink
fix(platform): fix test e2e failed (tkestack#1477)
Browse files Browse the repository at this point in the history
1. add platformAPIClientConfig
2. add namespace in tke-platform-api
3. modify validate spec logic

Co-authored-by: Cui Shuaijie <[email protected]>
  • Loading branch information
TomatoAres and Cui Shuaijie committed Aug 13, 2021
1 parent 53eb3a1 commit 083b789
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/platform/provider/baremetal/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/client-go/tools/clientcmd"

platformv1client "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
"tkestack.io/tke/api/platform"
"tkestack.io/tke/pkg/platform/provider/baremetal/config"
Expand Down Expand Up @@ -179,7 +180,6 @@ func NewProvider() (*Provider, error) {
}
}
}

return p, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/platform/provider/baremetal/conf/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
platformAPIClientConfig: conf/tke-platform-config.yaml
registry:
prefix: docker.io/tkestack
ip: ""
25 changes: 19 additions & 6 deletions pkg/platform/provider/baremetal/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
"net"
"strings"

k8serror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"tkestack.io/tke/api/platform"

netutils "k8s.io/utils/net"

platformv1client "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
"tkestack.io/tke/api/platform"
platformv1 "tkestack.io/tke/api/platform/v1"
csioperatorimage "tkestack.io/tke/pkg/platform/provider/baremetal/phases/csioperator/images"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/gpu"
Expand All @@ -38,6 +39,7 @@ import (
vendor "tkestack.io/tke/pkg/platform/util/kubevendor"
"tkestack.io/tke/pkg/spec"
"tkestack.io/tke/pkg/util/ipallocator"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/validation"
utilvalidation "tkestack.io/tke/pkg/util/validation"
)
Expand Down Expand Up @@ -98,15 +100,26 @@ func ValidateClusterSpecVersion(platformClient platformv1client.PlatformV1Interf
}

func getK8sValidVersions(platformClient platformv1client.PlatformV1Interface, clsName string) (validVersions []string, err error) {
k8sValidVersions := []string{}
if clsName == "global" || platformClient == nil {
return spec.K8sVersions, nil
}
client, err := util.BuildExternalClientSetWithName(context.Background(), platformClient, "global")

cluster, err := platformClient.Clusters().Get(context.Background(), "global", metav1.GetOptions{})
if err != nil {
return k8sValidVersions, err
if k8serror.IsNotFound(err) {
log.Warnf("global cluster is not exist")

return spec.K8sVersions, nil
}
return nil, err
}
_, k8sValidVersions, err = util.GetPlatformVersionsFromClusterInfo(context.Background(), client)

client, err := util.BuildExternalClientSet(context.Background(), cluster, platformClient)
if err != nil {
return nil, err
}

_, k8sValidVersions, err := util.GetPlatformVersionsFromClusterInfo(context.Background(), client)

return k8sValidVersions, err
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifests/tke-platform-api/tke-platform-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ data:
- name: tke
cluster:
insecure-skip-tls-verify: true
server: https://tke-platform-api
server: https://tke-platform-api.{{ .Namespace }}
users:
- name: admin-cert
user:
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/platform/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ import (
"errors"
"time"

"tkestack.io/tke/pkg/platform/apiserver/cluster"
"tkestack.io/tke/test/e2e/tke"
tke2 "tkestack.io/tke/test/tke"
"tkestack.io/tke/test/util"
"tkestack.io/tke/test/util/cloudprovider/tencent"
"tkestack.io/tke/test/util/env"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

tkeclientset "tkestack.io/tke/api/client/clientset/versioned"
platformv1 "tkestack.io/tke/api/platform/v1"
"tkestack.io/tke/pkg/platform/apiserver/cluster"
_ "tkestack.io/tke/pkg/platform/provider/baremetal/cluster"
_ "tkestack.io/tke/pkg/platform/provider/baremetal/machine"
_ "tkestack.io/tke/pkg/platform/provider/imported/cluster"
_ "tkestack.io/tke/pkg/platform/provider/registered/cluster"
"tkestack.io/tke/test/e2e/tke"
tke2 "tkestack.io/tke/test/tke"
"tkestack.io/tke/test/util"
"tkestack.io/tke/test/util/cloudprovider"
"tkestack.io/tke/test/util/cloudprovider/tencent"
"tkestack.io/tke/test/util/env"
)

const namespacePrefix = "platform-"
Expand Down
13 changes: 5 additions & 8 deletions test/e2e/tke/tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ import (
"os"
"time"

"k8s.io/klog"

"github.com/onsi/gomega"

"tkestack.io/tke/cmd/tke-installer/app/installer/types"

"tkestack.io/tke/test/e2e"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"

"tkestack.io/tke/cmd/tke-installer/app/installer/types"
"tkestack.io/tke/pkg/util/apiclient"
"tkestack.io/tke/test/e2e"
"tkestack.io/tke/test/e2e/certs"
testclient "tkestack.io/tke/test/util/client"
"tkestack.io/tke/test/util/env"
Expand Down

0 comments on commit 083b789

Please sign in to comment.