@@ -17,39 +17,36 @@ package deployment
17
17
import (
18
18
"slices"
19
19
20
- "github.com/pipe-cd/pipecd/pkg/model"
21
20
"github.com/pipe-cd/pipecd/pkg/plugin/sdk"
22
21
)
23
22
24
- type Stage string
25
-
26
23
const (
27
24
// StageK8sSync represents the state where
28
25
// all resources should be synced with the Git state.
29
- StageK8sSync Stage = "K8S_SYNC"
26
+ StageK8sSync = "K8S_SYNC"
30
27
// StageK8sPrimaryRollout represents the state where
31
28
// the PRIMARY variant resources has been updated to the new version/configuration.
32
- StageK8sPrimaryRollout Stage = "K8S_PRIMARY_ROLLOUT"
29
+ StageK8sPrimaryRollout = "K8S_PRIMARY_ROLLOUT"
33
30
// StageK8sCanaryRollout represents the state where
34
31
// the CANARY variant resources has been rolled out with the new version/configuration.
35
- StageK8sCanaryRollout Stage = "K8S_CANARY_ROLLOUT"
32
+ StageK8sCanaryRollout = "K8S_CANARY_ROLLOUT"
36
33
// StageK8sCanaryClean represents the state where
37
34
// the CANARY variant resources has been cleaned.
38
- StageK8sCanaryClean Stage = "K8S_CANARY_CLEAN"
35
+ StageK8sCanaryClean = "K8S_CANARY_CLEAN"
39
36
// StageK8sBaselineRollout represents the state where
40
37
// the BASELINE variant resources has been rolled out.
41
- StageK8sBaselineRollout Stage = "K8S_BASELINE_ROLLOUT"
38
+ StageK8sBaselineRollout = "K8S_BASELINE_ROLLOUT"
42
39
// StageK8sBaselineClean represents the state where
43
40
// the BASELINE variant resources has been cleaned.
44
- StageK8sBaselineClean Stage = "K8S_BASELINE_CLEAN"
41
+ StageK8sBaselineClean = "K8S_BASELINE_CLEAN"
45
42
// StageK8sTrafficRouting represents the state where the traffic to application
46
43
// should be splitted as the specified percentage to PRIMARY, CANARY, BASELINE variants.
47
- StageK8sTrafficRouting Stage = "K8S_TRAFFIC_ROUTING"
44
+ StageK8sTrafficRouting = "K8S_TRAFFIC_ROUTING"
48
45
// StageK8sRollback represents the state where all deployed resources should be rollbacked.
49
- StageK8sRollback Stage = "K8S_ROLLBACK"
46
+ StageK8sRollback = "K8S_ROLLBACK"
50
47
)
51
48
52
- var AllStages = []Stage {
49
+ var allStages = []string {
53
50
StageK8sSync ,
54
51
StageK8sPrimaryRollout ,
55
52
StageK8sCanaryRollout ,
@@ -60,54 +57,29 @@ var AllStages = []Stage{
60
57
StageK8sRollback ,
61
58
}
62
59
63
- func (s Stage ) String () string {
64
- return string (s )
65
- }
66
-
67
60
const (
68
- PredefinedStageK8sSync = "K8sSync"
69
- PredefinedStageRollback = "K8sRollback"
61
+ // StageDescriptionK8sSync represents the description of the K8sSync stage.
62
+ StageDescriptionK8sSync = "Sync by applying all manifests"
63
+ // StageDescriptionK8sRollback represents the description of the K8sRollback stage.
64
+ StageDescriptionK8sRollback = "Rollback the deployment"
70
65
)
71
66
72
- var predefinedStages = map [string ]* model.PipelineStage {
73
- PredefinedStageK8sSync : {
74
- Id : PredefinedStageK8sSync ,
75
- Name : string (StageK8sSync ),
76
- Desc : "Sync by applying all manifests" ,
77
- Rollback : false ,
78
- },
79
- PredefinedStageRollback : {
80
- Id : PredefinedStageRollback ,
81
- Name : string (StageK8sRollback ),
82
- Desc : "Rollback the deployment" ,
83
- Rollback : true ,
84
- },
85
- }
86
-
87
- // GetPredefinedStage finds and returns the predefined stage for the given id.
88
- func GetPredefinedStage (id string ) (* model.PipelineStage , bool ) {
89
- stage , ok := predefinedStages [id ]
90
- return stage , ok
91
- }
92
-
93
67
func buildQuickSyncPipeline (autoRollback bool ) []sdk.QuickSyncStage {
94
68
out := make ([]sdk.QuickSyncStage , 0 , 2 )
95
69
96
- stage , _ := GetPredefinedStage (PredefinedStageK8sSync )
97
70
out = append (out , sdk.QuickSyncStage {
98
- Name : stage . GetName () ,
99
- Description : stage . GetDesc () ,
71
+ Name : StageK8sSync ,
72
+ Description : StageDescriptionK8sSync ,
100
73
Rollback : false ,
101
74
Metadata : make (map [string ]string , 0 ),
102
75
AvailableOperation : sdk .ManualOperationNone ,
103
76
},
104
77
)
105
78
106
79
if autoRollback {
107
- s , _ := GetPredefinedStage (PredefinedStageRollback )
108
80
out = append (out , sdk.QuickSyncStage {
109
- Name : s . GetName () ,
110
- Description : s . GetDesc () ,
81
+ Name : StageK8sRollback ,
82
+ Description : StageDescriptionK8sRollback ,
111
83
Rollback : true ,
112
84
Metadata : make (map [string ]string , 0 ),
113
85
AvailableOperation : sdk .ManualOperationNone ,
@@ -136,9 +108,9 @@ func buildPipelineStages(stages []sdk.StageConfig, autoRollback bool) []sdk.Pipe
136
108
minIndex := slices .MinFunc (stages , func (a , b sdk.StageConfig ) int {
137
109
return a .Index - b .Index
138
110
}).Index
139
- // we copy the predefined stage to avoid modifying the original one.
111
+
140
112
out = append (out , sdk.PipelineStage {
141
- Name : StageK8sRollback . String () ,
113
+ Name : StageK8sRollback ,
142
114
Index : minIndex ,
143
115
Rollback : true ,
144
116
Metadata : make (map [string ]string , 0 ),
0 commit comments