Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] PVC template #162

Merged
merged 23 commits into from
Mar 25, 2024

Conversation

ColdsteelRail
Copy link
Collaborator

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ColdsteelRail ColdsteelRail changed the title basic pvc template support pvc template support Mar 7, 2024
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 74.40000% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 64.39%. Comparing base (72fb78d) to head (eca6001).

Files Patch % Lines
pkg/controllers/collaset/utils/pvc.go 73.52% 12 Missing and 6 partials ⚠️
.../controllers/poddeletion/poddeletion_controller.go 50.00% 10 Missing and 1 partial ⚠️
pkg/controllers/collaset/collaset_controller.go 85.71% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #162      +/-   ##
==========================================
+ Coverage   64.01%   64.39%   +0.37%     
==========================================
  Files          73       74       +1     
  Lines        4708     4825     +117     
==========================================
+ Hits         3014     3107      +93     
- Misses       1419     1438      +19     
- Partials      275      280       +5     
Flag Coverage Δ
unittests 64.39% <74.40%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ColdsteelRail ColdsteelRail changed the title pvc template support [feature] PVC Template support Mar 8, 2024
@ColdsteelRail ColdsteelRail changed the title [feature] PVC Template support [feature] PVC template support Mar 8, 2024
@ColdsteelRail ColdsteelRail changed the title [feature] PVC template support [feature] PVC template Mar 8, 2024
@ColdsteelRail ColdsteelRail force-pushed the collaset-support-pvc-template branch 3 times, most recently from 6cb4ecb to 04de789 Compare March 12, 2024 12:59
@@ -0,0 +1,366 @@
/*
Copyright 2023 The KusionStack Authors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The year should be 2024.

@@ -0,0 +1,111 @@
/*
Copyright 2023 The KusionStack Authors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The year should be 2024.

@@ -0,0 +1,111 @@
/*
Copyright 2023 The KusionStack Authors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The year should be 2024.

@@ -19,6 +19,7 @@ package collaset
import (
"context"
"fmt"
"kusionstack.io/operating/pkg/controllers/collaset/pvccontrol"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package should be in the third package group.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll check all imported packages

Copy link
Member

@Eikykun Eikykun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

Comment on lines 20 to 30
"context"
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
appsv1alpha1 "kusionstack.io/operating/apis/apps/v1alpha1"
collasetutils "kusionstack.io/operating/pkg/controllers/collaset/utils"
"kusionstack.io/operating/pkg/controllers/utils/expectations"
refmanagerutil "kusionstack.io/operating/pkg/controllers/utils/refmanager"
"sigs.k8s.io/controller-runtime/pkg/client"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort it plz. (*1)

}
pvcList := &corev1.PersistentVolumeClaimList{}
// list pvcs match label selector of set
err = pc.client.List(context.TODO(), pvcList, &client.ListOptions{Namespace: cls.Namespace, LabelSelector: selector})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to pass the caller's context here, instead of using context.TODO(). (*2)

@@ -19,6 +19,7 @@ package collaset
import (
"context"
"fmt"
"kusionstack.io/operating/pkg/controllers/collaset/pvccontrol"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports are not sorted. (*1)
You can config import style in settings.

return nil, err
}

if err := c.Create(context.TODO(), claim); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*2)

}

// delete pvcs labeled same id with pod
if err := pc.client.Delete(context.TODO(), pvc); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*2)

continue
}
// if pvc is not claimed in pvc templates, delete it
if err := c.Delete(context.TODO(), pvc); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*2)

if _, newPvcExist := (*newPvcs)[pvcTmpName]; !newPvcExist {
continue
}
if err := c.Delete(context.TODO(), pvc); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*2)

cls := &appsv1alpha1.CollaSet{}
for _, ref := range ownerRefs {
if ref.Kind == "CollaSet" {
if err := r.Client.Get(context.TODO(), types.NamespacedName{Namespace: pod.Namespace, Name: ref.Name}, cls); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*2)

Comment on lines 99 to 105
err = c.Watch(&source.Kind{Type: &corev1.PersistentVolumeClaim{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &appsv1alpha1.CollaSet{},
})
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think watching the PersistentVolumeClaim is necessary.

Comment on lines 57 to 67
var filteredPVCs []*corev1.PersistentVolumeClaim
ownerSelector := cls.Spec.Selector.DeepCopy()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary deepcopy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all reviews are fixed


// list pvcs match label selector of set
pvcList := &corev1.PersistentVolumeClaimList{}
err = pc.client.List(ctx, pvcList, &client.ListOptions{Namespace: cls.Namespace, LabelSelector: selector})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether these PVCs already in used still need to manage the ownership somehow, in case another CollaSet from same namespace takes over them and rebinds to new Pods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this problem soon. This is because some PVCs don't have ownerReferences if user configure "whenDelete=Retain". As your advice, it is necessary to keep an persistent ownerReference for PVCs, unless their owner CollaSet is deleted and user want to retain them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@ColdsteelRail ColdsteelRail force-pushed the collaset-support-pvc-template branch 2 times, most recently from 1245d89 to 413e546 Compare March 25, 2024 02:03
Eikykun
Eikykun previously approved these changes Mar 25, 2024
@wu8685
Copy link
Collaborator

wu8685 commented Mar 25, 2024

LGTM

@wu8685 wu8685 merged commit 2d59b9f into KusionStack:main Mar 25, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2024
@ColdsteelRail ColdsteelRail deleted the collaset-support-pvc-template branch July 8, 2024 06:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

提供灰度流量的能力 Enhancement: PVC template support of CollaSet
3 participants