@@ -2,34 +2,33 @@ package deploymentcontroller
22
33import (
44 "context"
5- clocktesting "k8s.io/utils/clock/testing"
65 "os"
76 "sort"
87 "time"
98
10- "github.com/google/go-cmp/cmp"
11- opv1 "github.com/openshift/api/operator/v1"
12- "github.com/openshift/library-go/pkg/operator/management"
13- "github.com/openshift/library-go/pkg/operator/resource/resourceapply"
14- appsv1 "k8s.io/api/apps/v1"
15- "k8s.io/apimachinery/pkg/api/equality"
16- "k8s.io/apimachinery/pkg/api/errors"
17- core "k8s.io/client-go/testing"
18-
199 "testing"
2010
11+ "github.com/google/go-cmp/cmp"
2112 configv1 "github.com/openshift/api/config/v1"
13+ opv1 "github.com/openshift/api/operator/v1"
2214 fakeconfig "github.com/openshift/client-go/config/clientset/versioned/fake"
2315 configinformers "github.com/openshift/client-go/config/informers/externalversions"
2416 "github.com/openshift/library-go/pkg/controller/factory"
2517 "github.com/openshift/library-go/pkg/operator/events"
18+ "github.com/openshift/library-go/pkg/operator/management"
19+ "github.com/openshift/library-go/pkg/operator/resource/resourceapply"
2620 "github.com/openshift/library-go/pkg/operator/v1helpers"
27-
21+ appsv1 "k8s.io/api/apps/v1"
22+ corev1 "k8s.io/api/core/v1"
2823 v1 "k8s.io/api/core/v1"
24+ "k8s.io/apimachinery/pkg/api/equality"
25+ "k8s.io/apimachinery/pkg/api/errors"
2926 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3027 "k8s.io/apimachinery/pkg/runtime"
3128 coreinformers "k8s.io/client-go/informers"
3229 fakecore "k8s.io/client-go/kubernetes/fake"
30+ core "k8s.io/client-go/testing"
31+ clocktesting "k8s.io/utils/clock/testing"
3332)
3433
3534const (
@@ -454,6 +453,7 @@ func sanitizeObjectMeta(meta *metav1.ObjectMeta) {
454453}
455454
456455func TestSync (t * testing.T ) {
456+ const replica0 = 0
457457 const replica1 = 1
458458 testCases := []testCase {
459459 {
@@ -535,20 +535,65 @@ func TestSync(t *testing.T) {
535535 initialObjects : testObjects {
536536 deployment : makeDeployment (
537537 withDeploymentGeneration (1 , 1 ),
538- withDeploymentStatus (replica1 , replica1 , replica1 )),
538+ withDeploymentStatus (replica1 , replica1 , replica1 ),
539+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionTrue )), // Deployment is fully deployed
539540 operator : makeFakeOperatorInstance (withGenerations (1 )),
540541 },
541542 expectedObjects : testObjects {
542543 deployment : makeDeployment (
543544 withDeploymentGeneration (1 , 1 ),
544- withDeploymentStatus (replica1 , replica1 , replica1 )),
545+ withDeploymentStatus (replica1 , replica1 , replica1 ),
546+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionTrue )), // Deployment is fully deployed
545547 operator : makeFakeOperatorInstance (
546548 // withStatus(replica1),
547549 withGenerations (1 ),
548550 withTrueConditions (conditionAvailable ),
549551 withFalseConditions (conditionProgressing )),
550552 },
551553 },
554+ {
555+ // Deployment is fully deployed with a missing pod and its status is synced to CR
556+ name : "pod missing after fully deployed" ,
557+ initialObjects : testObjects {
558+ deployment : makeDeployment (
559+ withDeploymentGeneration (1 , 1 ),
560+ withDeploymentStatus (replica0 , replica0 , replica0 ),
561+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionTrue )), // Deployment is fully deployed
562+ operator : makeFakeOperatorInstance (withGenerations (1 )),
563+ },
564+ expectedObjects : testObjects {
565+ deployment : makeDeployment (
566+ withDeploymentGeneration (1 , 1 ),
567+ withDeploymentStatus (replica0 , replica0 , replica0 ),
568+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionTrue )), // Deployment is fully deployed
569+ operator : makeFakeOperatorInstance (
570+ // withStatus(replica1),
571+ withGenerations (1 ),
572+ withFalseConditions (conditionAvailable ), // No pod is running
573+ withFalseConditions (conditionProgressing )), // Despite missing pod, the operator is not progressing
574+ },
575+ },
576+ {
577+ name : "pod missing before fully deployed" ,
578+ initialObjects : testObjects {
579+ deployment : makeDeployment (
580+ withDeploymentGeneration (1 , 1 ),
581+ withDeploymentStatus (replica0 , replica0 , replica0 ),
582+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionFalse )), // Deployment is not fully deployed
583+ operator : makeFakeOperatorInstance (withGenerations (1 )),
584+ },
585+ expectedObjects : testObjects {
586+ deployment : makeDeployment (
587+ withDeploymentGeneration (1 , 1 ),
588+ withDeploymentStatus (replica0 , replica0 , replica0 ),
589+ withDeploymentConditions (appsv1 .DeploymentProgressing , "NewReplicaSetAvailable" , corev1 .ConditionFalse )), // Deployment is not fully deployed
590+ operator : makeFakeOperatorInstance (
591+ // withStatus(replica1),
592+ withGenerations (1 ),
593+ withFalseConditions (conditionAvailable ), // No pod is running
594+ withTrueConditions (conditionProgressing )), // A pod is missing, the operator is progressing
595+ },
596+ },
552597 {
553598 // Deployment has wrong nr. of replicas, modified by user, and gets replaced by the operator.
554599 name : "deployment modified by user" ,
0 commit comments