You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
// TODO: might be we want to check if the task was exactly the expected task
Copyright2019TheKubernetes Authors.
LicensedundertheApacheLicense, Version2.0 (the"License");
youmaynotusethisfileexceptincompliancewiththe License.
YoumayobtainacopyoftheLicenseathttp://www.apache.org/licenses/LICENSE-2.0Unlessrequiredbyapplicablelaworagreedtoinwriting, softwaredistributedundertheLicenseisdistributedonan"AS IS"BASIS,
WITHOUTWARRANTIESORCONDITIONSOFANYKIND, eitherexpressor implied.
SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense.
*/packagecontrollersimport (
"sort"operatorv1"k8s.io/kubeadm/operator/api/v1alpha1"
)
// Reconcile TaskGroups is implemented by matching current and desired TaskGroup, so the controller// can determine what is necessary to do next// taskGroupReconcileItem defines match between desired TaskGroup and the corresponding current TaskGroup match.// supported combinations are:// - desired existing, current missing (current to be created)// - desired existing, current existing (current to be operated)// - desired missing, current existing (invalid)typetaskGroupReconcileItemstruct {
namestringplanned*operatorv1.RuntimeTaskGroupcurrent*operatorv1.RuntimeTaskGroup
}
funcnewTaskGroupReconcileItem(planned*operatorv1.RuntimeTaskGroup, current*operatorv1.RuntimeTaskGroup) *taskGroupReconcileItem {
varnamestringifplanned!=nil {
name=planned.Name
} else {
name=current.Name
}
return&taskGroupReconcileItem{
name: name,
planned: planned,
current: current,
}
}
typetaskGroupReconcileListstruct {
all []*taskGroupReconcileIteminvalid []*taskGroupReconcileItemtobeCreated []*taskGroupReconcileItempending []*taskGroupReconcileItemrunning []*taskGroupReconcileItemcompleted []*taskGroupReconcileItemfailed []*taskGroupReconcileItem
}
funcreconcileTaskGroups(desired*operatorv1.RuntimeTaskGroupList, current*operatorv1.RuntimeTaskGroupList) *taskGroupReconcileList {
// Build an empty match for each desired TaskGroup// N.B. we are storing matches in a Map so we can match desired and current TaskGroup by NamematchMap:=map[string]*taskGroupReconcileItem{}
for _, taskGroup :=rangedesired.Items {
desiredTaskGroup:=taskGroup// copies the desired TaskGroup to a local variable in order to avoid it to get overridden at the next iterationmatchMap[desiredTaskGroup.Name] =newTaskGroupReconcileItem(&desiredTaskGroup, nil)
}
// Match the current child objects (TaskGroup) with desired objects (desired TaskGroup).for _, taskGroup :=rangecurrent.Items {
currentTaskGroup:=taskGroup// copies the TaskGroup to a local variable in order to avoid it to get overridden at the next iteration// in case a current objects has a corresponding desired object, match them// NB. if there are more that one match, we track this, but this is an inconsistency// (more that one Task for the same node)ifv, ok:=matchMap[currentTaskGroup.Name]; ok {
// TODO: might be we want to check if the task was exactly the expected task
v.current=¤tTaskGroupcontinue
}
// in case a current objects does not have desired object, we track this, but this is an inconsistency// (a TaskGroup does not matching any desired TaskGroup)matchMap[currentTaskGroup.Name] =newTaskGroupReconcileItem(nil, ¤tTaskGroup)
}
// Transpose the childMap into a listmatchList:=&taskGroupReconcileList{
all: []*taskGroupReconcileItem{},
invalid: []*taskGroupReconcileItem{},
tobeCreated: []*taskGroupReconcileItem{},
pending: []*taskGroupReconcileItem{},
running: []*taskGroupReconcileItem{},
completed: []*taskGroupReconcileItem{},
failed: []*taskGroupReconcileItem{},
}
for _, v:=rangematchMap {
matchList.all=append(matchList.all, v)
}
// ensure the list is sorted in a predictable waysort.Slice(matchList.all, func(i, jint) bool { returnmatchList.all[i].name<matchList.all[j].name })
// Build all the derived views, so we can have a quick glance at taskGroups in different statesmatchList.deriveViews()
returnmatchList
}
func (a*taskGroupReconcileList) deriveViews() {
for_, v:=rangea.all {
switch {
casev.planned!=nil:
// If there is not TaskGroup for a desired TaskGroup, the TaskGroup has to be created by this controllerifv.current==nil {
a.tobeCreated=append(a.tobeCreated, v)
continue
}
// Failedifv.current.Status.ErrorReason!=nil||v.current.Status.ErrorMessage!=nil {
a.failed=append(a.failed, v)
continue
}
// Completedifv.current.Status.CompletionTime!=nil {
a.completed=append(a.completed, v)
continue
}
// Running (nb. paused TaskGroup fall into this counter)ifv.current.Status.StartTime!=nil {
a.running=append(a.running, v)
continue
}
// Pendinga.pending=append(a.pending, v)
casev.planned==nil:
a.invalid=append(a.invalid, v)
}
}
}
func (a*taskGroupReconcileList) activeTaskGroups() int {
returnlen(a.pending) +len(a.running)
}
ewfilemode100644ndex0000000..b064187++b/controllers/runtimetaskgroup_reconcile_test.go
5a54d06529004751ec1f73d1b71db323d69d1332
The text was updated successfully, but these errors were encountered:
might be we want to check if the task was exactly the expected task
kubeadm-operator/controllers/runtimetaskgroup_reconcile.go
Line 79 in dfef3ab
5a54d06529004751ec1f73d1b71db323d69d1332
The text was updated successfully, but these errors were encountered: