@@ -33,6 +33,7 @@ type testCase struct {
3333 // versions, so for test scenarios that start with existing deprecated version Deployments,
3434 // specify the number of replicas for each deprecated build here.
3535 deprecatedBuildReplicas map [string ]int32
36+ deprecatedBuildImages map [string ]string
3637 expectedStatus * temporaliov1alpha1.TemporalWorkerDeploymentStatus
3738}
3839
@@ -87,19 +88,8 @@ func TestIntegration(t *testing.T) {
8788 }),
8889 deprecatedBuildReplicas : nil ,
8990 expectedStatus : & temporaliov1alpha1.TemporalWorkerDeploymentStatus {
90- TargetVersion : nil ,
91- CurrentVersion : & temporaliov1alpha1.CurrentWorkerDeploymentVersion {
92- BaseWorkerDeploymentVersion : temporaliov1alpha1.BaseWorkerDeploymentVersion {
93- VersionID : testhelpers .MakeVersionId (testNamespace .Name , "all-at-once-rollout-2-replicas" , "v1" ),
94- Deployment : & corev1.ObjectReference {
95- Namespace : testNamespace .Name ,
96- Name : k8s .ComputeVersionedDeploymentName (
97- "all-at-once-rollout-2-replicas" ,
98- testhelpers .MakeBuildId ("all-at-once-rollout-2-replicas" , "v1" , nil ),
99- ),
100- },
101- },
102- },
91+ TargetVersion : nil ,
92+ CurrentVersion : testhelpers .MakeCurrentVersion (testNamespace .Name , "all-at-once-rollout-2-replicas" , "v1" , true , false ),
10393 RampingVersion : nil ,
10494 DeprecatedVersions : nil ,
10595 VersionConflictToken : nil ,
@@ -122,9 +112,18 @@ func TestIntegration(t *testing.T) {
122112 Namespace : testNamespace .Name ,
123113 Labels : map [string ]string {"app" : "test-worker" },
124114 }
115+ obj .Status = temporaliov1alpha1.TemporalWorkerDeploymentStatus {
116+ TargetVersion : nil ,
117+ CurrentVersion : testhelpers .MakeCurrentVersion (testNamespace .Name , "progressive-rollout-expect-first-step" , "v0" , true , true ),
118+ RampingVersion : nil ,
119+ DeprecatedVersions : nil ,
120+ VersionConflictToken : nil ,
121+ LastModifierIdentity : "" ,
122+ }
125123 return obj
126124 }),
127- deprecatedBuildReplicas : nil ,
125+ deprecatedBuildReplicas : map [string ]int32 {testhelpers .MakeBuildId ("progressive-rollout-expect-first-step" , "v0" , nil ): 1 },
126+ deprecatedBuildImages : map [string ]string {testhelpers .MakeBuildId ("progressive-rollout-expect-first-step" , "v0" , nil ): "v0" },
128127 expectedStatus : & temporaliov1alpha1.TemporalWorkerDeploymentStatus {
129128 TargetVersion : & temporaliov1alpha1.TargetWorkerDeploymentVersion {
130129 BaseWorkerDeploymentVersion : temporaliov1alpha1.BaseWorkerDeploymentVersion {
@@ -168,20 +167,129 @@ func TestIntegration(t *testing.T) {
168167
169168 for testName , tc := range tests {
170169 t .Run (testName , func (t * testing.T ) {
171- // TODO(carlydf): create starting test env
172- // - Use input.Status + deprecatedBuildReplicas to create (and maybe kill) pollers for deprecated versions in temporal
173- // - also get routing config of the deployment into the starting state before running the test
174-
175- testTemporalWorkerDeploymentCreation (t , k8sClient , ts , tc .input , tc .expectedStatus )
170+ ctx := context .Background ()
171+ // TODO(carlydf): populate all fields in tc that are set to testName, so that the user does not need to specify
172+ testTemporalWorkerDeploymentCreation (ctx , t , k8sClient , ts , tc )
176173 })
177174
178175 }
179176
180177}
181178
179+ // Uses input.Status + deprecatedBuildReplicas to create (and maybe kill) pollers for deprecated versions in temporal
180+ // also gets routing config of the deployment into the starting state before running the test.
181+ // Does not set Status.VersionConflictToken, since that is only set internally by the server.
182+ func makePreliminaryStatusTrue (
183+ ctx context.Context ,
184+ t * testing.T ,
185+ k8sClient client.Client ,
186+ ts * temporaltest.TestServer ,
187+ twd * temporaliov1alpha1.TemporalWorkerDeployment ,
188+ connection * temporaliov1alpha1.TemporalConnection ,
189+ replicas map [string ]int32 ,
190+ images map [string ]string ,
191+ ) {
192+ t .Logf ("Creating starting test env based on input.Status" )
193+ for _ , dv := range twd .Status .DeprecatedVersions {
194+ t .Logf ("Handling deprecated version %v" , dv .VersionID )
195+ switch dv .Status {
196+ case temporaliov1alpha1 .VersionStatusInactive :
197+ // start a poller -- is this included in deprecated versions list?
198+ case temporaliov1alpha1 .VersionStatusRamping , temporaliov1alpha1 .VersionStatusCurrent :
199+ // these won't be in deprecated versions
200+ case temporaliov1alpha1 .VersionStatusDraining :
201+ // TODO(carlydf): start a poller, set ramp, start a wf on that version, then unset
202+ case temporaliov1alpha1 .VersionStatusDrained :
203+ // TODO(carlydf): start a poller, set ramp, unset, wait for drainage status visibility grace period
204+ case temporaliov1alpha1 .VersionStatusNotRegistered :
205+ // no-op, although I think this won't occur in deprecated versions either
206+ }
207+ }
208+ // TODO(carlydf): handle Status.LastModifierIdentity
209+ if cv := twd .Status .CurrentVersion ; cv != nil {
210+ t .Logf ("Handling current version %v" , cv .VersionID )
211+ if cv .Status != temporaliov1alpha1 .VersionStatusCurrent {
212+ t .Errorf ("Current Version's status must be Current" )
213+ }
214+ if cv .Deployment != nil {
215+ t .Logf ("Creating Deployment %s for Current Version" , cv .Deployment .Name )
216+ createWorkerDeployment (ctx , t , k8sClient , twd , cv .VersionID , connection .Spec , replicas , images )
217+ expectedDeploymentName := k8s .ComputeVersionedDeploymentName (twd .Name , k8s .ComputeBuildID (twd ))
218+ waitForDeployment (t , k8sClient , expectedDeploymentName , twd .Namespace , 30 * time .Second )
219+ workerStopFuncs := applyDeployment (t , ctx , k8sClient , expectedDeploymentName , twd .Namespace )
220+ defer func () {
221+ for _ , f := range workerStopFuncs {
222+ if f != nil {
223+ f ()
224+ }
225+ }
226+ }()
227+ }
228+ }
229+
230+ if rv := twd .Status .RampingVersion ; rv != nil {
231+ t .Logf ("Handling ramping version %v" , rv .VersionID )
232+ if rv .Status != temporaliov1alpha1 .VersionStatusRamping {
233+ t .Errorf ("Ramping Version's status must be Ramping" )
234+ }
235+ if rv .Deployment != nil {
236+ t .Logf ("Creating Deployment %s for Ramping Version" , rv .Deployment .Name )
237+ }
238+ // TODO(carlydf): do this
239+ }
240+ }
241+
242+ func createWorkerDeployment (
243+ ctx context.Context ,
244+ t * testing.T ,
245+ k8sClient client.Client ,
246+ twd * temporaliov1alpha1.TemporalWorkerDeployment ,
247+ versionID string ,
248+ connection temporaliov1alpha1.TemporalConnectionSpec ,
249+ replicas map [string ]int32 ,
250+ images map [string ]string ,
251+ ) {
252+ t .Log ("Creating a Deployment" )
253+ _ , buildId , err := k8s .SplitVersionID (versionID )
254+ if err != nil {
255+ t .Error (err )
256+ }
257+
258+ prevImageName := twd .Spec .Template .Spec .Containers [0 ].Image
259+ prevReplicas := twd .Spec .Replicas
260+ // temporarily replace it
261+ twd .Spec .Template .Spec .Containers [0 ].Image = images [buildId ]
262+ newReplicas := replicas [buildId ]
263+ twd .Spec .Replicas = & newReplicas
264+ defer func () {
265+ twd .Spec .Template .Spec .Containers [0 ].Image = prevImageName
266+ twd .Spec .Replicas = prevReplicas
267+ }()
268+
269+ dep := k8s .NewDeploymentWithOwnerRef (
270+ & twd .TypeMeta ,
271+ & twd .ObjectMeta ,
272+ & twd .Spec ,
273+ k8s .ComputeWorkerDeploymentName (twd ),
274+ buildId ,
275+ connection ,
276+ )
277+
278+ if err := k8sClient .Create (ctx , dep ); err != nil {
279+ t .Fatalf ("failed to create Deployment: %v" , err )
280+ }
281+ }
282+
182283// testTemporalWorkerDeploymentCreation tests the creation of a TemporalWorkerDeployment and waits for the expected status
183- func testTemporalWorkerDeploymentCreation (t * testing.T , k8sClient client.Client , ts * temporaltest.TestServer , twd * temporaliov1alpha1.TemporalWorkerDeployment , expectedStatus * temporaliov1alpha1.TemporalWorkerDeploymentStatus ) {
184- ctx := context .Background ()
284+ func testTemporalWorkerDeploymentCreation (
285+ ctx context.Context ,
286+ t * testing.T ,
287+ k8sClient client.Client ,
288+ ts * temporaltest.TestServer ,
289+ tc testCase ,
290+ ) {
291+ twd := tc .input
292+ expectedStatus := tc .expectedStatus
185293
186294 t .Log ("Creating a TemporalConnection" )
187295 temporalConnection := & temporaliov1alpha1.TemporalConnection {
@@ -197,6 +305,8 @@ func testTemporalWorkerDeploymentCreation(t *testing.T, k8sClient client.Client,
197305 t .Fatalf ("failed to create TemporalConnection: %v" , err )
198306 }
199307
308+ makePreliminaryStatusTrue (ctx , t , k8sClient , ts , twd , temporalConnection , tc .deprecatedBuildReplicas , tc .deprecatedBuildImages )
309+
200310 t .Log ("Creating a TemporalWorkerDeployment" )
201311 if err := k8sClient .Create (ctx , twd ); err != nil {
202312 t .Fatalf ("failed to create TemporalWorkerDeployment: %v" , err )
0 commit comments