Skip to content

Commit

Permalink
feat: CollaSet supports exclude and include pod (#258)
Browse files Browse the repository at this point in the history
* remove progress FinishingOpsLifecycle

* refactor operateTargets

* refactor sync pods

* add orphan pod pvc

* exclude include done, todo (1) recreate pod if revision not exists; (2) expectations

* clean AllowPodExclude AllowPodInclude func

* fix replace and exclude

* ensure toDelete toReplace toExclude priority

* default to recreate pod when update, if currentRevision not found

* add recorder

* add expectation for exclude include

* remove scaleStrategy check

* fix replace panic

* fix resourcecontext bug

* do not clean podToDelete in scaleStrategy

* add ut: podToExclude

* add e2e: exclude include pod

* add ut: exclude origin pod

* refactor allocate ID

* add replacePods func

* refactor replace func

* add ut for utils

* refactor injectRevision

* exclude pods which have to-exclude label

* refactor getPodsToDelete comment

* improve exclude include event

* fix ut: TestAllowResourceInclude

* fix kube-api

* fix compile

* fix compile

* bump kube-api v0.6.5

* add cls validating for exinclude intersection

* rephrase recoder when rv label not effective

* check intersection for all pod lists in validating

---------

Co-authored-by: Chaer <[email protected]>
Co-authored-by: chaer <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent d95fb01 commit b4cce9e
Show file tree
Hide file tree
Showing 20 changed files with 2,405 additions and 250 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
make ginkgo
set -e
KUBECONFIG=/tmp/kind/kubeconfig.yaml ./bin/ginkgo -timeout 10m -v --focus='\[apps\] CollaSet' test/e2e
KUBECONFIG=/tmp/kind/kubeconfig.yaml ./bin/ginkgo -timeout 15m -v --focus='\[apps\] CollaSet' test/e2e
restartCount=$(kubectl get pod -n kusionstack-system -l control-plane=controller-manager --no-headers | awk '{print $4}')
if [ "${restartCount}" -eq "0" ];then
echo "Kusionstack-manager has not restarted"
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
run: |
make ginkgo
set -e
KUBECONFIG=/tmp/kind/kubeconfig.yaml ./bin/ginkgo -timeout 10m -v --focus='\[apps\] OperationJob' test/e2e
KUBECONFIG=/tmp/kind/kubeconfig.yaml ./bin/ginkgo -timeout 15m -v --focus='\[apps\] OperationJob' test/e2e
- name: Check Operating Manager
run: |
restartCount=$(kubectl get pod -n kusionstack-system -l control-plane=controller-manager --no-headers | awk '{print $4}')
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
k8s.io/klog/v2 v2.100.1
k8s.io/kubernetes v0.0.0-00010101000000-000000000000
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
kusionstack.io/kube-api v0.6.5
kusionstack.io/resourceconsist v0.0.1
sigs.k8s.io/controller-runtime v0.15.1
)
Expand Down Expand Up @@ -94,7 +95,6 @@ require (
k8s.io/apiserver v0.22.6 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.29.0
kusionstack.io/kube-api v0.6.3
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,8 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kusionstack.io/kube-api v0.6.3 h1:HKgB6E95DVRGkZ2OjXkuV4YE327gGt24sBFJRB+tc6A=
kusionstack.io/kube-api v0.6.3/go.mod h1:J0+EHiroG/88X904Y9TV9iMRcoEuD5tXMTLMBDSwM+Y=
kusionstack.io/kube-api v0.6.5 h1:aVF6YsejHd1ujpI5oW6rdu2bhsYzX0PM5OnoHvAtIzs=
kusionstack.io/kube-api v0.6.5/go.mod h1:J0+EHiroG/88X904Y9TV9iMRcoEuD5tXMTLMBDSwM+Y=
kusionstack.io/resourceconsist v0.0.1 h1:+k/jriq5Ld7fQUYfWSMGynz/FesHtl3Rk2fmQPjBe0g=
kusionstack.io/resourceconsist v0.0.1/go.mod h1:816xS/fY6EOUbPFjXIWW/TGs8/YE46qP4ElKeIiwFdU=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
Expand Down
13 changes: 10 additions & 3 deletions pkg/controllers/collaset/collaset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (r *CollaSetReconciler) doSync(
return podWrappers, nil, err
}

podWrappers, ownedIDs, err = r.syncControl.Replace(ctx, instance, podWrappers, ownedIDs, resources)
if err != nil {
return podWrappers, nil, err
}

_, scaleRequeueAfter, scaleErr := r.syncControl.Scale(ctx, instance, resources, podWrappers, ownedIDs)
_, updateRequeueAfter, updateErr := r.syncControl.Update(ctx, instance, resources, podWrappers, ownedIDs)

Expand Down Expand Up @@ -361,10 +366,12 @@ func (r *CollaSetReconciler) ensureReclaimPvcs(ctx context.Context, cls *appsv1a
needReclaimPvcs = append(needReclaimPvcs, pvcs[i])
}
}
if len(needReclaimPvcs) > 0 {
_, err = pvcControl.ReleasePvcsOwnerRef(cls, needReclaimPvcs)
for i := range needReclaimPvcs {
if err = pvcControl.OrphanPvc(cls, needReclaimPvcs[i]); err != nil {
return err
}
}
return err
return nil
}

func (r *CollaSetReconciler) ensureReclaimPodOwnerReferences(cls *appsv1alpha1.CollaSet) error {
Expand Down
Loading

0 comments on commit b4cce9e

Please sign in to comment.