Skip to content

Commit

Permalink
Merge pull request #987 from wenxinlee2015/fix/bcs-gamedeployment-gam…
Browse files Browse the repository at this point in the history
…estatefulset-hook

fix: predeletehookconditions preinplacehookconditions for out of range
  • Loading branch information
wenxinlee2015 authored Sep 8, 2021
2 parents c46a175 + d28cb2b commit 99540f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,15 @@ func (gdc *defaultGameDeploymentControl) deleteUnexpectedPreDeleteHookRuns(hrLis

// truncatePreDeleteHookConditions truncate unneeded PreDeleteHookConditions
func (gdc *defaultGameDeploymentControl) truncatePreDeleteHookConditions(pods []*v1.Pod, newStatus *gdv1alpha1.GameDeploymentStatus) {
for i, cond := range newStatus.PreDeleteHookConditions {
exist := false
tmpPredeleteHookConditions := []hookv1alpha1.PreDeleteHookCondition{}
for _, cond := range newStatus.PreDeleteHookConditions {
for _, pod := range pods {
if cond.PodName == pod.Name {
exist = true
tmpPredeleteHookConditions = append(tmpPredeleteHookConditions, cond)
break
}
}
if !exist {
newStatus.PreDeleteHookConditions = append(newStatus.PreDeleteHookConditions[:i], newStatus.PreDeleteHookConditions[i+1:]...)
}
newStatus.PreDeleteHookConditions = tmpPredeleteHookConditions
}
}

Expand Down Expand Up @@ -335,17 +333,15 @@ func (gdc *defaultGameDeploymentControl) deleteUnexpectedPreInplaceHookRuns(hrLi

// truncatePreInplaceHookConditions truncate unneeded PreInplaceHookConditions
func (gdc *defaultGameDeploymentControl) truncatePreInplaceHookConditions(pods []*v1.Pod, newStatus *gdv1alpha1.GameDeploymentStatus) {
for i, cond := range newStatus.PreInplaceHookConditions {
exist := false
tmpPreInplaceHookConditions := []hookv1alpha1.PreInplaceHookCondition{}
for _, cond := range newStatus.PreInplaceHookConditions {
for _, pod := range pods {
if cond.PodName == pod.Name {
exist = true
tmpPreInplaceHookConditions = append(tmpPreInplaceHookConditions, cond)
break
}
}
if !exist {
newStatus.PreInplaceHookConditions = append(newStatus.PreInplaceHookConditions[:i], newStatus.PreInplaceHookConditions[i+1:]...)
}
newStatus.PreInplaceHookConditions = tmpPreInplaceHookConditions
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,19 +1020,15 @@ func (ssc *defaultGameStatefulSetControl) truncatePreDeleteHookRuns(
func (ssc *defaultGameStatefulSetControl) truncatePreDeleteHookConditions(
pods []*v1.Pod,
newStatus *gstsv1alpha1.GameStatefulSetStatus) {
for i, cond := range newStatus.PreDeleteHookConditions {
exist := false
tmpPredeleteHookConditions := []hookv1alpha1.PreDeleteHookCondition{}
for _, cond := range newStatus.PreDeleteHookConditions {
for _, pod := range pods {
if cond.PodName == pod.Name {
exist = true
tmpPredeleteHookConditions = append(tmpPredeleteHookConditions, cond)
break
}
}
if !exist {
newStatus.PreDeleteHookConditions = append(
newStatus.PreDeleteHookConditions[:i],
newStatus.PreDeleteHookConditions[i+1:]...)
}
newStatus.PreDeleteHookConditions = tmpPredeleteHookConditions
}
}

Expand Down Expand Up @@ -1081,19 +1077,15 @@ func (ssc *defaultGameStatefulSetControl) truncatePreInplaceHookRuns(
func (ssc *defaultGameStatefulSetControl) truncatePreInplaceHookConditions(
pods []*v1.Pod,
newStatus *gstsv1alpha1.GameStatefulSetStatus) {
for i, cond := range newStatus.PreInplaceHookConditions {
exist := false
tmpPreInplaceHookConditions := []hookv1alpha1.PreInplaceHookCondition{}
for _, cond := range newStatus.PreInplaceHookConditions {
for _, pod := range pods {
if cond.PodName == pod.Name {
exist = true
tmpPreInplaceHookConditions = append(tmpPreInplaceHookConditions, cond)
break
}
}
if !exist {
newStatus.PreInplaceHookConditions = append(
newStatus.PreInplaceHookConditions[:i],
newStatus.PreInplaceHookConditions[i+1:]...)
}
newStatus.PreInplaceHookConditions = tmpPreInplaceHookConditions
}
}

Expand Down

0 comments on commit 99540f8

Please sign in to comment.