Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 20 additions & 12 deletions xset/api/well_knowns.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ const (
// XExcludeIndicationLabelKey is used to indicate a target is excluded by xset
XExcludeIndicationLabelKey

// SubResourcePvcTemplateLabelKey is used to attach pvc template name to pvc resources
SubResourcePvcTemplateLabelKey

// SubResourcePvcTemplateHashLabelKey is used to attach hash of pvc template to pvc subresource
SubResourcePvcTemplateHashLabelKey

// LastXStatusAnnotationKey is used to record the last status of a target by xset
LastXStatusAnnotationKey

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

ControlledByXSetLabel: appsv1alpha1.ControlledByKusionStackLabelKey,
XInstanceIdLabelKey: appsv1alpha1.PodInstanceIDLabelKey,
XSetUpdateIndicationLabelKey: appsv1alpha1.CollaSetUpdateIndicateLabelKey,
XDeletionIndicationLabelKey: appsv1alpha1.PodDeletionIndicationLabelKey,
XReplaceIndicationLabelKey: appsv1alpha1.PodReplaceIndicationLabelKey,
XReplacePairNewId: appsv1alpha1.PodReplacePairNewId,
XReplacePairOriginName: appsv1alpha1.PodReplacePairOriginName,
XReplaceByReplaceUpdateLabelKey: appsv1alpha1.PodReplaceByReplaceUpdateLabelKey,
XOrphanedIndicationLabelKey: appsv1alpha1.PodOrphanedIndicateLabelKey,
XCreatingLabel: appsv1alpha1.PodCreatingLabel,
XCompletingLabel: appsv1alpha1.PodCompletingLabel,
XExcludeIndicationLabelKey: appsv1alpha1.PodExcludeIndicationLabelKey,
ControlledByXSetLabel: appsv1alpha1.ControlledByKusionStackLabelKey,
XInstanceIdLabelKey: appsv1alpha1.PodInstanceIDLabelKey,
XSetUpdateIndicationLabelKey: appsv1alpha1.CollaSetUpdateIndicateLabelKey,
XDeletionIndicationLabelKey: appsv1alpha1.PodDeletionIndicationLabelKey,
XReplaceIndicationLabelKey: appsv1alpha1.PodReplaceIndicationLabelKey,
XReplacePairNewId: appsv1alpha1.PodReplacePairNewId,
XReplacePairOriginName: appsv1alpha1.PodReplacePairOriginName,
XReplaceByReplaceUpdateLabelKey: appsv1alpha1.PodReplaceByReplaceUpdateLabelKey,
XOrphanedIndicationLabelKey: appsv1alpha1.PodOrphanedIndicateLabelKey,
XCreatingLabel: appsv1alpha1.PodCreatingLabel,
XCompletingLabel: appsv1alpha1.PodCompletingLabel,
XExcludeIndicationLabelKey: appsv1alpha1.PodExcludeIndicationLabelKey,
SubResourcePvcTemplateLabelKey: appsv1alpha1.PvcTemplateLabelKey,
SubResourcePvcTemplateHashLabelKey: appsv1alpha1.PvcTemplateHashLabelKey,

LastXStatusAnnotationKey: appsv1alpha1.LastPodStatusAnnotationKey,
}
Expand Down
21 changes: 21 additions & 0 deletions xset/api/xset_controller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -56,6 +57,7 @@ type XOperation interface {
CheckScheduled(object client.Object) bool
CheckReadyTime(object client.Object) (bool, *metav1.Time)
CheckAvailable(object client.Object) bool
CheckInactive(object client.Object) bool
GetXOpsPriority(ctx context.Context, c client.Client, object client.Object) (*OpsPriority, error)
}

Expand All @@ -74,3 +76,22 @@ type ResourceContextAdapterGetter interface {
type LabelAnnotationManagerGetter interface {
GetLabelManagerAdapter() XSetLabelAnnotationManager
}

// SubResourcePvcAdapter is used to manage pvc subresource for X, which are declared on XSet, e.g., spec.volumeClaimTemplate.
// Once adapter is implemented, XSetController will automatically manage pvc: (1) create pvcs from GetXSetPvcTemplate for each
// X object and attach theses pvcs with same instance-id, (2) upgrade pvcs and recreate X object pvcs when PvcTemplateChanged,
// (3) retain pvcs when XSet is deleted or scaledIn according to RetainPvcWhenXSetDeleted and RetainPvcWhenXSetScaled.
type SubResourcePvcAdapter interface {
// RetainPvcWhenXSetDeleted returns true if pvc should be retained when XSet is deleted.
RetainPvcWhenXSetDeleted(object XSetObject) bool
// RetainPvcWhenXSetScaled returns true if pvc should be retained when XSet replicas is scaledIn.
RetainPvcWhenXSetScaled(object XSetObject) bool
// GetXSetPvcTemplate returns pvc template from XSet object.
GetXSetPvcTemplate(object XSetObject) []corev1.PersistentVolumeClaim
// GetXSpecVolumes returns spec.volumes from X object.
GetXSpecVolumes(object client.Object) []corev1.Volume
// GetXVolumeMounts returns containers volumeMounts from X (pod) object.
GetXVolumeMounts(object client.Object) []corev1.VolumeMount
// SetXSpecVolumes sets spec.volumes to X object.
SetXSpecVolumes(object client.Object, pvcs []corev1.Volume)
}
6 changes: 6 additions & 0 deletions xset/resourcecontexts/default_adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ var defaultResourceContextKeys = map[api.ResourceContextKeyEnum]string{
api.EnumReplaceOriginTargetIDContextDataKey: "ReplaceOriginTargetID",
}

type ResourceContextAdapterGetter struct{}

func (r *ResourceContextAdapterGetter) GetResourceContextAdapter() api.ResourceContextAdapter {
return &DefaultResourceContextAdapter{}
}

// DefaultResourceContextAdapter is the adapter to api apps.kusionstack.io.resourcecontexts
type DefaultResourceContextAdapter struct{}

Expand Down
24 changes: 24 additions & 0 deletions xset/subresources/getter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024-2025 KusionStack Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package subresources

import "kusionstack.io/kube-utils/xset/api"

func GetSubresourcePvcAdapter(control api.XSetController) (adapter api.SubResourcePvcAdapter, enabled bool) {
adapter, enabled = control.(api.SubResourcePvcAdapter)
return adapter, enabled
}
Loading
Loading