Skip to content

Commit 931a1e3

Browse files
committed
-
Signed-off-by: Chris Curwick <[email protected]>
1 parent 86a04a6 commit 931a1e3

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

pkg/requestgen/generator.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/cert-manager/csi-lib/manager"
3333
"github.com/cert-manager/csi-lib/metadata"
3434

35+
"github.com/cert-manager/csi-driver/pkg/apis"
3536
"github.com/cert-manager/csi-driver/pkg/apis/defaults"
3637
csiapi "github.com/cert-manager/csi-driver/pkg/apis/v1alpha1"
3738
"github.com/cert-manager/csi-driver/pkg/apis/validation"
@@ -73,6 +74,15 @@ func RequestForMetadata(meta metadata.Metadata) (*manager.CertificateRequestBund
7374
return nil, fmt.Errorf("%q: %w", csiapi.IPSANsKey, err)
7475
}
7576

77+
annotations := make(map[string]string)
78+
for key, val := range attrs {
79+
group, _, found := strings.Cut(key, "/")
80+
81+
if group != apis.GroupName || !found {
82+
annotations[key] = val
83+
}
84+
}
85+
7686
return &manager.CertificateRequestBundle{
7787
Request: &x509.CertificateRequest{
7888
Subject: pkix.Name{
@@ -91,7 +101,7 @@ func RequestForMetadata(meta metadata.Metadata) (*manager.CertificateRequestBund
91101
Kind: attrs[csiapi.IssuerKindKey],
92102
Group: attrs[csiapi.IssuerGroupKey],
93103
},
94-
Annotations: nil,
104+
Annotations: annotations,
95105
}, nil
96106
}
97107

test/e2e/suite/cases/annotations.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)