Skip to content

Commit 1685f33

Browse files
committed
add pvc adapter
1 parent 522ec57 commit 1685f33

10 files changed

Lines changed: 845 additions & 49 deletions

File tree

xset/api/well_knowns.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ const (
8888
// XExcludeIndicationLabelKey is used to indicate a target is excluded by xset
8989
XExcludeIndicationLabelKey
9090

91+
// SubResourcePvcTemplateLabelKey is used to attach pvc template name to pvc resources
92+
SubResourcePvcTemplateLabelKey
93+
94+
// SubResourcePvcTemplateHashLabelKey is used to attach hash of pvc template to pvc subresource
95+
SubResourcePvcTemplateHashLabelKey
96+
9197
// LastXStatusAnnotationKey is used to record the last status of a target by xset
9298
LastXStatusAnnotationKey
9399

@@ -110,18 +116,20 @@ var defaultXSetLabelAnnotationManager = map[XSetLabelAnnotationEnum]string{
110116
ServiceAvailableLabel: appsv1alpha1.PodServiceAvailableLabel,
111117
PreparingDeleteLabel: appsv1alpha1.PodPreparingDeleteLabel,
112118

113-
ControlledByXSetLabel: appsv1alpha1.ControlledByKusionStackLabelKey,
114-
XInstanceIdLabelKey: appsv1alpha1.PodInstanceIDLabelKey,
115-
XSetUpdateIndicationLabelKey: appsv1alpha1.CollaSetUpdateIndicateLabelKey,
116-
XDeletionIndicationLabelKey: appsv1alpha1.PodDeletionIndicationLabelKey,
117-
XReplaceIndicationLabelKey: appsv1alpha1.PodReplaceIndicationLabelKey,
118-
XReplacePairNewId: appsv1alpha1.PodReplacePairNewId,
119-
XReplacePairOriginName: appsv1alpha1.PodReplacePairOriginName,
120-
XReplaceByReplaceUpdateLabelKey: appsv1alpha1.PodReplaceByReplaceUpdateLabelKey,
121-
XOrphanedIndicationLabelKey: appsv1alpha1.PodOrphanedIndicateLabelKey,
122-
XCreatingLabel: appsv1alpha1.PodCreatingLabel,
123-
XCompletingLabel: appsv1alpha1.PodCompletingLabel,
124-
XExcludeIndicationLabelKey: appsv1alpha1.PodExcludeIndicationLabelKey,
119+
ControlledByXSetLabel: appsv1alpha1.ControlledByKusionStackLabelKey,
120+
XInstanceIdLabelKey: appsv1alpha1.PodInstanceIDLabelKey,
121+
XSetUpdateIndicationLabelKey: appsv1alpha1.CollaSetUpdateIndicateLabelKey,
122+
XDeletionIndicationLabelKey: appsv1alpha1.PodDeletionIndicationLabelKey,
123+
XReplaceIndicationLabelKey: appsv1alpha1.PodReplaceIndicationLabelKey,
124+
XReplacePairNewId: appsv1alpha1.PodReplacePairNewId,
125+
XReplacePairOriginName: appsv1alpha1.PodReplacePairOriginName,
126+
XReplaceByReplaceUpdateLabelKey: appsv1alpha1.PodReplaceByReplaceUpdateLabelKey,
127+
XOrphanedIndicationLabelKey: appsv1alpha1.PodOrphanedIndicateLabelKey,
128+
XCreatingLabel: appsv1alpha1.PodCreatingLabel,
129+
XCompletingLabel: appsv1alpha1.PodCompletingLabel,
130+
XExcludeIndicationLabelKey: appsv1alpha1.PodExcludeIndicationLabelKey,
131+
SubResourcePvcTemplateLabelKey: appsv1alpha1.PvcTemplateLabelKey,
132+
SubResourcePvcTemplateHashLabelKey: appsv1alpha1.PvcTemplateHashLabelKey,
125133

126134
LastXStatusAnnotationKey: appsv1alpha1.LastPodStatusAnnotationKey,
127135
}

xset/api/xset_controller_types.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ type XOperation interface {
6161
GetXOpsPriority(ctx context.Context, c client.Client, object client.Object) (*OpsPriority, error)
6262
}
6363

64-
type SubResourcePvcAdapter interface {
65-
RetainPvcWhenXSetDeleted(object XSetObject) bool
66-
RetainPvcWhenXSetScaled(object XSetObject) bool
67-
GetXSetPvcTemplate(object XSetObject) []corev1.PersistentVolumeClaim
68-
GetXMountedPvcs(object client.Object) []corev1.Volume
69-
MountXPvcs(object client.Object, pvcs []corev1.Volume)
70-
}
71-
7264
// LifecycleAdapterGetter is used to get lifecycle adapters.
7365
type LifecycleAdapterGetter interface {
7466
GetScaleInOpsLifecycleAdapter() LifecycleAdapter
@@ -84,3 +76,22 @@ type ResourceContextAdapterGetter interface {
8476
type LabelAnnotationManagerGetter interface {
8577
GetLabelManagerAdapter() XSetLabelAnnotationManager
8678
}
79+
80+
// SubResourcePvcAdapter is used to manage pvc subresource for X, which are declared on XSet, e.g., spec.volumeClaimTemplate.
81+
// Once adapter is implemented, XSetController will automatically manage pvc: (1) create pvcs from GetXSetPvcTemplate for each
82+
// X object and attach theses pvcs with same instance-id, (2) upgrade pvcs and recreate X object pvcs when PvcTemplateChanged,
83+
// (3) retain pvcs when XSet is deleted or scaledIn according to RetainPvcWhenXSetDeleted and RetainPvcWhenXSetScaled.
84+
type SubResourcePvcAdapter interface {
85+
// RetainPvcWhenXSetDeleted returns true if pvc should be retained when XSet is deleted.
86+
RetainPvcWhenXSetDeleted(object XSetObject) bool
87+
// RetainPvcWhenXSetScaled returns true if pvc should be retained when XSet replicas is scaledIn.
88+
RetainPvcWhenXSetScaled(object XSetObject) bool
89+
// GetXSetPvcTemplate returns pvc template from XSet object.
90+
GetXSetPvcTemplate(object XSetObject) []corev1.PersistentVolumeClaim
91+
// GetXSpecVolumes returns spec.volumes from X object.
92+
GetXSpecVolumes(object client.Object) []corev1.Volume
93+
// GetXVolumeMounts returns containers volumeMounts from X (pod) object.
94+
GetXVolumeMounts(object client.Object) []corev1.VolumeMount
95+
// SetXSpecVolumes sets spec.volumes to X object.
96+
SetXSpecVolumes(object client.Object, pvcs []corev1.Volume)
97+
}

xset/subresources/getter.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2024-2025 KusionStack Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package subresources
18+
19+
import "kusionstack.io/kube-utils/xset/api"
20+
21+
func GetSubresourcePvcAdapter(control api.XSetController) (adapter api.SubResourcePvcAdapter, enabled bool) {
22+
adapter, enabled = control.(api.SubResourcePvcAdapter)
23+
return adapter, enabled
24+
}

0 commit comments

Comments
 (0)