@@ -18,6 +18,7 @@ package cacheserver
1818
1919import (
2020 "fmt"
21+ "strings"
2122
2223 "k8c.io/reconciler/pkg/reconciling"
2324
@@ -37,8 +38,7 @@ const (
3738 ServerContainerName = "cache-server"
3839
3940 // embeddedEtcdStoragePath is the emptyDir path in the Deployment where the
40- // etcd data is temporarily stored. kcp's cache-server as of v0.30 does not
41- // support external etcd yet.
41+ // embedded etcd data is temporarily stored.
4242 embeddedEtcdStoragePath = "/var/etcd"
4343)
4444
@@ -62,13 +62,15 @@ func getCertificateMountPath(certName operatorv1alpha1.Certificate) string {
6262 return fmt .Sprintf ("/etc/cache-server/tls/%s" , certName )
6363}
6464
65+ func getEtcdCertificateMountPath () string {
66+ return "/etc/cache-server/etcd"
67+ }
68+
6569func getCAMountPath (caName operatorv1alpha1.CA ) string {
6670 return fmt .Sprintf ("/etc/cache-server/tls/ca/%s" , caName )
6771}
6872
6973func DeploymentReconciler (server * operatorv1alpha1.CacheServer ) reconciling.NamedDeploymentReconcilerFactory {
70- const etcdScratchVolume = "etcd-scratch"
71-
7274 return func () (string , reconciling.DeploymentReconciler ) {
7375 return resources .GetCacheServerDeploymentName (server ), func (dep * appsv1.Deployment ) (* appsv1.Deployment , error ) {
7476 labels := resources .GetCacheServerResourceLabels (server )
@@ -84,28 +86,12 @@ func DeploymentReconciler(server *operatorv1alpha1.CacheServer) reconciling.Name
8486
8587 dep .Spec .Template .SetLabels (labels )
8688
87- secretMounts := []utils.SecretMount {{
88- VolumeName : "serving-cert" ,
89- SecretName : resources .GetCacheServerCertificateName (server , operatorv1alpha1 .ServerCertificate ),
90- MountPath : getCertificateMountPath (operatorv1alpha1 .ServerCertificate ),
91- }}
92-
9389 // TODO: Why do we discard the imagePullSecrets?
9490 image , _ := resources .GetImageSettings (server .Spec .Image )
9591
96- args := getArgs (server )
97- volumes := []corev1.Volume {{
98- Name : etcdScratchVolume ,
99- VolumeSource : corev1.VolumeSource {
100- EmptyDir : & corev1.EmptyDirVolumeSource {},
101- },
102- }}
103- volumeMounts := []corev1.VolumeMount {{
104- Name : etcdScratchVolume ,
105- MountPath : embeddedEtcdStoragePath ,
106- }}
92+ volumes , volumeMounts := getVolumeMounts (server )
10793
108- for _ , sm := range secretMounts {
94+ for _ , sm := range getSecretMounts ( server ) {
10995 v , vm := sm .Build ()
11096 volumes = append (volumes , v )
11197 volumeMounts = append (volumeMounts , vm )
@@ -115,7 +101,7 @@ func DeploymentReconciler(server *operatorv1alpha1.CacheServer) reconciling.Name
115101 Name : ServerContainerName ,
116102 Image : image ,
117103 Command : []string {"/cache-server" },
118- Args : args ,
104+ Args : getArgs ( server ) ,
119105 VolumeMounts : volumeMounts ,
120106 Resources : defaultResourceRequirements ,
121107 SecurityContext : & corev1.SecurityContext {
@@ -188,18 +174,72 @@ func DeploymentReconciler(server *operatorv1alpha1.CacheServer) reconciling.Name
188174 }
189175}
190176
177+ func getVolumeMounts (server * operatorv1alpha1.CacheServer ) (volumes []corev1.Volume , volumeMounts []corev1.VolumeMount ) {
178+ const etcdScratchVolume = "etcd-scratch"
179+
180+ if server .Spec .Etcd == nil {
181+ volumes = []corev1.Volume {{
182+ Name : etcdScratchVolume ,
183+ VolumeSource : corev1.VolumeSource {
184+ EmptyDir : & corev1.EmptyDirVolumeSource {},
185+ },
186+ }}
187+ volumeMounts = []corev1.VolumeMount {{
188+ Name : etcdScratchVolume ,
189+ MountPath : embeddedEtcdStoragePath ,
190+ }}
191+ }
192+
193+ return
194+ }
195+
191196func getArgs (server * operatorv1alpha1.CacheServer ) []string {
192197 args := []string {
193- // Configure (lack of) persistence.
194- "--root-directory=" ,
195- fmt .Sprintf ("--embedded-etcd-directory=%s" , embeddedEtcdStoragePath ),
196-
197198 // Certificate flags (server, service account signing).
198199 fmt .Sprintf ("--tls-cert-file=%s/tls.crt" , getCertificateMountPath (operatorv1alpha1 .ServerCertificate )),
199200 fmt .Sprintf ("--tls-private-key-file=%s/tls.key" , getCertificateMountPath (operatorv1alpha1 .ServerCertificate )),
201+ // Configure (lack of) persistence.
202+ "--root-directory=" ,
203+ }
204+
205+ if server .Spec .Etcd == nil {
206+ // The CacheServer is configured with an embedded etcd store.
207+ args = append (args ,
208+ fmt .Sprintf ("--embedded-etcd-directory=%s" , embeddedEtcdStoragePath ),
209+ )
210+ } else {
211+ // The CacheServer is configured with a dedicated etcd store.
212+ args = append (args ,
213+ fmt .Sprintf ("--etcd-servers=%s" , strings .Join (server .Spec .Etcd .Endpoints , "," )),
214+ )
215+ if server .Spec .Etcd .TLSConfig != nil {
216+ args = append (args ,
217+ fmt .Sprintf ("--etcd-cafile=%s/ca.crt" , getEtcdCertificateMountPath ()),
218+ fmt .Sprintf ("--etcd-certfile=%s/tls.crt" , getEtcdCertificateMountPath ()),
219+ fmt .Sprintf ("--etcd-keyfile=%s/tls.key" , getEtcdCertificateMountPath ()),
220+ )
221+ }
200222 }
201223
202224 args = append (args , utils .GetLoggingArgs (server .Spec .Logging )... )
203225
204226 return args
205227}
228+
229+ func getSecretMounts (server * operatorv1alpha1.CacheServer ) []utils.SecretMount {
230+ secretMounts := []utils.SecretMount {{
231+ VolumeName : "serving-cert" ,
232+ SecretName : resources .GetCacheServerCertificateName (server , operatorv1alpha1 .ServerCertificate ),
233+ MountPath : getCertificateMountPath (operatorv1alpha1 .ServerCertificate ),
234+ }}
235+
236+ if server .Spec .Etcd != nil && server .Spec .Etcd .TLSConfig != nil {
237+ secretMounts = append (secretMounts , utils.SecretMount {
238+ VolumeName : "etcd-cert" ,
239+ SecretName : server .Spec .Etcd .TLSConfig .SecretRef .Name ,
240+ MountPath : getEtcdCertificateMountPath (),
241+ })
242+ }
243+
244+ return secretMounts
245+ }
0 commit comments