Skip to content

Commit a1567b5

Browse files
committed
upgrade cloneset from v1alpha1 to v1beta1
Signed-off-by: PersistentJZH <zhihao.kan17@gmail.com> - add OnDelete Strategy in v1bata1 CloneSet - add ProgressDeadlineSeconds in v1beta1 in cloneset - optimize CloneSetUpdateStrategy structure - transfer image preDownload related annotations to spec field - add image pre download field validate
1 parent c246310 commit a1567b5

77 files changed

Lines changed: 8525 additions & 1550 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apis/apps/defaults/v1beta1.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
v1 "k8s.io/kubernetes/pkg/apis/core/v1"
2424
"k8s.io/utils/ptr"
2525

26+
appspub "github.com/openkruise/kruise/apis/apps/pub"
2627
"github.com/openkruise/kruise/apis/apps/v1beta1"
2728
"github.com/openkruise/kruise/pkg/control/sidecarcontrol"
2829
"github.com/openkruise/kruise/pkg/features"
@@ -399,3 +400,73 @@ func setSidecarSetUpdateStrategyV1beta1(strategy *v1beta1.SidecarSetUpdateStrate
399400
strategy.Partition = &intstr.IntOrString{Type: intstr.Int, IntVal: 0}
400401
}
401402
}
403+
404+
// SetDefaultsCloneSetV1beta1 sets default values for v1beta1 CloneSet.
405+
func SetDefaultsCloneSetV1beta1(obj *v1beta1.CloneSet, injectTemplateDefaults bool) {
406+
if obj.Spec.Replicas == nil {
407+
obj.Spec.Replicas = ptr.To(int32(1))
408+
}
409+
if obj.Spec.RevisionHistoryLimit == nil {
410+
obj.Spec.RevisionHistoryLimit = ptr.To(int32(10))
411+
}
412+
413+
// For v1beta1, EnablePVCReuse defaults to false (safer default - do not reuse PVC)
414+
// This is set by CRD (+kubebuilder:default=false)
415+
// Note: v1alpha1 keeps DisablePVCReuse default as false (enable reuse) for backward compatibility
416+
417+
if injectTemplateDefaults {
418+
SetDefaultPodSpec(&obj.Spec.Template.Spec)
419+
for i := range obj.Spec.VolumeClaimTemplates {
420+
a := &obj.Spec.VolumeClaimTemplates[i]
421+
v1.SetDefaults_PersistentVolumeClaim(a)
422+
v1.SetDefaults_ResourceList(&a.Spec.Resources.Limits)
423+
v1.SetDefaults_ResourceList(&a.Spec.Resources.Requests)
424+
v1.SetDefaults_ResourceList(&a.Status.Capacity)
425+
}
426+
}
427+
428+
// Set default UpdateStrategy Type
429+
if obj.Spec.UpdateStrategy.Type == "" {
430+
obj.Spec.UpdateStrategy.Type = v1beta1.RollingUpdateCloneSetUpdateStrategyType
431+
}
432+
433+
// Ensure RollingUpdate is initialized for RollingUpdate strategy
434+
if obj.Spec.UpdateStrategy.Type == v1beta1.RollingUpdateCloneSetUpdateStrategyType {
435+
if obj.Spec.UpdateStrategy.RollingUpdate == nil {
436+
obj.Spec.UpdateStrategy.RollingUpdate = &v1beta1.RollingUpdateCloneSetStrategy{}
437+
}
438+
439+
// Set default PodUpdatePolicy
440+
if obj.Spec.UpdateStrategy.RollingUpdate.PodUpdatePolicy == "" {
441+
obj.Spec.UpdateStrategy.RollingUpdate.PodUpdatePolicy = v1beta1.RecreateCloneSetPodUpdateStrategyType
442+
}
443+
444+
// Set default InPlaceUpdateStrategy grace period for in-place updates
445+
if obj.Spec.UpdateStrategy.RollingUpdate.PodUpdatePolicy == v1beta1.InPlaceIfPossibleCloneSetPodUpdateStrategyType ||
446+
obj.Spec.UpdateStrategy.RollingUpdate.PodUpdatePolicy == v1beta1.InPlaceOnlyCloneSetPodUpdateStrategyType {
447+
if obj.Spec.UpdateStrategy.RollingUpdate.InPlaceUpdateStrategy == nil {
448+
obj.Spec.UpdateStrategy.RollingUpdate.InPlaceUpdateStrategy = &appspub.InPlaceUpdateStrategy{}
449+
}
450+
// Note: GracePeriodSeconds default should be handled by webhook or controller if needed
451+
// The v1beta1 API doesn't define a default constant for this yet
452+
}
453+
454+
// Set default Partition
455+
if obj.Spec.UpdateStrategy.RollingUpdate.Partition == nil {
456+
partition := intstr.FromInt(0)
457+
obj.Spec.UpdateStrategy.RollingUpdate.Partition = &partition
458+
}
459+
460+
// Set default MaxUnavailable
461+
if obj.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable == nil {
462+
maxUnavailable := intstr.FromString(v1beta1.DefaultCloneSetMaxUnavailable)
463+
obj.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable = &maxUnavailable
464+
}
465+
466+
// Set default MaxSurge
467+
if obj.Spec.UpdateStrategy.RollingUpdate.MaxSurge == nil {
468+
maxSurge := intstr.FromInt(0)
469+
obj.Spec.UpdateStrategy.RollingUpdate.MaxSurge = &maxSurge
470+
}
471+
}
472+
}

apis/apps/pub/inplace_update.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
v1 "k8s.io/api/core/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/util/intstr"
2425
)
2526

2627
const (
@@ -108,6 +109,24 @@ type InPlaceUpdateStrategy struct {
108109
// GracePeriodSeconds is the timespan between set Pod status to not-ready and update images in Pod spec
109110
// when in-place update a Pod.
110111
GracePeriodSeconds int32 `json:"gracePeriodSeconds,omitempty"`
112+
113+
// ImagePreDownloadParallelism is the requested parallelism, it can be set to any non-negative value. If it is unspecified,
114+
// it defaults to 1. If it is specified as 0, then the Job is effectively paused until it is increased.
115+
// In v1alpha1, this corresponds to annotation: apps.kruise.io/image-predownload-parallelism
116+
// +optional
117+
ImagePreDownloadParallelism *intstr.IntOrString `json:"imagePreDownloadParallelism,omitempty"`
118+
119+
// ImagePreDownloadTimeoutSeconds specifies the timeout of the pulling task.
120+
// Defaults to 600
121+
// In v1alpha1, this corresponds to annotation: apps.kruise.io/image-predownload-timeout-seconds
122+
// +optional
123+
ImagePreDownloadTimeoutSeconds *int32 `json:"imagePreDownloadTimeoutSeconds,omitempty"`
124+
125+
// ImagePreDownloadMinUpdatedReadyPods is the minimum number of updated ready Pods
126+
// required before starting image pre-download for the next batch.
127+
// In v1alpha1, this corresponds to annotation: apps.kruise.io/image-predownload-min-updated-ready-pods
128+
// +optional
129+
ImagePreDownloadMinUpdatedReadyPods *int32 `json:"imagePreDownloadMinUpdatedReadyPods,omitempty"`
111130
}
112131

113132
func GetInPlaceUpdateState(obj metav1.Object) (string, bool) {

apis/apps/pub/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)