Skip to content

Commit

Permalink
Merge pull request #8 from Tencent/1.19.x
Browse files Browse the repository at this point in the history
1.19.x
  • Loading branch information
AlexAi27 committed Sep 17, 2020
2 parents b885602 + 7a1e231 commit 285fe43
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 277 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -90,7 +90,6 @@ kube-agent:pre
client:pre
mkdir -p ${PACKAGEPATH}/bcs-services
cp -R ./install/conf/bcs-services/bcs-client ${PACKAGEPATH}/bcs-services
#go build ${LDFLAG} -o ${PACKAGEPATH}/bcs-services/bcs-client/bcs-client ./bcs-services/bcs-client/cmd/main.go
cd ./bcs-services/bcs-client && go build ${LDFLAG} -o ${WORKSPACE}/${PACKAGEPATH}/bcs-services/bcs-client/bcs-client ./cmd/main.go

dns:
Expand Down
2 changes: 1 addition & 1 deletion bcs-common/pkg/kubehelm/cmd.go
Expand Up @@ -24,7 +24,7 @@ import (

type cmdHelm struct{}

//new cmd helm struct, the object requires helm command-line tool
// NewCmdHelm new cmd helm struct, the object requires helm command-line tool
func NewCmdHelm() KubeHelm {
return &cmdHelm{}
}
Expand Down
14 changes: 7 additions & 7 deletions bcs-common/pkg/kubehelm/interface.go
Expand Up @@ -21,14 +21,14 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api/v1"
)

//helm parameters
//GlobalFlags helm parameters
type GlobalFlags struct {
KubeApiserver string
KubeToken string
Kubeconfig string
}

//parse helm parameters
//ParseParameters parse helm parameters
func (f *GlobalFlags) ParseParameters() (string, error) {
var parameters string
if f.KubeApiserver != "" && f.KubeToken != "" {
Expand All @@ -44,7 +44,7 @@ func (f *GlobalFlags) ParseParameters() (string, error) {
Kind: "Config",
Clusters: make([]clientcmdapi.NamedCluster, 0),
AuthInfos: make([]clientcmdapi.NamedAuthInfo, 0),
Contexts: make([]clientcmdapi.NamedContext, 0),
Contexts: make([]clientcmdapi.NamedContext, 0),
}
cluster := clientcmdapi.NamedCluster{
Name: "cluster",
Expand All @@ -64,7 +64,7 @@ func (f *GlobalFlags) ParseParameters() (string, error) {
context := clientcmdapi.NamedContext{
Name: "cluster-context",
Context: clientcmdapi.Context{
Cluster: cluster.Name,
Cluster: cluster.Name,
AuthInfo: authInfo.Name,
},
}
Expand All @@ -82,15 +82,15 @@ func (f *GlobalFlags) ParseParameters() (string, error) {
return parameters, nil
}

//chart parameters
//InstallFlags chart parameters
type InstallFlags struct {
//setParam --set hub=docker.io/istio tag=1.5.4
SetParam map[string]string
Chart string
Name string
}

//parse chart parameters
//ParseParameters parse chart parameters
func (f *InstallFlags) ParseParameters() string {
var parameters string
if f.Name != "" {
Expand All @@ -106,7 +106,7 @@ func (f *InstallFlags) ParseParameters() string {
return parameters
}

// kube helm interface
// KubeHelm kube helm interface
type KubeHelm interface {
//install
//setParam --set hub=docker.io/istio tag=1.5.4
Expand Down
Expand Up @@ -46,7 +46,7 @@ var (
kubeConfig string
masterURL string
//MinResyncPeriod period definition
MinResyncPeriod metav1.Duration
minResyncPeriod metav1.Duration
)

// leader-election config options
Expand Down Expand Up @@ -114,7 +114,7 @@ func main() {
func init() {
flag.StringVar(&kubeConfig, "kubeConfig", "", "Path to a kubeConfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeConfig. Only required if out-of-cluster.")
flag.DurationVar(&MinResyncPeriod.Duration, "min-resync-period", MinResyncPeriod.Duration, "The resync period in reflectors will be random between MinResyncPeriod and 2*MinResyncPeriod.")
flag.DurationVar(&minResyncPeriod.Duration, "min-resync-period", minResyncPeriod.Duration, "The resync period in reflectors will be random between MinResyncPeriod and 2*MinResyncPeriod.")
flag.BoolVar(&LeaderElect, "leader-elect", true, "Enable leader election")
flag.StringVar(&LockNameSpace, "leader-elect-namespace", "bcs-system", "The resourcelock namespace")
flag.StringVar(&LockName, "leader-elect-name", "gamestatefulset", "The resourcelock name")
Expand All @@ -126,10 +126,10 @@ func init() {

// resyncPeriod computes the time interval a shared informer waits before
// resyncing with the api server.
func resyncPeriod(MinResyncPeriod metav1.Duration) func() time.Duration {
func resyncPeriod(minResyncPeriod metav1.Duration) func() time.Duration {
return func() time.Duration {
factor := rand.Float64() + 1
return time.Duration(float64(MinResyncPeriod.Nanoseconds()) * factor)
return time.Duration(float64(minResyncPeriod.Nanoseconds()) * factor)
}
}

Expand All @@ -156,8 +156,8 @@ func run() {
klog.Fatalf("Error building gamestatefulset clientset: %s", err.Error())
}
fmt.Println("Operator builds tkex client success...")
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, resyncPeriod(MinResyncPeriod)())
gamestatefulsetInformerFactory := informers.NewSharedInformerFactory(tkexClient, resyncPeriod(MinResyncPeriod)())
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, resyncPeriod(minResyncPeriod)())
gamestatefulsetInformerFactory := informers.NewSharedInformerFactory(tkexClient, resyncPeriod(minResyncPeriod)())

stsplusController := gamestatefulset.NewGameStatefulSetController(
kubeInformerFactory.Core().V1().Pods(),
Expand Down
Expand Up @@ -56,7 +56,6 @@ var (
durationStore = requeueduration.DurationStore{}
)


// GameStatefulSetController controls statefulsets.
type GameStatefulSetController struct {
// client interface
Expand Down
Expand Up @@ -15,13 +15,14 @@ package gamestatefulset

import (
"fmt"
"math"
"sort"

stsplus "github.com/Tencent/bk-bcs/bcs-k8s/bcs-gamestatefulset-operator/pkg/apis/tkex/v1alpha1"
"github.com/Tencent/bk-bcs/bcs-k8s/bcs-gamestatefulset-operator/pkg/util"
"github.com/Tencent/bk-bcs/bcs-k8s/bcs-gamestatefulset-operator/pkg/util/constants"
"github.com/Tencent/bk-bcs/bcs-k8s/kubernetes/common/update/hotpatchupdate"
"github.com/Tencent/bk-bcs/bcs-k8s/kubernetes/common/update/inplaceupdate"
"math"
"sort"

apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -137,6 +138,7 @@ func (ssc *defaultGameStatefulSetControl) UpdateGameStatefulSet(set *stsplus.Gam
return ssc.truncateHistory(set, pods, revisions, currentRevision, updateRevision)
}

// ListRevisions list all revisions of gamestatefulset
func (ssc *defaultGameStatefulSetControl) ListRevisions(set *stsplus.GameStatefulSet) ([]*apps.ControllerRevision, error) {
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
if err != nil {
Expand All @@ -145,6 +147,7 @@ func (ssc *defaultGameStatefulSetControl) ListRevisions(set *stsplus.GameStatefu
return ssc.controllerHistory.ListControllerRevisions(set, selector)
}

// AdoptOrphanRevisions adopt orphan history revision of gamestatefulset
func (ssc *defaultGameStatefulSetControl) AdoptOrphanRevisions(
set *stsplus.GameStatefulSet,
revisions []*apps.ControllerRevision) error {
Expand Down
Expand Up @@ -41,11 +41,13 @@ func NewRealGameStatefulSetStatusUpdater(
return &realGameStatefulSetStatusUpdater{tkexClient, setLister}
}

// realGameStatefulSetStatusUpdater updater implementation
type realGameStatefulSetStatusUpdater struct {
tkexClient tkexclientset.Interface
setLister stspluslisters.GameStatefulSetLister
}

// UpdateGameStatefulSetStatus update gamesatefulset status
func (ssu *realGameStatefulSetStatusUpdater) UpdateGameStatefulSetStatus(
set *stsplus.GameStatefulSet,
status *stsplus.GameStatefulSetStatus) error {
Expand Down
Expand Up @@ -43,7 +43,7 @@ import (
const maxUpdateRetries = 10

const (
//support hot update container in annotation
//PodHotpatchContainerKey support hot update container in annotation
PodHotpatchContainerKey = "io.kubernetes.hotpatch.container"
)

Expand All @@ -56,10 +56,13 @@ var patchCodec = scheme.Codecs.LegacyCodec(stsplus.SchemeGroupVersion)
// Generally used to tie break between GameStatefulSetes that have overlapping selectors.
type overlappingGameStatefulSetes []*stsplus.GameStatefulSet

// Len sort interface implementation
func (o overlappingGameStatefulSetes) Len() int { return len(o) }

// Swap sort interface implementation
func (o overlappingGameStatefulSetes) Swap(i, j int) { o[i], o[j] = o[j], o[i] }

// Less sort interface implementation
func (o overlappingGameStatefulSetes) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
Expand Down Expand Up @@ -283,7 +286,7 @@ func newGameStatefulSetPod(set *stsplus.GameStatefulSet, ordinal int) *v1.Pod {
func newVersionedGameStatefulSetPod(currentSet, updateSet *stsplus.GameStatefulSet, currentRevision, updateRevision string, ordinal int) *v1.Pod {
if currentSet.Spec.UpdateStrategy.Type != stsplus.OnDeleteGameStatefulSetStrategyType &&
(currentSet.Spec.UpdateStrategy.RollingUpdate == nil && ordinal < int(currentSet.Status.CurrentReplicas)) ||
(currentSet.Spec.UpdateStrategy.RollingUpdate != nil && ordinal < int(*currentSet.Spec.UpdateStrategy.RollingUpdate.Partition)) { //nolint
(currentSet.Spec.UpdateStrategy.RollingUpdate != nil && ordinal < int(*currentSet.Spec.UpdateStrategy.RollingUpdate.Partition)) { //nolint
pod := newGameStatefulSetPod(currentSet, ordinal)
setPodRevision(pod, currentRevision)
return pod
Expand Down Expand Up @@ -523,14 +526,17 @@ func completeRollingUpdate(set *stsplus.GameStatefulSet, status *stsplus.GameSta
// to the front of the list.
type ascendingOrdinal []*v1.Pod

// Len sort interface implementation
func (ao ascendingOrdinal) Len() int {
return len(ao)
}

// Swap sort interface implementation
func (ao ascendingOrdinal) Swap(i, j int) {
ao[i], ao[j] = ao[j], ao[i]
}

// Less sort interface implementation
func (ao ascendingOrdinal) Less(i, j int) bool {
return getOrdinal(ao[i]) < getOrdinal(ao[j])
}
Expand Down
Expand Up @@ -72,6 +72,7 @@ type realGameStatefulSetPodControl struct {
recorder record.EventRecorder
}

// UpdateGameStatefulSetPod create pod according to definition in GameStatefulSet
func (spc *realGameStatefulSetPodControl) CreateGameStatefulSetPod(set *stsplus.GameStatefulSet, pod *v1.Pod) error {
// Create the Pod's PVCs prior to creating the Pod
if err := spc.createPersistentVolumeClaims(set, pod); err != nil {
Expand All @@ -88,6 +89,7 @@ func (spc *realGameStatefulSetPodControl) CreateGameStatefulSetPod(set *stsplus.
return err
}

// UpdateGameStatefulSetPod update pod info of GameStatefulSet
func (spc *realGameStatefulSetPodControl) UpdateGameStatefulSetPod(set *stsplus.GameStatefulSet, pod *v1.Pod, updateType string) error {
attemptedUpdate := false
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
Expand Down Expand Up @@ -140,12 +142,14 @@ func (spc *realGameStatefulSetPodControl) UpdateGameStatefulSetPod(set *stsplus.
return err
}

// DeleteGameStatefulSetPod delete pod according to GameStatefulSet
func (spc *realGameStatefulSetPodControl) DeleteGameStatefulSetPod(set *stsplus.GameStatefulSet, pod *v1.Pod) error {
err := spc.client.CoreV1().Pods(set.Namespace).Delete(pod.Name, nil)
spc.recordPodEvent("delete", set, pod, err)
return err
}

// ForceDeleteGameStatefulSetPod delete pod according to GameStatefulSet
func (spc *realGameStatefulSetPodControl) ForceDeleteGameStatefulSetPod(set *stsplus.GameStatefulSet, pod *v1.Pod) error {
err := spc.client.CoreV1().Pods(set.Namespace).Delete(pod.Name, metav1.NewDeleteOptions(0))
spc.recordPodEvent("force delete", set, pod, err)
Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-client/cmd/batch/apply.go
Expand Up @@ -68,6 +68,7 @@ func NewApplyCommand() cli.Command {
type createFunc func(string, string, []byte) error
type updateFunc func(string, string, []byte, url.Values) error

// metaInfo holder for resource
type metaInfo struct {
clusterID string
apiVersion string
Expand Down
42 changes: 21 additions & 21 deletions bcs-services/bcs-client/cmd/list/meshcluster.go
Expand Up @@ -16,20 +16,20 @@ package list
import (
"fmt"

meshv1 "github.com/Tencent/bk-bcs/bcs-services/bcs-mesh-manager/api/v1"
"github.com/Tencent/bk-bcs/bcs-services/bcs-client/cmd/utils"
"github.com/Tencent/bk-bcs/bcs-services/bcs-client/pkg/meshmanager/v1"
meshv1 "github.com/Tencent/bk-bcs/bcs-services/bcs-mesh-manager/api/v1"
"github.com/Tencent/bk-bcs/bcs-services/bcs-mesh-manager/proto/meshmanager"
)

func listMeshCluster(c *utils.ClientContext) error {
meshManager := v1.NewMeshManager(utils.GetClientOption())
resp,err := meshManager.ListMeshCluster(&meshmanager.ListMeshClusterReq{})
if err!=nil {
resp, err := meshManager.ListMeshCluster(&meshmanager.ListMeshClusterReq{})
if err != nil {
fmt.Println("error", err.Error())
return err
}
if resp.ErrCode!=meshmanager.ErrCode_ERROR_OK {
if resp.ErrCode != meshmanager.ErrCode_ERROR_OK {
return fmt.Errorf("failed to list meshclusters: %s", resp.ErrMsg)
}
if len(resp.MeshClusters) == 0 {
Expand All @@ -42,12 +42,12 @@ func listMeshCluster(c *utils.ClientContext) error {
"MESSAGE")

for _, mCluster := range resp.MeshClusters {
var status,message string
var status, message string
if mCluster.Deletion {
status = "DELETING"
message = "istio is deleting now"
}else {
status,message = getMeshClusterStatus(mCluster)
} else {
status, message = getMeshClusterStatus(mCluster)
}
fmt.Printf("%-15s %-10s %-10s %-25s\n",
mCluster.Clusterid,
Expand All @@ -59,27 +59,27 @@ func listMeshCluster(c *utils.ClientContext) error {
}

//return status、message
func getMeshClusterStatus(mCluster *meshmanager.MeshCluster)(string,string){
func getMeshClusterStatus(mCluster *meshmanager.MeshCluster) (string, string) {
var deploy, running, failed int
var message string
for _,component :=range mCluster.Components {
for _, component := range mCluster.Components {
switch component.Status {
case string(meshv1.InstallStatus_NONE), string(meshv1.InstallStatus_DEPLOY), string(meshv1.InstallStatus_STARTING):
deploy += 1
case string(meshv1.InstallStatus_RUNNING):
running += 1
case string(meshv1.InstallStatus_FAILED):
failed += 1
case string(meshv1.InstallStatusNONE), string(meshv1.InstallStatusDEPLOY), string(meshv1.InstallStatusSTARTING):
deploy++
case string(meshv1.InstallStatusRUNNING):
running++
case string(meshv1.InstallStatusFAILED):
failed++
message = component.Message
}
}
//failed
if failed>0 {
return string(meshv1.InstallStatus_FAILED), message
if failed > 0 {
return string(meshv1.InstallStatusFAILED), message
}
//running
if len(mCluster.Components)==running {
return string(meshv1.InstallStatus_RUNNING), "istio is running now"
if len(mCluster.Components) == running {
return string(meshv1.InstallStatusRUNNING), "istio is running now"
}
return string(meshv1.InstallStatus_DEPLOY), "istio is deploying now"
}
return string(meshv1.InstallStatusDEPLOY), "istio is deploying now"
}
1 change: 0 additions & 1 deletion bcs-services/bcs-client/go.mod
Expand Up @@ -4,7 +4,6 @@ go 1.14

replace (
github.com/Tencent/bk-bcs => ../../
github.com/Tencent/bk-bcs/bcs-services/bcs-client => ./
github.com/Tencent/bk-bcs/bcs-services/bcs-mesh-manager => ../bcs-mesh-manager
github.com/coreos/bbolt v1.3.4 => go.etcd.io/bbolt v1.3.4
github.com/openshift/api => github.com/openshift/api v0.0.0-20180801171038-322a19404e37
Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-client/pkg/metastream/json.go
Expand Up @@ -48,11 +48,12 @@ const (
YAMLFormat = "yaml"
)

// metaObject meta info for response
type metaObject struct {
mesostype.ObjectMeta `json:"metadata,omitempty"`
}

//NewJSONStream create stream implementation
//NewMetaStream create stream implementation
func NewMetaStream(r io.Reader, ft string) Stream {
allDatas, err := ioutil.ReadAll(r)
if err != nil || len(allDatas) == 0 {
Expand Down

0 comments on commit 285fe43

Please sign in to comment.