Skip to content

Commit

Permalink
Add TLS sample, functional test base for mounting volumes with TLS co…
Browse files Browse the repository at this point in the history
…nfig, kuttl is still WIP

Signed-off-by: Veronika Fisarova <[email protected]>
  • Loading branch information
Deydra71 committed Oct 25, 2023
1 parent af0ce3a commit 7157889
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 26 deletions.
6 changes: 6 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/samples/placement_v1beta1_placementapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ spec:
preserveJobs: false
replicas: 1
secret: placement-secret
# tls:
# ca:
# caSecretName: "ca-certs"
# service:
# secretName: "tls-certs"
#resources:
# requests:
# memory: "500Mi"
Expand Down
3 changes: 3 additions & 0 deletions pkg/placement/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func getVolumes(instance *placementv1.PlacementAPI) []corev1.Volume {
}

if instance.Spec.TLS != nil {
// fmt.Printf("Service: %+v\n", *instance.Spec.TLS.Service) // // For debug
// fmt.Printf("Ca: %+v\n", *instance.Spec.TLS.Ca) // For debug
// fmt.Println("instance.Spec.TLS is set. Adding TLS volumes...") // For debug
caVolumes := instance.Spec.TLS.CreateVolumes()
volumes = append(volumes, caVolumes...)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ func GetDefaultPlacementAPISpec() map[string]interface{} {
}
}

func GetDefaultPlacementAPISpecWithTLS() map[string]interface{} {
return map[string]interface{}{
"databaseInstance": "openstack",
"secret": SecretName,
"tls": map[string]interface{}{
"ca": map[string]interface{}{
"caSecretName": "ca-certs",
},
"service": map[string]interface{}{
"secretName": "tls-certs",
},
},
}
}

func CreatePlacementAPI(name types.NamespacedName, spec map[string]interface{}) client.Object {

raw := map[string]interface{}{
Expand Down
51 changes: 25 additions & 26 deletions tests/functional/placementapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,40 +684,39 @@ var _ = Describe("PlacementAPI controller", func() {

})

When("TLS config is present", func() {
var placementAPINames Names

Context("PlacementAPI is fully deployed with TLS", func() {
BeforeEach(func() {
specWithTLS := GetDefaultPlacementAPISpec()
instance := CreatePlacementAPI(names.PlacementAPIName, specWithTLS)

placementAPINames = CreateNames(types.NamespacedName{
Namespace: instance.GetNamespace(),
Name: instance.GetName(),
})
DeferCleanup(th.DeleteInstance, CreatePlacementAPI(names.PlacementAPIName, GetDefaultPlacementAPISpecWithTLS()))

DeferCleanup(
k8sClient.Delete, ctx, CreatePlacementAPISecret(namespace, SecretName))
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))

serviceSpec := corev1.ServiceSpec{Ports: []corev1.ServicePort{{Port: 3306}}}
DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(namespace, "openstack", serviceSpec),
)
mariadb.SimulateMariaDBDatabaseCompleted(names.MariaDBDatabaseName)
keystone.SimulateKeystoneServiceReady(names.KeystoneServiceName)
keystone.SimulateKeystoneEndpointReady(names.KeystoneEndpointName)
th.SimulateJobSuccess(names.DBSyncJobName)
th.SimulateDeploymentReplicaReady(names.DeploymentName)

th.ExpectCondition(
names.PlacementAPIName,
ConditionGetterFunc(PlacementConditionGetter),
condition.ReadyCondition,
corev1.ConditionTrue,
)
})

It("should create volumes with the TLS information", func() {
It("creates TLS related volumes and volume mounts", func() {
deployment := th.GetDeployment(names.DeploymentName)
Eventually(func() {
Expect(k8sClient.Get(ctx, placementAPINames.DeploymentName, deployment)).To(Succeed())
}).Should(Succeed())
Expect(deployment.Spec.Template.Spec.Volumes).To(ContainElement(HaveField("Name", Equal("tls-certs"))))
Expect(deployment.Spec.Template.Spec.Volumes).To(ContainElement(HaveField("Name", Equal("ca-certs"))))
})

It("should create volume mounts with the TLS information", func() {
deployment := th.GetDeployment(names.DeploymentName)
Eventually(func() {
Expect(k8sClient.Get(ctx, placementAPINames.DeploymentName, deployment)).To(Succeed())
}).Should(Succeed())

container := deployment.Spec.Template.Spec.Containers[0]

Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("tls-crt"))))
Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("tls-key"))))
Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("ca-certs"))))
})
})

})
70 changes: 70 additions & 0 deletions tests/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,69 @@ metadata:
kind: PlacementAPI
name: placement
---
apiVersion: v1
kind: Secret
metadata:
name: tls-certificates
type: Opaque
# Generated key/crt pair sorely for testing purposes
data:
tls.crt: |
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURaVENDQWsyZ0F3SUJBZ0lVVnJmOGIxTElN
NktvSWU0clNLcU9vUVQ1OW44d0RRWUpLb1pJaHZjTkFRRUwKQlFBd1FqRUxNQWtHQTFVRUJoTUNX
Rmd4RlRBVEJnTlZCQWNNREVSbFptRjFiSFFnUTJsMGVURWNNQm9HQTFVRQpDZ3dUUkdWbVlYVnNk
Q0JEYjIxd1lXNTVJRXgwWkRBZUZ3MHlNekV3TVRreE16QTRNelZhRncweU5ERXdNVGd4Ck16QTRN
elZhTUVJeEN6QUpCZ05WQkFZVEFsaFlNUlV3RXdZRFZRUUhEQXhFWldaaGRXeDBJRU5wZEhreEhE
QWEKQmdOVkJBb01FMFJsWm1GMWJIUWdRMjl0Y0dGdWVTQk1kR1F3Z2dFaU1BMEdDU3FHU0liM0RR
RUJBUVVBQTRJQgpEd0F3Z2dFS0FvSUJBUUNySGJnVml3eFZjZGtnb2VCV0xhZlRIa2Fpek50SE9Z
VWhYeG9nTGVvTklaNmFyZUtvCkM4UmJNRUlxOVJNeDBuTmxkdkFVaUI2WFNjM3RGU1NBSmRJRnhQ
N3o1dXE5UVQyM3h0SFFKUzRPNnM2UUgrTEI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ndNUTdWcFZwb2VpUGY5CjV4YjNtZ3Zl
N2owN040VlVaRlRwNDNOdmZGck84M2p0OVdybnFtRVJha0laK3V0SVVGM09YNHRVdExTSUE1VE4K
eDM3UUdYUHY4ZHB6by9ucjZvY3l5Q009Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
---
# the actual addresses of the api endpoints are platform specific, so we can't rely on
# kuttl asserts to check them. This short script gathers the addresses and checks that
# the two endpoints are defined and their addresses follow the default pattern
Expand All @@ -250,6 +313,13 @@ commands:
assert_regex $apiEndpoints 'http:\/\/placement-internal\..+\.svc.*'
assert_regex $apiEndpoints 'http:\/\/placement-public\..+\.svc.*'
# Verify if the TLS secret is mounted correctly
tlsMounted=$(oc get pod -l service=placement -o jsonpath='{.items[0].spec.volumes[?(@.name=="tls-vol")].secret.secretName}')
if [ "$tlsMounted" != "tls-certificates" ]; then
echo "TLS secret not mounted correctly."
exit 1
fi
# when using image digests the containerImage URLs are SHA's so we verify them with a script
tupleTemplate='{{ range (index .spec.template.spec.containers 1).env }}{{ .name }}{{ "#" }}{{ .value}}{{"\n"}}{{ end }}'
imageTuples=$(oc get -n openstack-operators deployment placement-operator-controller-manager -o go-template="$tupleTemplate")
Expand Down

0 comments on commit 7157889

Please sign in to comment.