Skip to content

Commit

Permalink
feat(platform): add kube vendor in cluster (tkestack#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ryu committed Apr 21, 2021
1 parent 6a9710b commit e015eae
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 372 deletions.
6 changes: 6 additions & 0 deletions api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 34 additions & 7 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ type ClusterMachine struct {
Taints []corev1.Taint
}

// KubeVendorType describe the kubernetes provider of the cluster
// ref https://github.com/open-cluster-management/multicloud-operators-foundation/blob/e94b719de6d5f3541e948dd70ad8f1ff748aa452/pkg/apis/internal.open-cluster-management.io/v1beta1/clusterinfo_types.go#L137
type KubeVendorType string

const (
// KubeVendorTKE TKE
KubeVendorTKE KubeVendorType = "TKE"
// KubeVendorOpenShift OpenShift
KubeVendorOpenShift KubeVendorType = "OpenShift"
// KubeVendorAKS Azure Kuberentes Service
KubeVendorAKS KubeVendorType = "AKS"
// KubeVendorEKS Elastic Kubernetes Service
KubeVendorEKS KubeVendorType = "EKS"
// KubeVendorGKE Google Kubernetes Engine
KubeVendorGKE KubeVendorType = "GKE"
// KubeVendorICP IBM Cloud Private
KubeVendorICP KubeVendorType = "ICP"
// KubeVendorIKS IBM Kubernetes Service
KubeVendorIKS KubeVendorType = "IKS"
// KubeVendorOSD OpenShiftDedicated
KubeVendorOSD KubeVendorType = "OpenShiftDedicated"
// KubeVendorOther other (unable to auto detect)
KubeVendorOther KubeVendorType = "Other"
)

// ClusterSpec is a description of a cluster.
type ClusterSpec struct {
// Finalizers is an opaque list of values that must be empty to permanently remove object from storage.
Expand Down Expand Up @@ -174,6 +199,8 @@ type ClusterStatus struct {
NodeCIDRMaskSizeIPv4 int32
// +optional
NodeCIDRMaskSizeIPv6 int32
// +optional
KubeVendor KubeVendorType
}

// FinalizerName is the name identifying a finalizer during cluster lifecycle.
Expand Down Expand Up @@ -367,7 +394,7 @@ type HA struct {
}

type TKEHA struct {
VIP string
VIP string
VRID *int32
}

Expand Down Expand Up @@ -760,12 +787,12 @@ type StorageBackEndCLS struct {
// StorageBackEndES records the attributes required when the backend storage
// type is ElasticSearch.
type StorageBackEndES struct {
IP string
Port int32
Scheme string
IndexName string
User string
Password string
IP string
Port int32
Scheme string
IndexName string
User string
Password string
ReserveDays int32
}

Expand Down
766 changes: 405 additions & 361 deletions api/platform/v1/generated.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/platform/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ type ClusterMachine struct {
Taints []corev1.Taint `json:"taints,omitempty" protobuf:"bytes,8,opt,name=taints"`
}

// KubeVendorType describe the kubernetes provider of the cluster
// ref https://github.com/open-cluster-management/multicloud-operators-foundation/blob/e94b719de6d5f3541e948dd70ad8f1ff748aa452/pkg/apis/internal.open-cluster-management.io/v1beta1/clusterinfo_types.go#L137
type KubeVendorType string

const (
// KubeVendorTKE TKE
KubeVendorTKE KubeVendorType = "TKE"
// KubeVendorOpenShift OpenShift
KubeVendorOpenShift KubeVendorType = "OpenShift"
// KubeVendorAKS Azure Kuberentes Service
KubeVendorAKS KubeVendorType = "AKS"
// KubeVendorEKS Elastic Kubernetes Service
KubeVendorEKS KubeVendorType = "EKS"
// KubeVendorGKE Google Kubernetes Engine
KubeVendorGKE KubeVendorType = "GKE"
// KubeVendorICP IBM Cloud Private
KubeVendorICP KubeVendorType = "ICP"
// KubeVendorIKS IBM Kubernetes Service
KubeVendorIKS KubeVendorType = "IKS"
// KubeVendorOSD OpenShiftDedicated
KubeVendorOSD KubeVendorType = "OpenShiftDedicated"
// KubeVendorOther other (unable to auto detect)
KubeVendorOther KubeVendorType = "Other"
)

// ClusterSpec is a description of a cluster.
type ClusterSpec struct {
// Finalizers is an opaque list of values that must be empty to permanently remove object from storage.
Expand Down Expand Up @@ -180,6 +205,8 @@ type ClusterStatus struct {
NodeCIDRMaskSizeIPv4 int32 `json:"nodeCIDRMaskSizeIPv4,omitempty" protobuf:"varint,18,opt,name=nodeCIDRMaskSizeIPv4"`
// +optional
NodeCIDRMaskSizeIPv6 int32 `json:"nodeCIDRMaskSizeIPv6,omitempty" protobuf:"varint,19,opt,name=nodeCIDRMaskSizeIPv6"`
// +optional
KubeVendor KubeVendorType `json:"kubeVendor" protobuf:"bytes,20,opt,name=kubeVendor"`
}

// FinalizerName is the name identifying a finalizer during cluster lifecycle.
Expand Down
2 changes: 2 additions & 0 deletions api/platform/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/mesh/apis/config/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/mesh/apis/config/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/mesh/apis/config/v1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/mesh/apis/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/platform/controller/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"tkestack.io/tke/pkg/platform/controller/cluster/deletion"
clusterprovider "tkestack.io/tke/pkg/platform/provider/cluster"
typesv1 "tkestack.io/tke/pkg/platform/types/v1"
"tkestack.io/tke/pkg/platform/util/vendor"
"tkestack.io/tke/pkg/util/apiclient"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/metrics"
Expand Down Expand Up @@ -481,6 +482,7 @@ func (c *Controller) checkHealth(ctx context.Context, cluster *typesv1.Cluster)
} else {
cluster.Status.Phase = platformv1.ClusterRunning
cluster.Status.Version = strings.TrimPrefix(version.String(), "v")
cluster.Status.KubeVendor = vendor.GetKubeVendor(cluster.Status.Version)

healthCheckCondition.Status = platformv1.ConditionTrue
}
Expand All @@ -490,6 +492,7 @@ func (c *Controller) checkHealth(ctx context.Context, cluster *typesv1.Cluster)

log.FromContext(ctx).Info("Update cluster health status",
"version", cluster.Status.Version,
"kubevendor", cluster.Status.KubeVendor,
"phase", cluster.Status.Phase)

return cluster
Expand Down
33 changes: 33 additions & 0 deletions pkg/platform/provider/baremetal/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import (
"net"
"strings"

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"
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"
"tkestack.io/tke/pkg/platform/types"
"tkestack.io/tke/pkg/platform/util"
"tkestack.io/tke/pkg/platform/util/vendor"
"tkestack.io/tke/pkg/spec"
"tkestack.io/tke/pkg/util/ipallocator"
"tkestack.io/tke/pkg/util/validation"
Expand Down Expand Up @@ -77,6 +80,19 @@ func ValidateClusterSpecVersion(platformClient platformv1client.PlatformV1Interf
if phase == platform.ClusterInitializing {
allErrs = utilvalidation.ValidateEnum(version, fldPath, k8sValidVersions)
}
if phase == platform.ClusterUpgrading {
c, err := platformClient.Clusters().Get(context.Background(), clsName, metav1.GetOptions{})
if err != nil {
allErrs = append(allErrs, field.InternalError(fldPath, err))
return allErrs
}
dstKubevendor := vendor.GetKubeVendor(version)
if err := validateKubevendor(c.Status.KubeVendor, dstKubevendor); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath,
err,
"current kubevendor is not supported to upgrade to input version"))
}
}

return allErrs
}
Expand All @@ -95,6 +111,23 @@ func getK8sValidVersions(platformClient platformv1client.PlatformV1Interface, cl
return k8sValidVersions, err
}

func validateKubevendor(srcKubevendor, dstKubevendor platformv1.KubeVendorType) (err error) {
notSupportUpgradeMessage := "not support upgrade from vendor %v to vendor %v"
switch srcKubevendor {
case platformv1.KubeVendorTKE:
if dstKubevendor != platformv1.KubeVendorTKE {
return fmt.Errorf(notSupportUpgradeMessage, srcKubevendor, dstKubevendor)
}
case platformv1.KubeVendorOther:
if dstKubevendor != platformv1.KubeVendorOther && dstKubevendor != platformv1.KubeVendorTKE {
return fmt.Errorf(notSupportUpgradeMessage, srcKubevendor, dstKubevendor)
}
default:
return fmt.Errorf(notSupportUpgradeMessage, srcKubevendor, dstKubevendor)
}
return nil
}

// ValidateCIDRs validates clusterCIDR and serviceCIDR.
func ValidateCIDRs(spec *platform.ClusterSpec, specPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
Expand Down
50 changes: 50 additions & 0 deletions pkg/platform/util/vendor/vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2021 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the “License”); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package vendor

import (
"strings"

platformv1 "tkestack.io/tke/api/platform/v1"
)

// GetKubeVendor get k8s vendor from k8s version
// ref https://github.com/open-cluster-management/multicloud-operators-foundation/blob/e94b719de6d5f3541e948dd70ad8f1ff748aa452/pkg/klusterlet/clusterinfo/clusterinfo_controller.go#L326
func GetKubeVendor(version string) (kubeVendor platformv1.KubeVendorType) {
version = strings.ToUpper(version)
switch {
case strings.Contains(version, string(platformv1.KubeVendorTKE)):
kubeVendor = platformv1.KubeVendorTKE
return
case strings.Contains(version, string(platformv1.KubeVendorIKS)):
kubeVendor = platformv1.KubeVendorIKS
return
case strings.Contains(version, string(platformv1.KubeVendorEKS)):
kubeVendor = platformv1.KubeVendorEKS
return
case strings.Contains(version, string(platformv1.KubeVendorGKE)):
kubeVendor = platformv1.KubeVendorGKE
return
case strings.Contains(version, string(platformv1.KubeVendorICP)):
kubeVendor = platformv1.KubeVendorICP
default:
kubeVendor = platformv1.KubeVendorOther
}
return
}

0 comments on commit e015eae

Please sign in to comment.