Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Kuromesi <[email protected]>
  • Loading branch information
Kuromesi committed Aug 31, 2023
1 parent 968b526 commit 6793f86
Show file tree
Hide file tree
Showing 85 changed files with 2,189 additions and 2,016 deletions.
87 changes: 87 additions & 0 deletions api/v1beta1/deployment_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package v1beta1

import (
apps "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

const (
// DeploymentStrategyAnnotation is annotation for deployment,
// which is strategy fields of Advanced Deployment.
DeploymentStrategyAnnotation = "rollouts.kruise.io/deployment-strategy"

// DeploymentExtraStatusAnnotation is annotation for deployment,
// which is extra status field of Advanced Deployment.
DeploymentExtraStatusAnnotation = "rollouts.kruise.io/deployment-extra-status"

// DeploymentStableRevisionLabel is label for deployment,
// which record the stable revision during the current rolling process.
DeploymentStableRevisionLabel = "rollouts.kruise.io/stable-revision"

// AdvancedDeploymentControlLabel is label for deployment,
// which labels whether the deployment is controlled by advanced-deployment-controller.
AdvancedDeploymentControlLabel = "rollouts.kruise.io/controlled-by-advanced-deployment-controller"
)

// DeploymentStrategy is strategy field for Advanced Deployment
type DeploymentStrategy struct {
// RollingStyle define the behavior of rolling for deployment.
RollingStyle RollingStyleType `json:"rollingStyle,omitempty"`
// original deployment strategy rolling update fields
RollingUpdate *apps.RollingUpdateDeployment `json:"rollingUpdate,omitempty"`
// Paused = true will block the upgrade of Pods
Paused bool `json:"paused,omitempty"`
// Partition describe how many Pods should be updated during rollout.
// We use this field to implement partition-style rolling update.
Partition intstr.IntOrString `json:"partition,omitempty"`
}

type RollingStyleType string

const (
// PartitionRollingStyle means rolling in batches just like CloneSet, and will NOT create any extra Deployment;
PartitionRollingStyle RollingStyleType = "Partition"
// CanaryRollingStyle means rolling in canary way, and will create a canary Deployment.
CanaryRollingStyle RollingStyleType = "Canary"
)

// DeploymentExtraStatus is extra status field for Advanced Deployment
type DeploymentExtraStatus struct {
// UpdatedReadyReplicas the number of pods that has been updated and ready.
UpdatedReadyReplicas int32 `json:"updatedReadyReplicas,omitempty"`
// ExpectedUpdatedReplicas is an absolute number calculated based on Partition
// and Deployment.Spec.Replicas, means how many pods are expected be updated under
// current strategy.
// This field is designed to avoid users to fall into the details of algorithm
// for Partition calculation.
ExpectedUpdatedReplicas int32 `json:"expectedUpdatedReplicas,omitempty"`
}

func SetDefaultDeploymentStrategy(strategy *DeploymentStrategy) {
if strategy.RollingStyle == CanaryRollingStyle {
return
}
if strategy.RollingUpdate == nil {
strategy.RollingUpdate = &apps.RollingUpdateDeployment{}
}
if strategy.RollingUpdate.MaxUnavailable == nil {
// Set MaxUnavailable as 25% by default
maxUnavailable := intstr.FromString("25%")
strategy.RollingUpdate.MaxUnavailable = &maxUnavailable
}
if strategy.RollingUpdate.MaxSurge == nil {
// Set MaxSurge as 25% by default
maxSurge := intstr.FromString("25%")
strategy.RollingUpdate.MaxUnavailable = &maxSurge
}

// Cannot allow maxSurge==0 && MaxUnavailable==0, otherwise, no pod can be updated when rolling update.
maxSurge, _ := intstr.GetScaledValueFromIntOrPercent(strategy.RollingUpdate.MaxSurge, 100, true)
maxUnavailable, _ := intstr.GetScaledValueFromIntOrPercent(strategy.RollingUpdate.MaxUnavailable, 100, true)
if maxSurge == 0 && maxUnavailable == 0 {
strategy.RollingUpdate = &apps.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
}
}
}
2 changes: 2 additions & 0 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

SchemeGroupVersion = GroupVersion
)
37 changes: 37 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/crd/bases/rollouts.kruise.io_batchreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -527,7 +527,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
subresources:
status: {}
status:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/rollouts.kruise.io_rollouthistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- name: v1beta1
Expand Down Expand Up @@ -317,7 +317,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
subresources:
status: {}
status:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -991,7 +991,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
subresources:
status: {}
status:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/rollouts.kruise.io_trafficroutings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -565,7 +565,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
subresources:
status: {}
status:
Expand Down
6 changes: 3 additions & 3 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
- patches/webhook_in_rollouts.yaml
#- patches/webhook_in_batchreleases.yaml
#- patches/webhook_in_trafficroutings.yaml
#- patches/webhook_in_rollouthistories.yaml
- patches/webhook_in_batchreleases.yaml
- patches/webhook_in_trafficroutings.yaml
- patches/webhook_in_rollouthistories.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
1 change: 1 addition & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ webhooks:
- apiGroups:
- rollouts.kruise.io
apiVersions:
- v1beta1
- v1alpha1
operations:
- CREATE
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/batchrelease/batchrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sync"
"time"

"github.com/openkruise/rollouts/api/v1alpha1"
"github.com/openkruise/rollouts/api/v1beta1"
"github.com/openkruise/rollouts/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -94,10 +94,10 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to BatchRelease
err = c.Watch(&source.Kind{Type: &v1alpha1.BatchRelease{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
err = c.Watch(&source.Kind{Type: &v1beta1.BatchRelease{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldObject := e.ObjectOld.(*v1alpha1.BatchRelease)
newObject := e.ObjectNew.(*v1alpha1.BatchRelease)
oldObject := e.ObjectOld.(*v1beta1.BatchRelease)
newObject := e.ObjectNew.(*v1beta1.BatchRelease)
if oldObject.Generation != newObject.Generation || newObject.DeletionTimestamp != nil {
klog.V(3).Infof("Observed updated Spec for BatchRelease: %s/%s", newObject.Namespace, newObject.Name)
return true
Expand Down Expand Up @@ -152,7 +152,7 @@ type BatchReleaseReconciler struct {
// Reconcile reads that state of the cluster for a Rollout object and makes changes based on the state read
// and what is in the Rollout.Spec
func (r *BatchReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
release := new(v1alpha1.BatchRelease)
release := new(v1beta1.BatchRelease)
err := r.Get(context.TODO(), req.NamespacedName, release)
if err != nil {
if errors.IsNotFound(err) {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (r *BatchReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

// updateStatus update BatchRelease status to newStatus
func (r *BatchReleaseReconciler) updateStatus(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus) error {
func (r *BatchReleaseReconciler) updateStatus(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus) error {
var err error
defer func() {
if err != nil {
Expand All @@ -234,7 +234,7 @@ func (r *BatchReleaseReconciler) updateStatus(release *v1alpha1.BatchRelease, ne
objectKey := client.ObjectKeyFromObject(release)
if !reflect.DeepEqual(release.Status, *newStatus) {
err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
clone := &v1alpha1.BatchRelease{}
clone := &v1beta1.BatchRelease{}
getErr := r.Get(context.TODO(), objectKey, clone)
if getErr != nil {
return getErr
Expand All @@ -247,7 +247,7 @@ func (r *BatchReleaseReconciler) updateStatus(release *v1alpha1.BatchRelease, ne
}

// handleFinalizer will remove finalizer in finalized phase and add finalizer in the other phases.
func (r *BatchReleaseReconciler) handleFinalizer(release *v1alpha1.BatchRelease) (bool, error) {
func (r *BatchReleaseReconciler) handleFinalizer(release *v1beta1.BatchRelease) (bool, error) {
var err error
defer func() {
if err != nil {
Expand All @@ -257,7 +257,7 @@ func (r *BatchReleaseReconciler) handleFinalizer(release *v1alpha1.BatchRelease)

// remove the release finalizer if it needs
if !release.DeletionTimestamp.IsZero() &&
release.Status.Phase == v1alpha1.RolloutPhaseCompleted &&
release.Status.Phase == v1beta1.RolloutPhaseCompleted &&
controllerutil.ContainsFinalizer(release, ReleaseFinalizer) {
err = util.UpdateFinalizer(r.Client, release, util.RemoveFinalizerOpType, ReleaseFinalizer)
if client.IgnoreNotFound(err) != nil {
Expand Down
Loading

0 comments on commit 6793f86

Please sign in to comment.