/
certman.go
80 lines (71 loc) · 2.63 KB
/
certman.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package operators
import (
"context"
"time"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
osv1 "github.com/openshift/api/config/v1"
"github.com/openshift/osde2e/pkg/common/alert"
viper "github.com/openshift/osde2e/pkg/common/concurrentviper"
"github.com/openshift/osde2e/pkg/common/config"
"github.com/openshift/osde2e/pkg/common/helper"
"github.com/openshift/osde2e/pkg/common/label"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)
var certmanOperatorTestName string = "[Suite: operators] [OSD] Certman Operator"
func init() {
alert.RegisterGinkgoAlert(certmanOperatorTestName, "SD-SREP", "@certman-operator", "sd-cicd-alerts", "sd-cicd@redhat.com", 4)
}
var _ = ginkgo.Describe(certmanOperatorTestName, label.Operators, func() {
ginkgo.BeforeEach(func() {
if viper.GetBool(config.Hypershift) {
ginkgo.Skip("Certman Operator is not supported on HyperShift")
}
})
h := helper.New()
ginkgo.Context("certificate secret should be applied when cluster installed", func() {
var secretName string
var secrets *v1.SecretList
var apiserver *osv1.APIServer
// Waiting period to wait for certman resources to appear
pollingDuration := 15 * time.Minute
ginkgo.It("certificate secret exist under openshift-config namespace", func(ctx context.Context) {
err := wait.PollImmediate(30*time.Second, pollingDuration, func() (bool, error) {
listOpts := metav1.ListOptions{
LabelSelector: "certificate_request",
}
var err error
secrets, err = h.Kube().CoreV1().Secrets("openshift-config").List(ctx, listOpts)
if err != nil {
return false, err
}
if len(secrets.Items) < 1 {
return false, nil
}
secretName = secrets.Items[0].Name
return true, nil
})
Expect(err).NotTo(HaveOccurred())
Expect(len(secrets.Items)).Should(Equal(1))
}, pollingDuration.Seconds())
ginkgo.It("certificate secret should be applied to apiserver object", func(ctx context.Context) {
err := wait.PollImmediate(30*time.Second, pollingDuration, func() (bool, error) {
getOpts := metav1.GetOptions{}
var err error
apiserver, err = h.Cfg().ConfigV1().APIServers().Get(ctx, "cluster", getOpts)
if err != nil {
return false, err
}
if len(apiserver.Spec.ServingCerts.NamedCertificates) < 1 {
return false, nil
}
return true, nil
})
Expect(err).NotTo(HaveOccurred())
Expect(len(apiserver.Spec.ServingCerts.NamedCertificates)).Should(BeNumerically(">", 0))
Expect(apiserver.Spec.ServingCerts.NamedCertificates[0].ServingCertificate.Name).Should(Equal(secretName))
}, pollingDuration.Seconds())
})
})