|
| 1 | +/* |
| 2 | +Copyright 2021 The cert-manager Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package cases |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "time" |
| 22 | + |
| 23 | + . "github.com/onsi/ginkgo/v2" |
| 24 | + . "github.com/onsi/gomega" |
| 25 | + |
| 26 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 27 | + |
| 28 | + "github.com/cert-manager/csi-driver/test/e2e/framework" |
| 29 | + "github.com/cert-manager/csi-driver/test/e2e/util" |
| 30 | +) |
| 31 | + |
| 32 | +var _ = framework.CasesDescribe("Should set extra attributes as annotations on the CertificateRequest", func() { |
| 33 | + f := framework.NewDefaultFramework("annotations") |
| 34 | + |
| 35 | + It("should create a pod with a certificate with custom attributes set", func() { |
| 36 | + testVolume, testPod := basePod(f, map[string]string{ |
| 37 | + "csi.cert-manager.io/issuer-name": f.Issuer.Name, |
| 38 | + "csi.cert-manager.io/issuer-kind": f.Issuer.Kind, |
| 39 | + "csi.cert-manager.io/issuer-group": f.Issuer.Group, |
| 40 | + "csi.cert-manager.io/dns-names": "a.example.com,b.example.com", |
| 41 | + "csi.cert-manager.io/uri-sans": "spiffe://my-service.sandbox.cluster.local,http://foo.bar", |
| 42 | + "csi.cert-manager.io/ip-sans": "192.168.0.1,123.4.5.6", |
| 43 | + "csi.cert-manager.io/duration": "123h", |
| 44 | + "csi.cert-manager.io/is-ca": "true", |
| 45 | + "csi.cert-manager.io/common-name": "foo-bar", |
| 46 | + "csi.cert-manager.io/key-usages": "signing,digital signature,content commitment,key encipherment,key agreement,data encipherment", |
| 47 | + "custom.group.io/custom-key": "custom-value", |
| 48 | + }) |
| 49 | + |
| 50 | + By("Creating a Pod") |
| 51 | + testPod, err := f.KubeClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), testPod, metav1.CreateOptions{}) |
| 52 | + Expect(err).NotTo(HaveOccurred()) |
| 53 | + |
| 54 | + By("Waiting for Pod to become ready") |
| 55 | + err = f.Helper().WaitForPodReady(f.Namespace.Name, testPod.Name, time.Minute) |
| 56 | + Expect(err).NotTo(HaveOccurred()) |
| 57 | + |
| 58 | + testPod, err = f.KubeClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), testPod.Name, metav1.GetOptions{}) |
| 59 | + Expect(err).NotTo(HaveOccurred()) |
| 60 | + |
| 61 | + By("Ensure the corresponding CertificateRequest should exist with the correct spec") |
| 62 | + crs, err := f.Helper().WaitForCertificateRequestsReady(testPod, time.Second) |
| 63 | + Expect(err).NotTo(HaveOccurred()) |
| 64 | + |
| 65 | + err = util.CertificateRequestMatchesSpec(crs[0], testVolume.CSI.VolumeAttributes) |
| 66 | + Expect(err).NotTo(HaveOccurred()) |
| 67 | + Expect(crs).To(HaveLen(1)) |
| 68 | + |
| 69 | + By("Ensuring the custom.group.io/custom-key annotation exists on the CertificateRequests with the value set to custom-value") |
| 70 | + Expect(crs[0].Annotations).NotTo(BeEmpty()) |
| 71 | + Expect(crs[0].Annotations["custom.group.io/custom-key"]).Should(Equal("custom-value")) |
| 72 | + |
| 73 | + By("Ensure the certificate key pair exists in the pod and matches that in the CertificateRequest") |
| 74 | + certData, keyData, err := f.Helper().CertificateKeyInPodPath(f.Namespace.Name, testPod.Name, "test-container-1", "/tls", |
| 75 | + testVolume.CSI.VolumeAttributes) |
| 76 | + Expect(err).NotTo(HaveOccurred()) |
| 77 | + |
| 78 | + err = f.Helper().CertificateKeyMatch(crs[0], certData, keyData) |
| 79 | + Expect(err).NotTo(HaveOccurred()) |
| 80 | + }) |
| 81 | +}) |
0 commit comments