Skip to content

Commit

Permalink
remove other collasets podContext if nesscessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdsteelRail committed Jan 7, 2025
1 parent df6d6e0 commit 00f1c9a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/controllers/collaset/podcontext/podcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "kusionstack.io/kube-api/apps/v1alpha1"

"kusionstack.io/kuperator/pkg/controllers/collaset/utils"
"kusionstack.io/kuperator/pkg/controllers/utils/expectations"
)
Expand Down Expand Up @@ -145,17 +146,19 @@ func doCreatePodContext(c client.Client, instance *appsv1alpha1.CollaSet, ownerI
return c.Create(context.TODO(), podContext)
}

func doUpdatePodContext(c client.Client, instance client.Object, ownedIDs map[int]*appsv1alpha1.ContextDetail, podContext *appsv1alpha1.ResourceContext) error {
func doUpdatePodContext(c client.Client, instance *appsv1alpha1.CollaSet, ownedIDs map[int]*appsv1alpha1.ContextDetail, podContext *appsv1alpha1.ResourceContext) error {
// store all IDs crossing all workload
existingIDs := map[int]*appsv1alpha1.ContextDetail{}

for i := range podContext.Spec.Contexts {
detail := podContext.Spec.Contexts[i]
if detail.Contains(OwnerContextKey, instance.GetName()) {
continue
// add other collaset podContexts only when instance enables context pool
if instance.Spec.ScaleStrategy.Context != "" {
for i := range podContext.Spec.Contexts {
detail := podContext.Spec.Contexts[i]
if detail.Contains(OwnerContextKey, instance.GetName()) {
continue
}
existingIDs[detail.ID] = &detail
}

existingIDs[detail.ID] = &detail
}

for _, contextDetail := range ownedIDs {
Expand All @@ -166,7 +169,7 @@ func doUpdatePodContext(c client.Client, instance client.Object, ownedIDs map[in
if len(existingIDs) == 0 {
err := c.Delete(context.TODO(), podContext)
if err != nil {
if err := utils.ActiveExpectations.ExpectDelete(instance, expectations.ResourceContext, podContext.Name); err != nil {
if err := utils.ActiveExpectations.ExpectDelete(instance.GetObjectMeta(), expectations.ResourceContext, podContext.Name); err != nil {

Check warning on line 172 in pkg/controllers/collaset/podcontext/podcontext.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/collaset/podcontext/podcontext.go#L172

Added line #L172 was not covered by tests
return err
}
}
Expand All @@ -185,7 +188,7 @@ func doUpdatePodContext(c client.Client, instance client.Object, ownedIDs map[in
sort.Sort(ContextDetailsByOrder(podContext.Spec.Contexts))
err := c.Update(context.TODO(), podContext)
if err != nil {
if err := utils.ActiveExpectations.ExpectUpdate(instance, expectations.ResourceContext, podContext.Name, podContext.ResourceVersion); err != nil {
if err := utils.ActiveExpectations.ExpectUpdate(instance.GetObjectMeta(), expectations.ResourceContext, podContext.Name, podContext.ResourceVersion); err != nil {

Check warning on line 191 in pkg/controllers/collaset/podcontext/podcontext.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/collaset/podcontext/podcontext.go#L191

Added line #L191 was not covered by tests
return err
}
}
Expand Down

0 comments on commit 00f1c9a

Please sign in to comment.