Skip to content

Commit f3b6a6f

Browse files
authored
Merge pull request #284 from Abirdcfly/rollback
feat: componentplan support rollback
2 parents 301a284 + 4ff364e commit f3b6a6f

File tree

9 files changed

+251
-69
lines changed

9 files changed

+251
-69
lines changed

api/v1alpha1/common.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,20 @@ type Config struct {
226226
// +kubebuilder:validation:Required
227227
Name string `json:"name"`
228228

229-
// Force is passed to helm upgrade --force
230-
// force resource updates through a replacement strategy
229+
// Force is passed to helm upgrade/rollback --force
230+
// in upgrade, force resource updates through a replacement strategy
231+
// in rollback, force resource update through delete/recreate if needed
231232
Force bool `json:"force,omitempty"`
232233

233-
// TimeoutSeconds is pass to helm install/upgrade --timeout, default is 300s
234+
// TimeoutSeconds is pass to helm install/upgrade/rollback --timeout, default is 300s
234235
// time to wait for any individual Kubernetes operation (like Jobs for hooks)
235236
TimeOutSeconds int `json:"timeoutSeconds,omitempty"`
236237

237-
// Wait is pass to helm install/upgrade --wait
238+
// Wait is pass to helm install/upgrade/rollback --wait
238239
// if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout
239240
Wait bool `json:"wait,omitempty"`
240241

241-
// WaitForJobs is pass to helm install/upgrade --wait-for-jobs
242+
// WaitForJobs is pass to helm install/upgrade/rollback --wait-for-jobs
242243
// if set and --wait enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as --timeout
243244
WaitForJobs bool `json:"waitForJobs,omitempty"`
244245

@@ -250,7 +251,7 @@ type Config struct {
250251
// update dependencies if they are missing before installing the chart
251252
DependencyUpdate bool `json:"dependencyUpdate,omitempty"`
252253

253-
// DisableHooks is pass to helm install/upgrade --no-hooks
254+
// DisableHooks is pass to helm install/upgrade/rollback --no-hooks
254255
// if set, prevent hooks from running during install and disable pre/post upgrade hooks
255256
DisableHooks bool `json:"disableHooks,omitempty"`
256257

@@ -270,11 +271,11 @@ type Config struct {
270271
// enable DNS lookups when rendering templates
271272
EnableDNS bool `json:"enableDNS,omitempty"`
272273

273-
// CleanupOnFail is pass to helm upgrade --cleanup-on-fail
274+
// CleanupOnFail is pass to helm upgrade/rollback --cleanup-on-fail
274275
// allow deletion of new resources created in this upgrade when upgrade fails
275276
CleanupOnFail bool `json:"cleanupOnFail,omitempty"`
276277

277-
// KeepHistory is paas to helm uninstall --keep-history
278+
// KeepHistory is paas to helm uninstall/rollback --keep-history
278279
// remove all associated resources and mark the release as deleted, but retain the release history.
279280
KeepHistory bool `json:"keepHistory,omitempty"`
280281

@@ -284,6 +285,10 @@ type Config struct {
284285

285286
// MaxRetry
286287
MaxRetry *int `json:"maxRetry,omitempty"`
288+
289+
// RecreatePods is pass to helm rollback --recreate-pods
290+
// performs pods restart for the resource if applicable. default is false
291+
RecreatePods bool `json:"recreatePods,omitempty"`
287292
}
288293

289294
func (c *Config) Timeout() time.Duration {

api/v1alpha1/componentplan.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
const (
3636
ComponentPlanReleaseNameLabel = Group + "/componentplan-release"
3737
ComponentPlanRetryTimesAnnotation = Group + "/componentplan-retry"
38+
ComponentPlanRollBackLabel = Group + "/rollback"
3839
)
3940

4041
// ConditionType for ComponentPlan
@@ -50,12 +51,15 @@ const (
5051
ComponentPlanReasonInstalling ConditionReason = "Installing"
5152
ComponentPlanReasonUpgrading ConditionReason = "Upgrading"
5253
ComponentPlanReasonUninstalling ConditionReason = "Uninstalling"
54+
ComponentPlanReasonRollingBack ConditionReason = "RollingBack"
5355
ComponentPlanReasonInstallSuccess ConditionReason = "InstallSuccess"
5456
ComponentPlanReasonInstallFailed ConditionReason = "InstallFailed"
5557
ComponentPlanReasonUninstallSuccess ConditionReason = "UninstallSuccess"
5658
ComponentPlanReasonUninstallFailed ConditionReason = "UninstallFailed"
5759
ComponentPlanReasonUpgradeSuccess ConditionReason = "UpgradeSuccess"
5860
ComponentPlanReasonUpgradeFailed ConditionReason = "UpgradeFailed"
61+
ComponentPlanReasonRollBackSuccess ConditionReason = "RollBackSuccess"
62+
ComponentPlanReasonRollBackFailed ConditionReason = "RollBackFailed"
5963
)
6064

6165
// GenerateComponentPlanName generates the name of the component plan for a given subscription
@@ -127,6 +131,17 @@ func ComponentPlanWaitDo(err error) Condition {
127131
return componentPlanCondition(ComponentPlanTypeActioned, ComponentPlanReasonWaitDo, corev1.ConditionFalse, err)
128132
}
129133

134+
func ComponentPlanRollBackSuccess() Condition {
135+
return componentPlanCondition(ComponentPlanTypeActioned, ComponentPlanReasonRollBackSuccess, corev1.ConditionTrue, nil)
136+
}
137+
138+
func ComponentPlanRollBackFailed(err error) Condition {
139+
return componentPlanCondition(ComponentPlanTypeActioned, ComponentPlanReasonRollBackFailed, corev1.ConditionFalse, err)
140+
}
141+
142+
func ComponentPlanRollingBack() Condition {
143+
return componentPlanCondition(ComponentPlanTypeActioned, ComponentPlanReasonRollingBack, corev1.ConditionFalse, nil)
144+
}
130145
func componentPlanCondition(ct ConditionType, reason ConditionReason, status corev1.ConditionStatus, err error) Condition {
131146
if status == "" {
132147
status = corev1.ConditionUnknown

config/crd/bases/core.kubebb.k8s.com.cn_componentplans.yaml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
--wait flag will be set automatically if --atomic is used
4949
type: boolean
5050
cleanupOnFail:
51-
description: CleanupOnFail is pass to helm upgrade --cleanup-on-fail
51+
description: CleanupOnFail is pass to helm upgrade/rollback --cleanup-on-fail
5252
allow deletion of new resources created in this upgrade when upgrade
5353
fails
5454
type: boolean
@@ -101,9 +101,9 @@ spec:
101101
add a custom description
102102
type: string
103103
disableHooks:
104-
description: DisableHooks is pass to helm install/upgrade --no-hooks
105-
if set, prevent hooks from running during install and disable pre/post
106-
upgrade hooks
104+
description: DisableHooks is pass to helm install/upgrade/rollback
105+
--no-hooks if set, prevent hooks from running during install and
106+
disable pre/post upgrade hooks
107107
type: boolean
108108
disableOpenAPIValidation:
109109
description: DisableOpenAPIValidation is pass to helm install/upgrade
@@ -115,16 +115,17 @@ spec:
115115
enable DNS lookups when rendering templates
116116
type: boolean
117117
force:
118-
description: Force is passed to helm upgrade --force force resource
119-
updates through a replacement strategy
118+
description: Force is passed to helm upgrade/rollback --force in upgrade,
119+
force resource updates through a replacement strategy in rollback,
120+
force resource update through delete/recreate if needed
120121
type: boolean
121122
historyMax:
122123
description: MaxHistory is pass to helm upgrade --history-max limit
123124
the maximum number of revisions saved per release. Use 0 for no
124125
limit
125126
type: integer
126127
keepHistory:
127-
description: KeepHistory is paas to helm uninstall --keep-history
128+
description: KeepHistory is paas to helm uninstall/rollback --keep-history
128129
remove all associated resources and mark the release as deleted,
129130
but retain the release history.
130131
type: boolean
@@ -227,32 +228,37 @@ spec:
227228
type: object
228229
type: array
229230
type: object
231+
recreatePods:
232+
description: RecreatePods is pass to helm rollback --recreate-pods
233+
performs pods restart for the resource if applicable. default is
234+
false
235+
type: boolean
230236
skipCRDs:
231237
description: SkipCRDs is pass to helm install/upgrade --skip-crds
232238
if set, no CRDs will be installed. By default, CRDs are installed
233239
if not already present
234240
type: boolean
235241
timeoutSeconds:
236-
description: TimeoutSeconds is pass to helm install/upgrade --timeout,
237-
default is 300s time to wait for any individual Kubernetes operation
238-
(like Jobs for hooks)
242+
description: TimeoutSeconds is pass to helm install/upgrade/rollback
243+
--timeout, default is 300s time to wait for any individual Kubernetes
244+
operation (like Jobs for hooks)
239245
type: integer
240246
version:
241247
description: InstallVersion represents the version that is to be installed
242248
by this ComponentPlan
243249
type: string
244250
wait:
245-
description: Wait is pass to helm install/upgrade --wait if set, will
246-
wait until all Pods, PVCs, Services, and minimum number of Pods
247-
of a Deployment, StatefulSet, or ReplicaSet are in a ready state
248-
before marking the release as successful. It will wait for as long
249-
as --timeout
251+
description: Wait is pass to helm install/upgrade/rollback --wait
252+
if set, will wait until all Pods, PVCs, Services, and minimum number
253+
of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready
254+
state before marking the release as successful. It will wait for
255+
as long as --timeout
250256
type: boolean
251257
waitForJobs:
252-
description: WaitForJobs is pass to helm install/upgrade --wait-for-jobs
253-
if set and --wait enabled, will wait until all Jobs have been completed
254-
before marking the release as successful. It will wait for as long
255-
as --timeout
258+
description: WaitForJobs is pass to helm install/upgrade/rollback
259+
--wait-for-jobs if set and --wait enabled, will wait until all Jobs
260+
have been completed before marking the release as successful. It
261+
will wait for as long as --timeout
256262
type: boolean
257263
required:
258264
- approved

config/crd/bases/core.kubebb.k8s.com.cn_subscriptions.yaml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ spec:
4444
--wait flag will be set automatically if --atomic is used
4545
type: boolean
4646
cleanupOnFail:
47-
description: CleanupOnFail is pass to helm upgrade --cleanup-on-fail
47+
description: CleanupOnFail is pass to helm upgrade/rollback --cleanup-on-fail
4848
allow deletion of new resources created in this upgrade when upgrade
4949
fails
5050
type: boolean
@@ -101,9 +101,9 @@ spec:
101101
add a custom description
102102
type: string
103103
disableHooks:
104-
description: DisableHooks is pass to helm install/upgrade --no-hooks
105-
if set, prevent hooks from running during install and disable pre/post
106-
upgrade hooks
104+
description: DisableHooks is pass to helm install/upgrade/rollback
105+
--no-hooks if set, prevent hooks from running during install and
106+
disable pre/post upgrade hooks
107107
type: boolean
108108
disableOpenAPIValidation:
109109
description: DisableOpenAPIValidation is pass to helm install/upgrade
@@ -115,16 +115,17 @@ spec:
115115
enable DNS lookups when rendering templates
116116
type: boolean
117117
force:
118-
description: Force is passed to helm upgrade --force force resource
119-
updates through a replacement strategy
118+
description: Force is passed to helm upgrade/rollback --force in upgrade,
119+
force resource updates through a replacement strategy in rollback,
120+
force resource update through delete/recreate if needed
120121
type: boolean
121122
historyMax:
122123
description: MaxHistory is pass to helm upgrade --history-max limit
123124
the maximum number of revisions saved per release. Use 0 for no
124125
limit
125126
type: integer
126127
keepHistory:
127-
description: KeepHistory is paas to helm uninstall --keep-history
128+
description: KeepHistory is paas to helm uninstall/rollback --keep-history
128129
remove all associated resources and mark the release as deleted,
129130
but retain the release history.
130131
type: boolean
@@ -227,6 +228,11 @@ spec:
227228
type: object
228229
type: array
229230
type: object
231+
recreatePods:
232+
description: RecreatePods is pass to helm rollback --recreate-pods
233+
performs pods restart for the resource if applicable. default is
234+
false
235+
type: boolean
230236
repository:
231237
description: RepositoryRef is a reference to the Repository
232238
properties:
@@ -274,22 +280,22 @@ spec:
274280
if not already present
275281
type: boolean
276282
timeoutSeconds:
277-
description: TimeoutSeconds is pass to helm install/upgrade --timeout,
278-
default is 300s time to wait for any individual Kubernetes operation
279-
(like Jobs for hooks)
283+
description: TimeoutSeconds is pass to helm install/upgrade/rollback
284+
--timeout, default is 300s time to wait for any individual Kubernetes
285+
operation (like Jobs for hooks)
280286
type: integer
281287
wait:
282-
description: Wait is pass to helm install/upgrade --wait if set, will
283-
wait until all Pods, PVCs, Services, and minimum number of Pods
284-
of a Deployment, StatefulSet, or ReplicaSet are in a ready state
285-
before marking the release as successful. It will wait for as long
286-
as --timeout
288+
description: Wait is pass to helm install/upgrade/rollback --wait
289+
if set, will wait until all Pods, PVCs, Services, and minimum number
290+
of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready
291+
state before marking the release as successful. It will wait for
292+
as long as --timeout
287293
type: boolean
288294
waitForJobs:
289-
description: WaitForJobs is pass to helm install/upgrade --wait-for-jobs
290-
if set and --wait enabled, will wait until all Jobs have been completed
291-
before marking the release as successful. It will wait for as long
292-
as --timeout
295+
description: WaitForJobs is pass to helm install/upgrade/rollback
296+
--wait-for-jobs if set and --wait enabled, will wait until all Jobs
297+
have been completed before marking the release as successful. It
298+
will wait for as long as --timeout
293299
type: boolean
294300
required:
295301
- component

0 commit comments

Comments
 (0)