From d41b1fa7d7c355501a1d9302e5d84401ebbc217d Mon Sep 17 00:00:00 2001 From: berg Date: Fri, 3 Nov 2023 13:38:55 +0800 Subject: [PATCH] rollout v1beta1 apis (#182) Signed-off-by: liheng.zms --- api/addtoscheme_apps_v1alpha1.go | 26 + api/addtoscheme_apps_v1beta1.go | 26 + api/apis.go | 29 + api/v1alpha1/zz_generated.deepcopy.go | 2 +- api/v1beta1/batchrelease_plan_types.go | 147 ++ api/v1beta1/batchrelease_types.go | 60 + api/v1beta1/convertion.go | 21 + api/v1beta1/deployment_types.go | 103 ++ api/v1beta1/groupversion_info.go | 43 + api/v1beta1/rollout_types.go | 312 ++++ api/v1beta1/zz_generated.deepcopy.go | 571 ++++++++ .../rollouts.kruise.io_batchreleases.yaml | 257 ++++ .../bases/rollouts.kruise.io_rollouts.yaml | 506 +++++++ hack/boilerplate.go.txt | 2 +- .../convert_test_case_to_lua_object.go | 6 +- main.go | 4 +- .../batchrelease/batchrelease_controller.go | 18 +- .../batchrelease_controller_test.go | 177 +-- .../batchrelease_event_handler.go | 8 +- .../batchrelease_event_handler_test.go | 6 +- .../batchrelease/batchrelease_executor.go | 47 +- .../batchrelease/batchrelease_status.go | 71 +- .../batchrelease/context/context.go | 4 +- .../batchrelease/context/context_test.go | 16 +- .../control/canarystyle/control_plane.go | 8 +- .../control/canarystyle/deployment/canary.go | 12 +- .../control/canarystyle/deployment/control.go | 6 +- .../canarystyle/deployment/control_test.go | 45 +- .../control/canarystyle/deployment/stable.go | 6 +- .../control/canarystyle/interface.go | 14 +- .../partitionstyle/cloneset/control.go | 8 +- .../partitionstyle/cloneset/control_test.go | 53 +- .../control/partitionstyle/control_plane.go | 7 +- .../partitionstyle/daemonset/control.go | 8 +- .../partitionstyle/daemonset/control_test.go | 53 +- .../partitionstyle/deployment/control.go | 7 +- .../partitionstyle/deployment/control_test.go | 58 +- .../control/partitionstyle/interface.go | 8 +- .../partitionstyle/statefulset/control.go | 8 +- .../statefulset/control_test.go | 83 +- pkg/controller/batchrelease/control/util.go | 12 +- .../batchrelease/control/util_test.go | 12 +- .../batchrelease/labelpatch/filter.go | 4 +- .../batchrelease/labelpatch/patcher.go | 8 +- .../batchrelease/labelpatch/patcher_test.go | 8 +- pkg/controller/rollout/rollout_canary.go | 93 +- pkg/controller/rollout/rollout_canary_test.go | 65 +- pkg/controller/rollout/rollout_controller.go | 16 +- .../rollout/rollout_controller_test.go | 40 +- .../rollout/rollout_event_handler.go | 6 +- pkg/controller/rollout/rollout_progressing.go | 51 +- .../rollout/rollout_progressing_test.go | 175 +-- pkg/controller/rollout/rollout_status.go | 69 +- pkg/controller/rollout/rollout_status_test.go | 35 +- .../rollouthistory_controller_test.go | 3 +- .../trafficrouting_controller_test.go | 5 +- pkg/trafficrouting/manager_test.go | 70 +- .../custom_network_provider_test.go | 6 +- .../network/ingress/ingress_test.go | 22 +- pkg/util/condition.go | 16 +- pkg/util/controller_finder.go | 19 +- pkg/util/rollout_utils.go | 7 +- pkg/util/workloads_utils_test.go | 4 +- .../rollout_create_update_handler.go | 118 +- .../rollout_create_update_handler_test.go | 98 +- .../validating/validate_v1alphal_rollout.go | 208 +++ .../mutating/workload_update_handler.go | 31 +- .../mutating/workload_update_handler_test.go | 71 +- test/e2e/batchrelease_test.go | 1268 ----------------- test/e2e/rollout_test.go | 140 +- test/e2e/suite_test.go | 4 +- 71 files changed, 3321 insertions(+), 2209 deletions(-) create mode 100644 api/addtoscheme_apps_v1alpha1.go create mode 100644 api/addtoscheme_apps_v1beta1.go create mode 100644 api/apis.go create mode 100644 api/v1beta1/batchrelease_plan_types.go create mode 100644 api/v1beta1/batchrelease_types.go create mode 100644 api/v1beta1/convertion.go create mode 100644 api/v1beta1/deployment_types.go create mode 100644 api/v1beta1/groupversion_info.go create mode 100644 api/v1beta1/rollout_types.go create mode 100644 api/v1beta1/zz_generated.deepcopy.go create mode 100644 pkg/webhook/rollout/validating/validate_v1alphal_rollout.go delete mode 100644 test/e2e/batchrelease_test.go diff --git a/api/addtoscheme_apps_v1alpha1.go b/api/addtoscheme_apps_v1alpha1.go new file mode 100644 index 00000000..9cf691cb --- /dev/null +++ b/api/addtoscheme_apps_v1alpha1.go @@ -0,0 +1,26 @@ +/* +Copyright 2023 The Kruise 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 apis + +import ( + "github.com/openkruise/rollouts/api/v1alpha1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) +} diff --git a/api/addtoscheme_apps_v1beta1.go b/api/addtoscheme_apps_v1beta1.go new file mode 100644 index 00000000..3887bbfb --- /dev/null +++ b/api/addtoscheme_apps_v1beta1.go @@ -0,0 +1,26 @@ +/* +Copyright 2023 The Kruise 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 apis + +import ( + "github.com/openkruise/rollouts/api/v1beta1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) +} diff --git a/api/apis.go b/api/apis.go new file mode 100644 index 00000000..56329221 --- /dev/null +++ b/api/apis.go @@ -0,0 +1,29 @@ +/* +Copyright 2023 The Kruise 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 apis + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// AddToSchemes may be used to add all resources defined in the project to a Scheme +var AddToSchemes runtime.SchemeBuilder + +// AddToScheme adds all Resources to the Scheme +func AddToScheme(s *runtime.Scheme) error { + return AddToSchemes.AddToScheme(s) +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 4a78d09e..05137fd5 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // +build !ignore_autogenerated /* -Copyright 2022 The Kruise Authors. +Copyright 2023 The Kruise Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/api/v1beta1/batchrelease_plan_types.go b/api/v1beta1/batchrelease_plan_types.go new file mode 100644 index 00000000..65b4ddb7 --- /dev/null +++ b/api/v1beta1/batchrelease_plan_types.go @@ -0,0 +1,147 @@ +/* +Copyright 2023 The Kruise 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 v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// ReleasePlan fines the details of the release plan +type ReleasePlan struct { + // Batches is the details on each batch of the ReleasePlan. + //Users can specify their batch plan in this field, such as: + // batches: + // - canaryReplicas: 1 # batches 0 + // - canaryReplicas: 2 # batches 1 + // - canaryReplicas: 5 # batches 2 + // Not that these canaryReplicas should be a non-decreasing sequence. + // +optional + Batches []ReleaseBatch `json:"batches"` + // All pods in the batches up to the batchPartition (included) will have + // the target resource specification while the rest still is the stable revision. + // This is designed for the operators to manually rollout. + // Default is nil, which means no partition and will release all batches. + // BatchPartition start from 0. + // +optional + BatchPartition *int32 `json:"batchPartition,omitempty"` + // RolloutID indicates an id for each rollout progress + RolloutID string `json:"rolloutID,omitempty"` + // FailureThreshold indicates how many failed pods can be tolerated in all upgraded pods. + // Only when FailureThreshold are satisfied, Rollout can enter ready state. + // If FailureThreshold is nil, Rollout will use the MaxUnavailable of workload as its + // FailureThreshold. + // Defaults to nil. + FailureThreshold *intstr.IntOrString `json:"failureThreshold,omitempty"` + // FinalizingPolicy define the behavior of controller when phase enter Finalizing + // Defaults to "Immediate" + FinalizingPolicy FinalizingPolicyType `json:"finalizingPolicy,omitempty"` + // PatchPodTemplateMetadata indicates patch configuration(e.g. labels, annotations) to the canary deployment podTemplateSpec.metadata + // only support for canary deployment + // +optional + PatchPodTemplateMetadata *PatchPodTemplateMetadata `json:"patchPodTemplateMetadata,omitempty"` +} + +type FinalizingPolicyType string + +const ( + // WaitResumeFinalizingPolicyType will wait workload to be resumed, which means + // controller will be hold at Finalizing phase util all pods of workload is upgraded. + // WaitResumeFinalizingPolicyType only works in canary-style BatchRelease controller. + WaitResumeFinalizingPolicyType FinalizingPolicyType = "WaitResume" + // ImmediateFinalizingPolicyType will not to wait workload to be resumed. + ImmediateFinalizingPolicyType FinalizingPolicyType = "Immediate" +) + +// ReleaseBatch is used to describe how each batch release should be +type ReleaseBatch struct { + // CanaryReplicas is the number of upgraded pods that should have in this batch. + // it can be an absolute number (ex: 5) or a percentage of workload replicas. + // batches[i].canaryReplicas should less than or equal to batches[j].canaryReplicas if i < j. + CanaryReplicas intstr.IntOrString `json:"canaryReplicas"` +} + +// BatchReleaseStatus defines the observed state of a release plan +type BatchReleaseStatus struct { + // Conditions represents the observed process state of each phase during executing the release plan. + Conditions []RolloutCondition `json:"conditions,omitempty"` + // CanaryStatus describes the state of the canary rollout. + CanaryStatus BatchReleaseCanaryStatus `json:"canaryStatus,omitempty"` + // StableRevision is the pod-template-hash of stable revision pod template. + StableRevision string `json:"stableRevision,omitempty"` + // UpdateRevision is the pod-template-hash of update revision pod template. + UpdateRevision string `json:"updateRevision,omitempty"` + // ObservedGeneration is the most recent generation observed for this BatchRelease. + // It corresponds to this BatchRelease's generation, which is updated on mutation + // by the API Server, and only if BatchRelease Spec was changed, its generation will increase 1. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + // ObservedRolloutID is the most recent rollout-id observed for this BatchRelease. + // If RolloutID was changed, we will restart to roll out from batch 0, + // to ensure the batch-id and rollout-id labels of Pods are correct. + ObservedRolloutID string `json:"observedRolloutID,omitempty"` + // ObservedWorkloadReplicas is observed replicas of target referenced workload. + // This field is designed to deal with scaling event during rollout, if this field changed, + // it means that the workload is scaling during rollout. + ObservedWorkloadReplicas int32 `json:"observedWorkloadReplicas,omitempty"` + // Count of hash collisions for creating canary Deployment. The controller uses this + // field as a collision avoidance mechanism when it needs to create the name for the + // newest canary Deployment. + // +optional + CollisionCount *int32 `json:"collisionCount,omitempty"` + // ObservedReleasePlanHash is a hash code of observed itself spec.releasePlan. + ObservedReleasePlanHash string `json:"observedReleasePlanHash,omitempty"` + // Phase is the release plan phase, which indicates the current state of release + // plan state machine in BatchRelease controller. + Phase RolloutPhase `json:"phase,omitempty"` +} + +type BatchReleaseCanaryStatus struct { + // CurrentBatchState indicates the release state of the current batch. + CurrentBatchState BatchReleaseBatchStateType `json:"batchState,omitempty"` + // The current batch the rollout is working on/blocked, it starts from 0 + CurrentBatch int32 `json:"currentBatch"` + // BatchReadyTime is the ready timestamp of the current batch or the last batch. + // This field is updated once a batch ready, and the batches[x].pausedSeconds + // relies on this field to calculate the real-time duration. + BatchReadyTime *metav1.Time `json:"batchReadyTime,omitempty"` + // UpdatedReplicas is the number of upgraded Pods. + UpdatedReplicas int32 `json:"updatedReplicas,omitempty"` + // UpdatedReadyReplicas is the number upgraded Pods that have a Ready Condition. + UpdatedReadyReplicas int32 `json:"updatedReadyReplicas,omitempty"` + // the number of pods that no need to rollback in rollback scene. + NoNeedUpdateReplicas *int32 `json:"noNeedUpdateReplicas,omitempty"` +} + +type BatchReleaseBatchStateType string + +const ( + // UpgradingBatchState indicates that current batch is at upgrading pod state + UpgradingBatchState BatchReleaseBatchStateType = "Upgrading" + // VerifyingBatchState indicates that current batch is at verifying whether it's ready state + VerifyingBatchState BatchReleaseBatchStateType = "Verifying" + // ReadyBatchState indicates that current batch is at batch ready state + ReadyBatchState BatchReleaseBatchStateType = "Ready" +) + +const ( + // RolloutPhasePreparing indicates a rollout is preparing for next progress. + RolloutPhasePreparing RolloutPhase = "Preparing" + // RolloutPhaseFinalizing indicates a rollout is finalizing + RolloutPhaseFinalizing RolloutPhase = "Finalizing" + // RolloutPhaseCompleted indicates a rollout is completed/cancelled/terminated + RolloutPhaseCompleted RolloutPhase = "Completed" +) diff --git a/api/v1beta1/batchrelease_types.go b/api/v1beta1/batchrelease_types.go new file mode 100644 index 00000000..ffb80409 --- /dev/null +++ b/api/v1beta1/batchrelease_types.go @@ -0,0 +1,60 @@ +/* +Copyright 2023 The Kruise 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 v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:openapi-gen=true +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:printcolumn:name="KIND",type=string,JSONPath=`.spec.targetReference.workloadRef.kind` +// +kubebuilder:printcolumn:name="PHASE",type=string,JSONPath=`.status.phase` +// +kubebuilder:printcolumn:name="BATCH",type=integer,JSONPath=`.status.canaryStatus.currentBatch` +// +kubebuilder:printcolumn:name="BATCH-STATE",type=string,JSONPath=`.status.canaryStatus.batchState` +// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp" + +type BatchRelease struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec BatchReleaseSpec `json:"spec,omitempty"` + Status BatchReleaseStatus `json:"status,omitempty"` +} + +// BatchReleaseSpec defines how to describe an update between different compRevision +type BatchReleaseSpec struct { + // TargetRef contains the GVK and name of the workload that we need to upgrade to. + TargetRef ObjectRef `json:"targetReference"` + // ReleasePlan is the details on how to rollout the resources + ReleasePlan ReleasePlan `json:"releasePlan"` +} + +// BatchReleaseList contains a list of BatchRelease +// +kubebuilder:object:root=true +type BatchReleaseList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []BatchRelease `json:"items"` +} + +func init() { + SchemeBuilder.Register(&BatchRelease{}, &BatchReleaseList{}) +} diff --git a/api/v1beta1/convertion.go b/api/v1beta1/convertion.go new file mode 100644 index 00000000..5d1600a3 --- /dev/null +++ b/api/v1beta1/convertion.go @@ -0,0 +1,21 @@ +/* +Copyright 2023 The Kruise 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 v1beta1 + +func (*Rollout) Hub() {} + +func (*BatchRelease) Hub() {} diff --git a/api/v1beta1/deployment_types.go b/api/v1beta1/deployment_types.go new file mode 100644 index 00000000..3db56143 --- /dev/null +++ b/api/v1beta1/deployment_types.go @@ -0,0 +1,103 @@ +/* +Copyright 2023 The Kruise 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 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}, + } + } +} diff --git a/api/v1beta1/groupversion_info.go b/api/v1beta1/groupversion_info.go new file mode 100644 index 00000000..133352ab --- /dev/null +++ b/api/v1beta1/groupversion_info.go @@ -0,0 +1,43 @@ +/* +Copyright 2023 The Kruise 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 v1beta1 contains API Schema definitions for the apps v1beta1 API group +// +kubebuilder:object:generate=true +// +groupName=rollouts.kruise.io +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "rollouts.kruise.io", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme + + SchemeGroupVersion = GroupVersion +) + +// Resource is required by pkg/client/listers/... +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} diff --git a/api/v1beta1/rollout_types.go b/api/v1beta1/rollout_types.go new file mode 100644 index 00000000..5e43eb48 --- /dev/null +++ b/api/v1beta1/rollout_types.go @@ -0,0 +1,312 @@ +/* +Copyright 2023 The Kruise 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 v1beta1 + +import ( + "github.com/openkruise/rollouts/api/v1alpha1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +const ( + // RolloutIDLabel is set to workload labels. + // RolloutIDLabel is designed to distinguish each workload revision publications. + // The value of RolloutIDLabel corresponds Rollout.Spec.RolloutID. + RolloutIDLabel = "rollouts.kruise.io/rollout-id" + + // RolloutBatchIDLabel is patched in pod labels. + // RolloutBatchIDLabel is the label key of batch id that will be patched to pods during rollout. + // Only when RolloutIDLabel is set, RolloutBatchIDLabel will be patched. + // Users can use RolloutIDLabel and RolloutBatchIDLabel to select the pods that are upgraded in some certain batch and release. + RolloutBatchIDLabel = "rollouts.kruise.io/rollout-batch-id" + + // RollbackInBatchAnnotation is set to rollout annotations. + // RollbackInBatchAnnotation allow use disable quick rollback, and will roll back in batch style. + RollbackInBatchAnnotation = "rollouts.kruise.io/rollback-in-batch" + + // RolloutStyleAnnotation define the rolling behavior for Deployment. + // must be "partition" or "canary": + // * "partition" means rolling in batches just like CloneSet, and will NOT create any extra Workload; + // * "canary" means rolling in canary way, and will create a canary Workload. + // Currently, only Deployment support both "partition" and "canary" rolling styles. + // For other workload types, they only support "partition" styles. + // Defaults to "canary" to Deployment. + // Defaults to "partition" to the others. + RolloutStyleAnnotation = "rollouts.kruise.io/rolling-style" + + // TrafficRoutingAnnotation is the TrafficRouting Name, and it is the Rollout's TrafficRouting. + // The Rollout release will trigger the TrafficRouting release. For example: + // A microservice consists of three applications, and the invocation relationship is as follows: a -> b -> c, + // and application(a, b, c)'s gateway is trafficRouting. Any application(a, b or b) release will trigger TrafficRouting release. + TrafficRoutingAnnotation = "rollouts.kruise.io/trafficrouting" +) + +// RolloutSpec defines the desired state of Rollout +type RolloutSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + // ObjectRef indicates workload + ObjectRef ObjectRef `json:"objectRef"` + // rollout strategy + Strategy RolloutStrategy `json:"strategy"` + // DeprecatedRolloutID is the deprecated field. + // It is recommended that configure RolloutId in workload.annotations[rollouts.kruise.io/rollout-id]. + // RolloutID should be changed before each workload revision publication. + // It is to distinguish consecutive multiple workload publications and rollout progress. + DeprecatedRolloutID string `json:"rolloutID,omitempty"` + // if a rollout disabled, then the rollout would not watch changes of workload + //+kubebuilder:validation:Optional + //+kubebuilder:default=false + Disabled bool `json:"disabled"` +} + +type ObjectRef struct { + // WorkloadRef contains enough information to let you identify a workload for Rollout + // Batch release of the bypass + WorkloadRef *WorkloadRef `json:"workloadRef,omitempty"` +} + +// WorkloadRef holds a references to the Kubernetes object +type WorkloadRef struct { + // API Version of the referent + APIVersion string `json:"apiVersion"` + // Kind of the referent + Kind string `json:"kind"` + // Name of the referent + Name string `json:"name"` +} + +// RolloutStrategy defines strategy to apply during next rollout +type RolloutStrategy struct { + // Paused indicates that the Rollout is paused. + // Default value is false + Paused bool `json:"paused,omitempty"` + // +optional + Canary *CanaryStrategy `json:"canary,omitempty"` +} + +// CanaryStrategy defines parameters for a Replica Based Canary +type CanaryStrategy struct { + // Steps define the order of phases to execute release in batches(20%, 40%, 60%, 80%, 100%) + // +optional + Steps []CanaryStep `json:"steps,omitempty"` + // TrafficRoutings hosts all the supported service meshes supported to enable more fine-grained traffic routing + // and current only support one TrafficRouting + TrafficRoutings []v1alpha1.TrafficRoutingRef `json:"trafficRoutings,omitempty"` + // FailureThreshold indicates how many failed pods can be tolerated in all upgraded pods. + // Only when FailureThreshold are satisfied, Rollout can enter ready state. + // If FailureThreshold is nil, Rollout will use the MaxUnavailable of workload as its + // FailureThreshold. + // Defaults to nil. + FailureThreshold *intstr.IntOrString `json:"failureThreshold,omitempty"` + // PatchPodTemplateMetadata indicates patch configuration(e.g. labels, annotations) to the canary deployment podTemplateSpec.metadata + // only support for canary deployment + // +optional + PatchPodTemplateMetadata *PatchPodTemplateMetadata `json:"patchPodTemplateMetadata,omitempty"` +} + +type PatchPodTemplateMetadata struct { + // annotations + Annotations map[string]string `json:"annotations,omitempty"` + // labels + Labels map[string]string `json:"labels,omitempty"` +} + +// CanaryStep defines a step of a canary workload. +type CanaryStep struct { + v1alpha1.TrafficRoutingStrategy `json:",inline"` + // Replicas is the number of expected canary pods in this batch + // it can be an absolute number (ex: 5) or a percentage of total pods. + Replicas *intstr.IntOrString `json:"replicas,omitempty"` + // Pause defines a pause stage for a rollout, manual or auto + // +optional + Pause RolloutPause `json:"pause,omitempty"` +} + +type HttpRouteMatch struct { + // Headers specifies HTTP request header matchers. Multiple match values are + // ANDed together, meaning, a request must match all the specified headers + // to select the route. + // +kubebuilder:validation:MaxItems=16 + Headers []gatewayv1alpha2.HTTPHeaderMatch `json:"headers,omitempty"` +} + +// RolloutPause defines a pause stage for a rollout +type RolloutPause struct { + // Duration the amount of time to wait before moving to the next step. + // +optional + Duration *int32 `json:"duration,omitempty"` +} + +// RolloutStatus defines the observed state of Rollout +type RolloutStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // observedGeneration is the most recent generation observed for this Rollout. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + // Canary describes the state of the canary rollout + // +optional + CanaryStatus *CanaryStatus `json:"canaryStatus,omitempty"` + // Conditions a list of conditions a rollout can have. + // +optional + Conditions []RolloutCondition `json:"conditions,omitempty"` + // +optional + //BlueGreenStatus *BlueGreenStatus `json:"blueGreenStatus,omitempty"` + // Phase is the rollout phase. + Phase RolloutPhase `json:"phase,omitempty"` + // Message provides details on why the rollout is in its current phase + Message string `json:"message,omitempty"` +} + +// RolloutCondition describes the state of a rollout at a certain point. +type RolloutCondition struct { + // Type of rollout condition. + Type RolloutConditionType `json:"type"` + // Phase of the condition, one of True, False, Unknown. + Status corev1.ConditionStatus `json:"status"` + // The last time this condition was updated. + LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` + // Last time the condition transitioned from one status to another. + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` + // The reason for the condition's last transition. + Reason string `json:"reason"` + // A human readable message indicating details about the transition. + Message string `json:"message"` +} + +// RolloutConditionType defines the conditions of Rollout +type RolloutConditionType string + +// These are valid conditions of a rollout. +const ( + // RolloutConditionProgressing means the rollout is progressing. Progress for a rollout is + // considered when a new replica set is created or adopted, when pods scale + // up or old pods scale down, or when the services are updated. Progress is not estimated + // for paused rollouts. + RolloutConditionProgressing RolloutConditionType = "Progressing" + // Progressing Reason + ProgressingReasonInitializing = "Initializing" + ProgressingReasonInRolling = "InRolling" + ProgressingReasonFinalising = "Finalising" + ProgressingReasonCompleted = "Completed" + ProgressingReasonCancelling = "Cancelling" + ProgressingReasonPaused = "Paused" + + // RolloutConditionSucceeded indicates whether rollout is succeeded or failed. + RolloutConditionSucceeded RolloutConditionType = "Succeeded" + + // Terminating condition + RolloutConditionTerminating RolloutConditionType = "Terminating" + // Terminating Reason + TerminatingReasonInTerminating = "InTerminating" + TerminatingReasonCompleted = "Completed" +) + +// CanaryStatus status fields that only pertain to the canary rollout +type CanaryStatus struct { + // observedWorkloadGeneration is the most recent generation observed for this Rollout ref workload generation. + ObservedWorkloadGeneration int64 `json:"observedWorkloadGeneration,omitempty"` + // ObservedRolloutID will record the newest spec.RolloutID if status.canaryRevision equals to workload.updateRevision + ObservedRolloutID string `json:"observedRolloutID,omitempty"` + // RolloutHash from rollout.spec object + RolloutHash string `json:"rolloutHash,omitempty"` + // StableRevision indicates the revision of stable pods + StableRevision string `json:"stableRevision,omitempty"` + // CanaryRevision is calculated by rollout based on podTemplateHash, and the internal logic flow uses + // It may be different from rs podTemplateHash in different k8s versions, so it cannot be used as service selector label + CanaryRevision string `json:"canaryRevision"` + // pod template hash is used as service selector label + PodTemplateHash string `json:"podTemplateHash"` + // CanaryReplicas the numbers of canary revision pods + CanaryReplicas int32 `json:"canaryReplicas"` + // CanaryReadyReplicas the numbers of ready canary revision pods + CanaryReadyReplicas int32 `json:"canaryReadyReplicas"` + // CurrentStepIndex defines the current step of the rollout is on. If the current step index is null, the + // controller will execute the rollout. + // +optional + CurrentStepIndex int32 `json:"currentStepIndex"` + CurrentStepState CanaryStepState `json:"currentStepState"` + Message string `json:"message,omitempty"` + LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"` +} + +type CanaryStepState string + +const ( + CanaryStepStateUpgrade CanaryStepState = "StepUpgrade" + CanaryStepStateTrafficRouting CanaryStepState = "StepTrafficRouting" + CanaryStepStateMetricsAnalysis CanaryStepState = "StepMetricsAnalysis" + CanaryStepStatePaused CanaryStepState = "StepPaused" + CanaryStepStateReady CanaryStepState = "StepReady" + CanaryStepStateCompleted CanaryStepState = "Completed" +) + +// RolloutPhase are a set of phases that this rollout +type RolloutPhase string + +const ( + // RolloutPhaseInitial indicates a rollout is Initial + RolloutPhaseInitial RolloutPhase = "Initial" + // RolloutPhaseHealthy indicates a rollout is healthy + RolloutPhaseHealthy RolloutPhase = "Healthy" + // RolloutPhaseProgressing indicates a rollout is not yet healthy but still making progress towards a healthy state + RolloutPhaseProgressing RolloutPhase = "Progressing" + // RolloutPhaseTerminating indicates a rollout is terminated + RolloutPhaseTerminating RolloutPhase = "Terminating" + // RolloutPhaseDisabled indicates a rollout is disabled + RolloutPhaseDisabled RolloutPhase = "Disabled" + // RolloutPhaseDisabling indicates a rollout is disabling and releasing resources + RolloutPhaseDisabling RolloutPhase = "Disabling" +) + +// +genclient +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.phase",description="The rollout status phase" +// +kubebuilder:printcolumn:name="CANARY_STEP",type="integer",JSONPath=".status.canaryStatus.currentStepIndex",description="The rollout canary status step" +// +kubebuilder:printcolumn:name="CANARY_STATE",type="string",JSONPath=".status.canaryStatus.currentStepState",description="The rollout canary status step state" +// +kubebuilder:printcolumn:name="MESSAGE",type="string",JSONPath=".status.message",description="The rollout canary status message" +// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp" + +// Rollout is the Schema for the rollouts API +type Rollout struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec RolloutSpec `json:"spec,omitempty"` + Status RolloutStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// RolloutList contains a list of Rollout +type RolloutList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Rollout `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Rollout{}, &RolloutList{}) +} diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000..6e753450 --- /dev/null +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,571 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2023 The Kruise 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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "github.com/openkruise/rollouts/api/v1alpha1" + "k8s.io/api/apps/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/intstr" + "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BatchRelease) DeepCopyInto(out *BatchRelease) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BatchRelease. +func (in *BatchRelease) DeepCopy() *BatchRelease { + if in == nil { + return nil + } + out := new(BatchRelease) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BatchRelease) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BatchReleaseCanaryStatus) DeepCopyInto(out *BatchReleaseCanaryStatus) { + *out = *in + if in.BatchReadyTime != nil { + in, out := &in.BatchReadyTime, &out.BatchReadyTime + *out = (*in).DeepCopy() + } + if in.NoNeedUpdateReplicas != nil { + in, out := &in.NoNeedUpdateReplicas, &out.NoNeedUpdateReplicas + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BatchReleaseCanaryStatus. +func (in *BatchReleaseCanaryStatus) DeepCopy() *BatchReleaseCanaryStatus { + if in == nil { + return nil + } + out := new(BatchReleaseCanaryStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BatchReleaseList) DeepCopyInto(out *BatchReleaseList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BatchRelease, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BatchReleaseList. +func (in *BatchReleaseList) DeepCopy() *BatchReleaseList { + if in == nil { + return nil + } + out := new(BatchReleaseList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BatchReleaseList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BatchReleaseSpec) DeepCopyInto(out *BatchReleaseSpec) { + *out = *in + in.TargetRef.DeepCopyInto(&out.TargetRef) + in.ReleasePlan.DeepCopyInto(&out.ReleasePlan) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BatchReleaseSpec. +func (in *BatchReleaseSpec) DeepCopy() *BatchReleaseSpec { + if in == nil { + return nil + } + out := new(BatchReleaseSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BatchReleaseStatus) DeepCopyInto(out *BatchReleaseStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]RolloutCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.CanaryStatus.DeepCopyInto(&out.CanaryStatus) + if in.CollisionCount != nil { + in, out := &in.CollisionCount, &out.CollisionCount + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BatchReleaseStatus. +func (in *BatchReleaseStatus) DeepCopy() *BatchReleaseStatus { + if in == nil { + return nil + } + out := new(BatchReleaseStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CanaryStatus) DeepCopyInto(out *CanaryStatus) { + *out = *in + if in.LastUpdateTime != nil { + in, out := &in.LastUpdateTime, &out.LastUpdateTime + *out = (*in).DeepCopy() + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CanaryStatus. +func (in *CanaryStatus) DeepCopy() *CanaryStatus { + if in == nil { + return nil + } + out := new(CanaryStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CanaryStep) DeepCopyInto(out *CanaryStep) { + *out = *in + in.TrafficRoutingStrategy.DeepCopyInto(&out.TrafficRoutingStrategy) + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(intstr.IntOrString) + **out = **in + } + in.Pause.DeepCopyInto(&out.Pause) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CanaryStep. +func (in *CanaryStep) DeepCopy() *CanaryStep { + if in == nil { + return nil + } + out := new(CanaryStep) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CanaryStrategy) DeepCopyInto(out *CanaryStrategy) { + *out = *in + if in.Steps != nil { + in, out := &in.Steps, &out.Steps + *out = make([]CanaryStep, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.TrafficRoutings != nil { + in, out := &in.TrafficRoutings, &out.TrafficRoutings + *out = make([]v1alpha1.TrafficRoutingRef, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.FailureThreshold != nil { + in, out := &in.FailureThreshold, &out.FailureThreshold + *out = new(intstr.IntOrString) + **out = **in + } + if in.PatchPodTemplateMetadata != nil { + in, out := &in.PatchPodTemplateMetadata, &out.PatchPodTemplateMetadata + *out = new(PatchPodTemplateMetadata) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CanaryStrategy. +func (in *CanaryStrategy) DeepCopy() *CanaryStrategy { + if in == nil { + return nil + } + out := new(CanaryStrategy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DeploymentExtraStatus) DeepCopyInto(out *DeploymentExtraStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentExtraStatus. +func (in *DeploymentExtraStatus) DeepCopy() *DeploymentExtraStatus { + if in == nil { + return nil + } + out := new(DeploymentExtraStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DeploymentStrategy) DeepCopyInto(out *DeploymentStrategy) { + *out = *in + if in.RollingUpdate != nil { + in, out := &in.RollingUpdate, &out.RollingUpdate + *out = new(v1.RollingUpdateDeployment) + (*in).DeepCopyInto(*out) + } + out.Partition = in.Partition +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentStrategy. +func (in *DeploymentStrategy) DeepCopy() *DeploymentStrategy { + if in == nil { + return nil + } + out := new(DeploymentStrategy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HttpRouteMatch) DeepCopyInto(out *HttpRouteMatch) { + *out = *in + if in.Headers != nil { + in, out := &in.Headers, &out.Headers + *out = make([]v1alpha2.HTTPHeaderMatch, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HttpRouteMatch. +func (in *HttpRouteMatch) DeepCopy() *HttpRouteMatch { + if in == nil { + return nil + } + out := new(HttpRouteMatch) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ObjectRef) DeepCopyInto(out *ObjectRef) { + *out = *in + if in.WorkloadRef != nil { + in, out := &in.WorkloadRef, &out.WorkloadRef + *out = new(WorkloadRef) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectRef. +func (in *ObjectRef) DeepCopy() *ObjectRef { + if in == nil { + return nil + } + out := new(ObjectRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PatchPodTemplateMetadata) DeepCopyInto(out *PatchPodTemplateMetadata) { + *out = *in + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PatchPodTemplateMetadata. +func (in *PatchPodTemplateMetadata) DeepCopy() *PatchPodTemplateMetadata { + if in == nil { + return nil + } + out := new(PatchPodTemplateMetadata) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ReleaseBatch) DeepCopyInto(out *ReleaseBatch) { + *out = *in + out.CanaryReplicas = in.CanaryReplicas +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReleaseBatch. +func (in *ReleaseBatch) DeepCopy() *ReleaseBatch { + if in == nil { + return nil + } + out := new(ReleaseBatch) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ReleasePlan) DeepCopyInto(out *ReleasePlan) { + *out = *in + if in.Batches != nil { + in, out := &in.Batches, &out.Batches + *out = make([]ReleaseBatch, len(*in)) + copy(*out, *in) + } + if in.BatchPartition != nil { + in, out := &in.BatchPartition, &out.BatchPartition + *out = new(int32) + **out = **in + } + if in.FailureThreshold != nil { + in, out := &in.FailureThreshold, &out.FailureThreshold + *out = new(intstr.IntOrString) + **out = **in + } + if in.PatchPodTemplateMetadata != nil { + in, out := &in.PatchPodTemplateMetadata, &out.PatchPodTemplateMetadata + *out = new(PatchPodTemplateMetadata) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReleasePlan. +func (in *ReleasePlan) DeepCopy() *ReleasePlan { + if in == nil { + return nil + } + out := new(ReleasePlan) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Rollout) DeepCopyInto(out *Rollout) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rollout. +func (in *Rollout) DeepCopy() *Rollout { + if in == nil { + return nil + } + out := new(Rollout) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Rollout) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutCondition) DeepCopyInto(out *RolloutCondition) { + *out = *in + in.LastUpdateTime.DeepCopyInto(&out.LastUpdateTime) + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutCondition. +func (in *RolloutCondition) DeepCopy() *RolloutCondition { + if in == nil { + return nil + } + out := new(RolloutCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutList) DeepCopyInto(out *RolloutList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Rollout, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutList. +func (in *RolloutList) DeepCopy() *RolloutList { + if in == nil { + return nil + } + out := new(RolloutList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RolloutList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutPause) DeepCopyInto(out *RolloutPause) { + *out = *in + if in.Duration != nil { + in, out := &in.Duration, &out.Duration + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutPause. +func (in *RolloutPause) DeepCopy() *RolloutPause { + if in == nil { + return nil + } + out := new(RolloutPause) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutSpec) DeepCopyInto(out *RolloutSpec) { + *out = *in + in.ObjectRef.DeepCopyInto(&out.ObjectRef) + in.Strategy.DeepCopyInto(&out.Strategy) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutSpec. +func (in *RolloutSpec) DeepCopy() *RolloutSpec { + if in == nil { + return nil + } + out := new(RolloutSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutStatus) DeepCopyInto(out *RolloutStatus) { + *out = *in + if in.CanaryStatus != nil { + in, out := &in.CanaryStatus, &out.CanaryStatus + *out = new(CanaryStatus) + (*in).DeepCopyInto(*out) + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]RolloutCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutStatus. +func (in *RolloutStatus) DeepCopy() *RolloutStatus { + if in == nil { + return nil + } + out := new(RolloutStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RolloutStrategy) DeepCopyInto(out *RolloutStrategy) { + *out = *in + if in.Canary != nil { + in, out := &in.Canary, &out.Canary + *out = new(CanaryStrategy) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutStrategy. +func (in *RolloutStrategy) DeepCopy() *RolloutStrategy { + if in == nil { + return nil + } + out := new(RolloutStrategy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WorkloadRef) DeepCopyInto(out *WorkloadRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkloadRef. +func (in *WorkloadRef) DeepCopy() *WorkloadRef { + if in == nil { + return nil + } + out := new(WorkloadRef) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/rollouts.kruise.io_batchreleases.yaml b/config/crd/bases/rollouts.kruise.io_batchreleases.yaml index 421b07f4..89cd6311 100644 --- a/config/crd/bases/rollouts.kruise.io_batchreleases.yaml +++ b/config/crd/bases/rollouts.kruise.io_batchreleases.yaml @@ -270,6 +270,263 @@ spec: type: object type: object served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - jsonPath: .spec.targetReference.workloadRef.kind + name: KIND + type: string + - jsonPath: .status.phase + name: PHASE + type: string + - jsonPath: .status.canaryStatus.currentBatch + name: BATCH + type: integer + - jsonPath: .status.canaryStatus.batchState + name: BATCH-STATE + type: string + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1beta1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: BatchReleaseSpec defines how to describe an update between + different compRevision + properties: + releasePlan: + description: ReleasePlan is the details on how to rollout the resources + properties: + batchPartition: + description: All pods in the batches up to the batchPartition + (included) will have the target resource specification while + the rest still is the stable revision. This is designed for + the operators to manually rollout. Default is nil, which means + no partition and will release all batches. BatchPartition start + from 0. + format: int32 + type: integer + batches: + description: 'Batches is the details on each batch of the ReleasePlan. + Users can specify their batch plan in this field, such as: batches: + - canaryReplicas: 1 # batches 0 - canaryReplicas: 2 # batches + 1 - canaryReplicas: 5 # batches 2 Not that these canaryReplicas + should be a non-decreasing sequence.' + items: + description: ReleaseBatch is used to describe how each batch + release should be + properties: + canaryReplicas: + anyOf: + - type: integer + - type: string + description: 'CanaryReplicas is the number of upgraded pods + that should have in this batch. it can be an absolute + number (ex: 5) or a percentage of workload replicas. batches[i].canaryReplicas + should less than or equal to batches[j].canaryReplicas + if i < j.' + x-kubernetes-int-or-string: true + required: + - canaryReplicas + type: object + type: array + failureThreshold: + anyOf: + - type: integer + - type: string + description: FailureThreshold indicates how many failed pods can + be tolerated in all upgraded pods. Only when FailureThreshold + are satisfied, Rollout can enter ready state. If FailureThreshold + is nil, Rollout will use the MaxUnavailable of workload as its + FailureThreshold. Defaults to nil. + x-kubernetes-int-or-string: true + finalizingPolicy: + description: FinalizingPolicy define the behavior of controller + when phase enter Finalizing Defaults to "Immediate" + type: string + patchPodTemplateMetadata: + description: PatchPodTemplateMetadata indicates patch configuration(e.g. + labels, annotations) to the canary deployment podTemplateSpec.metadata + only support for canary deployment + properties: + annotations: + additionalProperties: + type: string + description: annotations + type: object + labels: + additionalProperties: + type: string + description: labels + type: object + type: object + rolloutID: + description: RolloutID indicates an id for each rollout progress + type: string + type: object + targetReference: + description: TargetRef contains the GVK and name of the workload that + we need to upgrade to. + properties: + workloadRef: + description: WorkloadRef contains enough information to let you + identify a workload for Rollout Batch release of the bypass + properties: + apiVersion: + description: API Version of the referent + type: string + kind: + description: Kind of the referent + type: string + name: + description: Name of the referent + type: string + required: + - apiVersion + - kind + - name + type: object + type: object + required: + - releasePlan + - targetReference + type: object + status: + description: BatchReleaseStatus defines the observed state of a release + plan + properties: + canaryStatus: + description: CanaryStatus describes the state of the canary rollout. + properties: + batchReadyTime: + description: BatchReadyTime is the ready timestamp of the current + batch or the last batch. This field is updated once a batch + ready, and the batches[x].pausedSeconds relies on this field + to calculate the real-time duration. + format: date-time + type: string + batchState: + description: CurrentBatchState indicates the release state of + the current batch. + type: string + currentBatch: + description: The current batch the rollout is working on/blocked, + it starts from 0 + format: int32 + type: integer + noNeedUpdateReplicas: + description: the number of pods that no need to rollback in rollback + scene. + format: int32 + type: integer + updatedReadyReplicas: + description: UpdatedReadyReplicas is the number upgraded Pods + that have a Ready Condition. + format: int32 + type: integer + updatedReplicas: + description: UpdatedReplicas is the number of upgraded Pods. + format: int32 + type: integer + required: + - currentBatch + type: object + collisionCount: + description: Count of hash collisions for creating canary Deployment. + The controller uses this field as a collision avoidance mechanism + when it needs to create the name for the newest canary Deployment. + format: int32 + type: integer + conditions: + description: Conditions represents the observed process state of each + phase during executing the release plan. + items: + description: RolloutCondition describes the state of a rollout at + a certain point. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one status + to another. + format: date-time + type: string + lastUpdateTime: + description: The last time this condition was updated. + format: date-time + type: string + message: + description: A human readable message indicating details about + the transition. + type: string + reason: + description: The reason for the condition's last transition. + type: string + status: + description: Phase of the condition, one of True, False, Unknown. + type: string + type: + description: Type of rollout condition. + type: string + required: + - message + - reason + - status + - type + type: object + type: array + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this BatchRelease. It corresponds to this BatchRelease's generation, + which is updated on mutation by the API Server, and only if BatchRelease + Spec was changed, its generation will increase 1. + format: int64 + type: integer + observedReleasePlanHash: + description: ObservedReleasePlanHash is a hash code of observed itself + spec.releasePlan. + type: string + observedRolloutID: + description: ObservedRolloutID is the most recent rollout-id observed + for this BatchRelease. If RolloutID was changed, we will restart + to roll out from batch 0, to ensure the batch-id and rollout-id + labels of Pods are correct. + type: string + observedWorkloadReplicas: + description: ObservedWorkloadReplicas is observed replicas of target + referenced workload. This field is designed to deal with scaling + event during rollout, if this field changed, it means that the workload + is scaling during rollout. + format: int32 + type: integer + phase: + description: Phase is the release plan phase, which indicates the + current state of release plan state machine in BatchRelease controller. + type: string + stableRevision: + description: StableRevision is the pod-template-hash of stable revision + pod template. + type: string + updateRevision: + description: UpdateRevision is the pod-template-hash of update revision + pod template. + type: string + type: object + type: object + served: true storage: true subresources: status: {} diff --git a/config/crd/bases/rollouts.kruise.io_rollouts.yaml b/config/crd/bases/rollouts.kruise.io_rollouts.yaml index 84626f25..f99434da 100644 --- a/config/crd/bases/rollouts.kruise.io_rollouts.yaml +++ b/config/crd/bases/rollouts.kruise.io_rollouts.yaml @@ -519,6 +519,512 @@ spec: type: object type: object served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - description: The rollout status phase + jsonPath: .status.phase + name: STATUS + type: string + - description: The rollout canary status step + jsonPath: .status.canaryStatus.currentStepIndex + name: CANARY_STEP + type: integer + - description: The rollout canary status step state + jsonPath: .status.canaryStatus.currentStepState + name: CANARY_STATE + type: string + - description: The rollout canary status message + jsonPath: .status.message + name: MESSAGE + type: string + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: Rollout is the Schema for the rollouts API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: RolloutSpec defines the desired state of Rollout + properties: + disabled: + default: false + description: if a rollout disabled, then the rollout would not watch + changes of workload + type: boolean + objectRef: + description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + Important: Run "make" to regenerate code after modifying this file + ObjectRef indicates workload' + properties: + workloadRef: + description: WorkloadRef contains enough information to let you + identify a workload for Rollout Batch release of the bypass + properties: + apiVersion: + description: API Version of the referent + type: string + kind: + description: Kind of the referent + type: string + name: + description: Name of the referent + type: string + required: + - apiVersion + - kind + - name + type: object + type: object + rolloutID: + description: DeprecatedRolloutID is the deprecated field. It is recommended + that configure RolloutId in workload.annotations[rollouts.kruise.io/rollout-id]. + RolloutID should be changed before each workload revision publication. + It is to distinguish consecutive multiple workload publications + and rollout progress. + type: string + strategy: + description: rollout strategy + properties: + canary: + description: CanaryStrategy defines parameters for a Replica Based + Canary + properties: + failureThreshold: + anyOf: + - type: integer + - type: string + description: FailureThreshold indicates how many failed pods + can be tolerated in all upgraded pods. Only when FailureThreshold + are satisfied, Rollout can enter ready state. If FailureThreshold + is nil, Rollout will use the MaxUnavailable of workload + as its FailureThreshold. Defaults to nil. + x-kubernetes-int-or-string: true + patchPodTemplateMetadata: + description: PatchPodTemplateMetadata indicates patch configuration(e.g. + labels, annotations) to the canary deployment podTemplateSpec.metadata + only support for canary deployment + properties: + annotations: + additionalProperties: + type: string + description: annotations + type: object + labels: + additionalProperties: + type: string + description: labels + type: object + type: object + steps: + description: Steps define the order of phases to execute release + in batches(20%, 40%, 60%, 80%, 100%) + items: + description: CanaryStep defines a step of a canary workload. + properties: + matches: + description: Matches define conditions used for matching + the incoming HTTP requests to canary service. Each + match is independent, i.e. this rule will be matched + if **any** one of the matches is satisfied. If Gateway + API, current only support one match. And cannot support + both weight and matches, if both are configured, then + matches takes precedence. + items: + properties: + headers: + description: Headers specifies HTTP request header + matchers. Multiple match values are ANDed together, + meaning, a request must match all the specified + headers to select the route. + items: + description: HTTPHeaderMatch describes how to + select a HTTP route by matching HTTP request + headers. + properties: + name: + description: "Name is the name of the HTTP + Header to be matched. Name matching MUST + be case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). + \n If multiple entries specify equivalent + header names, only the first entry with + an equivalent name MUST be considered + for a match. Subsequent entries with an + equivalent header name MUST be ignored. + Due to the case-insensitivity of header + names, \"foo\" and \"Foo\" are considered + equivalent. \n When a header is repeated + in an HTTP request, it is implementation-specific + behavior as to how this is represented. + Generally, proxies should follow the guidance + from the RFC: https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 + regarding processing a repeated header, + with special handling for \"Set-Cookie\"." + maxLength: 256 + minLength: 1 + pattern: ^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$ + type: string + type: + default: Exact + description: "Type specifies how to match + against the value of the header. \n Support: + Core (Exact) \n Support: Custom (RegularExpression) + \n Since RegularExpression HeaderMatchType + has custom conformance, implementations + can support POSIX, PCRE or any other dialects + of regular expressions. Please read the + implementation's documentation to determine + the supported dialect." + enum: + - Exact + - RegularExpression + type: string + value: + description: Value is the value of HTTP + Header to be matched. + maxLength: 4096 + minLength: 1 + type: string + required: + - name + - value + type: object + maxItems: 16 + type: array + type: object + type: array + pause: + description: Pause defines a pause stage for a rollout, + manual or auto + properties: + duration: + description: Duration the amount of time to wait + before moving to the next step. + format: int32 + type: integer + type: object + replicas: + anyOf: + - type: integer + - type: string + description: 'Replicas is the number of expected canary + pods in this batch it can be an absolute number (ex: + 5) or a percentage of total pods.' + x-kubernetes-int-or-string: true + requestHeaderModifier: + description: "Set overwrites the request with the given + header (name, value) before the action. \n Input: + \ GET /foo HTTP/1.1 my-header: foo \n requestHeaderModifier: + \ set: - name: \"my-header\" value: \"bar\" + \n Output: GET /foo HTTP/1.1 my-header: bar" + properties: + add: + description: "Add adds the given header(s) (name, + value) to the request before the action. It appends + to any existing values associated with the header + name. \n Input: GET /foo HTTP/1.1 my-header: + foo \n Config: add: - name: \"my-header\" + \ value: \"bar\" \n Output: GET /foo HTTP/1.1 + \ my-header: foo my-header: bar" + items: + description: HTTPHeader represents an HTTP Header + name and value as defined by RFC 7230. + properties: + name: + description: "Name is the name of the HTTP + Header to be matched. Name matching MUST + be case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). + \n If multiple entries specify equivalent + header names, the first entry with an equivalent + name MUST be considered for a match. Subsequent + entries with an equivalent header name MUST + be ignored. Due to the case-insensitivity + of header names, \"foo\" and \"Foo\" are + considered equivalent." + maxLength: 256 + minLength: 1 + pattern: ^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$ + type: string + value: + description: Value is the value of HTTP Header + to be matched. + maxLength: 4096 + minLength: 1 + type: string + required: + - name + - value + type: object + maxItems: 16 + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + remove: + description: "Remove the given header(s) from the + HTTP request before the action. The value of Remove + is a list of HTTP header names. Note that the + header names are case-insensitive (see https://datatracker.ietf.org/doc/html/rfc2616#section-4.2). + \n Input: GET /foo HTTP/1.1 my-header1: foo + \ my-header2: bar my-header3: baz \n Config: + \ remove: [\"my-header1\", \"my-header3\"] \n + Output: GET /foo HTTP/1.1 my-header2: bar" + items: + type: string + maxItems: 16 + type: array + set: + description: "Set overwrites the request with the + given header (name, value) before the action. + \n Input: GET /foo HTTP/1.1 my-header: foo + \n Config: set: - name: \"my-header\" value: + \"bar\" \n Output: GET /foo HTTP/1.1 my-header: + bar" + items: + description: HTTPHeader represents an HTTP Header + name and value as defined by RFC 7230. + properties: + name: + description: "Name is the name of the HTTP + Header to be matched. Name matching MUST + be case insensitive. (See https://tools.ietf.org/html/rfc7230#section-3.2). + \n If multiple entries specify equivalent + header names, the first entry with an equivalent + name MUST be considered for a match. Subsequent + entries with an equivalent header name MUST + be ignored. Due to the case-insensitivity + of header names, \"foo\" and \"Foo\" are + considered equivalent." + maxLength: 256 + minLength: 1 + pattern: ^[A-Za-z0-9!#$%&'*+\-.^_\x60|~]+$ + type: string + value: + description: Value is the value of HTTP Header + to be matched. + maxLength: 4096 + minLength: 1 + type: string + required: + - name + - value + type: object + maxItems: 16 + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + type: object + weight: + description: Weight indicate how many percentage of + traffic the canary pods should receive + format: int32 + type: integer + type: object + type: array + trafficRoutings: + description: TrafficRoutings hosts all the supported service + meshes supported to enable more fine-grained traffic routing + and current only support one TrafficRouting + items: + description: TrafficRoutingRef hosts all the different configuration + for supported service meshes to enable more fine-grained + traffic routing + properties: + customNetworkRefs: + description: CustomNetworkRefs hold a list of custom + providers to route traffic + items: + properties: + apiVersion: + type: string + kind: + type: string + name: + type: string + required: + - apiVersion + - kind + - name + type: object + type: array + gateway: + description: Gateway holds Gateway specific configuration + to route traffic Gateway configuration only supports + >= v0.4.0 (v1alpha2). + properties: + httpRouteName: + description: HTTPRouteName refers to the name of + an `HTTPRoute` resource in the same namespace + as the `Rollout` + type: string + type: object + gracePeriodSeconds: + description: Optional duration in seconds the traffic + provider(e.g. nginx ingress controller) consumes the + service, ingress configuration changes gracefully. + format: int32 + type: integer + ingress: + description: Ingress holds Ingress specific configuration + to route traffic, e.g. Nginx, Alb. + properties: + classType: + description: ClassType refers to the type of `Ingress`. + current support nginx, aliyun-alb. default is + nginx. + type: string + name: + description: Name refers to the name of an `Ingress` + resource in the same namespace as the `Rollout` + type: string + required: + - name + type: object + service: + description: Service holds the name of a service which + selects pods with stable version and don't select + any pods with canary version. + type: string + required: + - service + type: object + type: array + type: object + paused: + description: Paused indicates that the Rollout is paused. Default + value is false + type: boolean + type: object + required: + - objectRef + - strategy + type: object + status: + description: RolloutStatus defines the observed state of Rollout + properties: + canaryStatus: + description: Canary describes the state of the canary rollout + properties: + canaryReadyReplicas: + description: CanaryReadyReplicas the numbers of ready canary revision + pods + format: int32 + type: integer + canaryReplicas: + description: CanaryReplicas the numbers of canary revision pods + format: int32 + type: integer + canaryRevision: + description: CanaryRevision is calculated by rollout based on + podTemplateHash, and the internal logic flow uses It may be + different from rs podTemplateHash in different k8s versions, + so it cannot be used as service selector label + type: string + currentStepIndex: + description: CurrentStepIndex defines the current step of the + rollout is on. If the current step index is null, the controller + will execute the rollout. + format: int32 + type: integer + currentStepState: + type: string + lastUpdateTime: + format: date-time + type: string + message: + type: string + observedRolloutID: + description: ObservedRolloutID will record the newest spec.RolloutID + if status.canaryRevision equals to workload.updateRevision + type: string + observedWorkloadGeneration: + description: observedWorkloadGeneration is the most recent generation + observed for this Rollout ref workload generation. + format: int64 + type: integer + podTemplateHash: + description: pod template hash is used as service selector label + type: string + rolloutHash: + description: RolloutHash from rollout.spec object + type: string + stableRevision: + description: StableRevision indicates the revision of stable pods + type: string + required: + - canaryReadyReplicas + - canaryReplicas + - canaryRevision + - currentStepState + - podTemplateHash + type: object + conditions: + description: Conditions a list of conditions a rollout can have. + items: + description: RolloutCondition describes the state of a rollout at + a certain point. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one status + to another. + format: date-time + type: string + lastUpdateTime: + description: The last time this condition was updated. + format: date-time + type: string + message: + description: A human readable message indicating details about + the transition. + type: string + reason: + description: The reason for the condition's last transition. + type: string + status: + description: Phase of the condition, one of True, False, Unknown. + type: string + type: + description: Type of rollout condition. + type: string + required: + - message + - reason + - status + - type + type: object + type: array + message: + description: Message provides details on why the rollout is in its + current phase + type: string + observedGeneration: + description: observedGeneration is the most recent generation observed + for this Rollout. + format: int64 + type: integer + phase: + description: BlueGreenStatus *BlueGreenStatus `json:"blueGreenStatus,omitempty"` + Phase is the rollout phase. + type: string + type: object + type: object + served: true storage: true subresources: status: {} diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 95a55cf6..cda11708 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2022 The Kruise Authors. +Copyright 2023 The Kruise Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lua_configuration/convert_test_case_to_lua_object.go b/lua_configuration/convert_test_case_to_lua_object.go index c58bdac5..dadf3ba9 100644 --- a/lua_configuration/convert_test_case_to_lua_object.go +++ b/lua_configuration/convert_test_case_to_lua_object.go @@ -8,18 +8,18 @@ import ( "strings" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" custom "github.com/openkruise/rollouts/pkg/trafficrouting/network/customNetworkProvider" "github.com/openkruise/rollouts/pkg/util/luamanager" lua "github.com/yuin/gopher-lua" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/yaml" - utilpointer "k8s.io/utils/pointer" + "sigs.k8s.io/yaml" ) type TestCase struct { - Rollout *v1alpha1.Rollout `json:"rollout,omitempty"` + Rollout *v1beta1.Rollout `json:"rollout,omitempty"` TrafficRouting *v1alpha1.TrafficRouting `json:"trafficRouting,omitempty"` Original *unstructured.Unstructured `json:"original,omitempty"` Expected []*unstructured.Unstructured `json:"expected,omitempty"` diff --git a/main.go b/main.go index 46682654..9a10572f 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ import ( kruisev1aplphal1 "github.com/openkruise/kruise-api/apps/v1alpha1" kruisev1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" - rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" br "github.com/openkruise/rollouts/pkg/controller/batchrelease" "github.com/openkruise/rollouts/pkg/controller/deployment" "github.com/openkruise/rollouts/pkg/controller/rollout" @@ -57,7 +57,7 @@ func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(kruisev1aplphal1.AddToScheme(scheme)) utilruntime.Must(kruisev1beta1.AddToScheme(scheme)) - utilruntime.Must(rolloutsv1alpha1.AddToScheme(scheme)) + utilruntime.Must(rolloutapi.AddToScheme(scheme)) utilruntime.Must(gatewayv1alpha2.AddToScheme(scheme)) utilruntime.Must(admissionregistrationv1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme diff --git a/pkg/controller/batchrelease/batchrelease_controller.go b/pkg/controller/batchrelease/batchrelease_controller.go index 304b4c9b..a2f5caee 100644 --- a/pkg/controller/batchrelease/batchrelease_controller.go +++ b/pkg/controller/batchrelease/batchrelease_controller.go @@ -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" @@ -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 @@ -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) { @@ -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 { @@ -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 @@ -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 { @@ -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 { diff --git a/pkg/controller/batchrelease/batchrelease_controller_test.go b/pkg/controller/batchrelease/batchrelease_controller_test.go index e6045562..7d434d06 100644 --- a/pkg/controller/batchrelease/batchrelease_controller_test.go +++ b/pkg/controller/batchrelease/batchrelease_controller_test.go @@ -27,7 +27,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -49,9 +50,9 @@ const TIME_LAYOUT = "2006-01-02 15:04:05" var ( scheme *runtime.Scheme - releaseDeploy = &v1alpha1.BatchRelease{ + releaseDeploy = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.GroupVersion.String(), + APIVersion: v1beta1.GroupVersion.String(), Kind: "BatchRelease", }, ObjectMeta: metav1.ObjectMeta{ @@ -59,17 +60,17 @@ var ( Namespace: "application", UID: types.UID("87076677"), }, - Spec: v1alpha1.BatchReleaseSpec{ - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.BatchReleaseSpec{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "sample", }, }, - ReleasePlan: v1alpha1.ReleasePlan{ + ReleasePlan: v1beta1.ReleasePlan{ BatchPartition: pointer.Int32(0), - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -129,9 +130,9 @@ var ( ) var ( - releaseClone = &v1alpha1.BatchRelease{ + releaseClone = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.GroupVersion.String(), + APIVersion: v1beta1.GroupVersion.String(), Kind: "BatchRelease", }, ObjectMeta: metav1.ObjectMeta{ @@ -139,17 +140,17 @@ var ( Namespace: "application", UID: types.UID("87076677"), }, - Spec: v1alpha1.BatchReleaseSpec{ - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.BatchReleaseSpec{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: "apps.kruise.io/v1alpha1", Kind: "CloneSet", Name: "sample", }, }, - ReleasePlan: v1alpha1.ReleasePlan{ + ReleasePlan: v1beta1.ReleasePlan{ BatchPartition: pointer.Int32Ptr(0), - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -209,7 +210,7 @@ var ( func init() { scheme = runtime.NewScheme() apimachineryruntime.Must(apps.AddToScheme(scheme)) - apimachineryruntime.Must(v1alpha1.AddToScheme(scheme)) + apimachineryruntime.Must(rolloutapi.AddToScheme(scheme)) apimachineryruntime.Must(kruiseappsv1alpha1.AddToScheme(scheme)) controlInfo, _ := json.Marshal(metav1.NewControllerRef(releaseDeploy, releaseDeploy.GroupVersionKind())) @@ -232,13 +233,13 @@ func TestReconcile_CloneSet(t *testing.T) { GetRelease func() client.Object GetCloneSet func() []client.Object ExpectedBatch int32 - ExpectedPhase v1alpha1.RolloutPhase - ExpectedState v1alpha1.BatchReleaseBatchStateType + ExpectedPhase v1beta1.RolloutPhase + ExpectedState v1beta1.BatchReleaseBatchStateType }{ { Name: "Preparing, Input-Phase=Preparing, Output-Phase=Progressing", GetRelease: func() client.Object { - release := setPhase(releaseClone, v1alpha1.RolloutPhasePreparing) + release := setPhase(releaseClone, v1beta1.RolloutPhasePreparing) stableTemplate := stableClone.Spec.Template.DeepCopy() canaryTemplate := stableClone.Spec.Template.DeepCopy() stableTemplate.Spec.Containers = containers("v1") @@ -254,12 +255,12 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, }, { Name: "Progressing, stage=0, Input-State=Upgrade, Output-State=Verify", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.UpgradingBatchState) + release := setState(releaseClone, v1beta1.UpgradingBatchState) stableTemplate := stableClone.Spec.Template.DeepCopy() canaryTemplate := stableClone.Spec.Template.DeepCopy() stableTemplate.Spec.Containers = containers("v1") @@ -275,13 +276,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.VerifyingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.VerifyingBatchState, }, { Name: "Progressing, stage=0, Input-State=Upgrade, Output-State=Verify", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.UpgradingBatchState) + release := setState(releaseClone, v1beta1.UpgradingBatchState) stableTemplate := stableClone.Spec.Template.DeepCopy() canaryTemplate := stableClone.Spec.Template.DeepCopy() stableTemplate.Spec.Containers = containers("v1") @@ -297,13 +298,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.VerifyingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.VerifyingBatchState, }, { Name: "Progressing, stage=0, Input-State=Verify, Output-State=BatchReady", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.VerifyingBatchState) + release := setState(releaseClone, v1beta1.VerifyingBatchState) stableTemplate := stableClone.Spec.Template.DeepCopy() canaryTemplate := stableClone.Spec.Template.DeepCopy() stableTemplate.Spec.Containers = containers("v1") @@ -321,13 +322,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: "Progressing, stage=0->1, Input-State=BatchReady, Output-State=Upgrade", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) release.Status.CanaryStatus.BatchReadyTime = getOldTime() stableTemplate := stableClone.Spec.Template.DeepCopy() canaryTemplate := stableClone.Spec.Template.DeepCopy() @@ -347,14 +348,14 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.UpgradingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.UpgradingBatchState, ExpectedBatch: 1, }, { Name: "Progressing, stage=0->1, Input-State=BatchReady, Output-State=BatchReady", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -374,13 +375,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: "Special Case: Scaling, Input-State=BatchReady, Output-State=Upgrade", GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -401,13 +402,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.UpgradingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.UpgradingBatchState, }, { Name: `Special Case: RollBack, Input-Phase=Progressing, Output-Phase=Progressing`, GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -431,13 +432,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: `Special Case: Deletion, Input-Phase=Progressing, Output-Phase=Finalizing`, GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -459,13 +460,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseFinalizing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseFinalizing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: `Special Case: Continuous Release, Input-Phase=Progressing, Output-Phase=Progressing`, GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -493,13 +494,13 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: `Special Case: BatchPartition=nil, Input-Phase=Progressing, Output-Phase=Finalizing`, GetRelease: func() client.Object { - release := setState(releaseClone, v1alpha1.ReadyBatchState) + release := setState(releaseClone, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableClone.Spec.Template.DeepCopy() @@ -521,8 +522,8 @@ func TestReconcile_CloneSet(t *testing.T) { canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseFinalizing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseFinalizing, + ExpectedState: v1beta1.ReadyBatchState, }, } @@ -545,7 +546,7 @@ func TestReconcile_CloneSet(t *testing.T) { Expect(err).NotTo(HaveOccurred()) Expect(result.RequeueAfter).Should(BeNumerically(">=", int64(0))) - newRelease := v1alpha1.BatchRelease{} + newRelease := v1beta1.BatchRelease{} err = cli.Get(context.TODO(), key, &newRelease) Expect(err).NotTo(HaveOccurred()) Expect(newRelease.Status.Phase).Should(Equal(cs.ExpectedPhase)) @@ -563,14 +564,14 @@ func TestReconcile_Deployment(t *testing.T) { GetRelease func() client.Object GetDeployments func() []client.Object ExpectedBatch int32 - ExpectedPhase v1alpha1.RolloutPhase - ExpectedState v1alpha1.BatchReleaseBatchStateType + ExpectedPhase v1beta1.RolloutPhase + ExpectedState v1beta1.BatchReleaseBatchStateType }{ // Following cases of Linear Transaction on State Machine { Name: "IfNeedProgress=true, Input-Phase=Healthy, Output-Phase=Progressing", GetRelease: func() client.Object { - return setPhase(releaseDeploy, v1alpha1.RolloutPhaseHealthy) + return setPhase(releaseDeploy, v1beta1.RolloutPhaseHealthy) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2").(*apps.Deployment) @@ -579,12 +580,12 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, }, { Name: "Preparing, Input-Phase=Preparing, Output-Phase=Progressing", GetRelease: func() client.Object { - return setPhase(releaseDeploy, v1alpha1.RolloutPhasePreparing) + return setPhase(releaseDeploy, v1beta1.RolloutPhasePreparing) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2") @@ -593,12 +594,12 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, }, { Name: "Progressing, stage=0, Input-State=Upgrade, Output-State=Verify", GetRelease: func() client.Object { - return setState(releaseDeploy, v1alpha1.UpgradingBatchState) + return setState(releaseDeploy, v1beta1.UpgradingBatchState) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2") @@ -607,8 +608,8 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.VerifyingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.VerifyingBatchState, }, { Name: "Progressing, stage=0, Input-State=Verify, Output-State=Upgrade", @@ -616,7 +617,7 @@ func TestReconcile_Deployment(t *testing.T) { release := releaseDeploy.DeepCopy() release.Status.CanaryStatus.UpdatedReplicas = 5 release.Status.CanaryStatus.UpdatedReadyReplicas = 5 - return setState(release, v1alpha1.VerifyingBatchState) + return setState(release, v1beta1.VerifyingBatchState) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2") @@ -625,8 +626,8 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.UpgradingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.UpgradingBatchState, }, { Name: "Progressing, stage=0, Input-State=Verify, Output-State=BatchReady", @@ -634,7 +635,7 @@ func TestReconcile_Deployment(t *testing.T) { release := releaseDeploy.DeepCopy() release.Status.CanaryStatus.UpdatedReplicas = 10 release.Status.CanaryStatus.UpdatedReadyReplicas = 10 - return setState(release, v1alpha1.VerifyingBatchState) + return setState(release, v1beta1.VerifyingBatchState) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2") @@ -643,8 +644,8 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: "Progressing, stage=0->1, Input-State=BatchReady, Output-State=Upgrade", @@ -653,7 +654,7 @@ func TestReconcile_Deployment(t *testing.T) { release.Status.CanaryStatus.UpdatedReplicas = 10 release.Status.CanaryStatus.UpdatedReadyReplicas = 10 release.Spec.ReleasePlan.BatchPartition = pointer.Int32Ptr(1) - return setState(release, v1alpha1.ReadyBatchState) + return setState(release, v1beta1.ReadyBatchState) }, GetDeployments: func() []client.Object { stable := getStableWithReady(stableDeploy, "v2") @@ -662,8 +663,8 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.UpgradingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.UpgradingBatchState, ExpectedBatch: 1, }, { @@ -672,7 +673,7 @@ func TestReconcile_Deployment(t *testing.T) { release := releaseDeploy.DeepCopy() release.Status.CanaryStatus.UpdatedReplicas = 10 release.Status.CanaryStatus.UpdatedReadyReplicas = 10 - release = setState(release, v1alpha1.ReadyBatchState) + release = setState(release, v1beta1.ReadyBatchState) return release }, GetDeployments: func() []client.Object { @@ -682,13 +683,13 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: "Special Case: Scaling, Input-State=BatchReady, Output-State=Upgrade", GetRelease: func() client.Object { - release := setState(releaseDeploy, v1alpha1.ReadyBatchState) + release := setState(releaseDeploy, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now return release @@ -701,13 +702,13 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.UpgradingBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.UpgradingBatchState, }, { Name: `Special Case: RollBack, Input-Phase=Progressing, Output-Phase=Progressing`, GetRelease: func() client.Object { - release := setState(releaseDeploy, v1alpha1.ReadyBatchState) + release := setState(releaseDeploy, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableDeploy.Spec.Template.DeepCopy() @@ -725,13 +726,13 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: `Special Case: Deletion, Input-Phase=Progressing, Output-Phase=Finalizing`, GetRelease: func() client.Object { - release := setState(releaseDeploy, v1alpha1.ReadyBatchState) + release := setState(releaseDeploy, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableDeploy.Spec.Template.DeepCopy() @@ -751,13 +752,13 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedPhase: v1alpha1.RolloutPhaseFinalizing, - ExpectedState: v1alpha1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseFinalizing, + ExpectedState: v1beta1.ReadyBatchState, }, { Name: `Special Case: Continuous Release, Input-Phase=Progressing, Output-Phase=Progressing`, GetRelease: func() client.Object { - release := setState(releaseDeploy, v1alpha1.ReadyBatchState) + release := setState(releaseDeploy, v1beta1.ReadyBatchState) now := metav1.Now() release.Status.CanaryStatus.BatchReadyTime = &now stableTemplate := stableDeploy.Spec.Template.DeepCopy() @@ -775,8 +776,8 @@ func TestReconcile_Deployment(t *testing.T) { stable, canary, } }, - ExpectedState: v1alpha1.ReadyBatchState, - ExpectedPhase: v1alpha1.RolloutPhaseProgressing, + ExpectedState: v1beta1.ReadyBatchState, + ExpectedPhase: v1beta1.RolloutPhaseProgressing, }, } @@ -808,7 +809,7 @@ func TestReconcile_Deployment(t *testing.T) { result, _ := reconciler.Reconcile(context.TODO(), request) Expect(result.RequeueAfter).Should(BeNumerically(">=", int64(0))) - newRelease := v1alpha1.BatchRelease{} + newRelease := v1beta1.BatchRelease{} err := cli.Get(context.TODO(), key, &newRelease) Expect(err).NotTo(HaveOccurred()) Expect(newRelease.Status.Phase).Should(Equal(cs.ExpectedPhase)) @@ -827,7 +828,7 @@ func containers(version string) []corev1.Container { } } -func setPhase(release *v1alpha1.BatchRelease, phase v1alpha1.RolloutPhase) *v1alpha1.BatchRelease { +func setPhase(release *v1beta1.BatchRelease, phase v1beta1.RolloutPhase) *v1beta1.BatchRelease { r := release.DeepCopy() r.Status.Phase = phase r.Status.ObservedWorkloadReplicas = 100 @@ -835,9 +836,9 @@ func setPhase(release *v1alpha1.BatchRelease, phase v1alpha1.RolloutPhase) *v1al return r } -func setState(release *v1alpha1.BatchRelease, state v1alpha1.BatchReleaseBatchStateType) *v1alpha1.BatchRelease { +func setState(release *v1beta1.BatchRelease, state v1beta1.BatchReleaseBatchStateType) *v1beta1.BatchRelease { r := release.DeepCopy() - r.Status.Phase = v1alpha1.RolloutPhaseProgressing + r.Status.Phase = v1beta1.RolloutPhaseProgressing r.Status.CanaryStatus.CurrentBatchState = state r.Status.ObservedWorkloadReplicas = 100 r.Status.ObservedReleasePlanHash = util.HashReleasePlanBatches(&release.Spec.ReleasePlan) diff --git a/pkg/controller/batchrelease/batchrelease_event_handler.go b/pkg/controller/batchrelease/batchrelease_event_handler.go index 7be717c9..a7a6d102 100644 --- a/pkg/controller/batchrelease/batchrelease_event_handler.go +++ b/pkg/controller/batchrelease/batchrelease_event_handler.go @@ -23,7 +23,7 @@ import ( kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" kruiseappsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" utilclient "github.com/openkruise/rollouts/pkg/util/client" expectations "github.com/openkruise/rollouts/pkg/util/expectation" @@ -224,14 +224,14 @@ func getBatchRelease(c client.Reader, workloadNamespaceName types.NamespacedName klog.Errorf("Failed to unmarshal controller info annotations for %v(%v)", gvk, workloadNamespaceName) } - if br.APIVersion == v1alpha1.GroupVersion.String() && br.Kind == "BatchRelease" { + if br.APIVersion == v1beta1.GroupVersion.String() && br.Kind == "BatchRelease" { klog.V(3).Infof("%s (%v) is managed by BatchRelease (%s), append queue and will reconcile BatchRelease", gvk.Kind, workloadNamespaceName, br.Name) nsn = types.NamespacedName{Namespace: workloadNamespaceName.Namespace, Name: br.Name} return } } - brList := &v1alpha1.BatchReleaseList{} + brList := &v1beta1.BatchReleaseList{} namespace := workloadNamespaceName.Namespace if err = c.List(context.TODO(), brList, client.InNamespace(namespace), utilclient.DisableDeepCopy); err != nil { klog.Errorf("List BatchRelease failed: %s", err.Error()) @@ -269,7 +269,7 @@ func getControllerKey(object client.Object) *string { if owner == nil { return nil } - if owner.APIVersion == v1alpha1.GroupVersion.String() { + if owner.Kind == "BatchRelease" { key := types.NamespacedName{Namespace: object.GetNamespace(), Name: owner.Name}.String() return &key } diff --git a/pkg/controller/batchrelease/batchrelease_event_handler_test.go b/pkg/controller/batchrelease/batchrelease_event_handler_test.go index 3e81e86e..886ce7db 100644 --- a/pkg/controller/batchrelease/batchrelease_event_handler_test.go +++ b/pkg/controller/batchrelease/batchrelease_event_handler_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -172,7 +172,7 @@ func TestWorkloadEventHandler_Create(t *testing.T) { GetNewWorkload: func() client.Object { object := getStableWithReady(stableDeploy, "v2").(*apps.Deployment) controlInfo, _ := json.Marshal(&metav1.OwnerReference{ - APIVersion: v1alpha1.GroupVersion.String(), + APIVersion: v1beta1.GroupVersion.String(), Kind: "Rollout", Name: "whatever", }) @@ -228,7 +228,7 @@ func TestWorkloadEventHandler_Delete(t *testing.T) { GetNewWorkload: func() client.Object { object := getStableWithReady(stableDeploy, "v2").(*apps.Deployment) controlInfo, _ := json.Marshal(&metav1.OwnerReference{ - APIVersion: v1alpha1.GroupVersion.String(), + APIVersion: v1beta1.GroupVersion.String(), Kind: "Rollout", Name: "whatever", }) diff --git a/pkg/controller/batchrelease/batchrelease_executor.go b/pkg/controller/batchrelease/batchrelease_executor.go index 7cb0b86f..23c9a1ed 100644 --- a/pkg/controller/batchrelease/batchrelease_executor.go +++ b/pkg/controller/batchrelease/batchrelease_executor.go @@ -24,6 +24,7 @@ import ( appsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/canarystyle" canarydeployment "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/canarystyle/deployment" @@ -63,7 +64,7 @@ func NewReleasePlanExecutor(cli client.Client, recorder record.EventRecorder) *E } // Do execute the release plan -func (r *Executor) Do(release *v1alpha1.BatchRelease) (reconcile.Result, *v1alpha1.BatchReleaseStatus, error) { +func (r *Executor) Do(release *v1beta1.BatchRelease) (reconcile.Result, *v1beta1.BatchReleaseStatus, error) { klog.InfoS("Starting one round of reconciling release plan", "BatchRelease", client.ObjectKeyFromObject(release), "phase", release.Status.Phase, @@ -84,7 +85,7 @@ func (r *Executor) Do(release *v1alpha1.BatchRelease) (reconcile.Result, *v1alph return r.executeBatchReleasePlan(release, newStatus, workloadController) } -func (r *Executor) executeBatchReleasePlan(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, workloadController control.Interface) (reconcile.Result, *v1alpha1.BatchReleaseStatus, error) { +func (r *Executor) executeBatchReleasePlan(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, workloadController control.Interface) (reconcile.Result, *v1beta1.BatchReleaseStatus, error) { var err error result := reconcile.Result{} @@ -93,34 +94,34 @@ func (r *Executor) executeBatchReleasePlan(release *v1alpha1.BatchRelease, newSt switch newStatus.Phase { default: // for compatibility. if it is an unknown phase, should start from beginning. - newStatus.Phase = v1alpha1.RolloutPhasePreparing + newStatus.Phase = v1beta1.RolloutPhasePreparing fallthrough - case v1alpha1.RolloutPhasePreparing: + case v1beta1.RolloutPhasePreparing: // prepare and initialize something before progressing in this state. err = workloadController.Initialize() switch { case err == nil: - newStatus.Phase = v1alpha1.RolloutPhaseProgressing + newStatus.Phase = v1beta1.RolloutPhaseProgressing result = reconcile.Result{RequeueAfter: DefaultDuration} default: klog.Warningf("Failed to initialize %v, err %v", klog.KObj(release), err) } - case v1alpha1.RolloutPhaseProgressing: + case v1beta1.RolloutPhaseProgressing: // progress the release plan in this state. result, err = r.progressBatches(release, newStatus, workloadController) - case v1alpha1.RolloutPhaseFinalizing: + case v1beta1.RolloutPhaseFinalizing: err = workloadController.Finalize() switch { case err == nil: - newStatus.Phase = v1alpha1.RolloutPhaseCompleted + newStatus.Phase = v1beta1.RolloutPhaseCompleted default: klog.Warningf("Failed to finalize %v, err %v", klog.KObj(release), err) } - case v1alpha1.RolloutPhaseCompleted: + case v1beta1.RolloutPhaseCompleted: // this state indicates that the plan is executed/cancelled successfully, should do nothing in these states. } @@ -128,7 +129,7 @@ func (r *Executor) executeBatchReleasePlan(release *v1alpha1.BatchRelease, newSt } // reconcile logic when we are in the middle of release, we have to go through finalizing state before succeed or fail -func (r *Executor) progressBatches(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, workloadController control.Interface) (reconcile.Result, error) { +func (r *Executor) progressBatches(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, workloadController control.Interface) (reconcile.Result, error) { var err error result := reconcile.Result{} @@ -137,43 +138,43 @@ func (r *Executor) progressBatches(release *v1alpha1.BatchRelease, newStatus *v1 switch newStatus.CanaryStatus.CurrentBatchState { default: // for compatibility. if it is an unknown state, should start from beginning. - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState fallthrough - case v1alpha1.UpgradingBatchState: + case v1beta1.UpgradingBatchState: // modify workload replicas/partition based on release plan in this state. err = workloadController.UpgradeBatch() switch { case err == nil: result = reconcile.Result{RequeueAfter: DefaultDuration} - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.VerifyingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.VerifyingBatchState default: klog.Warningf("Failed to upgrade %v, err %v", klog.KObj(release), err) } - case v1alpha1.VerifyingBatchState: + case v1beta1.VerifyingBatchState: // replicas/partition has been modified, should wait pod ready in this state. err = workloadController.CheckBatchReady() switch { case err != nil: // should go to upgrade state to do again to avoid dead wait. - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState klog.Warningf("%v current batch is not ready, err %v", klog.KObj(release), err) default: now := metav1.Now() newStatus.CanaryStatus.BatchReadyTime = &now result = reconcile.Result{RequeueAfter: DefaultDuration} - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.ReadyBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.ReadyBatchState } - case v1alpha1.ReadyBatchState: + case v1beta1.ReadyBatchState: // replicas/partition may be modified even though ready, should recheck in this state. err = workloadController.CheckBatchReady() switch { case err != nil: // if the batch ready condition changed due to some reasons, just recalculate the current batch. newStatus.CanaryStatus.BatchReadyTime = nil - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState klog.Warningf("%v current batch is not ready, err %v", klog.KObj(release), err) case !isPartitioned(release): r.moveToNextBatch(release, newStatus) @@ -185,7 +186,7 @@ func (r *Executor) progressBatches(release *v1alpha1.BatchRelease, newStatus *v1 } // GetWorkloadController pick the right workload controller to work on the workload -func (r *Executor) getReleaseController(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus) (control.Interface, error) { +func (r *Executor) getReleaseController(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus) (control.Interface, error) { targetRef := release.Spec.TargetRef.WorkloadRef if targetRef == nil { return nil, nil @@ -216,7 +217,7 @@ func (r *Executor) getReleaseController(release *v1alpha1.BatchRelease, newStatu case apps.SchemeGroupVersion.String(): if targetRef.Kind == reflect.TypeOf(apps.Deployment{}).Name() { - if strings.EqualFold(release.Annotations[v1alpha1.RolloutStyleAnnotation], string(v1alpha1.PartitionRollingStyle)) { + if strings.EqualFold(release.Annotations[v1beta1.RolloutStyleAnnotation], string(v1alpha1.PartitionRollingStyle)) { klog.InfoS("Using Deployment partition-style release controller for this batch release", "workload name", targetKey.Name, "namespace", targetKey.Namespace) return partitionstyle.NewControlPlane(partitiondeployment.NewController, r.client, r.recorder, release, newStatus, targetKey, gvk), nil } else { @@ -231,7 +232,7 @@ func (r *Executor) getReleaseController(release *v1alpha1.BatchRelease, newStatu return partitionstyle.NewControlPlane(statefulset.NewController, r.client, r.recorder, release, newStatus, targetKey, gvk), nil } -func (r *Executor) moveToNextBatch(release *v1alpha1.BatchRelease, status *v1alpha1.BatchReleaseStatus) { +func (r *Executor) moveToNextBatch(release *v1beta1.BatchRelease, status *v1beta1.BatchReleaseStatus) { currentBatch := int(status.CanaryStatus.CurrentBatch) if currentBatch >= len(release.Spec.ReleasePlan.Batches)-1 { klog.V(3).Infof("BatchRelease(%v) finished all batch, release current batch: %v", klog.KObj(release), status.CanaryStatus.CurrentBatch) @@ -239,11 +240,11 @@ func (r *Executor) moveToNextBatch(release *v1alpha1.BatchRelease, status *v1alp if release.Spec.ReleasePlan.BatchPartition == nil || *release.Spec.ReleasePlan.BatchPartition > status.CanaryStatus.CurrentBatch { status.CanaryStatus.CurrentBatch++ } - status.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + status.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState klog.V(3).Infof("BatchRelease(%v) finished one batch, release current batch: %v", klog.KObj(release), status.CanaryStatus.CurrentBatch) } -func isPartitioned(release *v1alpha1.BatchRelease) bool { +func isPartitioned(release *v1beta1.BatchRelease) bool { return release.Spec.ReleasePlan.BatchPartition != nil && *release.Spec.ReleasePlan.BatchPartition <= release.Status.CanaryStatus.CurrentBatch } diff --git a/pkg/controller/batchrelease/batchrelease_status.go b/pkg/controller/batchrelease/batchrelease_status.go index 81c660b9..6b0abc6a 100644 --- a/pkg/controller/batchrelease/batchrelease_status.go +++ b/pkg/controller/batchrelease/batchrelease_status.go @@ -20,6 +20,7 @@ import ( "reflect" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/util" "k8s.io/apimachinery/pkg/api/errors" @@ -29,7 +30,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" ) -func (r *Executor) syncStatusBeforeExecuting(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, controller control.Interface) (bool, reconcile.Result, error) { +func (r *Executor) syncStatusBeforeExecuting(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, controller control.Interface) (bool, reconcile.Result, error) { var err error var message string var needRetry bool @@ -145,7 +146,7 @@ func (r *Executor) syncStatusBeforeExecuting(release *v1alpha1.BatchRelease, new return needStopThisRound, result, err } -func refreshStatus(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, workloadInfo *util.WorkloadInfo) { +func refreshStatus(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, workloadInfo *util.WorkloadInfo) { // refresh workload info for status if workloadInfo != nil { newStatus.CanaryStatus.UpdatedReplicas = workloadInfo.Status.UpdatedReplicas @@ -156,76 +157,76 @@ func refreshStatus(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchRele } } -func isPlanFinalizing(release *v1alpha1.BatchRelease) bool { - if release.DeletionTimestamp != nil || release.Status.Phase == v1alpha1.RolloutPhaseFinalizing { +func isPlanFinalizing(release *v1beta1.BatchRelease) bool { + if release.DeletionTimestamp != nil || release.Status.Phase == v1beta1.RolloutPhaseFinalizing { return true } return release.Spec.ReleasePlan.BatchPartition == nil } -func isPlanCompleted(release *v1alpha1.BatchRelease) bool { - return release.Status.Phase == v1alpha1.RolloutPhaseCompleted +func isPlanCompleted(release *v1beta1.BatchRelease) bool { + return release.Status.Phase == v1beta1.RolloutPhaseCompleted } -func isPlanChanged(release *v1alpha1.BatchRelease) bool { - return release.Status.ObservedReleasePlanHash != util.HashReleasePlanBatches(&release.Spec.ReleasePlan) && release.Status.Phase == v1alpha1.RolloutPhaseProgressing +func isPlanChanged(release *v1beta1.BatchRelease) bool { + return release.Status.ObservedReleasePlanHash != util.HashReleasePlanBatches(&release.Spec.ReleasePlan) && release.Status.Phase == v1beta1.RolloutPhaseProgressing } -func isPlanUnhealthy(release *v1alpha1.BatchRelease) bool { - return int(release.Status.CanaryStatus.CurrentBatch) >= len(release.Spec.ReleasePlan.Batches) && release.Status.Phase == v1alpha1.RolloutPhaseProgressing +func isPlanUnhealthy(release *v1beta1.BatchRelease) bool { + return int(release.Status.CanaryStatus.CurrentBatch) >= len(release.Spec.ReleasePlan.Batches) && release.Status.Phase == v1beta1.RolloutPhaseProgressing } func isGetWorkloadInfoError(err error) bool { return err != nil && !errors.IsNotFound(err) } -func isWorkloadGone(event control.WorkloadEventType, release *v1alpha1.BatchRelease) bool { - return event == control.WorkloadHasGone && release.Status.Phase != v1alpha1.RolloutPhaseInitial && release.Status.Phase != "" +func isWorkloadGone(event control.WorkloadEventType, release *v1beta1.BatchRelease) bool { + return event == control.WorkloadHasGone && release.Status.Phase != v1beta1.RolloutPhaseInitial && release.Status.Phase != "" } -func isWorkloadScaling(event control.WorkloadEventType, release *v1alpha1.BatchRelease) bool { - return event == control.WorkloadReplicasChanged && release.Status.Phase == v1alpha1.RolloutPhaseProgressing +func isWorkloadScaling(event control.WorkloadEventType, release *v1beta1.BatchRelease) bool { + return event == control.WorkloadReplicasChanged && release.Status.Phase == v1beta1.RolloutPhaseProgressing } -func isWorkloadRevisionChanged(event control.WorkloadEventType, release *v1alpha1.BatchRelease) bool { - return event == control.WorkloadPodTemplateChanged && release.Status.Phase == v1alpha1.RolloutPhaseProgressing +func isWorkloadRevisionChanged(event control.WorkloadEventType, release *v1beta1.BatchRelease) bool { + return event == control.WorkloadPodTemplateChanged && release.Status.Phase == v1beta1.RolloutPhaseProgressing } -func isWorkloadRollbackInBatch(event control.WorkloadEventType, release *v1alpha1.BatchRelease) bool { +func isWorkloadRollbackInBatch(event control.WorkloadEventType, release *v1beta1.BatchRelease) bool { return (event == control.WorkloadRollbackInBatch || release.Annotations[v1alpha1.RollbackInBatchAnnotation] != "") && - release.Status.CanaryStatus.NoNeedUpdateReplicas == nil && release.Status.Phase == v1alpha1.RolloutPhaseProgressing + release.Status.CanaryStatus.NoNeedUpdateReplicas == nil && release.Status.Phase == v1beta1.RolloutPhaseProgressing } -func isWorkloadUnstable(event control.WorkloadEventType, _ *v1alpha1.BatchRelease) bool { +func isWorkloadUnstable(event control.WorkloadEventType, _ *v1beta1.BatchRelease) bool { return event == control.WorkloadStillReconciling } -func isRollbackInBatchSatisfied(workloadInfo *util.WorkloadInfo, release *v1alpha1.BatchRelease) bool { +func isRollbackInBatchSatisfied(workloadInfo *util.WorkloadInfo, release *v1beta1.BatchRelease) bool { return workloadInfo.Status.StableRevision == workloadInfo.Status.UpdateRevision && release.Annotations[v1alpha1.RollbackInBatchAnnotation] != "" } -func signalRePrepareRollback(newStatus *v1alpha1.BatchReleaseStatus) { - newStatus.Phase = v1alpha1.RolloutPhasePreparing +func signalRePrepareRollback(newStatus *v1beta1.BatchReleaseStatus) { + newStatus.Phase = v1beta1.RolloutPhasePreparing newStatus.CanaryStatus.BatchReadyTime = nil - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState } -func signalRestartBatch(status *v1alpha1.BatchReleaseStatus) { +func signalRestartBatch(status *v1beta1.BatchReleaseStatus) { status.CanaryStatus.BatchReadyTime = nil - status.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + status.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState } -func signalRestartAll(status *v1alpha1.BatchReleaseStatus) { - emptyStatus := v1alpha1.BatchReleaseStatus{} +func signalRestartAll(status *v1beta1.BatchReleaseStatus) { + emptyStatus := v1beta1.BatchReleaseStatus{} resetStatus(&emptyStatus) *status = emptyStatus } -func signalFinalizing(status *v1alpha1.BatchReleaseStatus) { - status.Phase = v1alpha1.RolloutPhaseFinalizing +func signalFinalizing(status *v1beta1.BatchReleaseStatus) { + status.Phase = v1beta1.RolloutPhaseFinalizing } -func signalRecalculate(release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus) { +func signalRecalculate(release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus) { // When BatchRelease plan was changed, rollout controller will update this batchRelease cr, // and rollout controller will set BatchPartition as its expected current batch index. currentBatch := int32(0) @@ -242,11 +243,11 @@ func signalRecalculate(release *v1alpha1.BatchRelease, newStatus *v1alpha1.Batch newStatus.CanaryStatus.BatchReadyTime = nil newStatus.CanaryStatus.CurrentBatch = currentBatch newStatus.ObservedRolloutID = release.Spec.ReleasePlan.RolloutID - newStatus.CanaryStatus.CurrentBatchState = v1alpha1.UpgradingBatchState + newStatus.CanaryStatus.CurrentBatchState = v1beta1.UpgradingBatchState newStatus.ObservedReleasePlanHash = util.HashReleasePlanBatches(&release.Spec.ReleasePlan) } -func getInitializedStatus(status *v1alpha1.BatchReleaseStatus) *v1alpha1.BatchReleaseStatus { +func getInitializedStatus(status *v1beta1.BatchReleaseStatus) *v1beta1.BatchReleaseStatus { newStatus := status.DeepCopy() if len(status.Phase) == 0 { resetStatus(newStatus) @@ -254,11 +255,11 @@ func getInitializedStatus(status *v1alpha1.BatchReleaseStatus) *v1alpha1.BatchRe return newStatus } -func resetStatus(status *v1alpha1.BatchReleaseStatus) { - status.Phase = v1alpha1.RolloutPhasePreparing +func resetStatus(status *v1beta1.BatchReleaseStatus) { + status.Phase = v1beta1.RolloutPhasePreparing status.StableRevision = "" status.UpdateRevision = "" status.ObservedReleasePlanHash = "" status.ObservedWorkloadReplicas = -1 - status.CanaryStatus = v1alpha1.BatchReleaseCanaryStatus{} + status.CanaryStatus = v1beta1.BatchReleaseCanaryStatus{} } diff --git a/pkg/controller/batchrelease/context/context.go b/pkg/controller/batchrelease/context/context.go index 7e95daa9..5a801249 100644 --- a/pkg/controller/batchrelease/context/context.go +++ b/pkg/controller/batchrelease/context/context.go @@ -20,7 +20,7 @@ import ( "encoding/json" "fmt" - "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/util/intstr" @@ -100,7 +100,7 @@ func batchLabelSatisfied(pods []*corev1.Pod, rolloutID string, targetCount int32 if !pod.DeletionTimestamp.IsZero() { return false } - return pod.Labels[v1alpha1.RolloutIDLabel] == rolloutID + return pod.Labels[v1beta1.RolloutIDLabel] == rolloutID }) return patchedCount >= int(targetCount) } diff --git a/pkg/controller/batchrelease/context/context_test.go b/pkg/controller/batchrelease/context/context_test.go index 9f2d7f2d..124bdbde 100644 --- a/pkg/controller/batchrelease/context/context_test.go +++ b/pkg/controller/batchrelease/context/context_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -36,14 +36,14 @@ func TestIsBatchReady(t *testing.T) { p := func(f intstr.IntOrString) *intstr.IntOrString { return &f } - r := func(f *intstr.IntOrString, id, revision string) *v1alpha1.BatchRelease { - return &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ReleasePlan: v1alpha1.ReleasePlan{RolloutID: id, FailureThreshold: f}}, - Status: v1alpha1.BatchReleaseStatus{UpdateRevision: revision}, + r := func(f *intstr.IntOrString, id, revision string) *v1beta1.BatchRelease { + return &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ReleasePlan: v1beta1.ReleasePlan{RolloutID: id, FailureThreshold: f}}, + Status: v1beta1.BatchReleaseStatus{UpdateRevision: revision}, } } cases := map[string]struct { - release *v1alpha1.BatchRelease + release *v1beta1.BatchRelease pods []*corev1.Pod maxUnavailable *intstr.IntOrString labelDesired int32 @@ -151,11 +151,11 @@ func TestIsBatchReady(t *testing.T) { func generatePods(updatedReplicas, noNeedRollbackReplicas int) []*corev1.Pod { podsNoNeed := generatePodsWith(map[string]string{ util.NoNeedUpdatePodLabel: "0x1", - v1alpha1.RolloutIDLabel: "1", + v1beta1.RolloutIDLabel: "1", apps.ControllerRevisionHashLabelKey: "version-1", }, noNeedRollbackReplicas, 0) return append(generatePodsWith(map[string]string{ - v1alpha1.RolloutIDLabel: "1", + v1beta1.RolloutIDLabel: "1", apps.ControllerRevisionHashLabelKey: "version-1", }, updatedReplicas-noNeedRollbackReplicas, noNeedRollbackReplicas), podsNoNeed...) } diff --git a/pkg/controller/batchrelease/control/canarystyle/control_plane.go b/pkg/controller/batchrelease/control/canarystyle/control_plane.go index 03f315ff..f5faba4e 100644 --- a/pkg/controller/batchrelease/control/canarystyle/control_plane.go +++ b/pkg/controller/batchrelease/control/canarystyle/control_plane.go @@ -19,7 +19,7 @@ package canarystyle import ( "fmt" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch" "github.com/openkruise/rollouts/pkg/util" @@ -36,14 +36,14 @@ type realCanaryController struct { client.Client record.EventRecorder patcher labelpatch.LabelPatcher - release *v1alpha1.BatchRelease - newStatus *v1alpha1.BatchReleaseStatus + release *v1beta1.BatchRelease + newStatus *v1beta1.BatchReleaseStatus } type NewInterfaceFunc func(cli client.Client, key types.NamespacedName) Interface // NewControlPlane creates a new release controller to drive batch release state machine -func NewControlPlane(f NewInterfaceFunc, cli client.Client, recorder record.EventRecorder, release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, key types.NamespacedName) *realCanaryController { +func NewControlPlane(f NewInterfaceFunc, cli client.Client, recorder record.EventRecorder, release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, key types.NamespacedName) *realCanaryController { return &realCanaryController{ Client: cli, EventRecorder: recorder, diff --git a/pkg/controller/batchrelease/control/canarystyle/deployment/canary.go b/pkg/controller/batchrelease/control/canarystyle/deployment/canary.go index 811db7d5..e8afc70c 100644 --- a/pkg/controller/batchrelease/control/canarystyle/deployment/canary.go +++ b/pkg/controller/batchrelease/control/canarystyle/deployment/canary.go @@ -22,7 +22,7 @@ import ( "fmt" "sort" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" utilclient "github.com/openkruise/rollouts/pkg/util/client" @@ -55,7 +55,7 @@ func (r *realCanaryController) GetCanaryInfo() *util.WorkloadInfo { // Delete do not delete canary deployments actually, it only removes the finalizers of // Deployments. These deployments will be cascaded deleted when BatchRelease is deleted. -func (r *realCanaryController) Delete(release *v1alpha1.BatchRelease) error { +func (r *realCanaryController) Delete(release *v1beta1.BatchRelease) error { deployments, err := r.listDeployment(release, client.InNamespace(r.objectKey.Namespace), utilclient.DisableDeepCopy) if err != nil { return err @@ -87,7 +87,7 @@ func (r *realCanaryController) UpgradeBatch(ctx *batchcontext.BatchContext) erro return r.canaryClient.Patch(context.TODO(), deployment, client.RawPatch(types.StrategicMergePatchType, []byte(body))) } -func (r *realCanaryController) Create(release *v1alpha1.BatchRelease) error { +func (r *realCanaryController) Create(release *v1beta1.BatchRelease) error { if r.canaryObject != nil { return nil // Don't re-create if exists } @@ -113,7 +113,7 @@ func (r *realCanaryController) Create(release *v1alpha1.BatchRelease) error { } return r.create(release, stable) } -func (r *realCanaryController) create(release *v1alpha1.BatchRelease, template *apps.Deployment) error { +func (r *realCanaryController) create(release *v1beta1.BatchRelease, template *apps.Deployment) error { canary := &apps.Deployment{ ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%v-", r.objectKey.Name), @@ -162,7 +162,7 @@ func (r *realCanaryController) create(release *v1alpha1.BatchRelease, template * return fmt.Errorf("created canary deployment %v succeeded, but waiting informer synced", klog.KObj(canary)) } -func (r *realCanaryController) listDeployment(release *v1alpha1.BatchRelease, options ...client.ListOption) ([]*apps.Deployment, error) { +func (r *realCanaryController) listDeployment(release *v1beta1.BatchRelease, options ...client.ListOption) ([]*apps.Deployment, error) { dList := &apps.DeploymentList{} if err := r.canaryClient.List(context.TODO(), dList, options...); err != nil { return nil, err @@ -181,7 +181,7 @@ func (r *realCanaryController) listDeployment(release *v1alpha1.BatchRelease, op } // return the latest deployment with the newer creation time -func filterCanaryDeployment(release *v1alpha1.BatchRelease, ds []*apps.Deployment, template *corev1.PodTemplateSpec) *apps.Deployment { +func filterCanaryDeployment(release *v1beta1.BatchRelease, ds []*apps.Deployment, template *corev1.PodTemplateSpec) *apps.Deployment { if len(ds) == 0 { return nil } diff --git a/pkg/controller/batchrelease/control/canarystyle/deployment/control.go b/pkg/controller/batchrelease/control/canarystyle/deployment/control.go index 15f46021..c0f61670 100644 --- a/pkg/controller/batchrelease/control/canarystyle/deployment/control.go +++ b/pkg/controller/batchrelease/control/canarystyle/deployment/control.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/canarystyle" @@ -59,7 +59,7 @@ func (rc *realController) BuildStableController() (canarystyle.StableInterface, return rc, nil } -func (rc *realController) BuildCanaryController(release *v1alpha1.BatchRelease) (canarystyle.CanaryInterface, error) { +func (rc *realController) BuildCanaryController(release *v1beta1.BatchRelease) (canarystyle.CanaryInterface, error) { if rc.canaryObject != nil { return rc, nil } @@ -82,7 +82,7 @@ func (rc *realController) BuildCanaryController(release *v1alpha1.BatchRelease) return rc, nil } -func (rc *realController) CalculateBatchContext(release *v1alpha1.BatchRelease) *batchcontext.BatchContext { +func (rc *realController) CalculateBatchContext(release *v1beta1.BatchRelease) *batchcontext.BatchContext { replicas := *rc.stableObject.Spec.Replicas currentBatch := release.Status.CanaryStatus.CurrentBatch desiredUpdate := int32(control.CalculateBatchReplicas(release, int(replicas), int(currentBatch))) diff --git a/pkg/controller/batchrelease/control/canarystyle/deployment/control_test.go b/pkg/controller/batchrelease/control/canarystyle/deployment/control_test.go index 2eaf31a0..29418012 100644 --- a/pkg/controller/batchrelease/control/canarystyle/deployment/control_test.go +++ b/pkg/controller/batchrelease/control/canarystyle/deployment/control_test.go @@ -24,7 +24,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" expectations "github.com/openkruise/rollouts/pkg/util/expectation" @@ -105,7 +106,7 @@ var ( }, } - releaseDemo = &v1alpha1.BatchRelease{ + releaseDemo = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", @@ -115,10 +116,10 @@ var ( Namespace: deploymentKey.Namespace, UID: uuid.NewUUID(), }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - FinalizingPolicy: v1alpha1.WaitResumeFinalizingPolicyType, - Batches: []v1alpha1.ReleaseBatch{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + FinalizingPolicy: v1beta1.WaitResumeFinalizingPolicyType, + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -130,16 +131,16 @@ var ( }, }, }, - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: deploymentDemo.APIVersion, Kind: deploymentDemo.Kind, Name: deploymentDemo.Name, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 1, }, }, @@ -148,7 +149,7 @@ var ( func init() { apps.AddToScheme(scheme) - v1alpha1.AddToScheme(scheme) + rolloutapi.AddToScheme(scheme) } func TestCalculateBatchContext(t *testing.T) { @@ -157,7 +158,7 @@ func TestCalculateBatchContext(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() (*apps.Deployment, *apps.Deployment) - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease result *batchcontext.BatchContext }{ "normal case": { @@ -184,21 +185,21 @@ func TestCalculateBatchContext(t *testing.T) { } return stable, canary }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - FinalizingPolicy: v1alpha1.WaitResumeFinalizingPolicyType, - Batches: []v1alpha1.ReleaseBatch{ + FinalizingPolicy: v1beta1.WaitResumeFinalizingPolicyType, + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, }, @@ -310,7 +311,7 @@ func TestRealCanaryController(t *testing.T) { Expect(len(d.Finalizers)).Should(Equal(0)) } -func getCanaryDeployment(release *v1alpha1.BatchRelease, stable *apps.Deployment, c *realController) *apps.Deployment { +func getCanaryDeployment(release *v1beta1.BatchRelease, stable *apps.Deployment, c *realController) *apps.Deployment { ds, err := c.listDeployment(release) Expect(err).NotTo(HaveOccurred()) if len(ds) == 0 { @@ -328,7 +329,7 @@ func checkWorkloadInfo(stableInfo *util.WorkloadInfo, deployment *apps.Deploymen Expect(stableInfo.Status.ObservedGeneration).Should(Equal(deployment.Status.ObservedGeneration)) } -func getControlInfo(release *v1alpha1.BatchRelease) string { +func getControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return string(owner) } diff --git a/pkg/controller/batchrelease/control/canarystyle/deployment/stable.go b/pkg/controller/batchrelease/control/canarystyle/deployment/stable.go index a90b9792..f79fcfae 100644 --- a/pkg/controller/batchrelease/control/canarystyle/deployment/stable.go +++ b/pkg/controller/batchrelease/control/canarystyle/deployment/stable.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" @@ -43,7 +43,7 @@ func (rc *realStableController) GetStableInfo() *util.WorkloadInfo { return rc.stableInfo } -func (rc *realStableController) Initialize(release *v1alpha1.BatchRelease) error { +func (rc *realStableController) Initialize(release *v1beta1.BatchRelease) error { if control.IsControlledByBatchRelease(release, rc.stableObject) { return nil } @@ -55,7 +55,7 @@ func (rc *realStableController) Initialize(release *v1alpha1.BatchRelease) error return rc.stableClient.Patch(context.TODO(), d, client.RawPatch(types.StrategicMergePatchType, []byte(body))) } -func (rc *realStableController) Finalize(release *v1alpha1.BatchRelease) error { +func (rc *realStableController) Finalize(release *v1beta1.BatchRelease) error { if rc.stableObject == nil { return nil // no need to process deleted object } diff --git a/pkg/controller/batchrelease/control/canarystyle/interface.go b/pkg/controller/batchrelease/control/canarystyle/interface.go index d50ec4ae..f2585446 100644 --- a/pkg/controller/batchrelease/control/canarystyle/interface.go +++ b/pkg/controller/batchrelease/control/canarystyle/interface.go @@ -17,7 +17,7 @@ limitations under the License. package canarystyle import ( - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" ) @@ -30,10 +30,10 @@ type Interface interface { BuildStableController() (StableInterface, error) // BuildCanaryController will get canary workload object and parse // canary workload info, and return a controller for canary workload. - BuildCanaryController(release *v1alpha1.BatchRelease) (CanaryInterface, error) + BuildCanaryController(release *v1beta1.BatchRelease) (CanaryInterface, error) // CalculateBatchContext calculate the current batch context according to // our release plan and the statues of stable workload and canary workload. - CalculateBatchContext(release *v1alpha1.BatchRelease) *batchcontext.BatchContext + CalculateBatchContext(release *v1beta1.BatchRelease) *batchcontext.BatchContext } // CanaryInterface contains the methods about canary workload @@ -43,9 +43,9 @@ type CanaryInterface interface { // UpgradeBatch upgrade canary workload according to current batch context UpgradeBatch(*batchcontext.BatchContext) error // Create creates canary workload before rolling out - Create(controller *v1alpha1.BatchRelease) error + Create(controller *v1beta1.BatchRelease) error // Delete deletes canary workload after rolling out - Delete(controller *v1alpha1.BatchRelease) error + Delete(controller *v1beta1.BatchRelease) error } // StableInterface contains the methods about stable workload @@ -53,9 +53,9 @@ type StableInterface interface { // GetStableInfo return the information about stable workload GetStableInfo() *util.WorkloadInfo // Initialize claim the stable workload is under rollout control - Initialize(controller *v1alpha1.BatchRelease) error + Initialize(controller *v1beta1.BatchRelease) error // Finalize do something after rolling out, for example: // - free the stable workload from rollout control; // - resume stable workload and wait all pods updated if we need. - Finalize(controller *v1alpha1.BatchRelease) error + Finalize(controller *v1beta1.BatchRelease) error } diff --git a/pkg/controller/batchrelease/control/partitionstyle/cloneset/control.go b/pkg/controller/batchrelease/control/partitionstyle/cloneset/control.go index 2e5e6194..b136b104 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/cloneset/control.go +++ b/pkg/controller/batchrelease/control/partitionstyle/cloneset/control.go @@ -21,7 +21,7 @@ import ( "fmt" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/partitionstyle" @@ -75,7 +75,7 @@ func (rc *realController) ListOwnedPods() ([]*corev1.Pod, error) { return rc.pods, err } -func (rc *realController) Initialize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Initialize(release *v1beta1.BatchRelease) error { if control.IsControlledByBatchRelease(release, rc.object) { return nil } @@ -110,7 +110,7 @@ func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error { return rc.client.Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Finalize(release *v1beta1.BatchRelease) error { if rc.object == nil { return nil } @@ -127,7 +127,7 @@ func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { return rc.client.Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) CalculateBatchContext(release *v1alpha1.BatchRelease) (*batchcontext.BatchContext, error) { +func (rc *realController) CalculateBatchContext(release *v1beta1.BatchRelease) (*batchcontext.BatchContext, error) { rolloutID := release.Spec.ReleasePlan.RolloutID if rolloutID != "" { // if rollout-id is set, the pod will be patched batch label, diff --git a/pkg/controller/batchrelease/control/partitionstyle/cloneset/control_test.go b/pkg/controller/batchrelease/control/partitionstyle/cloneset/control_test.go index 435ec33a..d55816ae 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/cloneset/control_test.go +++ b/pkg/controller/batchrelease/control/partitionstyle/cloneset/control_test.go @@ -25,7 +25,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch" "github.com/openkruise/rollouts/pkg/util" @@ -104,7 +105,7 @@ var ( }, } - releaseDemo = &v1alpha1.BatchRelease{ + releaseDemo = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", @@ -114,9 +115,9 @@ var ( Namespace: cloneKey.Namespace, UID: uuid.NewUUID(), }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - Batches: []v1alpha1.ReleaseBatch{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -128,16 +129,16 @@ var ( }, }, }, - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: cloneDemo.APIVersion, Kind: cloneDemo.Kind, Name: cloneDemo.Name, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, }, @@ -146,7 +147,7 @@ var ( func init() { apps.AddToScheme(scheme) - v1alpha1.AddToScheme(scheme) + rolloutapi.AddToScheme(scheme) kruiseappsv1alpha1.AddToScheme(scheme) } @@ -156,7 +157,7 @@ func TestCalculateBatchContext(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() *kruiseappsv1alpha1.CloneSet - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease result *batchcontext.BatchContext }{ "without NoNeedUpdate": { @@ -176,20 +177,20 @@ func TestCalculateBatchContext(t *testing.T) { }, } }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, }, @@ -226,20 +227,20 @@ func TestCalculateBatchContext(t *testing.T) { }, } }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, NoNeedUpdateReplicas: pointer.Int32(10), }, @@ -336,7 +337,7 @@ func checkWorkloadInfo(stableInfo *util.WorkloadInfo, clone *kruiseappsv1alpha1. Expect(stableInfo.Status.ObservedGeneration).Should(Equal(clone.Status.ObservedGeneration)) } -func getControlInfo(release *v1alpha1.BatchRelease) string { +func getControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return string(owner) } diff --git a/pkg/controller/batchrelease/control/partitionstyle/control_plane.go b/pkg/controller/batchrelease/control/partitionstyle/control_plane.go index 9788175b..e8dd8dc2 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/control_plane.go +++ b/pkg/controller/batchrelease/control/partitionstyle/control_plane.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch" "github.com/openkruise/rollouts/pkg/util" @@ -39,14 +40,14 @@ type realBatchControlPlane struct { client.Client record.EventRecorder patcher labelpatch.LabelPatcher - release *v1alpha1.BatchRelease - newStatus *v1alpha1.BatchReleaseStatus + release *v1beta1.BatchRelease + newStatus *v1beta1.BatchReleaseStatus } type NewInterfaceFunc func(cli client.Client, key types.NamespacedName, gvk schema.GroupVersionKind) Interface // NewControlPlane creates a new release controller with partitioned-style to drive batch release state machine -func NewControlPlane(f NewInterfaceFunc, cli client.Client, recorder record.EventRecorder, release *v1alpha1.BatchRelease, newStatus *v1alpha1.BatchReleaseStatus, key types.NamespacedName, gvk schema.GroupVersionKind) *realBatchControlPlane { +func NewControlPlane(f NewInterfaceFunc, cli client.Client, recorder record.EventRecorder, release *v1beta1.BatchRelease, newStatus *v1beta1.BatchReleaseStatus, key types.NamespacedName, gvk schema.GroupVersionKind) *realBatchControlPlane { return &realBatchControlPlane{ Client: cli, EventRecorder: recorder, diff --git a/pkg/controller/batchrelease/control/partitionstyle/daemonset/control.go b/pkg/controller/batchrelease/control/partitionstyle/daemonset/control.go index ec7b3311..d1f03885 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/daemonset/control.go +++ b/pkg/controller/batchrelease/control/partitionstyle/daemonset/control.go @@ -5,7 +5,7 @@ import ( "fmt" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/partitionstyle" @@ -89,7 +89,7 @@ func (rc *realController) ListOwnedPods() ([]*corev1.Pod, error) { return rc.pods, err } -func (rc *realController) Initialize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Initialize(release *v1beta1.BatchRelease) error { if control.IsControlledByBatchRelease(release, rc.object) { return nil } @@ -118,7 +118,7 @@ func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error { return rc.client.Patch(context.TODO(), daemon, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Finalize(release *v1beta1.BatchRelease) error { if rc.object == nil { return nil } @@ -135,7 +135,7 @@ func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { return rc.client.Patch(context.TODO(), daemon, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) CalculateBatchContext(release *v1alpha1.BatchRelease) (*batchcontext.BatchContext, error) { +func (rc *realController) CalculateBatchContext(release *v1beta1.BatchRelease) (*batchcontext.BatchContext, error) { rolloutID := release.Spec.ReleasePlan.RolloutID if rolloutID != "" { // if rollout-id is set, the pod will be patched batch label, diff --git a/pkg/controller/batchrelease/control/partitionstyle/daemonset/control_test.go b/pkg/controller/batchrelease/control/partitionstyle/daemonset/control_test.go index b1163571..a5633300 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/daemonset/control_test.go +++ b/pkg/controller/batchrelease/control/partitionstyle/daemonset/control_test.go @@ -9,7 +9,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch" "github.com/openkruise/rollouts/pkg/util" @@ -92,7 +93,7 @@ var ( }, } - releaseDemo = &v1alpha1.BatchRelease{ + releaseDemo = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", @@ -102,9 +103,9 @@ var ( Namespace: daemonKey.Namespace, UID: uuid.NewUUID(), }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - Batches: []v1alpha1.ReleaseBatch{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -116,16 +117,16 @@ var ( }, }, }, - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: daemonDemo.APIVersion, Kind: daemonDemo.Kind, Name: daemonDemo.Name, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, }, @@ -135,7 +136,7 @@ var ( func init() { apps.AddToScheme(scheme) corev1.AddToScheme(scheme) - v1alpha1.AddToScheme(scheme) + rolloutapi.AddToScheme(scheme) kruiseappsv1alpha1.AddToScheme(scheme) } @@ -145,7 +146,7 @@ func TestCalculateBatchContext(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() *kruiseappsv1alpha1.DaemonSet - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease result *batchcontext.BatchContext pods func() []*corev1.Pod }{ @@ -183,24 +184,24 @@ func TestCalculateBatchContext(t *testing.T) { updatedReadyPods := generatePods(5, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, UpdateRevision: "update-version", @@ -256,25 +257,25 @@ func TestCalculateBatchContext(t *testing.T) { updatedReadyPods := generatePods(5, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { + release: func() *v1beta1.BatchRelease { - r := &v1alpha1.BatchRelease{ + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, NoNeedUpdateReplicas: pointer.Int32(5), }, @@ -396,7 +397,7 @@ func checkWorkloadInfo(stableInfo *util.WorkloadInfo, daemon *kruiseappsv1alpha1 Expect(stableInfo.Status.ObservedGeneration).Should(Equal(daemon.Status.ObservedGeneration)) } -func getControlInfo(release *v1alpha1.BatchRelease) string { +func getControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return string(owner) } diff --git a/pkg/controller/batchrelease/control/partitionstyle/deployment/control.go b/pkg/controller/batchrelease/control/partitionstyle/deployment/control.go index 828590e5..e67ab33f 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/deployment/control.go +++ b/pkg/controller/batchrelease/control/partitionstyle/deployment/control.go @@ -20,6 +20,7 @@ import ( "context" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/partitionstyle" @@ -77,7 +78,7 @@ func (rc *realController) ListOwnedPods() ([]*corev1.Pod, error) { return rc.pods, err } -func (rc *realController) Initialize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Initialize(release *v1beta1.BatchRelease) error { if deploymentutil.IsUnderRolloutControl(rc.object) { return nil // No need initialize again. } @@ -127,7 +128,7 @@ func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error { return rc.client.Patch(context.TODO(), d, patchData) } -func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Finalize(release *v1beta1.BatchRelease) error { if rc.object == nil || !deploymentutil.IsUnderRolloutControl(rc.object) { return nil // No need to finalize again. } @@ -147,7 +148,7 @@ func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { return rc.client.Patch(context.TODO(), d, patchData) } -func (rc *realController) CalculateBatchContext(release *v1alpha1.BatchRelease) (*batchcontext.BatchContext, error) { +func (rc *realController) CalculateBatchContext(release *v1beta1.BatchRelease) (*batchcontext.BatchContext, error) { rolloutID := release.Spec.ReleasePlan.RolloutID if rolloutID != "" { // if rollout-id is set, the pod will be patched batch label, diff --git a/pkg/controller/batchrelease/control/partitionstyle/deployment/control_test.go b/pkg/controller/batchrelease/control/partitionstyle/deployment/control_test.go index c0c25885..3f03f8f8 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/deployment/control_test.go +++ b/pkg/controller/batchrelease/control/partitionstyle/deployment/control_test.go @@ -25,7 +25,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" @@ -104,7 +106,7 @@ var ( }, } - releaseDemo = &v1alpha1.BatchRelease{ + releaseDemo = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", @@ -114,10 +116,10 @@ var ( Namespace: deploymentKey.Namespace, UID: uuid.NewUUID(), }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - FinalizingPolicy: v1alpha1.WaitResumeFinalizingPolicyType, - Batches: []v1alpha1.ReleaseBatch{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + FinalizingPolicy: v1beta1.WaitResumeFinalizingPolicyType, + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -129,16 +131,16 @@ var ( }, }, }, - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: deploymentDemo.APIVersion, Kind: deploymentDemo.Kind, Name: deploymentDemo.Name, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 1, }, }, @@ -147,7 +149,7 @@ var ( func init() { apps.AddToScheme(scheme) - v1alpha1.AddToScheme(scheme) + rolloutapi.AddToScheme(scheme) kruiseappsv1alpha1.AddToScheme(scheme) } @@ -157,7 +159,7 @@ func TestCalculateBatchContext(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() *apps.Deployment - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease result *batchcontext.BatchContext }{ "noraml case": { @@ -189,21 +191,21 @@ func TestCalculateBatchContext(t *testing.T) { } return deployment }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - FinalizingPolicy: v1alpha1.WaitResumeFinalizingPolicyType, - Batches: []v1alpha1.ReleaseBatch{ + FinalizingPolicy: v1beta1.WaitResumeFinalizingPolicyType, + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, UpdateRevision: "version-2", @@ -253,21 +255,21 @@ func TestCalculateBatchContext(t *testing.T) { } return deployment }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - FinalizingPolicy: v1alpha1.WaitResumeFinalizingPolicyType, - Batches: []v1alpha1.ReleaseBatch{ + FinalizingPolicy: v1beta1.WaitResumeFinalizingPolicyType, + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("90%"), }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, UpdateRevision: "version-2", @@ -369,7 +371,7 @@ func checkWorkloadInfo(stableInfo *util.WorkloadInfo, clone *apps.Deployment) { Expect(stableInfo.Status.ObservedGeneration).Should(Equal(clone.Status.ObservedGeneration)) } -func getControlInfo(release *v1alpha1.BatchRelease) string { +func getControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return string(owner) } diff --git a/pkg/controller/batchrelease/control/partitionstyle/interface.go b/pkg/controller/batchrelease/control/partitionstyle/interface.go index 99fbacf0..c5a193fa 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/interface.go +++ b/pkg/controller/batchrelease/control/partitionstyle/interface.go @@ -17,7 +17,7 @@ limitations under the License. package partitionstyle import ( - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" corev1 "k8s.io/api/core/v1" @@ -34,16 +34,16 @@ type Interface interface { ListOwnedPods() ([]*corev1.Pod, error) // CalculateBatchContext calculate current batch context // according to release plan and current status of workload. - CalculateBatchContext(release *v1alpha1.BatchRelease) (*batchcontext.BatchContext, error) + CalculateBatchContext(release *v1beta1.BatchRelease) (*batchcontext.BatchContext, error) // Initialize do something before rolling out, for example: // - claim the workload is under our control; // - other things related with specific type of workload, such as 100% partition settings. - Initialize(release *v1alpha1.BatchRelease) error + Initialize(release *v1beta1.BatchRelease) error // UpgradeBatch upgrade workload according current batch context. UpgradeBatch(ctx *batchcontext.BatchContext) error // Finalize do something after rolling out, for example: // - free the stable workload from rollout control; // - resume workload if we need. - Finalize(release *v1alpha1.BatchRelease) error + Finalize(release *v1beta1.BatchRelease) error } diff --git a/pkg/controller/batchrelease/control/partitionstyle/statefulset/control.go b/pkg/controller/batchrelease/control/partitionstyle/statefulset/control.go index fa8e3219..8d83a559 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/statefulset/control.go +++ b/pkg/controller/batchrelease/control/partitionstyle/statefulset/control.go @@ -21,7 +21,7 @@ import ( "fmt" "math" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control" "github.com/openkruise/rollouts/pkg/controller/batchrelease/control/partitionstyle" @@ -97,7 +97,7 @@ func (rc *realController) ListOwnedPods() ([]*corev1.Pod, error) { return rc.pods, err } -func (rc *realController) Initialize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Initialize(release *v1beta1.BatchRelease) error { if control.IsControlledByBatchRelease(release, rc.object) { return nil } @@ -126,7 +126,7 @@ func (rc *realController) UpgradeBatch(ctx *batchcontext.BatchContext) error { return rc.client.Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { +func (rc *realController) Finalize(release *v1beta1.BatchRelease) error { if rc.object == nil { return nil } @@ -143,7 +143,7 @@ func (rc *realController) Finalize(release *v1alpha1.BatchRelease) error { return rc.client.Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body))) } -func (rc *realController) CalculateBatchContext(release *v1alpha1.BatchRelease) (*batchcontext.BatchContext, error) { +func (rc *realController) CalculateBatchContext(release *v1beta1.BatchRelease) (*batchcontext.BatchContext, error) { rolloutID := release.Spec.ReleasePlan.RolloutID if rolloutID != "" { // if rollout-id is set, the pod will be patched batch label, diff --git a/pkg/controller/batchrelease/control/partitionstyle/statefulset/control_test.go b/pkg/controller/batchrelease/control/partitionstyle/statefulset/control_test.go index 59451c52..b8490ed8 100644 --- a/pkg/controller/batchrelease/control/partitionstyle/statefulset/control_test.go +++ b/pkg/controller/batchrelease/control/partitionstyle/statefulset/control_test.go @@ -27,7 +27,8 @@ import ( appsv1pub "github.com/openkruise/kruise-api/apps/pub" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" kruiseappsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" - "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/controller/batchrelease/labelpatch" "github.com/openkruise/rollouts/pkg/util" @@ -111,7 +112,7 @@ var ( }, } - releaseDemo = &v1alpha1.BatchRelease{ + releaseDemo = &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", @@ -121,9 +122,9 @@ var ( Namespace: stsKey.Namespace, UID: uuid.NewUUID(), }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - Batches: []v1alpha1.ReleaseBatch{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, @@ -135,16 +136,16 @@ var ( }, }, }, - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: stsDemo.APIVersion, Kind: stsDemo.Kind, Name: stsDemo.Name, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, }, @@ -155,7 +156,7 @@ func init() { rand.Seed(87076677) apps.AddToScheme(scheme) corev1.AddToScheme(scheme) - v1alpha1.AddToScheme(scheme) + rolloutapi.AddToScheme(scheme) kruiseappsv1alpha1.AddToScheme(scheme) kruiseappsv1beta1.AddToScheme(scheme) } @@ -166,7 +167,7 @@ func TestCalculateBatchContextForNativeStatefulSet(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() *apps.StatefulSet - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease pods func() []*corev1.Pod result *batchcontext.BatchContext }{ @@ -206,24 +207,24 @@ func TestCalculateBatchContextForNativeStatefulSet(t *testing.T) { updatedReadyPods := generatePods(5, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, UpdateRevision: "update-version", @@ -281,24 +282,24 @@ func TestCalculateBatchContextForNativeStatefulSet(t *testing.T) { updatedReadyPods := generatePods(10, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, NoNeedUpdateReplicas: pointer.Int32(10), }, @@ -360,7 +361,7 @@ func TestCalculateBatchContextForAdvancedStatefulSet(t *testing.T) { percent := intstr.FromString("20%") cases := map[string]struct { workload func() *kruiseappsv1beta1.StatefulSet - release func() *v1alpha1.BatchRelease + release func() *v1beta1.BatchRelease pods func() []*corev1.Pod result *batchcontext.BatchContext }{ @@ -409,24 +410,24 @@ func TestCalculateBatchContextForAdvancedStatefulSet(t *testing.T) { updatedReadyPods := generatePods(5, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, }, UpdateRevision: "update-version", @@ -493,24 +494,24 @@ func TestCalculateBatchContextForAdvancedStatefulSet(t *testing.T) { updatedReadyPods := generatePods(10, "update-version", "True") return append(stablePods, updatedReadyPods...) }, - release: func() *v1alpha1.BatchRelease { - r := &v1alpha1.BatchRelease{ + release: func() *v1beta1.BatchRelease { + r := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "test-br", Namespace: "test", }, - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ FailureThreshold: &percent, - Batches: []v1alpha1.ReleaseBatch{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: percent, }, }, }, }, - Status: v1alpha1.BatchReleaseStatus{ - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ + Status: v1beta1.BatchReleaseStatus{ + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ CurrentBatch: 0, NoNeedUpdateReplicas: pointer.Int32(10), }, @@ -629,7 +630,7 @@ func checkWorkloadInfo(stableInfo *util.WorkloadInfo, sts *kruiseappsv1beta1.Sta Expect(stableInfo.Status.ObservedGeneration).Should(Equal(sts.Status.ObservedGeneration)) } -func getControlInfo(release *v1alpha1.BatchRelease) string { +func getControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return string(owner) } diff --git a/pkg/controller/batchrelease/control/util.go b/pkg/controller/batchrelease/control/util.go index 12acc420..0c0e36bd 100644 --- a/pkg/controller/batchrelease/control/util.go +++ b/pkg/controller/batchrelease/control/util.go @@ -21,7 +21,7 @@ import ( "fmt" "strings" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +32,7 @@ import ( ) // CalculateBatchReplicas return the planned updated replicas of current batch. -func CalculateBatchReplicas(release *v1alpha1.BatchRelease, workloadReplicas, currentBatch int) int { +func CalculateBatchReplicas(release *v1beta1.BatchRelease, workloadReplicas, currentBatch int) int { batchSize, _ := intstr.GetScaledValueFromIntOrPercent(&release.Spec.ReleasePlan.Batches[currentBatch].CanaryReplicas, workloadReplicas, true) if batchSize > workloadReplicas { klog.Warningf("releasePlan has wrong batch replicas, batches[%d].replicas %v is more than workload.replicas %v", currentBatch, batchSize, workloadReplicas) @@ -49,7 +49,7 @@ func CalculateBatchReplicas(release *v1alpha1.BatchRelease, workloadReplicas, cu // IsControlledByBatchRelease return true if // * object ownerReference has referred release; // * object has batchRelease control info annotation about release. -func IsControlledByBatchRelease(release *v1alpha1.BatchRelease, object client.Object) bool { +func IsControlledByBatchRelease(release *v1beta1.BatchRelease, object client.Object) bool { if owner := metav1.GetControllerOfNoCopy(object); owner != nil && owner.UID == release.UID { return true } @@ -64,7 +64,7 @@ func IsControlledByBatchRelease(release *v1alpha1.BatchRelease, object client.Ob } // BuildReleaseControlInfo return a NewControllerRef of release with escaped `"`. -func BuildReleaseControlInfo(release *v1alpha1.BatchRelease) string { +func BuildReleaseControlInfo(release *v1beta1.BatchRelease) string { owner, _ := json.Marshal(metav1.NewControllerRef(release, release.GetObjectKind().GroupVersionKind())) return strings.Replace(string(owner), `"`, `\"`, -1) } @@ -102,8 +102,8 @@ func GenerateNotFoundError(name, resource string) error { } // ShouldWaitResume return true if FinalizingPolicy is "waitResume". -func ShouldWaitResume(release *v1alpha1.BatchRelease) bool { - return release.Spec.ReleasePlan.FinalizingPolicy == v1alpha1.WaitResumeFinalizingPolicyType +func ShouldWaitResume(release *v1beta1.BatchRelease) bool { + return release.Spec.ReleasePlan.FinalizingPolicy == v1beta1.WaitResumeFinalizingPolicyType } // IsCurrentMoreThanOrEqualToDesired return true if current >= desired diff --git a/pkg/controller/batchrelease/control/util_test.go b/pkg/controller/batchrelease/control/util_test.go index baef4387..b8b0d0e1 100644 --- a/pkg/controller/batchrelease/control/util_test.go +++ b/pkg/controller/batchrelease/control/util_test.go @@ -24,7 +24,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -96,10 +96,10 @@ func TestCalculateBatchReplicas(t *testing.T) { for name, cs := range cases { t.Run(name, func(t *testing.T) { - release := &v1alpha1.BatchRelease{ - Spec: v1alpha1.BatchReleaseSpec{ - ReleasePlan: v1alpha1.ReleasePlan{ - Batches: []v1alpha1.ReleaseBatch{ + release := &v1beta1.BatchRelease{ + Spec: v1beta1.BatchReleaseSpec{ + ReleasePlan: v1beta1.ReleasePlan{ + Batches: []v1beta1.ReleaseBatch{ { CanaryReplicas: cs.batchReplicas, }, @@ -116,7 +116,7 @@ func TestCalculateBatchReplicas(t *testing.T) { func TestIsControlledByBatchRelease(t *testing.T) { RegisterFailHandler(Fail) - release := &v1alpha1.BatchRelease{ + release := &v1beta1.BatchRelease{ TypeMeta: metav1.TypeMeta{ APIVersion: "rollouts.kruise.io/v1alpha1", Kind: "BatchRelease", diff --git a/pkg/controller/batchrelease/labelpatch/filter.go b/pkg/controller/batchrelease/labelpatch/filter.go index f963bfef..315109b1 100644 --- a/pkg/controller/batchrelease/labelpatch/filter.go +++ b/pkg/controller/batchrelease/labelpatch/filter.go @@ -21,7 +21,7 @@ import ( "strconv" "strings" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" corev1 "k8s.io/api/core/v1" @@ -60,7 +60,7 @@ func FilterPodsForUnorderedUpdate(pods []*corev1.Pod, ctx *batchcontext.BatchCon if !util.IsConsistentWithRevision(pod, ctx.UpdateRevision) { continue } - if pod.Labels[util.NoNeedUpdatePodLabel] == ctx.RolloutID && pod.Labels[v1alpha1.RolloutIDLabel] != ctx.RolloutID { + if pod.Labels[util.NoNeedUpdatePodLabel] == ctx.RolloutID && pod.Labels[v1beta1.RolloutIDLabel] != ctx.RolloutID { noNeedUpdate++ lowPriorityPods = append(lowPriorityPods, pod) } else { diff --git a/pkg/controller/batchrelease/labelpatch/patcher.go b/pkg/controller/batchrelease/labelpatch/patcher.go index 3f53b1e7..a0175b45 100644 --- a/pkg/controller/batchrelease/labelpatch/patcher.go +++ b/pkg/controller/batchrelease/labelpatch/patcher.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" "github.com/openkruise/rollouts/pkg/util" corev1 "k8s.io/api/core/v1" @@ -65,7 +65,7 @@ func (r *realPatcher) patchPodBatchLabel(pods []*corev1.Pod, ctx *batchcontext.B continue } - podRolloutID := pod.Labels[v1alpha1.RolloutIDLabel] + podRolloutID := pod.Labels[v1beta1.RolloutIDLabel] if pod.DeletionTimestamp.IsZero() && podRolloutID == ctx.RolloutID { patchedUpdatedReplicas++ } @@ -89,13 +89,13 @@ func (r *realPatcher) patchPodBatchLabel(pods []*corev1.Pod, ctx *batchcontext.B } // if it has been patched, just ignore - if pod.Labels[v1alpha1.RolloutIDLabel] == ctx.RolloutID { + if pod.Labels[v1beta1.RolloutIDLabel] == ctx.RolloutID { continue } clone := util.GetEmptyObjectWithKey(pod) by := fmt.Sprintf(`{"metadata":{"labels":{"%s":"%s","%s":"%d"}}}`, - v1alpha1.RolloutIDLabel, ctx.RolloutID, v1alpha1.RolloutBatchIDLabel, ctx.CurrentBatch+1) + v1beta1.RolloutIDLabel, ctx.RolloutID, v1beta1.RolloutBatchIDLabel, ctx.CurrentBatch+1) if err := r.Patch(context.TODO(), clone, client.RawPatch(types.StrategicMergePatchType, []byte(by))); err != nil { return err } diff --git a/pkg/controller/batchrelease/labelpatch/patcher_test.go b/pkg/controller/batchrelease/labelpatch/patcher_test.go index fb31cb4c..f8bcbf38 100644 --- a/pkg/controller/batchrelease/labelpatch/patcher_test.go +++ b/pkg/controller/batchrelease/labelpatch/patcher_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" batchcontext "github.com/openkruise/rollouts/pkg/controller/batchrelease/context" apps "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -156,7 +156,7 @@ func TestLabelPatcher(t *testing.T) { Expect(err).NotTo(HaveOccurred()) patched := 0 for _, pod := range podList.Items { - if pod.Labels[v1alpha1.RolloutIDLabel] == ctx.RolloutID { + if pod.Labels[v1beta1.RolloutIDLabel] == ctx.RolloutID { patched++ } } @@ -170,8 +170,8 @@ func TestLabelPatcher(t *testing.T) { func generatePods(ordinalBegin, ordinalEnd, labeled int32, rolloutID, batchID, version string) []*corev1.Pod { podsWithLabel := generateLabeledPods(map[string]string{ - v1alpha1.RolloutIDLabel: rolloutID, - v1alpha1.RolloutBatchIDLabel: batchID, + v1beta1.RolloutIDLabel: rolloutID, + v1beta1.RolloutBatchIDLabel: batchID, apps.ControllerRevisionHashLabelKey: version, }, int(labeled), int(ordinalBegin)) diff --git a/pkg/controller/rollout/rollout_canary.go b/pkg/controller/rollout/rollout_canary.go index 9cd18e13..05c0514c 100644 --- a/pkg/controller/rollout/rollout_canary.go +++ b/pkg/controller/rollout/rollout_canary.go @@ -24,6 +24,7 @@ import ( "time" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" corev1 "k8s.io/api/core/v1" @@ -83,20 +84,20 @@ func (m *canaryReleaseManager) runCanary(c *RolloutContext) error { } } switch canaryStatus.CurrentStepState { - case v1alpha1.CanaryStepStateUpgrade: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStateUpgrade) + case v1beta1.CanaryStepStateUpgrade: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStateUpgrade) done, err := m.doCanaryUpgrade(c) if err != nil { return err } else if done { - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStateTrafficRouting + canaryStatus.CurrentStepState = v1beta1.CanaryStepStateTrafficRouting canaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} klog.Infof("rollout(%s/%s) step(%d) state from(%s) -> to(%s)", c.Rollout.Namespace, c.Rollout.Name, - canaryStatus.CurrentStepIndex, v1alpha1.CanaryStepStateUpgrade, canaryStatus.CurrentStepState) + canaryStatus.CurrentStepIndex, v1beta1.CanaryStepStateUpgrade, canaryStatus.CurrentStepState) } - case v1alpha1.CanaryStepStateTrafficRouting: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStateTrafficRouting) + case v1beta1.CanaryStepStateTrafficRouting: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStateTrafficRouting) tr := newTrafficRoutingContext(c) done, err := m.trafficRoutingManager.DoTrafficRouting(tr) c.NewStatus.CanaryStatus.LastUpdateTime = tr.LastUpdateTime @@ -104,55 +105,55 @@ func (m *canaryReleaseManager) runCanary(c *RolloutContext) error { return err } else if done { canaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStateMetricsAnalysis + canaryStatus.CurrentStepState = v1beta1.CanaryStepStateMetricsAnalysis klog.Infof("rollout(%s/%s) step(%d) state from(%s) -> to(%s)", c.Rollout.Namespace, c.Rollout.Name, - canaryStatus.CurrentStepIndex, v1alpha1.CanaryStepStateTrafficRouting, canaryStatus.CurrentStepState) + canaryStatus.CurrentStepIndex, v1beta1.CanaryStepStateTrafficRouting, canaryStatus.CurrentStepState) } expectedTime := time.Now().Add(time.Duration(defaultGracePeriodSeconds) * time.Second) c.RecheckTime = &expectedTime - case v1alpha1.CanaryStepStateMetricsAnalysis: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStateMetricsAnalysis) + case v1beta1.CanaryStepStateMetricsAnalysis: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStateMetricsAnalysis) done, err := m.doCanaryMetricsAnalysis(c) if err != nil { return err } else if done { - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStatePaused + canaryStatus.CurrentStepState = v1beta1.CanaryStepStatePaused klog.Infof("rollout(%s/%s) step(%d) state from(%s) -> to(%s)", c.Rollout.Namespace, c.Rollout.Name, - canaryStatus.CurrentStepIndex, v1alpha1.CanaryStepStateMetricsAnalysis, canaryStatus.CurrentStepState) + canaryStatus.CurrentStepIndex, v1beta1.CanaryStepStateMetricsAnalysis, canaryStatus.CurrentStepState) } - case v1alpha1.CanaryStepStatePaused: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStatePaused) + case v1beta1.CanaryStepStatePaused: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStatePaused) done, err := m.doCanaryPaused(c) if err != nil { return err } else if done { canaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStateReady + canaryStatus.CurrentStepState = v1beta1.CanaryStepStateReady klog.Infof("rollout(%s/%s) step(%d) state from(%s) -> to(%s)", c.Rollout.Namespace, c.Rollout.Name, - canaryStatus.CurrentStepIndex, v1alpha1.CanaryStepStatePaused, canaryStatus.CurrentStepState) + canaryStatus.CurrentStepIndex, v1beta1.CanaryStepStatePaused, canaryStatus.CurrentStepState) } - case v1alpha1.CanaryStepStateReady: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStateReady) + case v1beta1.CanaryStepStateReady: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStateReady) // run next step if len(c.Rollout.Spec.Strategy.Canary.Steps) > int(canaryStatus.CurrentStepIndex) { canaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} canaryStatus.CurrentStepIndex++ - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade + canaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade klog.Infof("rollout(%s/%s) canary step from(%d) -> to(%d)", c.Rollout.Namespace, c.Rollout.Name, canaryStatus.CurrentStepIndex-1, canaryStatus.CurrentStepIndex) } else { klog.Infof("rollout(%s/%s) canary run all steps, and completed", c.Rollout.Namespace, c.Rollout.Name) canaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} - canaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + canaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted return nil } klog.Infof("rollout(%s/%s) step(%d) state from(%s) -> to(%s)", c.Rollout.Namespace, c.Rollout.Name, - canaryStatus.CurrentStepIndex, v1alpha1.CanaryStepStateReady, canaryStatus.CurrentStepState) + canaryStatus.CurrentStepIndex, v1beta1.CanaryStepStateReady, canaryStatus.CurrentStepState) // canary completed - case v1alpha1.CanaryStepStateCompleted: - klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1alpha1.CanaryStepStateCompleted) + case v1beta1.CanaryStepStateCompleted: + klog.Infof("rollout(%s/%s) run canary strategy, and state(%s)", c.Rollout.Namespace, c.Rollout.Name, v1beta1.CanaryStepStateCompleted) } return nil @@ -162,7 +163,7 @@ func (m *canaryReleaseManager) doCanaryUpgrade(c *RolloutContext) (bool, error) // verify whether batchRelease configuration is the latest steps := len(c.Rollout.Spec.Strategy.Canary.Steps) canaryStatus := c.NewStatus.CanaryStatus - cond := util.GetRolloutCondition(*c.NewStatus, v1alpha1.RolloutConditionProgressing) + cond := util.GetRolloutCondition(*c.NewStatus, v1beta1.RolloutConditionProgressing) cond.Message = fmt.Sprintf("Rollout is in step(%d/%d), and upgrade workload to new version", canaryStatus.CurrentStepIndex, steps) c.NewStatus.Message = cond.Message // run batch release to upgrade the workloads @@ -178,7 +179,7 @@ func (m *canaryReleaseManager) doCanaryUpgrade(c *RolloutContext) (bool, error) return false, nil } // check whether batchRelease is ready(whether new pods is ready.) - if br.Status.CanaryStatus.CurrentBatchState != v1alpha1.ReadyBatchState || + if br.Status.CanaryStatus.CurrentBatchState != v1beta1.ReadyBatchState || br.Status.CanaryStatus.CurrentBatch+1 < canaryStatus.CurrentStepIndex { klog.Infof("rollout(%s/%s) batchRelease status(%s) is not ready, and wait a moment", c.Rollout.Namespace, c.Rollout.Name, util.DumpJSON(br.Status)) return false, nil @@ -205,7 +206,7 @@ func (m *canaryReleaseManager) doCanaryPaused(c *RolloutContext) (bool, error) { return true, nil } } - cond := util.GetRolloutCondition(*c.NewStatus, v1alpha1.RolloutConditionProgressing) + cond := util.GetRolloutCondition(*c.NewStatus, v1beta1.RolloutConditionProgressing) // need manual confirmation if currentStep.Pause.Duration == nil { klog.Infof("rollout(%s/%s) don't set pause duration, and need manual confirmation", c.Rollout.Namespace, c.Rollout.Name) @@ -289,7 +290,7 @@ func (m *canaryReleaseManager) removeRolloutProgressingAnnotation(c *RolloutCont return nil } -func (m *canaryReleaseManager) runBatchRelease(rollout *v1alpha1.Rollout, rolloutId string, batch int32, isRollback bool) (bool, *v1alpha1.BatchRelease, error) { +func (m *canaryReleaseManager) runBatchRelease(rollout *v1beta1.Rollout, rolloutId string, batch int32, isRollback bool) (bool, *v1beta1.BatchRelease, error) { batch = batch - 1 br, err := m.fetchBatchRelease(rollout.Namespace, rollout.Name) if errors.IsNotFound(err) { @@ -330,37 +331,37 @@ func (m *canaryReleaseManager) runBatchRelease(rollout *v1alpha1.Rollout, rollou return false, br, nil } -func (m *canaryReleaseManager) fetchBatchRelease(ns, name string) (*v1alpha1.BatchRelease, error) { - br := &v1alpha1.BatchRelease{} +func (m *canaryReleaseManager) fetchBatchRelease(ns, name string) (*v1beta1.BatchRelease, error) { + br := &v1beta1.BatchRelease{} // batchRelease.name is equal related rollout.name err := m.Get(context.TODO(), client.ObjectKey{Namespace: ns, Name: name}, br) return br, err } -func createBatchRelease(rollout *v1alpha1.Rollout, rolloutID string, batch int32, isRollback bool) *v1alpha1.BatchRelease { - var batches []v1alpha1.ReleaseBatch +func createBatchRelease(rollout *v1beta1.Rollout, rolloutID string, batch int32, isRollback bool) *v1beta1.BatchRelease { + var batches []v1beta1.ReleaseBatch for _, step := range rollout.Spec.Strategy.Canary.Steps { if step.Replicas == nil { - batches = append(batches, v1alpha1.ReleaseBatch{CanaryReplicas: intstr.FromString(strconv.Itoa(int(*step.Weight)) + "%")}) + batches = append(batches, v1beta1.ReleaseBatch{CanaryReplicas: intstr.FromString(strconv.Itoa(int(*step.Weight)) + "%")}) } else { - batches = append(batches, v1alpha1.ReleaseBatch{CanaryReplicas: *step.Replicas}) + batches = append(batches, v1beta1.ReleaseBatch{CanaryReplicas: *step.Replicas}) } } - br := &v1alpha1.BatchRelease{ + br := &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Namespace: rollout.Namespace, Name: rollout.Name, OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(rollout, rolloutControllerKind)}, }, - Spec: v1alpha1.BatchReleaseSpec{ - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.BatchReleaseSpec{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: rollout.Spec.ObjectRef.WorkloadRef.APIVersion, Kind: rollout.Spec.ObjectRef.WorkloadRef.Kind, Name: rollout.Spec.ObjectRef.WorkloadRef.Name, }, }, - ReleasePlan: v1alpha1.ReleasePlan{ + ReleasePlan: v1beta1.ReleasePlan{ Batches: batches, RolloutID: rolloutID, BatchPartition: utilpointer.Int32Ptr(batch), @@ -373,8 +374,8 @@ func createBatchRelease(rollout *v1alpha1.Rollout, rolloutID string, batch int32 if isRollback { annotations[v1alpha1.RollbackInBatchAnnotation] = rollout.Annotations[v1alpha1.RollbackInBatchAnnotation] } - if style, ok := rollout.Annotations[v1alpha1.RolloutStyleAnnotation]; ok { - annotations[v1alpha1.RolloutStyleAnnotation] = style + if style, ok := rollout.Annotations[v1beta1.RolloutStyleAnnotation]; ok { + annotations[v1beta1.RolloutStyleAnnotation] = style } if len(annotations) > 0 { br.Annotations = annotations @@ -383,7 +384,7 @@ func createBatchRelease(rollout *v1alpha1.Rollout, rolloutID string, batch int32 } func (m *canaryReleaseManager) removeBatchRelease(c *RolloutContext) (bool, error) { - batch := &v1alpha1.BatchRelease{} + batch := &v1beta1.BatchRelease{} err := m.Get(context.TODO(), client.ObjectKey{Namespace: c.Rollout.Namespace, Name: c.Rollout.Name}, batch) if err != nil && errors.IsNotFound(err) { return true, nil @@ -418,7 +419,7 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, // The Completed phase means batchRelease controller has processed all it // should process. If BatchRelease phase is completed, we can do nothing. if br.Spec.ReleasePlan.BatchPartition == nil && - br.Status.Phase == v1alpha1.RolloutPhaseCompleted { + br.Status.Phase == v1beta1.RolloutPhaseCompleted { klog.Infof("rollout(%s/%s) finalizing batchRelease(%s) done", c.Rollout.Namespace, c.Rollout.Name, util.DumpJSON(br.Status)) return true, nil } @@ -431,7 +432,7 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, // - If checkReady is false, finalizing policy must be NOT "WaitResume"; // Otherwise, we should correct it. switch br.Spec.ReleasePlan.FinalizingPolicy { - case v1alpha1.WaitResumeFinalizingPolicyType: + case v1beta1.WaitResumeFinalizingPolicyType: if waitReady { // no need to patch again return false, nil } @@ -443,9 +444,9 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, } // Correct finalizing policy. - policy := v1alpha1.ImmediateFinalizingPolicyType + policy := v1beta1.ImmediateFinalizingPolicyType if waitReady { - policy = v1alpha1.WaitResumeFinalizingPolicyType + policy = v1beta1.WaitResumeFinalizingPolicyType } // Patch BatchPartition and FinalizingPolicy, BatchPartition always patch null here. @@ -458,7 +459,7 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, } // syncBatchRelease sync status of br to canaryStatus, and sync rollout-id of canaryStatus to br. -func (m *canaryReleaseManager) syncBatchRelease(br *v1alpha1.BatchRelease, canaryStatus *v1alpha1.CanaryStatus) error { +func (m *canaryReleaseManager) syncBatchRelease(br *v1beta1.BatchRelease, canaryStatus *v1beta1.CanaryStatus) error { // sync from BatchRelease status to Rollout canaryStatus canaryStatus.CanaryReplicas = br.Status.CanaryStatus.UpdatedReplicas canaryStatus.CanaryReadyReplicas = br.Status.CanaryStatus.UpdatedReadyReplicas diff --git a/pkg/controller/rollout/rollout_canary_test.go b/pkg/controller/rollout/rollout_canary_test.go index 0bf93690..cf77fa0e 100644 --- a/pkg/controller/rollout/rollout_canary_test.go +++ b/pkg/controller/rollout/rollout_canary_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" @@ -40,9 +41,9 @@ func TestRunCanary(t *testing.T) { name string getObj func() ([]*apps.Deployment, []*apps.ReplicaSet) getNetwork func() ([]*corev1.Service, []*netv1.Ingress) - getRollout func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease) - expectStatus func() *v1alpha1.RolloutStatus - expectBr func() *v1alpha1.BatchRelease + getRollout func() (*v1beta1.Rollout, *v1beta1.BatchRelease) + expectStatus func() *v1beta1.RolloutStatus + expectBr func() *v1beta1.BatchRelease }{ { name: "run canary upgrade1", @@ -54,35 +55,35 @@ func TestRunCanary(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" obj.Status.CanaryStatus.StableRevision = "pod-template-hash-v1" obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 1 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" s.CanaryStatus.StableRevision = "pod-template-hash-v1" s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) return s }, - expectBr: func() *v1alpha1.BatchRelease { + expectBr: func() *v1beta1.BatchRelease { br := batchDemo.DeepCopy() - br.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + br.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromInt(1), }, @@ -127,19 +128,19 @@ func TestRunCanary(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" obj.Status.CanaryStatus.StableRevision = "pod-template-hash-v1" obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 1 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) br := batchDemo.DeepCopy() - br.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + br.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromInt(1), }, @@ -154,11 +155,11 @@ func TestRunCanary(t *testing.T) { }, } br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0) - br.Status = v1alpha1.BatchReleaseStatus{ + br.Status = v1beta1.BatchReleaseStatus{ ObservedGeneration: 1, ObservedReleasePlanHash: "6d6a40791161e88ec0483688e951b589a4cbd0bf351974827706b79f99378fd5", - CanaryStatus: v1alpha1.BatchReleaseCanaryStatus{ - CurrentBatchState: v1alpha1.ReadyBatchState, + CanaryStatus: v1beta1.BatchReleaseCanaryStatus{ + CurrentBatchState: v1beta1.ReadyBatchState, CurrentBatch: 0, UpdatedReplicas: 1, UpdatedReadyReplicas: 1, @@ -166,7 +167,7 @@ func TestRunCanary(t *testing.T) { } return obj, br }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -176,15 +177,15 @@ func TestRunCanary(t *testing.T) { s.CanaryStatus.CanaryReplicas = 1 s.CanaryStatus.CanaryReadyReplicas = 1 s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateTrafficRouting - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateTrafficRouting + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) return s }, - expectBr: func() *v1alpha1.BatchRelease { + expectBr: func() *v1beta1.BatchRelease { br := batchDemo.DeepCopy() - br.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + br.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromInt(1), }, @@ -253,7 +254,7 @@ func TestRunCanary(t *testing.T) { cStatus.CanaryStatus.LastUpdateTime = nil cStatus.CanaryStatus.Message = "" } - cond := util.GetRolloutCondition(*cStatus, v1alpha1.RolloutConditionProgressing) + cond := util.GetRolloutCondition(*cStatus, v1beta1.RolloutConditionProgressing) cond.Message = "" util.SetRolloutCondition(cStatus, *cond) expectStatus := cs.expectStatus() @@ -267,12 +268,12 @@ func TestRunCanary(t *testing.T) { func TestRunCanaryPaused(t *testing.T) { cases := []struct { name string - getRollout func() *v1alpha1.Rollout - expectStatus func() *v1alpha1.RolloutStatus + getRollout func() *v1beta1.Rollout + expectStatus func() *v1beta1.RolloutStatus }{ { name: "paused, last step, 60% weight", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -280,10 +281,10 @@ func TestRunCanaryPaused(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 3 obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStatePaused + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStatePaused return obj }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { obj := rolloutDemo.Status.DeepCopy() obj.CanaryStatus.ObservedWorkloadGeneration = 2 obj.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -291,7 +292,7 @@ func TestRunCanaryPaused(t *testing.T) { obj.CanaryStatus.CanaryRevision = "56855c89f9" obj.CanaryStatus.CurrentStepIndex = 3 obj.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" - obj.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStatePaused + obj.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStatePaused return obj }, }, @@ -332,8 +333,8 @@ func TestRunCanaryPaused(t *testing.T) { } } -func checkBatchReleaseEqual(c client.WithWatch, t *testing.T, key client.ObjectKey, expect *v1alpha1.BatchRelease) { - obj := &v1alpha1.BatchRelease{} +func checkBatchReleaseEqual(c client.WithWatch, t *testing.T, key client.ObjectKey, expect *v1beta1.BatchRelease) { + obj := &v1beta1.BatchRelease{} err := c.Get(context.TODO(), key, obj) if err != nil { t.Fatalf("get object failed: %s", err.Error()) diff --git a/pkg/controller/rollout/rollout_controller.go b/pkg/controller/rollout/rollout_controller.go index 4fac2ccd..194ddd06 100755 --- a/pkg/controller/rollout/rollout_controller.go +++ b/pkg/controller/rollout/rollout_controller.go @@ -22,7 +22,7 @@ import ( "sync" "time" - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" "k8s.io/apimachinery/pkg/api/errors" @@ -42,7 +42,7 @@ var ( workloadHandler handler.EventHandler watchedWorkload sync.Map - rolloutControllerKind = v1alpha1.SchemeGroupVersion.WithKind("Rollout") + rolloutControllerKind = v1beta1.SchemeGroupVersion.WithKind("Rollout") ) func init() { @@ -96,7 +96,7 @@ type RolloutReconciler struct { // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile func (r *RolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { // Fetch the Rollout instance - rollout := &v1alpha1.Rollout{} + rollout := &v1beta1.Rollout{} err := r.Get(context.TODO(), req.NamespacedName, rollout) if err != nil { if errors.IsNotFound(err) { @@ -147,11 +147,11 @@ func (r *RolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct var recheckTime *time.Time switch rollout.Status.Phase { - case v1alpha1.RolloutPhaseProgressing: + case v1beta1.RolloutPhaseProgressing: recheckTime, err = r.reconcileRolloutProgressing(rollout, newStatus) - case v1alpha1.RolloutPhaseTerminating: + case v1beta1.RolloutPhaseTerminating: recheckTime, err = r.reconcileRolloutTerminating(rollout, newStatus) - case v1alpha1.RolloutPhaseDisabling: + case v1beta1.RolloutPhaseDisabling: recheckTime, err = r.reconcileRolloutDisabling(rollout, newStatus) } if err != nil { @@ -179,11 +179,11 @@ func (r *RolloutReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } // Watch for changes to rollout - if err = c.Watch(&source.Kind{Type: &v1alpha1.Rollout{}}, &handler.EnqueueRequestForObject{}); err != nil { + if err = c.Watch(&source.Kind{Type: &v1beta1.Rollout{}}, &handler.EnqueueRequestForObject{}); err != nil { return err } // Watch for changes to batchRelease - if err = c.Watch(&source.Kind{Type: &v1alpha1.BatchRelease{}}, &enqueueRequestForBatchRelease{reader: mgr.GetCache()}); err != nil { + if err = c.Watch(&source.Kind{Type: &v1beta1.BatchRelease{}}, &enqueueRequestForBatchRelease{reader: mgr.GetCache()}); err != nil { return err } runtimeController = c diff --git a/pkg/controller/rollout/rollout_controller_test.go b/pkg/controller/rollout/rollout_controller_test.go index 8afa8346..339ae38f 100644 --- a/pkg/controller/rollout/rollout_controller_test.go +++ b/pkg/controller/rollout/rollout_controller_test.go @@ -19,8 +19,9 @@ package rollout import ( "fmt" - kruisev1aplphal "github.com/openkruise/kruise-api/apps/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/util/configuration" apps "k8s.io/api/apps/v1" @@ -38,7 +39,7 @@ import ( var ( scheme *runtime.Scheme - rolloutDemo = &v1alpha1.Rollout{ + rolloutDemo = &v1beta1.Rollout{ ObjectMeta: metav1.ObjectMeta{ Name: "rollout-demo", Labels: map[string]string{}, @@ -46,17 +47,17 @@ var ( util.RolloutHashAnnotation: "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd", }, }, - Spec: v1alpha1.RolloutSpec{ - ObjectRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.RolloutSpec{ + ObjectRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "echoserver", }, }, - Strategy: v1alpha1.RolloutStrategy{ - Canary: &v1alpha1.CanaryStrategy{ - Steps: []v1alpha1.CanaryStep{ + Strategy: v1beta1.RolloutStrategy{ + Canary: &v1beta1.CanaryStrategy{ + Steps: []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(5), @@ -93,12 +94,12 @@ var ( }, }, }, - Status: v1alpha1.RolloutStatus{ - Phase: v1alpha1.RolloutPhaseProgressing, - CanaryStatus: &v1alpha1.CanaryStatus{}, - Conditions: []v1alpha1.RolloutCondition{ + Status: v1beta1.RolloutStatus{ + Phase: v1beta1.RolloutPhaseProgressing, + CanaryStatus: &v1beta1.CanaryStatus{}, + Conditions: []v1beta1.RolloutCondition{ { - Type: v1alpha1.RolloutConditionProgressing, + Type: v1beta1.RolloutConditionProgressing, Reason: v1alpha1.ProgressingReasonInitializing, Status: corev1.ConditionTrue, }, @@ -199,22 +200,22 @@ var ( }, } - batchDemo = &v1alpha1.BatchRelease{ + batchDemo = &v1beta1.BatchRelease{ ObjectMeta: metav1.ObjectMeta{ Name: "rollout-demo", Labels: map[string]string{}, Generation: 1, }, - Spec: v1alpha1.BatchReleaseSpec{ - TargetRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.BatchReleaseSpec{ + TargetRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "echoserver", }, }, }, - Status: v1alpha1.BatchReleaseStatus{}, + Status: v1beta1.BatchReleaseStatus{}, } demoService = corev1.Service{ @@ -352,6 +353,5 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = kruisev1aplphal.AddToScheme(scheme) - _ = v1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } diff --git a/pkg/controller/rollout/rollout_event_handler.go b/pkg/controller/rollout/rollout_event_handler.go index 6dc2930d..321bcda6 100644 --- a/pkg/controller/rollout/rollout_event_handler.go +++ b/pkg/controller/rollout/rollout_event_handler.go @@ -19,7 +19,7 @@ package rollout import ( "context" - rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutv1beta1 "github.com/openkruise/rollouts/api/v1beta1" utilclient "github.com/openkruise/rollouts/pkg/util/client" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -77,8 +77,8 @@ func (w *enqueueRequestForWorkload) handleEvent(q workqueue.RateLimitingInterfac } } -func (w *enqueueRequestForWorkload) getRolloutForWorkload(key types.NamespacedName, gvk schema.GroupVersionKind) (*rolloutv1alpha1.Rollout, error) { - rList := &rolloutv1alpha1.RolloutList{} +func (w *enqueueRequestForWorkload) getRolloutForWorkload(key types.NamespacedName, gvk schema.GroupVersionKind) (*rolloutv1beta1.Rollout, error) { + rList := &rolloutv1beta1.RolloutList{} if err := w.reader.List(context.TODO(), rList, client.InNamespace(key.Namespace), utilclient.DisableDeepCopy); err != nil { klog.Errorf("List WorkloadSpread failed: %s", err.Error()) return nil, err diff --git a/pkg/controller/rollout/rollout_progressing.go b/pkg/controller/rollout/rollout_progressing.go index 9635d6d0..a224735e 100644 --- a/pkg/controller/rollout/rollout_progressing.go +++ b/pkg/controller/rollout/rollout_progressing.go @@ -23,6 +23,7 @@ import ( "time" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" corev1 "k8s.io/api/core/v1" @@ -37,8 +38,8 @@ import ( var defaultGracePeriodSeconds int32 = 3 type RolloutContext struct { - Rollout *v1alpha1.Rollout - NewStatus *v1alpha1.RolloutStatus + Rollout *v1beta1.Rollout + NewStatus *v1beta1.RolloutStatus // related workload Workload *util.Workload // reconcile RequeueAfter recheckTime @@ -48,8 +49,8 @@ type RolloutContext struct { } // parameter1 retryReconcile, parameter2 error -func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) (*time.Time, error) { - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) +func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1beta1.Rollout, newStatus *v1beta1.RolloutStatus) (*time.Time, error) { + cond := util.GetRolloutCondition(rollout.Status, v1beta1.RolloutConditionProgressing) klog.Infof("reconcile rollout(%s/%s) progressing action...", rollout.Namespace, rollout.Name) workload, err := r.finder.GetWorkloadForRef(rollout) if err != nil { @@ -67,14 +68,14 @@ func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1alpha1.Rollou case v1alpha1.ProgressingReasonInitializing: klog.Infof("rollout(%s/%s) is Progressing, and in reason(%s)", rollout.Namespace, rollout.Name, cond.Reason) // new canaryStatus - newStatus.CanaryStatus = &v1alpha1.CanaryStatus{ + newStatus.CanaryStatus = &v1beta1.CanaryStatus{ ObservedWorkloadGeneration: rolloutContext.Workload.Generation, RolloutHash: rolloutContext.Rollout.Annotations[util.RolloutHashAnnotation], ObservedRolloutID: getRolloutID(rolloutContext.Workload), StableRevision: rolloutContext.Workload.StableRevision, CanaryRevision: rolloutContext.Workload.CanaryRevision, CurrentStepIndex: 1, - CurrentStepState: v1alpha1.CanaryStepStateUpgrade, + CurrentStepState: v1beta1.CanaryStepStateUpgrade, LastUpdateTime: &metav1.Time{Time: time.Now()}, } done, err := r.doProgressingInitializing(rolloutContext) @@ -142,7 +143,7 @@ func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1alpha1.Rollou case v1alpha1.ProgressingReasonCompleted: // rollout phase from progressing to healthy klog.Infof("rollout(%s/%s) phase is from progressing to healthy", rollout.Namespace, rollout.Name) - newStatus.Phase = v1alpha1.RolloutPhaseHealthy + newStatus.Phase = v1beta1.RolloutPhaseHealthy } return rolloutContext.RecheckTime, nil @@ -160,7 +161,7 @@ func (r *RolloutReconciler) doProgressingInitializing(c *RolloutContext) (bool, // but in many scenarios the user may modify the workload and rollout spec at the same time, // and there is a possibility that the workload is released first, and due to some network or other reasons the rollout spec is delayed by a few seconds, // so this is mainly compatible with this scenario. - cond := util.GetRolloutCondition(*c.NewStatus, v1alpha1.RolloutConditionProgressing) + cond := util.GetRolloutCondition(*c.NewStatus, v1beta1.RolloutConditionProgressing) if verifyTime := cond.LastUpdateTime.Add(time.Second * time.Duration(defaultGracePeriodSeconds)); verifyTime.After(time.Now()) { klog.Infof("verify rollout(%s/%s) TrafficRouting, and wait a moment", c.Rollout.Namespace, c.Rollout.Name) return false, nil @@ -200,7 +201,7 @@ func (r *RolloutReconciler) doProgressingInRolling(c *RolloutContext) error { return r.handleNormalRolling(c) } -func (r *RolloutReconciler) handleRolloutPaused(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) error { +func (r *RolloutReconciler) handleRolloutPaused(rollout *v1beta1.Rollout, newStatus *v1beta1.RolloutStatus) error { klog.Infof("rollout(%s/%s) is Progressing, but paused", rollout.Namespace, rollout.Name) progressingStateTransition(newStatus, corev1.ConditionTrue, v1alpha1.ProgressingReasonPaused, "Rollout has been paused, you can resume it by kube-cli") return nil @@ -228,7 +229,7 @@ func (r *RolloutReconciler) handleContinuousRelease(c *RolloutContext) error { return nil } -func (r *RolloutReconciler) handleRollbackDirectly(rollout *v1alpha1.Rollout, workload *util.Workload, newStatus *v1alpha1.RolloutStatus) error { +func (r *RolloutReconciler) handleRollbackDirectly(rollout *v1beta1.Rollout, workload *util.Workload, newStatus *v1beta1.RolloutStatus) error { newStatus.CanaryStatus.CanaryRevision = workload.CanaryRevision r.Recorder.Eventf(rollout, corev1.EventTypeNormal, "Progressing", "workload has been rollback, then rollout is canceled") klog.Infof("rollout(%s/%s) workload has been rollback directly, then rollout canceled", rollout.Namespace, rollout.Name) @@ -236,11 +237,11 @@ func (r *RolloutReconciler) handleRollbackDirectly(rollout *v1alpha1.Rollout, wo return nil } -func (r *RolloutReconciler) handleRollbackInBatches(rollout *v1alpha1.Rollout, workload *util.Workload, newStatus *v1alpha1.RolloutStatus) error { +func (r *RolloutReconciler) handleRollbackInBatches(rollout *v1beta1.Rollout, workload *util.Workload, newStatus *v1beta1.RolloutStatus) error { // restart from the beginning newStatus.CanaryStatus.CurrentStepIndex = 1 newStatus.CanaryStatus.CanaryRevision = workload.CanaryRevision - newStatus.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade + newStatus.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade newStatus.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} newStatus.CanaryStatus.RolloutHash = rollout.Annotations[util.RolloutHashAnnotation] klog.Infof("rollout(%s/%s) workload has been rollback in batches, then restart from beginning", rollout.Namespace, rollout.Name) @@ -255,7 +256,7 @@ func (r *RolloutReconciler) handleRolloutPlanChanged(c *RolloutContext) error { } // canary step configuration change causes current step index change c.NewStatus.CanaryStatus.CurrentStepIndex = newStepIndex - c.NewStatus.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade + c.NewStatus.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade c.NewStatus.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} c.NewStatus.CanaryStatus.RolloutHash = c.Rollout.Annotations[util.RolloutHashAnnotation] klog.Infof("rollout(%s/%s) canary step configuration change, and stepIndex(%d) state(%s)", @@ -265,7 +266,7 @@ func (r *RolloutReconciler) handleRolloutPlanChanged(c *RolloutContext) error { func (r *RolloutReconciler) handleNormalRolling(c *RolloutContext) error { // check if canary is done - if c.NewStatus.CanaryStatus.CurrentStepState == v1alpha1.CanaryStepStateCompleted { + if c.NewStatus.CanaryStatus.CurrentStepState == v1beta1.CanaryStepStateCompleted { klog.Infof("rollout(%s/%s) progressing rolling done", c.Rollout.Namespace, c.Rollout.Name) progressingStateTransition(c.NewStatus, corev1.ConditionTrue, v1alpha1.ProgressingReasonFinalising, "Rollout has been completed and some closing work is being done") return nil @@ -330,27 +331,27 @@ func (r *RolloutReconciler) finalizeTrafficRouting(namespace, name, tr string) e *********************************************************************** */ -func isRolloutPaused(rollout *v1alpha1.Rollout) bool { +func isRolloutPaused(rollout *v1beta1.Rollout) bool { return rollout.Spec.Strategy.Paused } -func isRolloutPlanChanged(rollout *v1alpha1.Rollout) bool { +func isRolloutPlanChanged(rollout *v1beta1.Rollout) bool { status := &rollout.Status return status.CanaryStatus.RolloutHash != "" && status.CanaryStatus.RolloutHash != rollout.Annotations[util.RolloutHashAnnotation] } -func isContinuousRelease(rollout *v1alpha1.Rollout, workload *util.Workload) bool { +func isContinuousRelease(rollout *v1beta1.Rollout, workload *util.Workload) bool { status := &rollout.Status return status.CanaryStatus.CanaryRevision != "" && workload.CanaryRevision != status.CanaryStatus.CanaryRevision && !workload.IsInRollback } -func isRollingBackDirectly(rollout *v1alpha1.Rollout, workload *util.Workload) bool { +func isRollingBackDirectly(rollout *v1beta1.Rollout, workload *util.Workload) bool { status := &rollout.Status inBatch := util.IsRollbackInBatchPolicy(rollout, workload.Labels) return workload.IsInRollback && workload.CanaryRevision != status.CanaryStatus.CanaryRevision && !inBatch } -func isRollingBackInBatches(rollout *v1alpha1.Rollout, workload *util.Workload) bool { +func isRollingBackInBatches(rollout *v1beta1.Rollout, workload *util.Workload) bool { status := &rollout.Status inBatch := util.IsRollbackInBatchPolicy(rollout, workload.Labels) return workload.IsInRollback && workload.CanaryRevision != status.CanaryStatus.CanaryRevision && inBatch @@ -425,10 +426,10 @@ func (r *RolloutReconciler) doFinalising(c *RolloutContext) (bool, error) { return true, nil } -func progressingStateTransition(status *v1alpha1.RolloutStatus, condStatus corev1.ConditionStatus, reason, message string) { - cond := util.GetRolloutCondition(*status, v1alpha1.RolloutConditionProgressing) +func progressingStateTransition(status *v1beta1.RolloutStatus, condStatus corev1.ConditionStatus, reason, message string) { + cond := util.GetRolloutCondition(*status, v1beta1.RolloutConditionProgressing) if cond == nil { - cond = util.NewRolloutCondition(v1alpha1.RolloutConditionProgressing, condStatus, reason, message) + cond = util.NewRolloutCondition(v1beta1.RolloutConditionProgressing, condStatus, reason, message) } else { cond.Status = condStatus cond.Reason = reason @@ -440,10 +441,10 @@ func progressingStateTransition(status *v1alpha1.RolloutStatus, condStatus corev status.Message = cond.Message } -func setRolloutSucceededCondition(status *v1alpha1.RolloutStatus, condStatus corev1.ConditionStatus) { - cond := util.GetRolloutCondition(*status, v1alpha1.RolloutConditionSucceeded) +func setRolloutSucceededCondition(status *v1beta1.RolloutStatus, condStatus corev1.ConditionStatus) { + cond := util.GetRolloutCondition(*status, v1beta1.RolloutConditionSucceeded) if cond == nil { - cond = util.NewRolloutCondition(v1alpha1.RolloutConditionSucceeded, condStatus, "", "") + cond = util.NewRolloutCondition(v1beta1.RolloutConditionSucceeded, condStatus, "", "") } else { cond.Status = condStatus } diff --git a/pkg/controller/rollout/rollout_progressing_test.go b/pkg/controller/rollout/rollout_progressing_test.go index c1443b0e..3e316f73 100644 --- a/pkg/controller/rollout/rollout_progressing_test.go +++ b/pkg/controller/rollout/rollout_progressing_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" apps "k8s.io/api/apps/v1" @@ -40,8 +41,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { name string getObj func() ([]*apps.Deployment, []*apps.ReplicaSet) getNetwork func() ([]*corev1.Service, []*netv1.Ingress) - getRollout func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) - expectStatus func() *v1alpha1.RolloutStatus + getRollout func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) + expectStatus func() *v1beta1.RolloutStatus expectTr func() *v1alpha1.TrafficRouting }{ { @@ -54,19 +55,19 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Annotations[v1alpha1.TrafficRoutingAnnotation] = "tr-demo" return obj, nil, demoTR.DeepCopy() }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" s.CanaryStatus.StableRevision = "pod-template-hash-v1" s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade return s }, expectTr: func() *v1alpha1.TrafficRouting { @@ -85,21 +86,21 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() tr := demoTR.DeepCopy() tr.Finalizers = []string{util.ProgressingRolloutFinalizer(rolloutDemo.Name)} return obj, nil, tr }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" s.CanaryStatus.StableRevision = "pod-template-hash-v1" s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) return s @@ -132,20 +133,20 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" obj.Status.CanaryStatus.StableRevision = "pod-template-hash-v1" obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 1 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -153,8 +154,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) return s @@ -187,7 +188,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -195,13 +196,13 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" obj.Status.CanaryStatus.CurrentStepIndex = 4 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -209,8 +210,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 4 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond) @@ -235,7 +236,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Annotations[v1alpha1.TrafficRoutingAnnotation] = "tr-demo" obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 @@ -244,13 +245,13 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" obj.Status.CanaryStatus.CurrentStepIndex = 4 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(&obj.Status, *cond) br := batchDemo.DeepCopy() - br.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + br.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromInt(1), }, @@ -259,7 +260,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { tr.Finalizers = []string{util.ProgressingRolloutFinalizer(rolloutDemo.Name)} return obj, br, tr }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -267,8 +268,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 4 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond) @@ -297,7 +298,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -305,21 +306,21 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" obj.Status.CanaryStatus.CurrentStepIndex = 4 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(&obj.Status, *cond) br := batchDemo.DeepCopy() - br.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + br.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromInt(1), }, } - br.Status.Phase = v1alpha1.RolloutPhaseCompleted + br.Status.Phase = v1beta1.RolloutPhaseCompleted return obj, br, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -327,8 +328,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 4 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond2 := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond2 := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond2.Reason = v1alpha1.ProgressingReasonFinalising cond2.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond2) @@ -353,7 +354,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -361,14 +362,14 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" obj.Status.CanaryStatus.CurrentStepIndex = 4 - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -376,12 +377,12 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "56855c89f9" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 4 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted - cond2 := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted + cond2 := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond2.Reason = v1alpha1.ProgressingReasonCompleted cond2.Status = corev1.ConditionFalse util.SetRolloutCondition(s, *cond2) - cond1 := util.NewRolloutCondition(v1alpha1.RolloutConditionSucceeded, corev1.ConditionTrue, "", "") + cond1 := util.NewRolloutCondition(v1beta1.RolloutConditionSucceeded, corev1.ConditionTrue, "", "") cond1.LastUpdateTime = metav1.Time{} cond1.LastTransitionTime = metav1.Time{} util.SetRolloutCondition(s, *cond1) @@ -416,7 +417,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -424,13 +425,13 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 1 obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -438,8 +439,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "5d48f79ff8" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonCancelling util.SetRolloutCondition(s, *cond) return s @@ -473,7 +474,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -481,13 +482,13 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryRevision = "56855c89f9" obj.Status.CanaryStatus.CurrentStepIndex = 1 obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus.ObservedWorkloadGeneration = 2 s.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -495,8 +496,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.CanaryRevision = "5d48f79ff8" s.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" s.CanaryStatus.CurrentStepIndex = 1 - s.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonCancelling util.SetRolloutCondition(s, *cond) return s @@ -530,7 +531,7 @@ func TestReconcileRolloutProgressing(t *testing.T) { getNetwork: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *v1alpha1.BatchRelease, *v1alpha1.TrafficRouting) { + getRollout: func() (*v1beta1.Rollout, *v1beta1.BatchRelease, *v1alpha1.TrafficRouting) { obj := rolloutDemo.DeepCopy() obj.Status.CanaryStatus.ObservedWorkloadGeneration = 2 obj.Status.CanaryStatus.RolloutHash = "f55bvd874d5f2fzvw46bv966x4bwbdv4wx6bd9f7b46ww788954b8z8w29b7wxfd" @@ -540,16 +541,16 @@ func TestReconcileRolloutProgressing(t *testing.T) { obj.Status.CanaryStatus.CanaryReplicas = 5 obj.Status.CanaryStatus.CanaryReadyReplicas = 3 obj.Status.CanaryStatus.PodTemplateHash = "pod-template-hash-v2" - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateUpgrade - cond := util.GetRolloutCondition(obj.Status, v1alpha1.RolloutConditionProgressing) + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade + cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(&obj.Status, *cond) return obj, nil, nil }, - expectStatus: func() *v1alpha1.RolloutStatus { + expectStatus: func() *v1beta1.RolloutStatus { s := rolloutDemo.Status.DeepCopy() s.CanaryStatus = nil - cond := util.GetRolloutCondition(*s, v1alpha1.RolloutConditionProgressing) + cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInitializing util.SetRolloutCondition(s, *cond) return s @@ -615,8 +616,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { } } -func checkRolloutEqual(c client.WithWatch, t *testing.T, key client.ObjectKey, expect *v1alpha1.RolloutStatus) { - obj := &v1alpha1.Rollout{} +func checkRolloutEqual(c client.WithWatch, t *testing.T, key client.ObjectKey, expect *v1beta1.RolloutStatus) { + obj := &v1beta1.Rollout{} err := c.Get(context.TODO(), key, obj) if err != nil { t.Fatalf("get object failed: %s", err.Error()) @@ -626,12 +627,12 @@ func checkRolloutEqual(c client.WithWatch, t *testing.T, key client.ObjectKey, e if cStatus.CanaryStatus != nil { cStatus.CanaryStatus.LastUpdateTime = nil } - cond1 := util.GetRolloutCondition(*cStatus, v1alpha1.RolloutConditionProgressing) + cond1 := util.GetRolloutCondition(*cStatus, v1beta1.RolloutConditionProgressing) cond1.Message = "" util.SetRolloutCondition(cStatus, *cond1) - cond2 := util.GetRolloutCondition(*cStatus, v1alpha1.RolloutConditionSucceeded) + cond2 := util.GetRolloutCondition(*cStatus, v1beta1.RolloutConditionSucceeded) if cond2 != nil { - util.RemoveRolloutCondition(cStatus, v1alpha1.RolloutConditionSucceeded) + util.RemoveRolloutCondition(cStatus, v1beta1.RolloutConditionSucceeded) cond2.LastUpdateTime = metav1.Time{} cond2.LastTransitionTime = metav1.Time{} util.SetRolloutCondition(cStatus, *cond2) @@ -645,8 +646,8 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { cases := []struct { name string getObj func() (*apps.Deployment, *apps.ReplicaSet) - getRollout func() *v1alpha1.Rollout - getBatchRelease func() *v1alpha1.BatchRelease + getRollout func() *v1beta1.Rollout + getBatchRelease func() *v1beta1.BatchRelease expectStepIndex int32 }{ { @@ -655,9 +656,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { obj := deploymentDemo.DeepCopy() return obj, rsDemo.DeepCopy() }, - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(20), @@ -676,9 +677,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { } return obj }, - getBatchRelease: func() *v1alpha1.BatchRelease { + getBatchRelease: func() *v1beta1.BatchRelease { obj := batchDemo.DeepCopy() - obj.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + obj.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("40%"), }, @@ -700,9 +701,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { obj := deploymentDemo.DeepCopy() return obj, rsDemo.DeepCopy() }, - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(20), @@ -721,9 +722,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { } return obj }, - getBatchRelease: func() *v1alpha1.BatchRelease { + getBatchRelease: func() *v1beta1.BatchRelease { obj := batchDemo.DeepCopy() - obj.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + obj.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("40%"), }, @@ -745,9 +746,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { obj := deploymentDemo.DeepCopy() return obj, rsDemo.DeepCopy() }, - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(40), @@ -766,9 +767,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { } return obj }, - getBatchRelease: func() *v1alpha1.BatchRelease { + getBatchRelease: func() *v1beta1.BatchRelease { obj := batchDemo.DeepCopy() - obj.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + obj.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("20%"), }, @@ -790,9 +791,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { obj := deploymentDemo.DeepCopy() return obj, rsDemo.DeepCopy() }, - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(10), @@ -811,9 +812,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { } return obj }, - getBatchRelease: func() *v1alpha1.BatchRelease { + getBatchRelease: func() *v1beta1.BatchRelease { obj := batchDemo.DeepCopy() - obj.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + obj.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("20%"), }, @@ -835,9 +836,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { obj := deploymentDemo.DeepCopy() return obj, rsDemo.DeepCopy() }, - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(2), @@ -859,9 +860,9 @@ func TestReCalculateCanaryStepIndex(t *testing.T) { } return obj }, - getBatchRelease: func() *v1alpha1.BatchRelease { + getBatchRelease: func() *v1beta1.BatchRelease { obj := batchDemo.DeepCopy() - obj.Spec.ReleasePlan.Batches = []v1alpha1.ReleaseBatch{ + obj.Spec.ReleasePlan.Batches = []v1beta1.ReleaseBatch{ { CanaryReplicas: intstr.FromString("10%"), }, diff --git a/pkg/controller/rollout/rollout_status.go b/pkg/controller/rollout/rollout_status.go index 161523cf..8165bcc4 100755 --- a/pkg/controller/rollout/rollout_status.go +++ b/pkg/controller/rollout/rollout_status.go @@ -23,6 +23,7 @@ import ( "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/runtime/schema" @@ -34,7 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) -func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (retry bool, newStatus *v1alpha1.RolloutStatus, err error) { +func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1beta1.Rollout) (retry bool, newStatus *v1beta1.RolloutStatus, err error) { // hash rollout if err = r.calculateRolloutHash(rollout); err != nil { return false, nil, err @@ -43,27 +44,27 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r newStatus.ObservedGeneration = rollout.GetGeneration() // delete rollout CRD if !rollout.DeletionTimestamp.IsZero() { - if newStatus.Phase != v1alpha1.RolloutPhaseTerminating { - newStatus.Phase = v1alpha1.RolloutPhaseTerminating - cond := util.NewRolloutCondition(v1alpha1.RolloutConditionTerminating, corev1.ConditionTrue, v1alpha1.TerminatingReasonInTerminating, "Rollout is in terminating") + if newStatus.Phase != v1beta1.RolloutPhaseTerminating { + newStatus.Phase = v1beta1.RolloutPhaseTerminating + cond := util.NewRolloutCondition(v1beta1.RolloutConditionTerminating, corev1.ConditionTrue, v1alpha1.TerminatingReasonInTerminating, "Rollout is in terminating") util.SetRolloutCondition(newStatus, *cond) } return false, newStatus, nil } - if rollout.Spec.Disabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabling { + if rollout.Spec.Disabled && newStatus.Phase != v1beta1.RolloutPhaseDisabled && newStatus.Phase != v1beta1.RolloutPhaseDisabling { // if rollout in progressing, indicates a working rollout is disabled, then the rollout should be finalized - if newStatus.Phase == v1alpha1.RolloutPhaseProgressing { - newStatus.Phase = v1alpha1.RolloutPhaseDisabling + if newStatus.Phase == v1beta1.RolloutPhaseProgressing { + newStatus.Phase = v1beta1.RolloutPhaseDisabling newStatus.Message = "Disabling rollout, release resources" } else { - newStatus.Phase = v1alpha1.RolloutPhaseDisabled + newStatus.Phase = v1beta1.RolloutPhaseDisabled newStatus.Message = "Rollout is disabled" } } if newStatus.Phase == "" { - newStatus.Phase = v1alpha1.RolloutPhaseInitial + newStatus.Phase = v1beta1.RolloutPhaseInitial } // get ref workload workload, err := r.finder.GetWorkloadForRef(rollout) @@ -72,9 +73,9 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r return false, nil, err } else if workload == nil { if !rollout.Spec.Disabled { - newStatus = &v1alpha1.RolloutStatus{ + newStatus = &v1beta1.RolloutStatus{ ObservedGeneration: rollout.Generation, - Phase: v1alpha1.RolloutPhaseInitial, + Phase: v1beta1.RolloutPhaseInitial, Message: "Workload Not Found", } klog.Infof("rollout(%s/%s) workload not found, and reset status be Initial", rollout.Namespace, rollout.Name) @@ -97,18 +98,18 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r } switch newStatus.Phase { - case v1alpha1.RolloutPhaseInitial: - klog.Infof("rollout(%s/%s) status phase from(%s) -> to(%s)", rollout.Namespace, rollout.Name, v1alpha1.RolloutPhaseInitial, v1alpha1.RolloutPhaseHealthy) - newStatus.Phase = v1alpha1.RolloutPhaseHealthy + case v1beta1.RolloutPhaseInitial: + klog.Infof("rollout(%s/%s) status phase from(%s) -> to(%s)", rollout.Namespace, rollout.Name, v1beta1.RolloutPhaseInitial, v1beta1.RolloutPhaseHealthy) + newStatus.Phase = v1beta1.RolloutPhaseHealthy newStatus.Message = "rollout is healthy" - case v1alpha1.RolloutPhaseHealthy: + case v1beta1.RolloutPhaseHealthy: // workload released, entering the rollout progressing phase if workload.InRolloutProgressing { - klog.Infof("rollout(%s/%s) status phase from(%s) -> to(%s)", rollout.Namespace, rollout.Name, v1alpha1.RolloutPhaseHealthy, v1alpha1.RolloutPhaseProgressing) - newStatus.Phase = v1alpha1.RolloutPhaseProgressing - cond := util.NewRolloutCondition(v1alpha1.RolloutConditionProgressing, corev1.ConditionTrue, v1alpha1.ProgressingReasonInitializing, "Rollout is in Progressing") + klog.Infof("rollout(%s/%s) status phase from(%s) -> to(%s)", rollout.Namespace, rollout.Name, v1beta1.RolloutPhaseHealthy, v1beta1.RolloutPhaseProgressing) + newStatus.Phase = v1beta1.RolloutPhaseProgressing + cond := util.NewRolloutCondition(v1beta1.RolloutConditionProgressing, corev1.ConditionTrue, v1alpha1.ProgressingReasonInitializing, "Rollout is in Progressing") util.SetRolloutCondition(newStatus, *cond) - util.RemoveRolloutCondition(newStatus, v1alpha1.RolloutConditionSucceeded) + util.RemoveRolloutCondition(newStatus, v1beta1.RolloutConditionSucceeded) } else if newStatus.CanaryStatus == nil { // The following logic is to make PaaS be able to judge whether the rollout is ready // at the first deployment of the Rollout/Workload. For example: generally, a PaaS @@ -123,21 +124,21 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r // and PaaS platform cannot judge whether the deployment is completed base on the code above. So we have // to update the status just like the rollout was completed. - newStatus.CanaryStatus = &v1alpha1.CanaryStatus{ + newStatus.CanaryStatus = &v1beta1.CanaryStatus{ ObservedRolloutID: getRolloutID(workload), ObservedWorkloadGeneration: workload.Generation, PodTemplateHash: workload.PodTemplateHash, CanaryRevision: workload.CanaryRevision, StableRevision: workload.StableRevision, CurrentStepIndex: int32(len(rollout.Spec.Strategy.Canary.Steps)), - CurrentStepState: v1alpha1.CanaryStepStateCompleted, + CurrentStepState: v1beta1.CanaryStepStateCompleted, RolloutHash: rollout.Annotations[util.RolloutHashAnnotation], } newStatus.Message = "workload deployment is completed" } - case v1alpha1.RolloutPhaseDisabled: + case v1beta1.RolloutPhaseDisabled: if !rollout.Spec.Disabled { - newStatus.Phase = v1alpha1.RolloutPhaseHealthy + newStatus.Phase = v1beta1.RolloutPhaseHealthy newStatus.Message = "rollout is healthy" } } @@ -146,13 +147,13 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r // rolloutHash mainly records the step batch information, when the user step changes, // the current batch can be recalculated -func (r *RolloutReconciler) calculateRolloutHash(rollout *v1alpha1.Rollout) error { +func (r *RolloutReconciler) calculateRolloutHash(rollout *v1beta1.Rollout) error { canary := rollout.Spec.Strategy.Canary.DeepCopy() canary.FailureThreshold = nil canary.Steps = nil for i := range rollout.Spec.Strategy.Canary.Steps { step := rollout.Spec.Strategy.Canary.Steps[i].DeepCopy() - step.Pause = v1alpha1.RolloutPause{} + step.Pause = v1beta1.RolloutPause{} canary.Steps = append(canary.Steps, *step) } data := util.DumpJSON(canary) @@ -176,7 +177,7 @@ func (r *RolloutReconciler) calculateRolloutHash(rollout *v1alpha1.Rollout) erro return nil } -func (r *RolloutReconciler) updateRolloutStatusInternal(rollout *v1alpha1.Rollout, newStatus v1alpha1.RolloutStatus) error { +func (r *RolloutReconciler) updateRolloutStatusInternal(rollout *v1beta1.Rollout, newStatus v1beta1.RolloutStatus) error { if reflect.DeepEqual(rollout.Status, newStatus) { return nil } @@ -197,8 +198,8 @@ func (r *RolloutReconciler) updateRolloutStatusInternal(rollout *v1alpha1.Rollou return nil } -func (r *RolloutReconciler) reconcileRolloutTerminating(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) (*time.Time, error) { - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionTerminating) +func (r *RolloutReconciler) reconcileRolloutTerminating(rollout *v1beta1.Rollout, newStatus *v1beta1.RolloutStatus) (*time.Time, error) { + cond := util.GetRolloutCondition(rollout.Status, v1beta1.RolloutConditionTerminating) if cond.Reason == v1alpha1.TerminatingReasonCompleted { return nil, nil } @@ -225,7 +226,7 @@ func (r *RolloutReconciler) reconcileRolloutTerminating(rollout *v1alpha1.Rollou return c.RecheckTime, nil } -func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) (*time.Time, error) { +func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1beta1.Rollout, newStatus *v1beta1.RolloutStatus) (*time.Time, error) { workload, err := r.finder.GetWorkloadForRef(rollout) if err != nil { klog.Errorf("rollout(%s/%s) get workload failed: %s", rollout.Namespace, rollout.Name, err.Error()) @@ -237,7 +238,7 @@ func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout, return nil, err } else if done { klog.Infof("rollout(%s/%s) is disabled", rollout.Namespace, rollout.Name) - newStatus.Phase = v1alpha1.RolloutPhaseDisabled + newStatus.Phase = v1beta1.RolloutPhaseDisabled newStatus.Message = "Rollout is disabled" } else { // Incomplete, recheck @@ -248,7 +249,7 @@ func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout, return c.RecheckTime, nil } -func (r *RolloutReconciler) patchWorkloadRolloutWebhookLabel(rollout *v1alpha1.Rollout) error { +func (r *RolloutReconciler) patchWorkloadRolloutWebhookLabel(rollout *v1beta1.Rollout) error { // get ref workload workload, err := r.finder.GetWorkloadForRef(rollout) if err != nil { @@ -285,10 +286,10 @@ func (r *RolloutReconciler) patchWorkloadRolloutWebhookLabel(rollout *v1alpha1.R } // handle adding and handle finalizer logic, it turns if we should continue to reconcile -func (r *RolloutReconciler) handleFinalizer(rollout *v1alpha1.Rollout) error { +func (r *RolloutReconciler) handleFinalizer(rollout *v1beta1.Rollout) error { // delete rollout crd, remove finalizer if !rollout.DeletionTimestamp.IsZero() { - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionTerminating) + cond := util.GetRolloutCondition(rollout.Status, v1beta1.RolloutConditionTerminating) if cond != nil && cond.Reason == v1alpha1.TerminatingReasonCompleted { // Completed if controllerutil.ContainsFinalizer(rollout, util.KruiseRolloutFinalizer) { @@ -318,7 +319,7 @@ func (r *RolloutReconciler) handleFinalizer(rollout *v1alpha1.Rollout) error { func getRolloutID(workload *util.Workload) string { if workload != nil { - return workload.Labels[v1alpha1.RolloutIDLabel] + return workload.Labels[v1beta1.RolloutIDLabel] } return "" } diff --git a/pkg/controller/rollout/rollout_status_test.go b/pkg/controller/rollout/rollout_status_test.go index 62c75c10..96e27290 100755 --- a/pkg/controller/rollout/rollout_status_test.go +++ b/pkg/controller/rollout/rollout_status_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" "k8s.io/apimachinery/pkg/util/intstr" @@ -32,12 +33,12 @@ import ( func TestCalculateRolloutHash(t *testing.T) { cases := []struct { name string - getRollout func() *v1alpha1.Rollout + getRollout func() *v1beta1.Rollout expectHash func() string }{ { name: "hash, test1", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() return obj }, @@ -47,11 +48,11 @@ func TestCalculateRolloutHash(t *testing.T) { }, { name: "hash, test2", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() obj.Spec.Strategy.Paused = true obj.Spec.Strategy.Canary.FailureThreshold = &intstr.IntOrString{Type: intstr.Int} - obj.Spec.Strategy.Canary.Steps[0].Pause = v1alpha1.RolloutPause{Duration: utilpointer.Int32(10)} + obj.Spec.Strategy.Canary.Steps[0].Pause = v1beta1.RolloutPause{Duration: utilpointer.Int32(10)} return obj }, expectHash: func() string { @@ -60,9 +61,9 @@ func TestCalculateRolloutHash(t *testing.T) { }, { name: "hash, test3", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ + obj.Spec.Strategy.Canary.Steps = []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(50), @@ -109,41 +110,41 @@ func TestCalculateRolloutHash(t *testing.T) { func TestCalculateRolloutStatus(t *testing.T) { cases := []struct { name string - getRollout func() *v1alpha1.Rollout - expectPhase v1alpha1.RolloutPhase + getRollout func() *v1beta1.Rollout + expectPhase v1beta1.RolloutPhase }{ { name: "apply an enabled rollout", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() obj.Name = "Rollout-demo1" - obj.Status = v1alpha1.RolloutStatus{} + obj.Status = v1beta1.RolloutStatus{} obj.Spec.Disabled = false return obj }, - expectPhase: v1alpha1.RolloutPhaseInitial, + expectPhase: v1beta1.RolloutPhaseInitial, }, { name: "disable an working rollout", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() obj.Name = "Rollout-demo1" - obj.Status = v1alpha1.RolloutStatus{} + obj.Status = v1beta1.RolloutStatus{} obj.Spec.Disabled = true return obj }, - expectPhase: v1alpha1.RolloutPhaseDisabled, + expectPhase: v1beta1.RolloutPhaseDisabled, }, { name: "enable an disabled rollout", - getRollout: func() *v1alpha1.Rollout { + getRollout: func() *v1beta1.Rollout { obj := rolloutDemo.DeepCopy() obj.Name = "Rollout-demo2" - obj.Status = v1alpha1.RolloutStatus{} + obj.Status = v1beta1.RolloutStatus{} obj.Spec.Disabled = false return obj }, - expectPhase: v1alpha1.RolloutPhaseInitial, + expectPhase: v1beta1.RolloutPhaseInitial, }, } diff --git a/pkg/controller/rollouthistory/rollouthistory_controller_test.go b/pkg/controller/rollouthistory/rollouthistory_controller_test.go index 52a73bd0..980a4088 100644 --- a/pkg/controller/rollouthistory/rollouthistory_controller_test.go +++ b/pkg/controller/rollouthistory/rollouthistory_controller_test.go @@ -36,6 +36,7 @@ import ( "github.com/openkruise/kruise-api/apps/pub" kruisev1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" ) @@ -43,7 +44,7 @@ func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) _ = kruisev1alpha1.AddToScheme(scheme) - _ = rolloutv1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) _ = v1alpha2.AddToScheme(scheme) } diff --git a/pkg/controller/trafficrouting/trafficrouting_controller_test.go b/pkg/controller/trafficrouting/trafficrouting_controller_test.go index 6485a3f2..2e095b12 100644 --- a/pkg/controller/trafficrouting/trafficrouting_controller_test.go +++ b/pkg/controller/trafficrouting/trafficrouting_controller_test.go @@ -22,7 +22,7 @@ import ( "reflect" "testing" - kruisev1aplphal "github.com/openkruise/kruise-api/apps/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" "github.com/openkruise/rollouts/api/v1alpha1" "github.com/openkruise/rollouts/pkg/trafficrouting" "github.com/openkruise/rollouts/pkg/util" @@ -184,8 +184,7 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = kruisev1aplphal.AddToScheme(scheme) - _ = v1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } func TestTrafficRoutingTest(t *testing.T) { diff --git a/pkg/trafficrouting/manager_test.go b/pkg/trafficrouting/manager_test.go index 720f767a..b18f5658 100644 --- a/pkg/trafficrouting/manager_test.go +++ b/pkg/trafficrouting/manager_test.go @@ -23,8 +23,9 @@ import ( "testing" "time" - kruisev1aplphal "github.com/openkruise/kruise-api/apps/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/util/configuration" apps "k8s.io/api/apps/v1" @@ -103,7 +104,7 @@ var ( }, } - demoRollout = &v1alpha1.Rollout{ + demoRollout = &v1beta1.Rollout{ ObjectMeta: metav1.ObjectMeta{ Name: "rollout-demo", Labels: map[string]string{}, @@ -111,17 +112,17 @@ var ( util.RolloutHashAnnotation: "rollout-hash-v1", }, }, - Spec: v1alpha1.RolloutSpec{ - ObjectRef: v1alpha1.ObjectRef{ - WorkloadRef: &v1alpha1.WorkloadRef{ + Spec: v1beta1.RolloutSpec{ + ObjectRef: v1beta1.ObjectRef{ + WorkloadRef: &v1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "echoserver", }, }, - Strategy: v1alpha1.RolloutStrategy{ - Canary: &v1alpha1.CanaryStrategy{ - Steps: []v1alpha1.CanaryStep{ + Strategy: v1beta1.RolloutStrategy{ + Canary: &v1beta1.CanaryStrategy{ + Steps: []v1beta1.CanaryStep{ { TrafficRoutingStrategy: v1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(5), @@ -158,22 +159,22 @@ var ( }, }, }, - Status: v1alpha1.RolloutStatus{ - Phase: v1alpha1.RolloutPhaseProgressing, - CanaryStatus: &v1alpha1.CanaryStatus{ + Status: v1beta1.RolloutStatus{ + Phase: v1beta1.RolloutPhaseProgressing, + CanaryStatus: &v1beta1.CanaryStatus{ ObservedWorkloadGeneration: 1, RolloutHash: "rollout-hash-v1", ObservedRolloutID: "rollout-id-1", StableRevision: "podtemplatehash-v1", CanaryRevision: "revision-v2", CurrentStepIndex: 1, - CurrentStepState: v1alpha1.CanaryStepStateTrafficRouting, + CurrentStepState: v1beta1.CanaryStepStateTrafficRouting, PodTemplateHash: "podtemplatehash-v2", LastUpdateTime: &metav1.Time{Time: time.Now()}, }, - Conditions: []v1alpha1.RolloutCondition{ + Conditions: []v1beta1.RolloutCondition{ { - Type: v1alpha1.RolloutConditionProgressing, + Type: v1beta1.RolloutConditionProgressing, Reason: v1alpha1.ProgressingReasonInRolling, Status: corev1.ConditionFalse, }, @@ -227,15 +228,14 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = kruisev1aplphal.AddToScheme(scheme) - _ = v1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } func TestDoTrafficRouting(t *testing.T) { cases := []struct { name string getObj func() ([]*corev1.Service, []*netv1.Ingress) - getRollout func() (*v1alpha1.Rollout, *util.Workload) + getRollout func() (*v1beta1.Rollout, *util.Workload) expectObj func() ([]*corev1.Service, []*netv1.Ingress) expectDone bool }{ @@ -244,7 +244,7 @@ func TestDoTrafficRouting(t *testing.T) { getObj: func() ([]*corev1.Service, []*netv1.Ingress) { return []*corev1.Service{demoService.DeepCopy()}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { return demoRollout.DeepCopy(), &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} }, expectObj: func() ([]*corev1.Service, []*netv1.Ingress) { @@ -267,7 +267,7 @@ func TestDoTrafficRouting(t *testing.T) { s2.Spec.Selector[apps.DefaultDeploymentUniqueLabelKey] = "podtemplatehash-v2" return []*corev1.Service{s1, s2}, []*netv1.Ingress{demoIngress.DeepCopy()} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now()} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -299,7 +299,7 @@ func TestDoTrafficRouting(t *testing.T) { c2.Annotations[fmt.Sprintf("%s/canary-weight", nginxIngressAnnotationDefaultPrefix)] = "0" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-10 * time.Second)} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -336,7 +336,7 @@ func TestDoTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-10 * time.Second)} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -373,7 +373,7 @@ func TestDoTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-10 * time.Second)} obj.Status.CanaryStatus.CurrentStepIndex = 2 @@ -415,7 +415,7 @@ func TestDoTrafficRouting(t *testing.T) { Namespace: rollout.Namespace, ObjectRef: rollout.Spec.Strategy.Canary.TrafficRoutings, Strategy: currentStep.TrafficRoutingStrategy, - OwnerRef: *metav1.NewControllerRef(rollout, v1alpha1.SchemeGroupVersion.WithKind("Rollout")), + OwnerRef: *metav1.NewControllerRef(rollout, v1beta1.SchemeGroupVersion.WithKind("Rollout")), RevisionLabelKey: workload.RevisionLabelKey, StableRevision: newStatus.CanaryStatus.StableRevision, CanaryRevision: newStatus.CanaryStatus.PodTemplateHash, @@ -448,7 +448,7 @@ func TestFinalisingTrafficRouting(t *testing.T) { cases := []struct { name string getObj func() ([]*corev1.Service, []*netv1.Ingress) - getRollout func() (*v1alpha1.Rollout, *util.Workload) + getRollout func() (*v1beta1.Rollout, *util.Workload) onlyRestoreStableService bool expectObj func() ([]*corev1.Service, []*netv1.Ingress) expectDone bool @@ -469,9 +469,9 @@ func TestFinalisingTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted obj.Status.CanaryStatus.CurrentStepIndex = 4 return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} }, @@ -506,9 +506,9 @@ func TestFinalisingTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted obj.Status.CanaryStatus.CurrentStepIndex = 4 return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} }, @@ -543,9 +543,9 @@ func TestFinalisingTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted obj.Status.CanaryStatus.CurrentStepIndex = 4 obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-10 * time.Second)} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -581,9 +581,9 @@ func TestFinalisingTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted obj.Status.CanaryStatus.CurrentStepIndex = 4 obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-3 * time.Second)} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -619,9 +619,9 @@ func TestFinalisingTrafficRouting(t *testing.T) { c2.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*corev1.Service{s1, s2}, []*netv1.Ingress{c1, c2} }, - getRollout: func() (*v1alpha1.Rollout, *util.Workload) { + getRollout: func() (*v1beta1.Rollout, *util.Workload) { obj := demoRollout.DeepCopy() - obj.Status.CanaryStatus.CurrentStepState = v1alpha1.CanaryStepStateCompleted + obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateCompleted obj.Status.CanaryStatus.CurrentStepIndex = 4 obj.Status.CanaryStatus.LastUpdateTime = &metav1.Time{Time: time.Now().Add(-3 * time.Second)} return obj, &util.Workload{RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey} @@ -654,7 +654,7 @@ func TestFinalisingTrafficRouting(t *testing.T) { Namespace: rollout.Namespace, ObjectRef: rollout.Spec.Strategy.Canary.TrafficRoutings, Strategy: currentStep.TrafficRoutingStrategy, - OwnerRef: *metav1.NewControllerRef(rollout, v1alpha1.SchemeGroupVersion.WithKind("Rollout")), + OwnerRef: *metav1.NewControllerRef(rollout, v1beta1.SchemeGroupVersion.WithKind("Rollout")), RevisionLabelKey: workload.RevisionLabelKey, StableRevision: newStatus.CanaryStatus.StableRevision, CanaryRevision: newStatus.CanaryStatus.PodTemplateHash, diff --git a/pkg/trafficrouting/network/customNetworkProvider/custom_network_provider_test.go b/pkg/trafficrouting/network/customNetworkProvider/custom_network_provider_test.go index 01bf63f9..c4835355 100644 --- a/pkg/trafficrouting/network/customNetworkProvider/custom_network_provider_test.go +++ b/pkg/trafficrouting/network/customNetworkProvider/custom_network_provider_test.go @@ -26,7 +26,9 @@ import ( "strings" "testing" + rolloutapi "github.com/openkruise/rollouts/api" rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/util/configuration" "github.com/openkruise/rollouts/pkg/util/luamanager" @@ -118,7 +120,7 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = rolloutsv1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } func TestInitialize(t *testing.T) { @@ -480,7 +482,7 @@ func TestFinalise(t *testing.T) { } type TestCase struct { - Rollout *rolloutsv1alpha1.Rollout `json:"rollout,omitempty"` + Rollout *rolloutsv1beta1.Rollout `json:"rollout,omitempty"` TrafficRouting *rolloutsv1alpha1.TrafficRouting `json:"trafficRouting,omitempty"` Original *unstructured.Unstructured `json:"original,omitempty"` Expected []*unstructured.Unstructured `json:"expected,omitempty"` diff --git a/pkg/trafficrouting/network/ingress/ingress_test.go b/pkg/trafficrouting/network/ingress/ingress_test.go index 95e1ec99..aebf00ed 100644 --- a/pkg/trafficrouting/network/ingress/ingress_test.go +++ b/pkg/trafficrouting/network/ingress/ingress_test.go @@ -19,7 +19,9 @@ import ( "reflect" "testing" + rolloutsapi "github.com/openkruise/rollouts/api" rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/util/configuration" corev1 "k8s.io/api/core/v1" @@ -253,7 +255,7 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = rolloutsv1alpha1.AddToScheme(scheme) + _ = rolloutsapi.AddToScheme(scheme) } func TestInitialize(t *testing.T) { @@ -307,7 +309,7 @@ func TestEnsureRoutes(t *testing.T) { name string getConfigmap func() *corev1.ConfigMap getIngress func() []*netv1.Ingress - getRoutes func() *rolloutsv1alpha1.CanaryStep + getRoutes func() *rolloutsv1beta1.CanaryStep expectIngress func() *netv1.Ingress ingressType string }{ @@ -327,8 +329,8 @@ func TestEnsureRoutes(t *testing.T) { canary.Spec.Rules[1].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*netv1.Ingress{demoIngress.DeepCopy(), canary} }, - getRoutes: func() *rolloutsv1alpha1.CanaryStep { - return &rolloutsv1alpha1.CanaryStep{ + getRoutes: func() *rolloutsv1beta1.CanaryStep { + return &rolloutsv1beta1.CanaryStep{ TrafficRoutingStrategy: rolloutsv1alpha1.TrafficRoutingStrategy{ Weight: nil, Matches: []rolloutsv1alpha1.HttpRouteMatch{ @@ -398,8 +400,8 @@ func TestEnsureRoutes(t *testing.T) { canary.Spec.Rules[1].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*netv1.Ingress{demoIngress.DeepCopy(), canary} }, - getRoutes: func() *rolloutsv1alpha1.CanaryStep { - return &rolloutsv1alpha1.CanaryStep{ + getRoutes: func() *rolloutsv1beta1.CanaryStep { + return &rolloutsv1beta1.CanaryStep{ TrafficRoutingStrategy: rolloutsv1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(40), }, @@ -433,9 +435,9 @@ func TestEnsureRoutes(t *testing.T) { canary.Spec.Rules[1].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*netv1.Ingress{demoIngress.DeepCopy(), canary} }, - getRoutes: func() *rolloutsv1alpha1.CanaryStep { + getRoutes: func() *rolloutsv1beta1.CanaryStep { iType := gatewayv1alpha2.HeaderMatchRegularExpression - return &rolloutsv1alpha1.CanaryStep{ + return &rolloutsv1beta1.CanaryStep{ TrafficRoutingStrategy: rolloutsv1alpha1.TrafficRoutingStrategy{ Matches: []rolloutsv1alpha1.HttpRouteMatch{ // header @@ -481,8 +483,8 @@ func TestEnsureRoutes(t *testing.T) { canary.Spec.Rules[1].HTTP.Paths[0].Backend.Service.Name = "echoserver-canary" return []*netv1.Ingress{demoIngress.DeepCopy(), canary} }, - getRoutes: func() *rolloutsv1alpha1.CanaryStep { - return &rolloutsv1alpha1.CanaryStep{ + getRoutes: func() *rolloutsv1beta1.CanaryStep { + return &rolloutsv1beta1.CanaryStep{ TrafficRoutingStrategy: rolloutsv1alpha1.TrafficRoutingStrategy{ Matches: []rolloutsv1alpha1.HttpRouteMatch{ // header diff --git a/pkg/util/condition.go b/pkg/util/condition.go index 85fd755c..b1ed7075 100644 --- a/pkg/util/condition.go +++ b/pkg/util/condition.go @@ -17,14 +17,14 @@ limitations under the License. package util import ( - "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/api/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // NewRolloutCondition creates a new rollout condition. -func NewRolloutCondition(condType v1alpha1.RolloutConditionType, status corev1.ConditionStatus, reason, message string) *v1alpha1.RolloutCondition { - return &v1alpha1.RolloutCondition{ +func NewRolloutCondition(condType v1beta1.RolloutConditionType, status corev1.ConditionStatus, reason, message string) *v1beta1.RolloutCondition { + return &v1beta1.RolloutCondition{ Type: condType, Status: status, LastUpdateTime: metav1.Now(), @@ -35,7 +35,7 @@ func NewRolloutCondition(condType v1alpha1.RolloutConditionType, status corev1.C } // GetRolloutCondition returns the condition with the provided type. -func GetRolloutCondition(status v1alpha1.RolloutStatus, condType v1alpha1.RolloutConditionType) *v1alpha1.RolloutCondition { +func GetRolloutCondition(status v1beta1.RolloutStatus, condType v1beta1.RolloutConditionType) *v1beta1.RolloutCondition { for i := range status.Conditions { c := status.Conditions[i] if c.Type == condType { @@ -48,7 +48,7 @@ func GetRolloutCondition(status v1alpha1.RolloutStatus, condType v1alpha1.Rollou // SetRolloutCondition updates the rollout to include the provided condition. If the condition that // we are about to add already exists and has the same status and reason, then we are not going to update // by returning false. Returns true if the condition was updated -func SetRolloutCondition(status *v1alpha1.RolloutStatus, condition v1alpha1.RolloutCondition) bool { +func SetRolloutCondition(status *v1beta1.RolloutStatus, condition v1beta1.RolloutCondition) bool { currentCond := GetRolloutCondition(*status, condition.Type) if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason && currentCond.Message == condition.Message { @@ -64,8 +64,8 @@ func SetRolloutCondition(status *v1alpha1.RolloutStatus, condition v1alpha1.Roll } // filterOutCondition returns a new slice of rollout conditions without conditions with the provided type. -func filterOutCondition(conditions []v1alpha1.RolloutCondition, condType v1alpha1.RolloutConditionType) []v1alpha1.RolloutCondition { - var newConditions []v1alpha1.RolloutCondition +func filterOutCondition(conditions []v1beta1.RolloutCondition, condType v1beta1.RolloutConditionType) []v1beta1.RolloutCondition { + var newConditions []v1beta1.RolloutCondition for _, c := range conditions { if c.Type == condType { continue @@ -75,6 +75,6 @@ func filterOutCondition(conditions []v1alpha1.RolloutCondition, condType v1alpha return newConditions } -func RemoveRolloutCondition(status *v1alpha1.RolloutStatus, condType v1alpha1.RolloutConditionType) { +func RemoveRolloutCondition(status *v1beta1.RolloutStatus, condType v1beta1.RolloutConditionType) { status.Conditions = filterOutCondition(status.Conditions, condType) } diff --git a/pkg/util/controller_finder.go b/pkg/util/controller_finder.go index cc16baf8..07f05b93 100644 --- a/pkg/util/controller_finder.go +++ b/pkg/util/controller_finder.go @@ -24,6 +24,7 @@ import ( appsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" appsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutv1beta1 "github.com/openkruise/rollouts/api/v1beta1" utilclient "github.com/openkruise/rollouts/pkg/util/client" apps "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -65,7 +66,7 @@ type Workload struct { // ControllerFinderFunc is a function type that maps a pod to a list of // controllers and their scale. -type ControllerFinderFunc func(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) +type ControllerFinderFunc func(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) type ControllerFinder struct { client.Client @@ -84,13 +85,13 @@ func NewControllerFinder(c client.Client) *ControllerFinder { // +kubebuilder:rbac:groups=apps,resources=replicasets,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=apps,resources=replicasets/status,verbs=get;update;patch -func (r *ControllerFinder) GetWorkloadForRef(rollout *rolloutv1alpha1.Rollout) (*Workload, error) { +func (r *ControllerFinder) GetWorkloadForRef(rollout *rolloutv1beta1.Rollout) (*Workload, error) { workloadRef := rollout.Spec.ObjectRef.WorkloadRef if workloadRef == nil { return nil, nil } - switch strings.ToLower(rollout.Annotations[rolloutv1alpha1.RolloutStyleAnnotation]) { + switch strings.ToLower(rollout.Annotations[rolloutv1beta1.RolloutStyleAnnotation]) { case strings.ToLower(string(rolloutv1alpha1.PartitionRollingStyle)): for _, finder := range r.partitionStyleFinders() { workload, err := finder(rollout.Namespace, workloadRef) @@ -137,7 +138,7 @@ var ( ) // getKruiseCloneSet returns the kruise cloneSet referenced by the provided controllerRef. -func (r *ControllerFinder) getKruiseCloneSet(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) { +func (r *ControllerFinder) getKruiseCloneSet(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) { // This error is irreversible, so there is no need to return error ok, _ := verifyGroupKind(ref, ControllerKruiseKindCS.Kind, []string{ControllerKruiseKindCS.Group}) if !ok { @@ -179,7 +180,7 @@ func (r *ControllerFinder) getKruiseCloneSet(namespace string, ref *rolloutv1alp return workload, nil } -func (r *ControllerFinder) getKruiseDaemonSet(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) { +func (r *ControllerFinder) getKruiseDaemonSet(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) { // This error is irreversible, so there is no need to return error ok, _ := verifyGroupKind(ref, ControllerKruiseKindDS.Kind, []string{ControllerKruiseKindDS.Group}) if !ok { @@ -223,7 +224,7 @@ func (r *ControllerFinder) getKruiseDaemonSet(namespace string, ref *rolloutv1al } // getPartitionStyleDeployment returns the Advanced Deployment referenced by the provided controllerRef. -func (r *ControllerFinder) getAdvancedDeployment(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) { +func (r *ControllerFinder) getAdvancedDeployment(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) { // This error is irreversible, so there is no need to return error ok, _ := verifyGroupKind(ref, ControllerKindDep.Kind, []string{ControllerKindDep.Group}) if !ok { @@ -277,7 +278,7 @@ func (r *ControllerFinder) getAdvancedDeployment(namespace string, ref *rolloutv } // getDeployment returns the k8s native deployment referenced by the provided controllerRef. -func (r *ControllerFinder) getDeployment(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) { +func (r *ControllerFinder) getDeployment(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) { // This error is irreversible, so there is no need to return error ok, _ := verifyGroupKind(ref, ControllerKindDep.Kind, []string{ControllerKindDep.Group}) if !ok { @@ -334,7 +335,7 @@ func (r *ControllerFinder) getDeployment(namespace string, ref *rolloutv1alpha1. return workload, err } -func (r *ControllerFinder) getStatefulSetLikeWorkload(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error) { +func (r *ControllerFinder) getStatefulSetLikeWorkload(namespace string, ref *rolloutv1beta1.WorkloadRef) (*Workload, error) { if ref == nil { return nil, nil } @@ -445,7 +446,7 @@ func (r *ControllerFinder) getDeploymentStableRs(obj *apps.Deployment) (*apps.Re return rss[0], nil } -func verifyGroupKind(ref *rolloutv1alpha1.WorkloadRef, expectedKind string, expectedGroups []string) (bool, error) { +func verifyGroupKind(ref *rolloutv1beta1.WorkloadRef, expectedKind string, expectedGroups []string) (bool, error) { gv, err := schema.ParseGroupVersion(ref.APIVersion) if err != nil { return false, err diff --git a/pkg/util/rollout_utils.go b/pkg/util/rollout_utils.go index 090c6783..bc13f39f 100644 --- a/pkg/util/rollout_utils.go +++ b/pkg/util/rollout_utils.go @@ -27,6 +27,7 @@ import ( kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" kruiseappsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util/client" apps "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -44,7 +45,7 @@ type RolloutState struct { RolloutName string `json:"rolloutName"` } -func IsRollbackInBatchPolicy(rollout *rolloutv1alpha1.Rollout, labels map[string]string) bool { +func IsRollbackInBatchPolicy(rollout *rolloutv1beta1.Rollout, labels map[string]string) bool { // currently, only support the case of no traffic routing if len(rollout.Spec.Strategy.Canary.TrafficRoutings) > 0 { return false @@ -130,7 +131,7 @@ func DiscoverGVK(gvk schema.GroupVersionKind) bool { return true } -func GetGVKFrom(workloadRef *rolloutv1alpha1.WorkloadRef) schema.GroupVersionKind { +func GetGVKFrom(workloadRef *rolloutv1beta1.WorkloadRef) schema.GroupVersionKind { if workloadRef == nil { return schema.GroupVersionKind{} } @@ -148,7 +149,7 @@ func AddWatcherDynamically(c controller.Controller, h handler.EventHandler, gvk return true, c.Watch(&source.Kind{Type: object}, h) } -func HashReleasePlanBatches(releasePlan *rolloutv1alpha1.ReleasePlan) string { +func HashReleasePlanBatches(releasePlan *rolloutv1beta1.ReleasePlan) string { by, _ := json.Marshal(releasePlan) md5Hash := sha256.Sum256(by) return hex.EncodeToString(md5Hash[:]) diff --git a/pkg/util/workloads_utils_test.go b/pkg/util/workloads_utils_test.go index a9aca549..91a2b4be 100644 --- a/pkg/util/workloads_utils_test.go +++ b/pkg/util/workloads_utils_test.go @@ -25,7 +25,7 @@ import ( . "github.com/onsi/gomega" kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" appsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" - appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -41,7 +41,7 @@ func init() { scheme = runtime.NewScheme() _ = appsv1.AddToScheme(scheme) _ = appsv1beta1.AddToScheme(scheme) - _ = appsv1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) _ = kruiseappsv1alpha1.AddToScheme(scheme) } diff --git a/pkg/webhook/rollout/validating/rollout_create_update_handler.go b/pkg/webhook/rollout/validating/rollout_create_update_handler.go index bf3fa6a8..9b7103c0 100644 --- a/pkg/webhook/rollout/validating/rollout_create_update_handler.go +++ b/pkg/webhook/rollout/validating/rollout_create_update_handler.go @@ -24,6 +24,7 @@ import ( "strings" appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + appsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" utilclient "github.com/openkruise/rollouts/pkg/util/client" addmissionv1 "k8s.io/api/admission/v1" @@ -53,39 +54,72 @@ var _ admission.Handler = &RolloutCreateUpdateHandler{} func (h *RolloutCreateUpdateHandler) Handle(ctx context.Context, req admission.Request) admission.Response { switch req.Operation { case addmissionv1.Create: - obj := &appsv1alpha1.Rollout{} - if err := h.Decoder.Decode(req, obj); err != nil { - return admission.Errored(http.StatusBadRequest, err) - } - errList := h.validateRollout(obj) - if len(errList) != 0 { - return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + // v1alpha1 + if req.Kind.Version == appsv1alpha1.GroupVersion.Version { + obj := &appsv1alpha1.Rollout{} + if err := h.Decoder.Decode(req, obj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList := h.validateV1alpha1Rollout(obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } + // v1beta1 + } else { + obj := &appsv1beta1.Rollout{} + if err := h.Decoder.Decode(req, obj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList := h.validateRollout(obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } } case addmissionv1.Update: - obj := &appsv1alpha1.Rollout{} - if err := h.Decoder.Decode(req, obj); err != nil { - return admission.Errored(http.StatusBadRequest, err) - } - errList := h.validateRollout(obj) - if len(errList) != 0 { - return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) - } - oldObj := &appsv1alpha1.Rollout{} - if err := h.Decoder.DecodeRaw(req.AdmissionRequest.OldObject, oldObj); err != nil { - return admission.Errored(http.StatusBadRequest, err) - } - errList = h.validateRolloutUpdate(oldObj, obj) - if len(errList) != 0 { - return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + // v1alpha1 + if req.Kind.Version == appsv1alpha1.GroupVersion.Version { + obj := &appsv1alpha1.Rollout{} + if err := h.Decoder.Decode(req, obj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList := h.validateV1alpha1Rollout(obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } + oldObj := &appsv1alpha1.Rollout{} + if err := h.Decoder.DecodeRaw(req.AdmissionRequest.OldObject, oldObj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList = h.validateV1alpha1RolloutUpdate(oldObj, obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } + } else { + obj := &appsv1beta1.Rollout{} + if err := h.Decoder.Decode(req, obj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList := h.validateRollout(obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } + oldObj := &appsv1beta1.Rollout{} + if err := h.Decoder.DecodeRaw(req.AdmissionRequest.OldObject, oldObj); err != nil { + return admission.Errored(http.StatusBadRequest, err) + } + errList = h.validateRolloutUpdate(oldObj, obj) + if len(errList) != 0 { + return admission.Errored(http.StatusUnprocessableEntity, errList.ToAggregate()) + } } } return admission.ValidationResponse(true, "") } -func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv1alpha1.Rollout) field.ErrorList { - latestObject := &appsv1alpha1.Rollout{} +func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv1beta1.Rollout) field.ErrorList { + latestObject := &appsv1beta1.Rollout{} err := h.Client.Get(context.TODO(), client.ObjectKeyFromObject(newObj), latestObject) if err != nil { return field.ErrorList{field.InternalError(field.NewPath("Rollout"), err)} @@ -96,7 +130,7 @@ func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv switch latestObject.Status.Phase { // The workloadRef and TrafficRouting are not allowed to be modified in the Progressing, Terminating state - case appsv1alpha1.RolloutPhaseProgressing, appsv1alpha1.RolloutPhaseTerminating: + case appsv1beta1.RolloutPhaseProgressing, appsv1beta1.RolloutPhaseTerminating: if !reflect.DeepEqual(oldObj.Spec.ObjectRef, newObj.Spec.ObjectRef) { return field.ErrorList{field.Forbidden(field.NewPath("Spec.ObjectRef"), "Rollout 'ObjectRef' field is immutable")} } @@ -104,15 +138,15 @@ func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv if !reflect.DeepEqual(oldObj.Spec.Strategy.Canary.TrafficRoutings, newObj.Spec.Strategy.Canary.TrafficRoutings) { return field.ErrorList{field.Forbidden(field.NewPath("Spec.Strategy.Canary.TrafficRoutings"), "Rollout 'Strategy.Canary.TrafficRoutings' field is immutable")} } - if !strings.EqualFold(oldObj.Annotations[appsv1alpha1.RolloutStyleAnnotation], newObj.Annotations[appsv1alpha1.RolloutStyleAnnotation]) { + if !strings.EqualFold(oldObj.Annotations[appsv1beta1.RolloutStyleAnnotation], newObj.Annotations[appsv1beta1.RolloutStyleAnnotation]) { return field.ErrorList{field.Forbidden(field.NewPath("Metadata.Annotation"), "Rollout 'Rolling-Style' annotation is immutable")} } } - /*if newObj.Status.CanaryStatus != nil && newObj.Status.CanaryStatus.CurrentStepState == appsv1alpha1.CanaryStepStateReady { + /*if newObj.Status.CanaryStatus != nil && newObj.Status.CanaryStatus.CurrentStepState == appsv1beta1.CanaryStepStateReady { if oldObj.Status.CanaryStatus != nil { switch oldObj.Status.CanaryStatus.CurrentStepState { - case appsv1alpha1.CanaryStepStateCompleted, appsv1alpha1.CanaryStepStatePaused: + case appsv1beta1.CanaryStepStateCompleted, appsv1beta1.CanaryStepStatePaused: default: return field.ErrorList{field.Forbidden(field.NewPath("Status"), "CanaryStatus.CurrentStepState only allow to translate to 'StepInCompleted' from 'StepInPaused'")} } @@ -122,15 +156,15 @@ func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv return nil } -func (h *RolloutCreateUpdateHandler) validateRollout(rollout *appsv1alpha1.Rollout) field.ErrorList { +func (h *RolloutCreateUpdateHandler) validateRollout(rollout *appsv1beta1.Rollout) field.ErrorList { errList := validateRolloutSpec(rollout, field.NewPath("Spec")) errList = append(errList, h.validateRolloutConflict(rollout, field.NewPath("Conflict Checker"))...) return errList } -func (h *RolloutCreateUpdateHandler) validateRolloutConflict(rollout *appsv1alpha1.Rollout, path *field.Path) field.ErrorList { +func (h *RolloutCreateUpdateHandler) validateRolloutConflict(rollout *appsv1beta1.Rollout, path *field.Path) field.ErrorList { errList := field.ErrorList{} - rolloutList := &appsv1alpha1.RolloutList{} + rolloutList := &appsv1beta1.RolloutList{} err := h.Client.List(context.TODO(), rolloutList, client.InNamespace(rollout.Namespace), utilclient.DisableDeepCopy) if err != nil { return append(errList, field.InternalError(path, err)) @@ -146,18 +180,18 @@ func (h *RolloutCreateUpdateHandler) validateRolloutConflict(rollout *appsv1alph return nil } -func validateRolloutSpec(rollout *appsv1alpha1.Rollout, fldPath *field.Path) field.ErrorList { +func validateRolloutSpec(rollout *appsv1beta1.Rollout, fldPath *field.Path) field.ErrorList { errList := validateRolloutSpecObjectRef(&rollout.Spec.ObjectRef, fldPath.Child("ObjectRef")) errList = append(errList, validateRolloutRollingStyle(rollout, field.NewPath("RollingStyle"))...) errList = append(errList, validateRolloutSpecStrategy(&rollout.Spec.Strategy, fldPath.Child("Strategy"))...) return errList } -func validateRolloutRollingStyle(rollout *appsv1alpha1.Rollout, fldPath *field.Path) field.ErrorList { - switch strings.ToLower(rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation]) { +func validateRolloutRollingStyle(rollout *appsv1beta1.Rollout, fldPath *field.Path) field.ErrorList { + switch strings.ToLower(rollout.Annotations[appsv1beta1.RolloutStyleAnnotation]) { case "", strings.ToLower(string(appsv1alpha1.CanaryRollingStyle)), strings.ToLower(string(appsv1alpha1.PartitionRollingStyle)): default: - return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], + return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1beta1.RolloutStyleAnnotation], "Rolling style must be 'Canary', 'Partition' or empty")} } @@ -165,14 +199,14 @@ func validateRolloutRollingStyle(rollout *appsv1alpha1.Rollout, fldPath *field.P if workloadRef == nil || workloadRef.Kind == util.ControllerKindDep.Kind { return nil // Deployment support all rolling styles, no need to validate. } - if strings.EqualFold(rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], string(appsv1alpha1.CanaryRollingStyle)) { - return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], + if strings.EqualFold(rollout.Annotations[appsv1beta1.RolloutStyleAnnotation], string(appsv1alpha1.CanaryRollingStyle)) { + return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1beta1.RolloutStyleAnnotation], "Only Deployment support canary rolling style")} } return nil } -func validateRolloutSpecObjectRef(objectRef *appsv1alpha1.ObjectRef, fldPath *field.Path) field.ErrorList { +func validateRolloutSpecObjectRef(objectRef *appsv1beta1.ObjectRef, fldPath *field.Path) field.ErrorList { if objectRef.WorkloadRef == nil { return field.ErrorList{field.Invalid(fldPath.Child("WorkloadRef"), objectRef.WorkloadRef, "WorkloadRef is required")} } @@ -184,11 +218,11 @@ func validateRolloutSpecObjectRef(objectRef *appsv1alpha1.ObjectRef, fldPath *fi return nil } -func validateRolloutSpecStrategy(strategy *appsv1alpha1.RolloutStrategy, fldPath *field.Path) field.ErrorList { +func validateRolloutSpecStrategy(strategy *appsv1beta1.RolloutStrategy, fldPath *field.Path) field.ErrorList { return validateRolloutSpecCanaryStrategy(strategy.Canary, fldPath.Child("Canary")) } -func validateRolloutSpecCanaryStrategy(canary *appsv1alpha1.CanaryStrategy, fldPath *field.Path) field.ErrorList { +func validateRolloutSpecCanaryStrategy(canary *appsv1beta1.CanaryStrategy, fldPath *field.Path) field.ErrorList { if canary == nil { return field.ErrorList{field.Invalid(fldPath, nil, "Canary cannot be empty")} } @@ -227,7 +261,7 @@ func validateRolloutSpecCanaryTraffic(traffic appsv1alpha1.TrafficRoutingRef, fl return errList } -func validateRolloutSpecCanarySteps(steps []appsv1alpha1.CanaryStep, fldPath *field.Path, isTraffic bool) field.ErrorList { +func validateRolloutSpecCanarySteps(steps []appsv1beta1.CanaryStep, fldPath *field.Path, isTraffic bool) field.ErrorList { stepCount := len(steps) if stepCount == 0 { return field.ErrorList{field.Invalid(fldPath, steps, "The number of Canary.Steps cannot be empty")} @@ -281,7 +315,7 @@ func IsPercentageCanaryReplicasType(replicas *intstr.IntOrString) bool { return replicas == nil || replicas.Type == intstr.String } -func IsSameWorkloadRefGVKName(a, b *appsv1alpha1.WorkloadRef) bool { +func IsSameWorkloadRefGVKName(a, b *appsv1beta1.WorkloadRef) bool { if a == nil || b == nil { return false } diff --git a/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go b/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go index ce181dab..be8236f4 100644 --- a/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go +++ b/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go @@ -21,7 +21,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + rolloutapi "github.com/openkruise/rollouts/api" appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + appsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" apps "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -34,9 +36,9 @@ import ( var ( scheme = runtime.NewScheme() - rollout = appsv1alpha1.Rollout{ + rollout = appsv1beta1.Rollout{ TypeMeta: metav1.TypeMeta{ - APIVersion: appsv1alpha1.SchemeGroupVersion.String(), + APIVersion: appsv1beta1.SchemeGroupVersion.String(), Kind: "Rollout", }, ObjectMeta: metav1.ObjectMeta{ @@ -44,36 +46,36 @@ var ( Namespace: "namespace-unit-test", Annotations: map[string]string{}, }, - Spec: appsv1alpha1.RolloutSpec{ - ObjectRef: appsv1alpha1.ObjectRef{ - WorkloadRef: &appsv1alpha1.WorkloadRef{ + Spec: appsv1beta1.RolloutSpec{ + ObjectRef: appsv1beta1.ObjectRef{ + WorkloadRef: &appsv1beta1.WorkloadRef{ APIVersion: apps.SchemeGroupVersion.String(), Kind: "Deployment", Name: "deployment-demo", }, }, - Strategy: appsv1alpha1.RolloutStrategy{ - Canary: &appsv1alpha1.CanaryStrategy{ - Steps: []appsv1alpha1.CanaryStep{ + Strategy: appsv1beta1.RolloutStrategy{ + Canary: &appsv1beta1.CanaryStrategy{ + Steps: []appsv1beta1.CanaryStep{ { TrafficRoutingStrategy: appsv1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(10), }, Replicas: &intstr.IntOrString{Type: intstr.Int, IntVal: int32(1)}, - Pause: appsv1alpha1.RolloutPause{}, + Pause: appsv1beta1.RolloutPause{}, }, { TrafficRoutingStrategy: appsv1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(10), }, Replicas: &intstr.IntOrString{Type: intstr.Int, IntVal: int32(3)}, - Pause: appsv1alpha1.RolloutPause{Duration: utilpointer.Int32(1 * 24 * 60 * 60)}, + Pause: appsv1beta1.RolloutPause{Duration: utilpointer.Int32(1 * 24 * 60 * 60)}, }, { TrafficRoutingStrategy: appsv1alpha1.TrafficRoutingStrategy{ Weight: utilpointer.Int32(30), }, - Pause: appsv1alpha1.RolloutPause{Duration: utilpointer.Int32(7 * 24 * 60 * 60)}, + Pause: appsv1beta1.RolloutPause{Duration: utilpointer.Int32(7 * 24 * 60 * 60)}, }, { TrafficRoutingStrategy: appsv1alpha1.TrafficRoutingStrategy{ @@ -103,16 +105,16 @@ var ( }, }, }, - Status: appsv1alpha1.RolloutStatus{ - CanaryStatus: &appsv1alpha1.CanaryStatus{ - CurrentStepState: appsv1alpha1.CanaryStepStateCompleted, + Status: appsv1beta1.RolloutStatus{ + CanaryStatus: &appsv1beta1.CanaryStatus{ + CurrentStepState: appsv1beta1.CanaryStepStateCompleted, }, }, } ) func init() { - _ = appsv1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } func TestRolloutValidateCreate(t *testing.T) { @@ -177,7 +179,7 @@ func TestRolloutValidateCreate(t *testing.T) { Succeed: false, GetObject: func() []client.Object { object := rollout.DeepCopy() - object.Spec.Strategy.Canary.Steps = []appsv1alpha1.CanaryStep{} + object.Spec.Strategy.Canary.Steps = []appsv1beta1.CanaryStep{} return []client.Object{object} }, }, @@ -186,7 +188,7 @@ func TestRolloutValidateCreate(t *testing.T) { Succeed: true, GetObject: func() []client.Object { object := rollout.DeepCopy() - object.Spec.ObjectRef.WorkloadRef = &appsv1alpha1.WorkloadRef{ + object.Spec.ObjectRef.WorkloadRef = &appsv1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "StatefulSet", Name: "whatever", @@ -263,7 +265,7 @@ func TestRolloutValidateCreate(t *testing.T) { GetObject: func() []client.Object { object := rollout.DeepCopy() object.Annotations = map[string]string{ - appsv1alpha1.RolloutStyleAnnotation: "Canary", + appsv1beta1.RolloutStyleAnnotation: "Canary", } return []client.Object{object} }, @@ -274,7 +276,7 @@ func TestRolloutValidateCreate(t *testing.T) { GetObject: func() []client.Object { object := rollout.DeepCopy() object.Annotations = map[string]string{ - appsv1alpha1.RolloutStyleAnnotation: "Partition", + appsv1beta1.RolloutStyleAnnotation: "Partition", } return []client.Object{object} }, @@ -285,7 +287,7 @@ func TestRolloutValidateCreate(t *testing.T) { GetObject: func() []client.Object { object := rollout.DeepCopy() object.Annotations = map[string]string{ - appsv1alpha1.RolloutStyleAnnotation: "Other", + appsv1beta1.RolloutStyleAnnotation: "Other", } return []client.Object{object} }, @@ -296,7 +298,7 @@ func TestRolloutValidateCreate(t *testing.T) { GetObject: func() []client.Object { object := rollout.DeepCopy() object.Annotations = map[string]string{ - appsv1alpha1.RolloutStyleAnnotation: "Canary", + appsv1beta1.RolloutStyleAnnotation: "Canary", } object.Spec.ObjectRef.WorkloadRef.APIVersion = "apps.kruise.io/v1alpha1" object.Spec.ObjectRef.WorkloadRef.Kind = "CloneSet" @@ -373,7 +375,7 @@ func TestRolloutValidateCreate(t *testing.T) { handler := RolloutCreateUpdateHandler{ Client: cli, } - errList := handler.validateRollout(objects[0].(*appsv1alpha1.Rollout)) + errList := handler.validateRollout(objects[0].(*appsv1beta1.Rollout)) t.Log(errList) Expect(len(errList) == 0).Should(Equal(cs.Succeed)) }) @@ -407,12 +409,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing object.Status.CanaryStatus.CurrentStepIndex = 1 return object }, @@ -422,12 +424,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing object.Spec.Strategy.Canary.Steps[0].Weight = utilpointer.Int32Ptr(5) return object }, @@ -437,14 +439,14 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: false, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Annotations[appsv1alpha1.RolloutStyleAnnotation] = "Partition" - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing + object.Annotations[appsv1beta1.RolloutStyleAnnotation] = "Partition" + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseProgressing - object.Annotations[appsv1alpha1.RolloutStyleAnnotation] = "Canary" + object.Status.Phase = appsv1beta1.RolloutPhaseProgressing + object.Annotations[appsv1beta1.RolloutStyleAnnotation] = "Canary" return object }, }, @@ -453,12 +455,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: false, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseTerminating + object.Status.Phase = appsv1beta1.RolloutPhaseTerminating return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseTerminating + object.Status.Phase = appsv1beta1.RolloutPhaseTerminating object.Spec.Strategy.Canary.TrafficRoutings[0].Ingress.ClassType = "alb" return object }, @@ -468,12 +470,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseInitial + object.Status.Phase = appsv1beta1.RolloutPhaseInitial return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseInitial + object.Status.Phase = appsv1beta1.RolloutPhaseInitial object.Spec.Strategy.Canary.Steps[0].Weight = utilpointer.Int32Ptr(5) return object }, @@ -483,12 +485,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseHealthy + object.Status.Phase = appsv1beta1.RolloutPhaseHealthy return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.Phase = appsv1alpha1.RolloutPhaseHealthy + object.Status.Phase = appsv1beta1.RolloutPhaseHealthy object.Spec.Strategy.Canary.Steps[0].Weight = utilpointer.Int32Ptr(5) return object }, @@ -498,12 +500,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStatePaused + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStatePaused return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, }, @@ -512,12 +514,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: true, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, }, @@ -526,12 +528,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: false, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateUpgrade + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateUpgrade return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, }, @@ -540,12 +542,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: false, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateTrafficRouting + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateTrafficRouting return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, }, @@ -554,12 +556,12 @@ func TestRolloutValidateUpdate(t *testing.T) { Succeed: false, GetOldObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateMetricsAnalysis + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateMetricsAnalysis return object }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, }, @@ -573,7 +575,7 @@ func TestRolloutValidateUpdate(t *testing.T) { }, GetNewObject: func() client.Object { object := rollout.DeepCopy() - object.Status.CanaryStatus.CurrentStepState = appsv1alpha1.CanaryStepStateCompleted + object.Status.CanaryStatus.CurrentStepState = appsv1beta1.CanaryStepStateCompleted return object }, },*/ @@ -587,7 +589,7 @@ func TestRolloutValidateUpdate(t *testing.T) { handler := RolloutCreateUpdateHandler{ Client: cli, } - errList := handler.validateRolloutUpdate(oldObject.(*appsv1alpha1.Rollout), newObject.(*appsv1alpha1.Rollout)) + errList := handler.validateRolloutUpdate(oldObject.(*appsv1beta1.Rollout), newObject.(*appsv1beta1.Rollout)) t.Log(errList) Expect(len(errList) == 0).Should(Equal(cs.Succeed)) }) diff --git a/pkg/webhook/rollout/validating/validate_v1alphal_rollout.go b/pkg/webhook/rollout/validating/validate_v1alphal_rollout.go new file mode 100644 index 00000000..58163094 --- /dev/null +++ b/pkg/webhook/rollout/validating/validate_v1alphal_rollout.go @@ -0,0 +1,208 @@ +/* +Copyright 2023 The Kruise 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 validating + +import ( + "context" + "fmt" + "reflect" + "strings" + + appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + "github.com/openkruise/rollouts/pkg/util" + utilclient "github.com/openkruise/rollouts/pkg/util/client" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/validation/field" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func (h *RolloutCreateUpdateHandler) validateV1alpha1RolloutUpdate(oldObj, newObj *appsv1alpha1.Rollout) field.ErrorList { + latestObject := &appsv1alpha1.Rollout{} + err := h.Client.Get(context.TODO(), client.ObjectKeyFromObject(newObj), latestObject) + if err != nil { + return field.ErrorList{field.InternalError(field.NewPath("Rollout"), err)} + } + if errorList := h.validateV1alpha1Rollout(newObj); errorList != nil { + return errorList + } + + switch latestObject.Status.Phase { + // The workloadRef and TrafficRouting are not allowed to be modified in the Progressing, Terminating state + case appsv1alpha1.RolloutPhaseProgressing, appsv1alpha1.RolloutPhaseTerminating: + if !reflect.DeepEqual(oldObj.Spec.ObjectRef, newObj.Spec.ObjectRef) { + return field.ErrorList{field.Forbidden(field.NewPath("Spec.ObjectRef"), "Rollout 'ObjectRef' field is immutable")} + } + // canary strategy + if !reflect.DeepEqual(oldObj.Spec.Strategy.Canary.TrafficRoutings, newObj.Spec.Strategy.Canary.TrafficRoutings) { + return field.ErrorList{field.Forbidden(field.NewPath("Spec.Strategy.Canary.TrafficRoutings"), "Rollout 'Strategy.Canary.TrafficRoutings' field is immutable")} + } + if !strings.EqualFold(oldObj.Annotations[appsv1alpha1.RolloutStyleAnnotation], newObj.Annotations[appsv1alpha1.RolloutStyleAnnotation]) { + return field.ErrorList{field.Forbidden(field.NewPath("Metadata.Annotation"), "Rollout 'Rolling-Style' annotation is immutable")} + } + } + + /*if newObj.Status.CanaryStatus != nil && newObj.Status.CanaryStatus.CurrentStepState == appsv1alpha1.CanaryStepStateReady { + if oldObj.Status.CanaryStatus != nil { + switch oldObj.Status.CanaryStatus.CurrentStepState { + case appsv1alpha1.CanaryStepStateCompleted, appsv1alpha1.CanaryStepStatePaused: + default: + return field.ErrorList{field.Forbidden(field.NewPath("Status"), "CanaryStatus.CurrentStepState only allow to translate to 'StepInCompleted' from 'StepInPaused'")} + } + } + }*/ + + return nil +} + +func (h *RolloutCreateUpdateHandler) validateV1alpha1Rollout(rollout *appsv1alpha1.Rollout) field.ErrorList { + errList := validateV1alpha1RolloutSpec(rollout, field.NewPath("Spec")) + errList = append(errList, h.validateV1alpha1RolloutConflict(rollout, field.NewPath("Conflict Checker"))...) + return errList +} + +func (h *RolloutCreateUpdateHandler) validateV1alpha1RolloutConflict(rollout *appsv1alpha1.Rollout, path *field.Path) field.ErrorList { + errList := field.ErrorList{} + rolloutList := &appsv1alpha1.RolloutList{} + err := h.Client.List(context.TODO(), rolloutList, client.InNamespace(rollout.Namespace), utilclient.DisableDeepCopy) + if err != nil { + return append(errList, field.InternalError(path, err)) + } + for i := range rolloutList.Items { + r := &rolloutList.Items[i] + if r.Name == rollout.Name || !IsSameV1alpha1WorkloadRefGVKName(r.Spec.ObjectRef.WorkloadRef, rollout.Spec.ObjectRef.WorkloadRef) { + continue + } + return field.ErrorList{field.Invalid(path, rollout.Name, + fmt.Sprintf("This rollout conflict with Rollout(%v), one workload only have less than one Rollout", client.ObjectKeyFromObject(r)))} + } + return nil +} + +func validateV1alpha1RolloutSpec(rollout *appsv1alpha1.Rollout, fldPath *field.Path) field.ErrorList { + errList := validateV1alpha1RolloutSpecObjectRef(&rollout.Spec.ObjectRef, fldPath.Child("ObjectRef")) + errList = append(errList, validateV1alpha1RolloutRollingStyle(rollout, field.NewPath("RollingStyle"))...) + errList = append(errList, validateV1alpha1RolloutSpecStrategy(&rollout.Spec.Strategy, fldPath.Child("Strategy"))...) + return errList +} + +func validateV1alpha1RolloutRollingStyle(rollout *appsv1alpha1.Rollout, fldPath *field.Path) field.ErrorList { + switch strings.ToLower(rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation]) { + case "", strings.ToLower(string(appsv1alpha1.CanaryRollingStyle)), strings.ToLower(string(appsv1alpha1.PartitionRollingStyle)): + default: + return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], + "Rolling style must be 'Canary', 'Partition' or empty")} + } + + workloadRef := rollout.Spec.ObjectRef.WorkloadRef + if workloadRef == nil || workloadRef.Kind == util.ControllerKindDep.Kind { + return nil // Deployment support all rolling styles, no need to validate. + } + if strings.EqualFold(rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], string(appsv1alpha1.CanaryRollingStyle)) { + return field.ErrorList{field.Invalid(fldPath, rollout.Annotations[appsv1alpha1.RolloutStyleAnnotation], + "Only Deployment support canary rolling style")} + } + return nil +} + +func validateV1alpha1RolloutSpecObjectRef(objectRef *appsv1alpha1.ObjectRef, fldPath *field.Path) field.ErrorList { + if objectRef.WorkloadRef == nil { + return field.ErrorList{field.Invalid(fldPath.Child("WorkloadRef"), objectRef.WorkloadRef, "WorkloadRef is required")} + } + + gvk := schema.FromAPIVersionAndKind(objectRef.WorkloadRef.APIVersion, objectRef.WorkloadRef.Kind) + if !util.IsSupportedWorkload(gvk) { + return field.ErrorList{field.Invalid(fldPath.Child("WorkloadRef"), objectRef.WorkloadRef, "WorkloadRef kind is not supported")} + } + return nil +} + +func validateV1alpha1RolloutSpecStrategy(strategy *appsv1alpha1.RolloutStrategy, fldPath *field.Path) field.ErrorList { + return validateV1alpha1RolloutSpecCanaryStrategy(strategy.Canary, fldPath.Child("Canary")) +} + +func validateV1alpha1RolloutSpecCanaryStrategy(canary *appsv1alpha1.CanaryStrategy, fldPath *field.Path) field.ErrorList { + if canary == nil { + return field.ErrorList{field.Invalid(fldPath, nil, "Canary cannot be empty")} + } + + errList := validateV1alpha1RolloutSpecCanarySteps(canary.Steps, fldPath.Child("Steps"), len(canary.TrafficRoutings) > 0) + if len(canary.TrafficRoutings) > 1 { + errList = append(errList, field.Invalid(fldPath, canary.TrafficRoutings, "Rollout currently only support single TrafficRouting.")) + } + for _, traffic := range canary.TrafficRoutings { + errList = append(errList, validateRolloutSpecCanaryTraffic(traffic, fldPath.Child("TrafficRouting"))...) + } + return errList +} + +func validateV1alpha1RolloutSpecCanarySteps(steps []appsv1alpha1.CanaryStep, fldPath *field.Path, isTraffic bool) field.ErrorList { + stepCount := len(steps) + if stepCount == 0 { + return field.ErrorList{field.Invalid(fldPath, steps, "The number of Canary.Steps cannot be empty")} + } + + for i := range steps { + s := &steps[i] + if s.Weight == nil && s.Replicas == nil { + return field.ErrorList{field.Invalid(fldPath.Index(i).Child("steps"), steps, `weight and replicas cannot be empty at the same time`)} + } + if s.Replicas != nil { + canaryReplicas, err := intstr.GetScaledValueFromIntOrPercent(s.Replicas, 100, true) + if err != nil || + canaryReplicas <= 0 || + (canaryReplicas > 100 && s.Replicas.Type == intstr.String) { + return field.ErrorList{field.Invalid(fldPath.Index(i).Child("Replicas"), + s.Replicas, `replicas must be positive number, or a percentage with "0%" < canaryReplicas <= "100%"`)} + } + } + } + + for i := 1; i < stepCount; i++ { + prev := &steps[i-1] + curr := &steps[i] + if isTraffic && curr.Weight != nil && prev.Weight != nil && *curr.Weight < *prev.Weight { + return field.ErrorList{field.Invalid(fldPath.Child("Weight"), steps, `Steps.Weight must be a non decreasing sequence`)} + } + + // if they are comparable, then compare them + if IsPercentageCanaryReplicasType(prev.Replicas) != IsPercentageCanaryReplicasType(curr.Replicas) { + continue + } + + prevCanaryReplicas, _ := intstr.GetScaledValueFromIntOrPercent(prev.Replicas, 100, true) + currCanaryReplicas, _ := intstr.GetScaledValueFromIntOrPercent(curr.Replicas, 100, true) + if prev.Replicas == nil { + prevCanaryReplicas = int(*prev.Weight) + } + if curr.Replicas == nil { + currCanaryReplicas = int(*curr.Weight) + } + if currCanaryReplicas < prevCanaryReplicas { + return field.ErrorList{field.Invalid(fldPath.Child("CanaryReplicas"), steps, `Steps.CanaryReplicas must be a non decreasing sequence`)} + } + } + + return nil +} + +func IsSameV1alpha1WorkloadRefGVKName(a, b *appsv1alpha1.WorkloadRef) bool { + if a == nil || b == nil { + return false + } + return reflect.DeepEqual(a, b) +} diff --git a/pkg/webhook/workload/mutating/workload_update_handler.go b/pkg/webhook/workload/mutating/workload_update_handler.go index 2968e643..b8f08e85 100644 --- a/pkg/webhook/workload/mutating/workload_update_handler.go +++ b/pkg/webhook/workload/mutating/workload_update_handler.go @@ -25,6 +25,7 @@ import ( kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + appsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" utilclient "github.com/openkruise/rollouts/pkg/util/client" util2 "github.com/openkruise/rollouts/pkg/webhook/util" @@ -231,10 +232,10 @@ func (h *WorkloadHandler) handleStatefulSetLikeWorkload(newObj, oldObj *unstruct return false, nil } oldMetadata, newMetadata := util.GetMetadata(oldObj), util.GetMetadata(newObj) - if newMetadata.Annotations[appsv1alpha1.RolloutIDLabel] != "" && - oldMetadata.Annotations[appsv1alpha1.RolloutIDLabel] == newMetadata.Annotations[appsv1alpha1.RolloutIDLabel] { + if newMetadata.Annotations[appsv1beta1.RolloutIDLabel] != "" && + oldMetadata.Annotations[appsv1beta1.RolloutIDLabel] == newMetadata.Annotations[appsv1beta1.RolloutIDLabel] { return false, nil - } else if newMetadata.Annotations[appsv1alpha1.RolloutIDLabel] == "" && util.EqualIgnoreHash(oldTemplate, newTemplate) { + } else if newMetadata.Annotations[appsv1beta1.RolloutIDLabel] == "" && util.EqualIgnoreHash(oldTemplate, newTemplate) { return false, nil } @@ -353,10 +354,10 @@ func (h *WorkloadHandler) handleCloneSet(newObj, oldObj *kruiseappsv1alpha1.Clon if newObj.Spec.Replicas != nil && *newObj.Spec.Replicas == 0 { return false, nil } - if newObj.Annotations[appsv1alpha1.RolloutIDLabel] != "" && - oldObj.Annotations[appsv1alpha1.RolloutIDLabel] == newObj.Annotations[appsv1alpha1.RolloutIDLabel] { + if newObj.Annotations[appsv1beta1.RolloutIDLabel] != "" && + oldObj.Annotations[appsv1beta1.RolloutIDLabel] == newObj.Annotations[appsv1beta1.RolloutIDLabel] { return false, nil - } else if newObj.Annotations[appsv1alpha1.RolloutIDLabel] == "" && util.EqualIgnoreHash(&oldObj.Spec.Template, &newObj.Spec.Template) { + } else if newObj.Annotations[appsv1beta1.RolloutIDLabel] == "" && util.EqualIgnoreHash(&oldObj.Spec.Template, &newObj.Spec.Template) { return false, nil } @@ -386,10 +387,10 @@ func (h *WorkloadHandler) handleCloneSet(newObj, oldObj *kruiseappsv1alpha1.Clon func (h *WorkloadHandler) handleDaemonSet(newObj, oldObj *kruiseappsv1alpha1.DaemonSet) (bool, error) { // indicate whether the workload can enter the rollout process - if newObj.Annotations[appsv1alpha1.RolloutIDLabel] != "" && - oldObj.Annotations[appsv1alpha1.RolloutIDLabel] == newObj.Annotations[appsv1alpha1.RolloutIDLabel] { + if newObj.Annotations[appsv1beta1.RolloutIDLabel] != "" && + oldObj.Annotations[appsv1beta1.RolloutIDLabel] == newObj.Annotations[appsv1beta1.RolloutIDLabel] { return false, nil - } else if newObj.Annotations[appsv1alpha1.RolloutIDLabel] == "" && util.EqualIgnoreHash(&oldObj.Spec.Template, &newObj.Spec.Template) { + } else if newObj.Annotations[appsv1beta1.RolloutIDLabel] == "" && util.EqualIgnoreHash(&oldObj.Spec.Template, &newObj.Spec.Template) { return false, nil } @@ -411,9 +412,9 @@ func (h *WorkloadHandler) handleDaemonSet(newObj, oldObj *kruiseappsv1alpha1.Dae return true, nil } -func (h *WorkloadHandler) fetchMatchedRollout(obj client.Object) (*appsv1alpha1.Rollout, error) { +func (h *WorkloadHandler) fetchMatchedRollout(obj client.Object) (*appsv1beta1.Rollout, error) { oGv := obj.GetObjectKind().GroupVersionKind() - rolloutList := &appsv1alpha1.RolloutList{} + rolloutList := &appsv1beta1.RolloutList{} if err := h.Client.List(context.TODO(), rolloutList, utilclient.DisableDeepCopy, &client.ListOptions{Namespace: obj.GetNamespace()}); err != nil { klog.Errorf("WorkloadHandler List rollout failed: %s", err.Error()) @@ -424,7 +425,7 @@ func (h *WorkloadHandler) fetchMatchedRollout(obj client.Object) (*appsv1alpha1. if !rollout.DeletionTimestamp.IsZero() || rollout.Spec.ObjectRef.WorkloadRef == nil { continue } - if rollout.Status.Phase == appsv1alpha1.RolloutPhaseDisabled { + if rollout.Status.Phase == appsv1beta1.RolloutPhaseDisabled { klog.Infof("Disabled rollout(%s/%s) fetched when fetching matched rollout", rollout.Namespace, rollout.Name) continue } @@ -459,10 +460,10 @@ func (h *WorkloadHandler) InjectDecoder(d *admission.Decoder) error { } func isEffectiveDeploymentRevisionChange(oldObj, newObj *apps.Deployment) bool { - if newObj.Annotations[appsv1alpha1.RolloutIDLabel] != "" && - oldObj.Annotations[appsv1alpha1.RolloutIDLabel] == newObj.Annotations[appsv1alpha1.RolloutIDLabel] { + if newObj.Annotations[appsv1beta1.RolloutIDLabel] != "" && + oldObj.Annotations[appsv1beta1.RolloutIDLabel] == newObj.Annotations[appsv1beta1.RolloutIDLabel] { return false - } else if newObj.Annotations[appsv1alpha1.RolloutIDLabel] == "" && + } else if newObj.Annotations[appsv1beta1.RolloutIDLabel] == "" && util.EqualIgnoreHash(&oldObj.Spec.Template, &newObj.Spec.Template) { return false } diff --git a/pkg/webhook/workload/mutating/workload_update_handler_test.go b/pkg/webhook/workload/mutating/workload_update_handler_test.go index 53930b3d..5d3b599d 100644 --- a/pkg/webhook/workload/mutating/workload_update_handler_test.go +++ b/pkg/webhook/workload/mutating/workload_update_handler_test.go @@ -25,7 +25,9 @@ import ( kruisev1aplphal "github.com/openkruise/kruise-api/apps/v1alpha1" kruiseappsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" + rolloutapi "github.com/openkruise/rollouts/api" appsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + appsv1beta1 "github.com/openkruise/rollouts/api/v1beta1" "github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/webhook/util/configuration" "github.com/stretchr/testify/assert" @@ -266,21 +268,21 @@ var ( }, } - rolloutDemo = &appsv1alpha1.Rollout{ + rolloutDemo = &appsv1beta1.Rollout{ ObjectMeta: metav1.ObjectMeta{ Name: "rollout-demo", Labels: map[string]string{}, }, - Spec: appsv1alpha1.RolloutSpec{ - ObjectRef: appsv1alpha1.ObjectRef{ - WorkloadRef: &appsv1alpha1.WorkloadRef{ + Spec: appsv1beta1.RolloutSpec{ + ObjectRef: appsv1beta1.ObjectRef{ + WorkloadRef: &appsv1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "echoserver", }, }, - Strategy: appsv1alpha1.RolloutStrategy{ - Canary: &appsv1alpha1.CanaryStrategy{}, + Strategy: appsv1beta1.RolloutStrategy{ + Canary: &appsv1beta1.CanaryStrategy{}, }, }, } @@ -289,8 +291,7 @@ var ( func init() { scheme = runtime.NewScheme() _ = clientgoscheme.AddToScheme(scheme) - _ = kruisev1aplphal.AddToScheme(scheme) - _ = appsv1alpha1.AddToScheme(scheme) + _ = rolloutapi.AddToScheme(scheme) } func TestHandlerDeployment(t *testing.T) { @@ -298,7 +299,7 @@ func TestHandlerDeployment(t *testing.T) { name string getObjs func() (*apps.Deployment, *apps.Deployment) expectObj func() *apps.Deployment - getRollout func() *appsv1alpha1.Rollout + getRollout func() *appsv1beta1.Rollout getRs func() []*apps.ReplicaSet isError bool }{ @@ -321,7 +322,7 @@ func TestHandlerDeployment(t *testing.T) { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { return rolloutDemo.DeepCopy() }, }, @@ -342,9 +343,9 @@ func TestHandlerDeployment(t *testing.T) { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.ObjectRef.WorkloadRef = &appsv1alpha1.WorkloadRef{ + obj.Spec.ObjectRef.WorkloadRef = &appsv1beta1.WorkloadRef{ APIVersion: "apps/v1", Kind: "Deployment", Name: "other", @@ -373,9 +374,9 @@ func TestHandlerDeployment(t *testing.T) { rs2.Spec.Template.Spec.Containers[0].Image = "echoserver:v2" return []*apps.ReplicaSet{rs1, rs2} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { demo := rolloutDemo.DeepCopy() - demo.Spec.Strategy.Canary = &appsv1alpha1.CanaryStrategy{ + demo.Spec.Strategy.Canary = &appsv1beta1.CanaryStrategy{ TrafficRoutings: []appsv1alpha1.TrafficRoutingRef{ { Service: "echoserver", @@ -412,7 +413,7 @@ func TestHandlerDeployment(t *testing.T) { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { return rolloutDemo.DeepCopy() }, }, @@ -440,7 +441,7 @@ func TestHandlerDeployment(t *testing.T) { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() return obj }, @@ -450,7 +451,7 @@ func TestHandlerDeployment(t *testing.T) { getObjs: func() (*apps.Deployment, *apps.Deployment) { oldObj := deploymentDemo.DeepCopy() newObj := deploymentDemo.DeepCopy() - newObj.Annotations[appsv1alpha1.RolloutIDLabel] = "v2" + newObj.Annotations[appsv1beta1.RolloutIDLabel] = "v2" newObj.Spec.Template.Spec.Containers[0].Image = "echoserver:v2" return oldObj, newObj }, @@ -459,14 +460,14 @@ func TestHandlerDeployment(t *testing.T) { obj.Spec.Template.Spec.Containers[0].Image = "echoserver:v2" obj.Annotations[util.InRolloutProgressingAnnotation] = `{"rolloutName":"rollout-demo"}` obj.Spec.Paused = true - obj.Annotations[appsv1alpha1.RolloutIDLabel] = "v2" + obj.Annotations[appsv1beta1.RolloutIDLabel] = "v2" return obj }, getRs: func() []*apps.ReplicaSet { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() return obj }, @@ -476,21 +477,21 @@ func TestHandlerDeployment(t *testing.T) { getObjs: func() (*apps.Deployment, *apps.Deployment) { oldObj := deploymentDemo.DeepCopy() newObj := deploymentDemo.DeepCopy() - newObj.Annotations[appsv1alpha1.RolloutIDLabel] = "v1-alpha1" + newObj.Annotations[appsv1beta1.RolloutIDLabel] = "v1-alpha1" return oldObj, newObj }, expectObj: func() *apps.Deployment { obj := deploymentDemo.DeepCopy() obj.Annotations[util.InRolloutProgressingAnnotation] = `{"rolloutName":"rollout-demo"}` obj.Spec.Paused = true - obj.Annotations[appsv1alpha1.RolloutIDLabel] = "v1-alpha1" + obj.Annotations[appsv1beta1.RolloutIDLabel] = "v1-alpha1" return obj }, getRs: func() []*apps.ReplicaSet { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() return obj }, @@ -499,23 +500,23 @@ func TestHandlerDeployment(t *testing.T) { name: "rolloutId no change, and podTemplateSpec change", getObjs: func() (*apps.Deployment, *apps.Deployment) { oldObj := deploymentDemo.DeepCopy() - oldObj.Annotations[appsv1alpha1.RolloutIDLabel] = "v1" + oldObj.Annotations[appsv1beta1.RolloutIDLabel] = "v1" newObj := deploymentDemo.DeepCopy() newObj.Spec.Template.Spec.Containers[0].Image = "echoserver:v2" - newObj.Annotations[appsv1alpha1.RolloutIDLabel] = "v1" + newObj.Annotations[appsv1beta1.RolloutIDLabel] = "v1" return oldObj, newObj }, expectObj: func() *apps.Deployment { obj := deploymentDemo.DeepCopy() obj.Spec.Template.Spec.Containers[0].Image = "echoserver:v2" - obj.Annotations[appsv1alpha1.RolloutIDLabel] = "v1" + obj.Annotations[appsv1beta1.RolloutIDLabel] = "v1" return obj }, getRs: func() []*apps.ReplicaSet { rs := rsDemo.DeepCopy() return []*apps.ReplicaSet{rs} }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() return obj }, @@ -561,7 +562,7 @@ func TestHandlerCloneSet(t *testing.T) { name string getObjs func() (*kruisev1aplphal.CloneSet, *kruisev1aplphal.CloneSet) expectObj func() *kruisev1aplphal.CloneSet - getRollout func() *appsv1alpha1.Rollout + getRollout func() *appsv1beta1.Rollout isError bool }{ { @@ -579,9 +580,9 @@ func TestHandlerCloneSet(t *testing.T) { obj.Spec.UpdateStrategy.Partition = &intstr.IntOrString{Type: intstr.String, StrVal: "100%"} return obj }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.ObjectRef.WorkloadRef = &appsv1alpha1.WorkloadRef{ + obj.Spec.ObjectRef.WorkloadRef = &appsv1beta1.WorkloadRef{ APIVersion: "apps.kruise.io/v1alpha1", Kind: "CloneSet", Name: "echoserver", @@ -625,7 +626,7 @@ func TestHandlerDaemonSet(t *testing.T) { name string getObjs func() (*kruisev1aplphal.DaemonSet, *kruisev1aplphal.DaemonSet) expectObj func() *kruisev1aplphal.DaemonSet - getRollout func() *appsv1alpha1.Rollout + getRollout func() *appsv1beta1.Rollout isError bool }{ { @@ -643,9 +644,9 @@ func TestHandlerDaemonSet(t *testing.T) { obj.Spec.UpdateStrategy.RollingUpdate.Partition = pointer.Int32(math.MaxInt16) return obj }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.ObjectRef.WorkloadRef = &appsv1alpha1.WorkloadRef{ + obj.Spec.ObjectRef.WorkloadRef = &appsv1beta1.WorkloadRef{ APIVersion: "apps.kruise.io/v1alpha1", Kind: "DaemonSet", Name: "echoserver", @@ -689,7 +690,7 @@ func TestHandleStatefulSet(t *testing.T) { name string getObjs func() (*kruiseappsv1beta1.StatefulSet, *kruiseappsv1beta1.StatefulSet) expectObj func() *kruiseappsv1beta1.StatefulSet - getRollout func() *appsv1alpha1.Rollout + getRollout func() *appsv1beta1.Rollout isError bool }{ { @@ -707,9 +708,9 @@ func TestHandleStatefulSet(t *testing.T) { obj.Spec.UpdateStrategy.RollingUpdate.Partition = pointer.Int32(math.MaxInt16) return obj }, - getRollout: func() *appsv1alpha1.Rollout { + getRollout: func() *appsv1beta1.Rollout { obj := rolloutDemo.DeepCopy() - obj.Spec.ObjectRef.WorkloadRef = &appsv1alpha1.WorkloadRef{ + obj.Spec.ObjectRef.WorkloadRef = &appsv1beta1.WorkloadRef{ APIVersion: "apps.kruise.io/v1beta1", Kind: "StatefulSet", Name: "echoserver", diff --git a/test/e2e/batchrelease_test.go b/test/e2e/batchrelease_test.go deleted file mode 100644 index 1830f4df..00000000 --- a/test/e2e/batchrelease_test.go +++ /dev/null @@ -1,1268 +0,0 @@ -/* -Copyright 2022 The Kruise 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 e2e - -import ( - "context" - "fmt" - "sort" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" - rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" - workloads "github.com/openkruise/rollouts/pkg/util" - "github.com/openkruise/rollouts/test/images" - apps "k8s.io/api/apps/v1" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/client-go/util/retry" - "k8s.io/utils/integer" - "k8s.io/utils/pointer" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -var _ = SIGDescribe("BatchRelease", func() { - var namespace string - - DumpAllResources := func() { - rollout := &rolloutsv1alpha1.RolloutList{} - k8sClient.List(context.TODO(), rollout, client.InNamespace(namespace)) - fmt.Println(workloads.DumpJSON(rollout)) - batch := &rolloutsv1alpha1.BatchReleaseList{} - k8sClient.List(context.TODO(), batch, client.InNamespace(namespace)) - fmt.Println(workloads.DumpJSON(batch)) - deploy := &apps.DeploymentList{} - k8sClient.List(context.TODO(), deploy, client.InNamespace(namespace)) - fmt.Println(workloads.DumpJSON(deploy)) - rs := &apps.ReplicaSetList{} - k8sClient.List(context.TODO(), rs, client.InNamespace(namespace)) - fmt.Println(workloads.DumpJSON(rs)) - } - - CreateObject := func(object client.Object, options ...client.CreateOption) { - object.SetNamespace(namespace) - Expect(k8sClient.Create(context.TODO(), object)).NotTo(HaveOccurred()) - } - - GetObject := func(namespace, name string, object client.Object) error { - key := types.NamespacedName{Namespace: namespace, Name: name} - return k8sClient.Get(context.TODO(), key, object) - } - - DeleteObject := func(object client.Object, options ...client.DeleteOption) { - Expect(k8sClient.Delete(context.TODO(), object)).NotTo(HaveOccurred()) - } - - UpdateRelease := func(object *rolloutsv1alpha1.BatchRelease) *rolloutsv1alpha1.BatchRelease { - var release *rolloutsv1alpha1.BatchRelease - Expect(retry.RetryOnConflict(retry.DefaultRetry, func() error { - release = &rolloutsv1alpha1.BatchRelease{} - err := GetObject(object.Namespace, object.Name, release) - if err != nil { - return err - } - release.Spec = *object.Spec.DeepCopy() - return k8sClient.Update(context.TODO(), release) - })).NotTo(HaveOccurred()) - - return release - } - - UpdateCloneSet := func(object *kruiseappsv1alpha1.CloneSet) *kruiseappsv1alpha1.CloneSet { - object = object.DeepCopy() - var clone *kruiseappsv1alpha1.CloneSet - Expect(retry.RetryOnConflict(retry.DefaultRetry, func() error { - clone = &kruiseappsv1alpha1.CloneSet{} - err := GetObject(object.Namespace, object.Name, clone) - if err != nil { - return err - } - object.Spec.UpdateStrategy = clone.Spec.UpdateStrategy - clone.Spec = *object.Spec.DeepCopy() - return k8sClient.Update(context.TODO(), clone) - })).NotTo(HaveOccurred()) - - return clone - } - - WaitCloneSetAllPodsReady := func(cloneset *kruiseappsv1alpha1.CloneSet) { - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.ObservedGeneration == clone.Generation && clone.Status.Replicas == clone.Status.ReadyReplicas - }, 20*time.Minute, time.Second).Should(BeTrue()) - } - - GetUpdateRevision := func(cloneset *kruiseappsv1alpha1.CloneSet) string { - var revision string - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - revision = clone.Status.UpdateRevision - return clone.Status.ObservedGeneration == clone.Generation - }, 20*time.Minute, time.Second).Should(BeTrue()) - return revision - } - - UpdateDeployment := func(object *apps.Deployment) *apps.Deployment { - object = object.DeepCopy() - var clone *apps.Deployment - Expect(retry.RetryOnConflict(retry.DefaultRetry, func() error { - clone = &apps.Deployment{} - err := GetObject(object.Namespace, object.Name, clone) - if err != nil { - return err - } - object.Spec.Strategy = clone.Spec.Strategy - clone.Spec = *object.Spec.DeepCopy() - return k8sClient.Update(context.TODO(), clone) - })).NotTo(HaveOccurred()) - - return clone - } - - GetCanaryDeployment := func(release *rolloutsv1alpha1.BatchRelease) *apps.Deployment { - var dList *apps.DeploymentList - dList = &apps.DeploymentList{} - Expect(k8sClient.List(context.TODO(), dList, client.InNamespace(release.Namespace))).NotTo(HaveOccurred()) - - var ds []*apps.Deployment - for i := range dList.Items { - d := &dList.Items[i] - if d.DeletionTimestamp != nil { - continue - } - if owner := metav1.GetControllerOf(d); owner == nil { - continue - } - ds = append(ds, d) - } - - if len(ds) == 0 { - return nil - } - - sort.Slice(ds, func(i, j int) bool { - return ds[j].CreationTimestamp.Before(&ds[i].CreationTimestamp) - }) - - return ds[0] - } - - WaitDeploymentAllPodsReady := func(deployment *apps.Deployment) { - Eventually(func() bool { - clone := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.ObservedGeneration == clone.Generation && clone.Status.Replicas == clone.Status.ReadyReplicas - }, 20*time.Minute, time.Second).Should(BeTrue()) - } - - WaitBatchReleaseProgressing := func(object *rolloutsv1alpha1.BatchRelease) { - startTime := time.Now() - Eventually(func() rolloutsv1alpha1.RolloutPhase { - release := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(object.Namespace, object.Name, release)).NotTo(HaveOccurred()) - if startTime.Add(time.Minute * 5).Before(time.Now()) { - DumpAllResources() - Fail("Timeout waiting batchRelease to 'Progressing' phase") - } - fmt.Println(release.Status.Phase) - return release.Status.Phase - }, 10*time.Minute, time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseProgressing)) - } - - BeforeEach(func() { - namespace = randomNamespaceName("batchrelease") - ns := v1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: namespace, - }, - } - Expect(k8sClient.Create(context.TODO(), &ns)).Should(SatisfyAny(BeNil())) - }) - - AfterEach(func() { - By("[TEST] Clean up resources after an integration test") - k8sClient.DeleteAllOf(context.TODO(), &apps.Deployment{}, client.InNamespace(namespace)) - if workloads.DiscoverGVK(workloads.ControllerKruiseKindCS) { - k8sClient.DeleteAllOf(context.TODO(), &kruiseappsv1alpha1.CloneSet{}, client.InNamespace(namespace)) - } - k8sClient.DeleteAllOf(context.TODO(), &rolloutsv1alpha1.BatchRelease{}, client.InNamespace(namespace)) - Expect(k8sClient.Delete(context.TODO(), &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, client.PropagationPolicy(metav1.DeletePropagationForeground))).Should(Succeed()) - }) - - KruiseDescribe("CloneSet BatchRelease Checker", func() { - It("V1->V2: Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneset.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - }) - - It("V1->V2: Percentage, 50%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_percentage_50.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneset.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - expectedReplicas, _ := intstr.GetScaledValueFromIntOrPercent( - &release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1].CanaryReplicas, int(*cloneset.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(Equal(int32(expectedReplicas))) - }) - - It("V1->V2(UnCompleted)->V3: Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease....") - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating CloneSet and waiting for all pods ready....") - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - stableRevisionV1 := GetUpdateRevision(cloneset) - - /************************************************************************************* - Start to release V1->V2 - *************************************************************************************/ - By("Start to release V1->V2....") - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevisionV2 := GetUpdateRevision(cloneset) - Expect(canaryRevisionV2).ShouldNot(Equal(stableRevisionV1)) - - By("V1->V2: Checking CloneSet updated replicas...") - for i := 0; i < len(release.Spec.ReleasePlan.Batches)-2; i++ { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneset.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("V1->V2: Checking BatchRelease status...") - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - Expect(clone.Status.Phase).ShouldNot(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - /************************************************************************************* - V1->V2 Succeeded, Start to release V2->V3 - *************************************************************************************/ - By("Start to release V2->V3....") - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV3) - UpdateCloneSet(cloneset) - - // record canary revision --> v3 - canaryRevisionV3 := GetUpdateRevision(cloneset) - Expect(canaryRevisionV3).ShouldNot(Equal(stableRevisionV1)) - Expect(canaryRevisionV3).ShouldNot(Equal(canaryRevisionV2)) - - By("V2->V3: Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - }) - - It("V1->V2: ScalingUp, Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneCopy.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling up from 5 to 10...") - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - cloneCopy.Spec.Replicas = pointer.Int32Ptr(10) - UpdateCloneSet(cloneCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas == *clone.Spec.Replicas - }, 15*time.Minute, 5*time.Second).Should(BeTrue()) - }) - - It("V1->V2: ScalingDown, Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(10) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneCopy.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling down from 10 to 2...") - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - cloneCopy.Spec.Replicas = pointer.Int32Ptr(2) - UpdateCloneSet(cloneCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas == *clone.Spec.Replicas - }, 15*time.Minute, 5*time.Second).Should(BeTrue()) - }) - - It("V1->V2: ScalingUp, Number, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_number_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(5) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneCopy.Spec.Replicas), true) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling up from 5 to 10...") - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - cloneCopy.Spec.Replicas = pointer.Int32Ptr(10) - UpdateCloneSet(cloneCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas == *clone.Spec.Replicas - }, 15*time.Minute, 5*time.Second).Should(BeTrue()) - }) - - It("V1->V2: ScalingDown, Number, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset_number_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - cloneset := &kruiseappsv1alpha1.CloneSet{} - Expect(ReadYamlToObject("./test_data/batchrelease/cloneset.yaml", cloneset)).ToNot(HaveOccurred()) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(cloneset) - WaitCloneSetAllPodsReady(cloneset) - - // record stable revision --> v1 - stableRevision := GetUpdateRevision(cloneset) - - cloneset.Spec.UpdateStrategy.Paused = true - cloneset.Spec.Replicas = pointer.Int32Ptr(10) - cloneset.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateCloneSet(cloneset) - - // record canary revision --> v2 - canaryRevision := GetUpdateRevision(cloneset) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking CloneSet updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*cloneCopy.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*cloneCopy.Spec.Replicas)) - Eventually(func() int32 { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling down from 10 to 2...") - cloneCopy := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, cloneCopy)).NotTo(HaveOccurred()) - cloneCopy.Spec.Replicas = pointer.Int32Ptr(2) - UpdateCloneSet(cloneCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - Eventually(func() bool { - clone := &kruiseappsv1alpha1.CloneSet{} - Expect(GetObject(cloneset.Namespace, cloneset.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.UpdatedReplicas == *clone.Spec.Replicas - }, 15*time.Minute, 5*time.Second).Should(BeTrue()) - }) - }) - - KruiseDescribe("Deployment BatchRelease Checker", func() { - - It("V1->V2: Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*deployment.Spec.Replicas), true) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.Replicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - }) - - It("V1->V2: Percentage, 50%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_50.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - WaitBatchReleaseProgressing(release) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*deployment.Spec.Replicas), true) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 5*time.Minute, time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking expected pods were updated when release completed...") - expectedReplicas, _ := intstr.GetScaledValueFromIntOrPercent( - &release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1].CanaryReplicas, int(*deployment.Spec.Replicas), true) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(Equal(int32(expectedReplicas))) - }) - - It("V1->V2(UnCompleted)->V3: Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease....") - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating Deployment and waiting for all pods ready....") - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - stableRevisionV1 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - /************************************************************************************* - Start to release V1->V2 - *************************************************************************************/ - By("Start to release V1->V2....") - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevisionV2 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV2).ShouldNot(Equal(stableRevisionV1)) - - By("V1->V2: Checking Deployment updated replicas...") - for i := 0; i < len(release.Spec.ReleasePlan.Batches)-2; i++ { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*deployment.Spec.Replicas), true) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - } - - By("V1->V2: Checking BatchRelease status...") - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - Expect(clone.Status.Phase).ShouldNot(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - /************************************************************************************* - V1->V2 Not Completed, Start to release V1,V2->V3 - *************************************************************************************/ - By("Start to release V1,V2->V3...") - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV3) - UpdateDeployment(deployment) - - // record canary revision --> v3 - canaryRevisionV3 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV3).ShouldNot(Equal(stableRevisionV1)) - Expect(canaryRevisionV3).ShouldNot(Equal(canaryRevisionV2)) - - By("V2->V3: Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - }) - - It("V1->V2: ScalingUp, Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - fetchedDeployment := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling up from 5 to 10....") - deployCopy := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, deployCopy)).NotTo(HaveOccurred()) - deployCopy.Spec.Replicas = pointer.Int32Ptr(10) - UpdateDeployment(deployCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - fetchedDeployment := &apps.Deployment{} - batch := release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1] - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - }) - - It("V1->V2: ScalingDown, Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(10) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - fetchedDeployment := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 0 { - By("\tScaling down from 10 to 2....") - deployCopy := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, deployCopy)).NotTo(HaveOccurred()) - deployCopy.Spec.Replicas = pointer.Int32Ptr(2) - UpdateDeployment(deployCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - fetchedDeployment := &apps.Deployment{} - batch := release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1] - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - }) - - It("V1->V2: ScalingUp, Number, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_number_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - batch := &release.Spec.ReleasePlan.Batches[i] - fetchedDeployment := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling up from 5 to 10....") - deployCopy := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, deployCopy)).NotTo(HaveOccurred()) - deployCopy.Spec.Replicas = pointer.Int32Ptr(10) - UpdateDeployment(deployCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - fetchedDeployment := &apps.Deployment{} - batch := release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1] - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(Equal(int32(expectedUpdatedReplicas))) - }) - - It("V1->V2: ScalingDown, Number, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_number_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Replicas = pointer.Int32Ptr(5) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - - By("Checking Deployment updated replicas...") - for i := range release.Spec.ReleasePlan.Batches { - By(fmt.Sprintf("\tWaiting for batch[%v] completed...", i)) - batch := &release.Spec.ReleasePlan.Batches[i] - fetchedDeployment := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - clone := GetCanaryDeployment(release) - Expect(clone).ShouldNot(BeNil()) - return clone.Status.UpdatedReplicas - }, 5*time.Minute, time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - if i == 1 { - By("\tScaling down from 10 to 2....") - deployCopy := &apps.Deployment{} - Expect(GetObject(deployment.Namespace, deployment.Name, deployCopy)).NotTo(HaveOccurred()) - deployCopy.Spec.Replicas = pointer.Int32Ptr(2) - UpdateDeployment(deployCopy) - } - } - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - fetchedDeployment := &apps.Deployment{} - batch := release.Spec.ReleasePlan.Batches[len(release.Spec.ReleasePlan.Batches)-1] - Expect(GetObject(deployment.Namespace, deployment.Name, fetchedDeployment)).NotTo(HaveOccurred()) - expectedUpdatedReplicas, _ := intstr.GetScaledValueFromIntOrPercent(&batch.CanaryReplicas, int(*fetchedDeployment.Spec.Replicas), true) - expectedUpdatedReplicas = integer.IntMin(expectedUpdatedReplicas, int(*fetchedDeployment.Spec.Replicas)) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(BeNumerically(">=", int32(expectedUpdatedReplicas))) - }) - - It("Rollback V1->V2->V1: Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy = v1.PullIfNotPresent - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevisionV1 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - //deployment.Spec.Replicas = pointer.Int32Ptr(10) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.FailedImage) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevisionV2 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV2).ShouldNot(Equal(stableRevisionV1)) - - By("Waiting a minute and checking failed revision...") - time.Sleep(time.Minute) - for i := 0; i < 30; i++ { - fetchedRelease := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, fetchedRelease)).NotTo(HaveOccurred()) - Expect(fetchedRelease.Status.CanaryStatus.UpdatedReplicas).Should(Equal(int32(1))) - Expect(fetchedRelease.Status.CanaryStatus.UpdatedReadyReplicas).Should(Equal(int32(0))) - Expect(fetchedRelease.Status.CanaryStatus.CurrentBatch).Should(Equal(int32(0))) - time.Sleep(time.Second) - } - - By("Updating deployment to V1...") - deployment.Spec.Paused = true - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - UpdateDeployment(deployment) - // record canary revision --> v2 - canaryRevisionV3 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV3).Should(Equal(stableRevisionV1)) - - By("Checking BatchRelease completed status phase...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - }) - - It("Rollback V1->V2: Delete BatchRelease, Percentage, 100%, Succeeded", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Replicas = pointer.Int32Ptr(10) - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy = v1.PullIfNotPresent - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevisionV1 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.FailedImage) - UpdateDeployment(deployment) - WaitBatchReleaseProgressing(release) - - // record canary revision --> v2 - canaryRevisionV2 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV2).ShouldNot(Equal(stableRevisionV1)) - - By("Waiting a minute and checking failed revision...") - time.Sleep(time.Minute) - for i := 0; i < 30; i++ { - fetchedRelease := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, fetchedRelease)).NotTo(HaveOccurred()) - Expect(fetchedRelease.Status.CanaryStatus.CurrentBatch).Should(Equal(int32(0))) - time.Sleep(time.Second) - } - - By("Updating deployment to V1...") - deployment.Spec.Paused = true - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV1) - UpdateDeployment(deployment) - canaryRevisionV3 := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevisionV3).Should(Equal(stableRevisionV1)) - - By("Deleting BatchReleasing...") - DeleteObject(release) - Eventually(func() bool { - objectCopy := &rolloutsv1alpha1.BatchRelease{} - err := GetObject(release.Namespace, release.Name, objectCopy) - return errors.IsNotFound(err) - }, time.Minute, time.Second).Should(BeTrue()) - - By("Check canary deployment was cleaned up") - Eventually(func() bool { - return GetCanaryDeployment(release) == nil - }, 5*time.Minute, time.Second).Should(BeTrue()) - }) - - It("Plan changed during rollout", func() { - By("Creating BatchRelease...") - release := &rolloutsv1alpha1.BatchRelease{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment_percentage_100.yaml", release)).ToNot(HaveOccurred()) - CreateObject(release) - - By("Creating workload and waiting for all pods ready...") - deployment := &apps.Deployment{} - Expect(ReadYamlToObject("./test_data/batchrelease/deployment.yaml", deployment)).ToNot(HaveOccurred()) - deployment.Spec.Replicas = pointer.Int32Ptr(10) - deployment.Spec.Strategy.Type = apps.RollingUpdateDeploymentStrategyType - deployment.Spec.Strategy.RollingUpdate = &apps.RollingUpdateDeployment{ - MaxSurge: &intstr.IntOrString{Type: intstr.Int, IntVal: 1}, - MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0}, - } - CreateObject(deployment) - WaitDeploymentAllPodsReady(deployment) - Expect(GetObject(release.Namespace, release.Name, release)) - Expect(release.Status.Phase).Should(Equal(rolloutsv1alpha1.RolloutPhaseHealthy)) - - // record stable revision --> v1 - stableRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - - deployment.Spec.Paused = true - deployment.Spec.Template.Spec.Containers[0].Image = images.GetE2EImage(images.BusyBoxV2) - UpdateDeployment(deployment) - - // record canary revision --> v2 - canaryRevision := workloads.ComputeHash(&deployment.Spec.Template, deployment.Status.CollisionCount) - Expect(canaryRevision).ShouldNot(Equal(stableRevision)) - WaitBatchReleaseProgressing(release) - - var fetchedRelease *rolloutsv1alpha1.BatchRelease - Eventually(func() bool { - fetchedRelease = &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, fetchedRelease)).NotTo(HaveOccurred()) - return fetchedRelease.Status.CanaryStatus.CurrentBatch == 1 && - fetchedRelease.Status.CanaryStatus.CurrentBatchState == rolloutsv1alpha1.ReadyBatchState - }, time.Minute, 5*time.Second).Should(BeTrue()) - - // now canary: 4 - fetchedRelease.Spec.ReleasePlan.Batches = []rolloutsv1alpha1.ReleaseBatch{ - { - CanaryReplicas: intstr.FromInt(4), - }, - { - CanaryReplicas: intstr.FromString("100%"), - }, - } - - By("Update BatchRelease plan...") - UpdateRelease(fetchedRelease) - - By("Checking BatchRelease status...") - Eventually(func() rolloutsv1alpha1.RolloutPhase { - clone := &rolloutsv1alpha1.BatchRelease{} - Expect(GetObject(release.Namespace, release.Name, clone)).NotTo(HaveOccurred()) - return clone.Status.Phase - }, 15*time.Minute, 5*time.Second).Should(Equal(rolloutsv1alpha1.RolloutPhaseCompleted)) - - By("Checking all pod were updated when release completed...") - Expect(GetObject(deployment.Namespace, deployment.Name, deployment)).NotTo(HaveOccurred()) - Eventually(func() int32 { - canary := GetCanaryDeployment(release) - Expect(canary).ShouldNot(BeNil()) - return canary.Status.UpdatedReplicas - }, 15*time.Minute, 5*time.Second).Should(Equal(*deployment.Spec.Replicas)) - }) - }) -}) diff --git a/test/e2e/rollout_test.go b/test/e2e/rollout_test.go index bc7393ed..31151158 100644 --- a/test/e2e/rollout_test.go +++ b/test/e2e/rollout_test.go @@ -49,6 +49,16 @@ const ( OriginalSpecAnnotation = "rollouts.kruise.io/original-spec-configuration" ) +func getRolloutCondition(status v1alpha1.RolloutStatus, condType v1alpha1.RolloutConditionType) *v1alpha1.RolloutCondition { + for i := range status.Conditions { + c := status.Conditions[i] + if c.Type == condType { + return &c + } + } + return nil +} + var _ = SIGDescribe("Rollout", func() { var namespace string @@ -571,10 +581,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -739,10 +749,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -857,10 +867,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing canceled Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision)) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -1011,10 +1021,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -1151,10 +1161,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -1288,10 +1298,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -1396,7 +1406,7 @@ var _ = SIGDescribe("Rollout", func() { // check rollout status Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonPaused)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(rollout.Status.CanaryStatus.CurrentStepIndex).Should(BeNumerically("==", cIndex)) @@ -1430,10 +1440,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -1652,10 +1662,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -1787,10 +1797,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -1949,10 +1959,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2113,10 +2123,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2287,10 +2297,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2429,10 +2439,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -2598,10 +2608,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2704,10 +2714,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2819,10 +2829,10 @@ var _ = SIGDescribe("Rollout", func() { } // check progressing succeed Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -2966,10 +2976,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -3063,10 +3073,10 @@ var _ = SIGDescribe("Rollout", func() { By("rollout completed, and check") // check progressing canceled Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) Expect(string(cond.Status)).Should(Equal("False")) Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision)) @@ -3230,10 +3240,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) }) @@ -3327,10 +3337,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) }) @@ -3420,10 +3430,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -3581,10 +3591,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -3731,10 +3741,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) }) @@ -3824,10 +3834,10 @@ var _ = SIGDescribe("Rollout", func() { By("rollout completed, and check") // check progressing canceled Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision)) @@ -3932,10 +3942,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -4092,10 +4102,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -4242,10 +4252,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) }) @@ -4335,10 +4345,10 @@ var _ = SIGDescribe("Rollout", func() { By("rollout completed, and check") // check progressing canceled Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision)) @@ -4443,10 +4453,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -5173,10 +5183,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) //Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(canaryRevision)) @@ -5645,10 +5655,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) @@ -5785,10 +5795,10 @@ var _ = SIGDescribe("Rollout", func() { // check progressing succeed Expect(GetObject(workload.Name, workload)).NotTo(HaveOccurred()) Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) - cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) + cond := getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionProgressing) Expect(cond.Reason).Should(Equal(v1alpha1.ProgressingReasonCompleted)) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionFalse))) - cond = util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) + cond = getRolloutCondition(rollout.Status, v1alpha1.RolloutConditionSucceeded) Expect(string(cond.Status)).Should(Equal(string(metav1.ConditionTrue))) WaitRolloutWorkloadGeneration(rollout.Name, workload.Generation) }) diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index d344ca6c..2f48f7a6 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -30,7 +30,7 @@ import ( . "github.com/onsi/gomega" kruisev1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1" kruisev1beta1 "github.com/openkruise/kruise-api/apps/v1beta1" - rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" + rolloutapi "github.com/openkruise/rollouts/api" crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -62,7 +62,7 @@ var _ = BeforeSuite(func(done Done) { logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(GinkgoWriter))) err := clientgoscheme.AddToScheme(scheme) Expect(err).Should(BeNil()) - err = rolloutsv1alpha1.AddToScheme(scheme) + err = rolloutapi.AddToScheme(scheme) Expect(err).Should(BeNil()) err = crdv1.AddToScheme(scheme) Expect(err).Should(BeNil())