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
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c77d520
basic pvc template support
ColdsteelRail Mar 7, 2024
eaabf13
support PVC Retention policy
ColdsteelRail Mar 8, 2024
3b6c209
add pvc template unit test
ColdsteelRail Mar 10, 2024
d1e231e
add pvc utils unit test
ColdsteelRail Mar 11, 2024
908a8ac
add file header lisences
ColdsteelRail Mar 11, 2024
dcbb4c9
supprt pvc with replace update
ColdsteelRail Mar 12, 2024
aa52814
rephrase some typo
ColdsteelRail Mar 12, 2024
f5de776
pvc compatible with replace update + scale in
ColdsteelRail Mar 13, 2024
a889221
support retain pvc when update pvc template
ColdsteelRail Mar 19, 2024
11728f6
fix:re-mount the old pvc when pvc template rollback
ColdsteelRail Mar 22, 2024
0d21ce2
sort inported packages, correct new files Copyright 2024
ColdsteelRail Mar 22, 2024
9810fd4
pass caller's context
ColdsteelRail Mar 22, 2024
7c49a35
remove redundant DeepCopy()
ColdsteelRail Mar 22, 2024
cc69984
validating webhook: denied delete pvc while pending
ColdsteelRail Mar 22, 2024
e99e739
validating webhook: denied delete pvc (must be mounted) while pending
ColdsteelRail Mar 22, 2024
2fa005e
rename files
ColdsteelRail Mar 22, 2024
2dc6442
fix: support persistent ownerReference for owned pvcs
ColdsteelRail Mar 25, 2024
3e9aa8f
fix: use latest available version
ColdsteelRail Mar 25, 2024
c8fe52c
fix:reclaim pvcs in 1 reconcile
ColdsteelRail Mar 25, 2024
8a6fcea
type
ColdsteelRail Mar 25, 2024
eb22d5a
import files
ColdsteelRail Mar 25, 2024
d2b0683
always adopt pvcs
ColdsteelRail Mar 25, 2024
eca6001
add some comment
ColdsteelRail Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
3 changes: 3 additions & 0 deletions apis/apps/v1alpha1/well_known_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (
PodReplacePairOriginName = "collaset.kusionstack.io/replace-pair-origin-name" // used to indicate the original Pod name for replacement.

PodReplacePairNewId = "collaset.kusionstack.io/replace-pair-new-id" // used to indicate the new created Pod instance ID for replacement.

PvcTemplateHashLabelKey = "collaset.kusionstack.io/pvc-template-hash" // used to attach hash of pvc template to pvc resource

)

const (
Expand Down
17 changes: 17 additions & 0 deletions config/crd/bases/apps.kusionstack.io_collasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,23 @@ spec:
type: string
metadata:
description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata'
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: 'Spec defines the desired characteristics of a
Expand Down
17 changes: 17 additions & 0 deletions config/crd/bases/apps.kusionstack.io_poddecorations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4213,6 +4213,23 @@ spec:
that will be copied into the PVC when creating
it. No other fields are allowed and will be rejected
during validation.
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: The specification for the PersistentVolumeClaim.
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
25 changes: 25 additions & 0 deletions config/webhook/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ webhooks:
operator: In
values:
- 'true'
- name: validating-pvc.apps.kusionstack.io
sideEffects: NoneOnDryRun
admissionReviewVersions: ["v1", "v1beta1"]
clientConfig:
service:
namespace: kusionstack-system
name: controller-manager
path: /validating-generic
failurePolicy: Fail
rules:
- apiGroups:
- "*"
apiVersions:
- v1
operations:
- DELETE
resources:
- persistentvolumeclaims
scope: '*'
objectSelector:
matchExpressions:
- key: kusionstack.io/control
operator: In
values:
- 'true'
- name: validating-generic.apps.kusionstack.io
sideEffects: NoneOnDryRun
admissionReviewVersions: ["v1", "v1beta1"]
Expand Down
28 changes: 27 additions & 1 deletion pkg/controllers/collaset/collaset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
appsv1alpha1 "kusionstack.io/operating/apis/apps/v1alpha1"
"kusionstack.io/operating/pkg/controllers/collaset/podcontext"
"kusionstack.io/operating/pkg/controllers/collaset/podcontrol"
"kusionstack.io/operating/pkg/controllers/collaset/pvccontrol"
"kusionstack.io/operating/pkg/controllers/collaset/synccontrol"
"kusionstack.io/operating/pkg/controllers/collaset/utils"
collasetutils "kusionstack.io/operating/pkg/controllers/collaset/utils"
Expand Down Expand Up @@ -71,7 +72,7 @@
return &CollaSetReconciler{
ReconcilerMixin: mixin,
revisionManager: revision.NewRevisionManager(mixin.Client, mixin.Scheme, NewRevisionOwnerAdapter(podcontrol.NewRealPodControl(mixin.Client, mixin.Scheme))),
syncControl: synccontrol.NewRealSyncControl(mixin.Client, mixin.Logger, podcontrol.NewRealPodControl(mixin.Client, mixin.Scheme), mixin.Recorder),
syncControl: synccontrol.NewRealSyncControl(mixin.Client, mixin.Logger, podcontrol.NewRealPodControl(mixin.Client, mixin.Scheme), pvccontrol.NewRealPvcControl(mixin.Client, mixin.Scheme), mixin.Recorder),
}
}

Expand Down Expand Up @@ -112,6 +113,7 @@
// +kubebuilder:rbac:groups=apps.kusionstack.io,resources=resourcecontexts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps.kusionstack.io,resources=resourcecontexts/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.kusionstack.io,resources=resourcecontexts/finalizers,verbs=update
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=controllerrevisions,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;update;patch
Expand Down Expand Up @@ -140,6 +142,10 @@
}

if instance.DeletionTimestamp != nil {
if err := r.ensureReclaimPvcs(ctx, instance); err != nil {
// reclaim pvcs before remove finalizers
return ctrl.Result{}, err
}
if controllerutil.ContainsFinalizer(instance, preReclaimFinalizer) {
// reclaim owner IDs in ResourceContext
if err := r.reclaimResourceContext(instance); err != nil {
Expand Down Expand Up @@ -325,3 +331,23 @@
}
return reconcile.Result{}
}

func (r *CollaSetReconciler) ensureReclaimPvcs(ctx context.Context, cls *appsv1alpha1.CollaSet) error {
var needReclaimPvcs []*corev1.PersistentVolumeClaim
pvcControl := pvccontrol.NewRealPvcControl(r.Client, r.Scheme)
pvcs, err := pvcControl.GetFilteredPvcs(ctx, cls)
if err != nil {
return err
}

Check warning on line 341 in pkg/controllers/collaset/collaset_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/collaset/collaset_controller.go#L340-L341

Added lines #L340 - L341 were not covered by tests
// reclaim pvcs according to whenDelete retention policy
for i := range pvcs {
owned := pvcs[i].OwnerReferences != nil && len(pvcs[i].OwnerReferences) > 0
if owned && collasetutils.PvcPolicyWhenDelete(cls) == appsv1alpha1.RetainPersistentVolumeClaimRetentionPolicyType {
needReclaimPvcs = append(needReclaimPvcs, pvcs[i])
}
}
if len(needReclaimPvcs) > 0 {
_, err = pvcControl.ReleasePvcsOwnerRef(cls, needReclaimPvcs)
}
return err
}
Loading
Loading