-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathset_tls.go
64 lines (58 loc) · 1.37 KB
/
set_tls.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
package utils
import (
"errors"
"github.com/securesign/operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
)
func SetTLS(template *corev1.PodTemplateSpec, tls v1alpha1.TLS) error {
if template == nil {
return errors.New("SetTLS: PodTemplateSpec is not set")
}
if tls.CertRef == nil {
return nil
}
template.Spec.Volumes = append(template.Spec.Volumes, corev1.Volume{
Name: "tls-cert",
VolumeSource: corev1.VolumeSource{
Projected: &corev1.ProjectedVolumeSource{
Sources: []corev1.VolumeProjection{
{
Secret: &corev1.SecretProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: tls.CertRef.Name,
},
Items: []corev1.KeyToPath{
{
Key: tls.CertRef.Key,
Path: "tls.crt",
},
},
},
},
{
Secret: &corev1.SecretProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: tls.PrivateKeyRef.Name,
},
Items: []corev1.KeyToPath{
{
Key: tls.PrivateKeyRef.Key,
Path: "tls.key",
},
},
},
},
},
},
},
})
for i := range template.Spec.Containers {
template.Spec.Containers[i].VolumeMounts = append(template.Spec.Containers[i].VolumeMounts,
corev1.VolumeMount{
Name: "tls-cert",
MountPath: "/var/run/secrets/tas",
ReadOnly: true,
})
}
return nil
}