Skip to content

Commit 53b6da5

Browse files
committed
Verify status.generations is updated
with all cert-manager deployments Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
1 parent ae53ee1 commit 53b6da5

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/e2e/overrides_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
corev1 "k8s.io/api/core/v1"
1515
k8sresource "k8s.io/apimachinery/pkg/api/resource"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
)
1718

1819
var _ = Describe("Overrides test", Ordered, func() {
@@ -29,6 +30,14 @@ var _ = Describe("Overrides test", Ordered, func() {
2930
certManagerCAInjectorDeploymentControllerName},
3031
validOperatorStatusConditions)
3132
Expect(err).NotTo(HaveOccurred(), "Operator is expected to be available")
33+
34+
By("Wait for non-empty generations status")
35+
err = verifyDeploymentGenerationIsNotEmpty(certmanageroperatorclient, []metav1.ObjectMeta{
36+
{Name: certmanagerControllerDeployment, Namespace: operandNamespace},
37+
{Name: certManagerWebhookDeploymentControllerName, Namespace: operandNamespace},
38+
{Name: certManagerCAInjectorDeploymentControllerName, Namespace: operandNamespace},
39+
})
40+
Expect(err).NotTo(HaveOccurred(), "Operator status Generations should contain deployment last generation")
3241
})
3342

3443
Context("When adding valid cert-manager controller override args", func() {

test/e2e/utils_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,53 @@ func verifyOperatorStatusCondition(client *certmanoperatorclient.Clientset, cont
104104
return errors.NewAggregate(errs)
105105
}
106106

107+
func verifyDeploymentGenerationIsNotEmpty(client *certmanoperatorclient.Clientset, deployments []metav1.ObjectMeta) error {
108+
var wg sync.WaitGroup
109+
errs := make([]error, len(deployments))
110+
for index, deployMeta := range deployments {
111+
wg.Add(1)
112+
113+
go func(idx int, nameAndNs *metav1.ObjectMeta) {
114+
defer wg.Done()
115+
116+
err := wait.PollUntilContextTimeout(context.TODO(), time.Second*1, time.Minute*5, true, func(context.Context) (bool, error) {
117+
operator, err := client.OperatorV1alpha1().CertManagers().Get(context.TODO(), "cluster", metav1.GetOptions{})
118+
if err != nil {
119+
if apierrors.IsNotFound(err) {
120+
return false, nil
121+
}
122+
return false, err
123+
}
124+
125+
if operator.DeletionTimestamp != nil {
126+
return false, nil
127+
}
128+
129+
var exists bool
130+
for _, gen := range operator.Status.Generations {
131+
// match deployment: name and namespace, group, resource
132+
if gen.Name != nameAndNs.Name || gen.Namespace != nameAndNs.Namespace ||
133+
gen.Group != "apps" || gen.Resource != "deployments" {
134+
continue
135+
}
136+
exists = true
137+
138+
if gen.LastGeneration <= 0 {
139+
return false, nil
140+
}
141+
}
142+
143+
return exists, nil
144+
})
145+
146+
errs[idx] = err
147+
}(index, &deployMeta)
148+
}
149+
wg.Wait()
150+
151+
return errors.NewAggregate(errs)
152+
}
153+
107154
// resetCertManagerState is used to revert back to the default cert-manager operands' state
108155
func resetCertManagerState(ctx context.Context, client *certmanoperatorclient.Clientset, loader library.DynamicResourceLoader) error {
109156
// update operator spec to empty *Config and set operatorSpec to default values

0 commit comments

Comments
 (0)