Skip to content

Commit 741de4c

Browse files
committed
[tlse] add TLS status config, func to return server list and tls support
Adds a TLSSupport to the memcached status which reflects if the instance got configured with TLS. Same flag was also introduced to mariadbdatabase a while back. Also * adds functions to return the memcached server list and the status of tls support, which can be used for clients for easy consumption * creates the service list for memcached fqdn svc hostnames to be able to use fqdn hostnames in tls certs. Jira: OSPRH-5283
1 parent 038a5ec commit 741de4c

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

apis/bases/memcached.openstack.org_memcacheds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ spec:
134134
items:
135135
type: string
136136
type: array
137+
tlsSupport:
138+
description: Whether TLS is supported by the memcached instance
139+
type: boolean
137140
type: object
138141
type: object
139142
served: true

apis/memcached/v1beta1/memcached_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"strings"
21+
2022
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2123
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2224
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
@@ -69,6 +71,9 @@ type MemcachedStatus struct {
6971

7072
// ServerListWithInet - List of memcached endpoints with inet(6) prefix
7173
ServerListWithInet []string `json:"serverListWithInet,omitempty" optional:"true"`
74+
75+
// Whether TLS is supported by the memcached instance
76+
TLSSupport bool `json:"tlsSupport,omitempty"`
7277
}
7378

7479
// +kubebuilder:object:root=true
@@ -127,3 +132,14 @@ func SetupDefaults() {
127132

128133
SetupMemcachedDefaults(memcachedDefaults)
129134
}
135+
136+
// GetMemcachedServerListString - return the memcached servers as comma separated list
137+
// to be used in OpenStack config.
138+
func (s *MemcachedStatus) GetMemcachedServerListString() string {
139+
return strings.Join(s.ServerList, ",")
140+
}
141+
142+
// GetMemcachedTLSSupport - return the TLS support of the memcached instance
143+
func (s *MemcachedStatus) GetMemcachedTLSSupport() bool {
144+
return s.TLSSupport
145+
}

config/crd/bases/memcached.openstack.org_memcacheds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ spec:
134134
items:
135135
type: string
136136
type: array
137+
tlsSupport:
138+
description: Whether TLS is supported by the memcached instance
139+
type: boolean
137140
type: object
138141
type: object
139142
served: true

controllers/memcached/memcached_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ func (r *Reconciler) generateConfigMaps(
341341
"-o ssl_chain_cert=/etc/pki/tls/certs/memcached.crt " +
342342
"-o ssl_key=/etc/pki/tls/private/memcached.key " +
343343
"-o ssl_ca_cert=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
344+
instance.Status.TLSSupport = true
344345
} else {
345346
memcachedTLSConfig = ""
347+
instance.Status.TLSSupport = false
346348
}
347349
templateParameters := map[string]interface{}{
348350
"memcachedTLSConfig": memcachedTLSConfig,
@@ -460,7 +462,7 @@ func (r *Reconciler) GetServerLists(
460462
}
461463

462464
for i := int32(0); i < *(instance.Spec.Replicas); i++ {
463-
server := fmt.Sprintf("%s-%d.%s", instance.Name, i, instance.Name)
465+
server := fmt.Sprintf("%s-%d.%s.%s.svc", instance.Name, i, instance.Name, instance.Namespace)
464466
serverList = append(serverList, fmt.Sprintf("%s:%d", server, memcached.MemcachedPort))
465467

466468
// python-memcached requires inet(6) prefix according to the IP version

tests/kuttl/tests/memcached/01-assert.yaml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,41 @@ spec:
1212
replicas: 1
1313
status:
1414
readyCount: 1
15-
serverList:
16-
- 'memcached-0.memcached:11211'
17-
serverListWithInet:
18-
- 'inet:[memcached-0.memcached]:11211'
15+
---
16+
# the namespace of the fqdn of the serverList is namespace
17+
# dependent, so we can't rely on kuttl asserts to check them. This short script
18+
# gathers the first entry and checks that it matches the regex
19+
apiVersion: kuttl.dev/v1beta1
20+
kind: TestAssert
21+
commands:
22+
- script: |
23+
# get the first memcached from serverList and validate
24+
template='{{ (index .status.serverList 0) }}'
25+
regex="memcached-0.memcached.$NAMESPACE.svc:11211"
26+
memcached=$(oc get -n $NAMESPACE memcached memcached -o go-template="$template")
27+
matches=$(echo "$memcached" | sed -e "s?$regex??")
28+
if [ -z "$matches" ]; then
29+
exit 0
30+
else
31+
echo "Memcached Server: $memcached do not match regex"
32+
exit 1
33+
fi
34+
---
35+
# the namespace of the fqdn of the serverListWithInet is namespace
36+
# dependent, so we can't rely on kuttl asserts to check them. This short script
37+
# gathers the first entry and checks that it matches the regex
38+
apiVersion: kuttl.dev/v1beta1
39+
kind: TestAssert
40+
commands:
41+
- script: |
42+
# get the first memcached from serverListWithInet and validate
43+
template='{{ (index .status.serverListWithInet 0) }}'
44+
regex="inet:\[memcached-0.memcached.$NAMESPACE.svc\]:11211"
45+
memcached=$(oc get -n $NAMESPACE memcached memcached -o go-template="$template")
46+
matches=$(echo "$memcached" | sed -e "s?$regex??")
47+
if [ -z "$matches" ]; then
48+
exit 0
49+
else
50+
echo "Memcached ServerListWithInet: $memcached do not match regex"
51+
exit 1
52+
fi

0 commit comments

Comments
 (0)