@@ -426,12 +426,13 @@ func TestGeneratePlan(t *testing.T) {
426426
427427func TestGetDeleteDeployments (t * testing.T ) {
428428 testCases := []struct {
429- name string
430- k8sState * k8s.DeploymentState
431- status * temporaliov1alpha1.TemporalWorkerDeploymentStatus
432- spec * temporaliov1alpha1.TemporalWorkerDeploymentSpec
433- config * Config
434- expectDeletes int
429+ name string
430+ k8sState * k8s.DeploymentState
431+ status * temporaliov1alpha1.TemporalWorkerDeploymentStatus
432+ spec * temporaliov1alpha1.TemporalWorkerDeploymentSpec
433+ config * Config
434+ expectDeletes int
435+ foundDeploymentInTemporal bool
435436 }{
436437 {
437438 name : "drained version should be deleted" ,
@@ -463,7 +464,8 @@ func TestGetDeleteDeployments(t *testing.T) {
463464 config : & Config {
464465 RolloutStrategy : temporaliov1alpha1.RolloutStrategy {},
465466 },
466- expectDeletes : 1 ,
467+ expectDeletes : 1 ,
468+ foundDeploymentInTemporal : true ,
467469 },
468470 {
469471 name : "not yet drained long enough" ,
@@ -492,7 +494,8 @@ func TestGetDeleteDeployments(t *testing.T) {
492494 },
493495 Replicas : func () * int32 { r := int32 (1 ); return & r }(),
494496 },
495- expectDeletes : 0 ,
497+ expectDeletes : 0 ,
498+ foundDeploymentInTemporal : true ,
496499 },
497500 {
498501 name : "not registered version should be deleted" ,
@@ -523,15 +526,48 @@ func TestGetDeleteDeployments(t *testing.T) {
523526 spec : & temporaliov1alpha1.TemporalWorkerDeploymentSpec {
524527 Replicas : func () * int32 { r := int32 (1 ); return & r }(),
525528 },
526- expectDeletes : 1 ,
529+ expectDeletes : 1 ,
530+ foundDeploymentInTemporal : true ,
531+ },
532+ {
533+ name : "not registered version should NOT be deleted, deployment not found in temporal" ,
534+ k8sState : & k8s.DeploymentState {
535+ Deployments : map [string ]* appsv1.Deployment {
536+ "123" : createDeploymentWithDefaultConnectionSpecHash (1 ),
537+ "456" : createDeploymentWithDefaultConnectionSpecHash (1 ),
538+ },
539+ },
540+ status : & temporaliov1alpha1.TemporalWorkerDeploymentStatus {
541+ TargetVersion : temporaliov1alpha1.TargetWorkerDeploymentVersion {
542+ BaseWorkerDeploymentVersion : temporaliov1alpha1.BaseWorkerDeploymentVersion {
543+ BuildID : "123" ,
544+ Status : temporaliov1alpha1 .VersionStatusCurrent ,
545+ Deployment : & corev1.ObjectReference {Name : "test-123" },
546+ },
547+ },
548+ DeprecatedVersions : []* temporaliov1alpha1.DeprecatedWorkerDeploymentVersion {
549+ {
550+ BaseWorkerDeploymentVersion : temporaliov1alpha1.BaseWorkerDeploymentVersion {
551+ BuildID : "456" ,
552+ Status : temporaliov1alpha1 .VersionStatusNotRegistered ,
553+ Deployment : & corev1.ObjectReference {Name : "test-456" },
554+ },
555+ },
556+ },
557+ },
558+ spec : & temporaliov1alpha1.TemporalWorkerDeploymentSpec {
559+ Replicas : func () * int32 { r := int32 (1 ); return & r }(),
560+ },
561+ expectDeletes : 0 ,
562+ foundDeploymentInTemporal : false ,
527563 },
528564 }
529565
530566 for _ , tc := range testCases {
531567 t .Run (tc .name , func (t * testing.T ) {
532568 err := tc .spec .Default (context .Background ())
533569 require .NoError (t , err )
534- deletes := getDeleteDeployments (tc .k8sState , tc .status , tc .spec )
570+ deletes := getDeleteDeployments (tc .k8sState , tc .status , tc .spec , tc . foundDeploymentInTemporal )
535571 assert .Equal (t , tc .expectDeletes , len (deletes ), "unexpected number of deletes" )
536572 })
537573 }
0 commit comments