@@ -76,6 +76,43 @@ func (tc *TestHelper) CreateMemcached(namespace string, memcachedName string, sp
7676 return name
7777}
7878
79+ // CreateMemcachedMTLS creates a new Memcached instance with the specified namespace in the Kubernetes cluster.
80+ func (tc * TestHelper ) CreateMTLSMemcached (namespace string , memcachedName string , spec memcachedv1.MemcachedSpec ) types.NamespacedName {
81+ name := types.NamespacedName {
82+ Name : memcachedName ,
83+ Namespace : namespace ,
84+ }
85+
86+ memcachedMTLSSecretName := "cert-memcached-mtls"
87+ _ = tc .CreateSecret (
88+ types.NamespacedName {Name : memcachedMTLSSecretName , Namespace : namespace },
89+ map [string ][]byte {
90+ "tls-ca.crt" : []byte ("---BEGIN FAKE CA---" ),
91+ "tls.crt" : []byte ("---BEGIN FAKE CERT---" ),
92+ "tls.key" : []byte ("---BEGIN FAKE KEY---" ),
93+ },
94+ )
95+
96+ spec .TLS .MTLS .SslVerifyMode = "Request"
97+ spec .TLS .MTLS .AuthCertSecret .SecretName = & memcachedMTLSSecretName
98+
99+ mc := & memcachedv1.Memcached {
100+ TypeMeta : metav1.TypeMeta {
101+ APIVersion : "memcached.openstack.org/v1beta1" ,
102+ Kind : "Memcached" ,
103+ },
104+ ObjectMeta : metav1.ObjectMeta {
105+ Name : memcachedName ,
106+ Namespace : namespace ,
107+ },
108+ Spec : spec ,
109+ }
110+
111+ t .Expect (tc .K8sClient .Create (tc .Ctx , mc )).Should (t .Succeed ())
112+
113+ return name
114+ }
115+
79116// DeleteMemcached deletes a Memcached instance from the Kubernetes cluster.
80117func (tc * TestHelper ) DeleteMemcached (name types.NamespacedName ) {
81118 t .Eventually (func (g t.Gomega ) {
@@ -154,6 +191,33 @@ func (tc *TestHelper) SimulateTLSMemcachedReady(name types.NamespacedName) {
154191 tc .Logger .Info ("Simulated memcached ready" , "on" , name )
155192}
156193
194+ // SimulateMTLSMemcachedReady simulates a ready state for a Memcached instance in a Kubernetes cluster which supports TLS and uses MTLS auth
195+ func (tc * TestHelper ) SimulateMTLSMemcachedReady (name types.NamespacedName ) {
196+ t .Eventually (func (g t.Gomega ) {
197+ mc := tc .GetMemcached (name )
198+ mc .Status .ObservedGeneration = mc .Generation
199+ mc .Status .Conditions .MarkTrue (condition .ReadyCondition , condition .ReadyMessage )
200+ mc .Status .ReadyCount = * mc .Spec .Replicas
201+
202+ serverList := []string {}
203+ serverListWithInet := []string {}
204+ for i := 0 ; i < int (* mc .Spec .Replicas ); i ++ {
205+ serverList = append (serverList , fmt .Sprintf ("%s-%d.%s.%s.svc:11211" , mc .Name , i , mc .Name , mc .Namespace ))
206+ serverListWithInet = append (serverListWithInet , fmt .Sprintf ("inet:[%s-%d.%s.%s.svc]:11211" , mc .Name , i , mc .Name , mc .Namespace ))
207+ }
208+ mc .Status .ServerList = serverList
209+ mc .Status .ServerListWithInet = serverListWithInet
210+ mc .Status .TLSSupport = true
211+ mc .Status .MTLSCert = "cert-memcached-mtls"
212+
213+ // This can return conflict so we have the t.Eventually block to retry
214+ g .Expect (tc .K8sClient .Status ().Update (tc .Ctx , mc )).To (t .Succeed ())
215+
216+ }, tc .Timeout , tc .Interval ).Should (t .Succeed ())
217+
218+ tc .Logger .Info ("Simulated memcached with MTLS ready" , "on" , name )
219+ }
220+
157221// GetDefaultMemcachedSpec returns memcachedv1.MemcachedSpec for test-helpers
158222func (tc * TestHelper ) GetDefaultMemcachedSpec () memcachedv1.MemcachedSpec {
159223 return memcachedv1.MemcachedSpec {
0 commit comments