Skip to content

Commit

Permalink
fix: kube-apiserver存储失败后,version latest报错 TencentBlueKing#525
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg committed Jul 30, 2020
1 parent bcfe433 commit b89d98b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
DefaultNamespace = "bkbcs"
)

const (
ObjectVersionNotLatestError = "please apply your changes to the latest version and try again"
)

//bcs mesos custom resources list
const (
CrdAdmissionWebhookConfiguration = "AdmissionWebhookConfiguration"
Expand Down Expand Up @@ -431,3 +435,7 @@ func (store *managerStore) filterSpecialLabels(oriLabels map[string]string) map[
}
return labels
}

func (store *managerStore) ObjectNotLatestErr(err error)bool{
return strings.Contains(err.Error(), ObjectVersionNotLatestError)
}
14 changes: 14 additions & 0 deletions bcs-mesos/bcs-scheduler/src/manager/store/etcd/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package etcd

import (
"github.com/Tencent/bk-bcs/bcs-common/common/blog"
mstore "github.com/Tencent/bk-bcs/bcs-mesos/bcs-scheduler/src/manager/store"
"github.com/Tencent/bk-bcs/bcs-mesos/bcs-scheduler/src/types"
"github.com/Tencent/bk-bcs/bcs-mesos/pkg/apis/bkbcs/v2"
Expand Down Expand Up @@ -57,6 +58,9 @@ func (store *managerStore) SaveTask(task *types.Task) error {
v2Task, err = client.Create(v2Task)
}
if err != nil {
if store.ObjectNotLatestErr(err) {
store.syncTaskInCache(task.ID)
}
return err
}

Expand All @@ -65,6 +69,16 @@ func (store *managerStore) SaveTask(task *types.Task) error {
return nil
}

func (store *managerStore) syncTaskInCache(taskId string){
task,err := store.FetchDBTask(taskId)
if err!=nil {
blog.Errorf("fetch task(%s) in kube-apiserver failed: %s", taskId, err.Error())
return
}

saveCacheTask(task)
}

/*func (store *managerStore) ListTasks(runAs, appID string) ([]*types.Task, error) {
client := store.BkbcsClient.Tasks(runAs)
v2Tasks, err := client.List(metav1.ListOptions{})
Expand Down
13 changes: 13 additions & 0 deletions bcs-mesos/bcs-scheduler/src/manager/store/etcd/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (store *managerStore) SaveTaskGroup(taskGroup *types.TaskGroup) error {
v2Taskgroup, err = client.Create(v2Taskgroup)
}
if err != nil {
if store.ObjectNotLatestErr(err) {
store.syncTaskgroupInCache(taskGroup.ID)
}
return err
}

Expand All @@ -83,6 +86,16 @@ func (store *managerStore) SaveTaskGroup(taskGroup *types.TaskGroup) error {
return nil
}

func (store *managerStore) syncTaskgroupInCache(taskgroupId string){
taskgroup,err := store.FetchDBTaskGroup(taskgroupId)
if err!=nil {
blog.Errorf("fetch taskgroup(%s) in kube-apiserver failed: %s", taskgroupId, err.Error())
return
}

saveCacheTaskGroup(taskgroup)
}

//list mesos cluster taskgroups, include: application、deployment、daemonset...
func (store *managerStore) ListClusterTaskgroups() ([]*types.TaskGroup, error) {
return listCacheTaskgroups()
Expand Down

0 comments on commit b89d98b

Please sign in to comment.