Skip to content

Commit

Permalink
Add kuttl tests to cover single glanceAPI instance
Browse files Browse the repository at this point in the history
With the new structure we can either split the glanceAPI (preserving the
old behavior) or deploy a "single" instance that will serve both
internal and external workloads.
This patch introduces kuttl tests to cover the glance_single scenario.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Oct 24, 2023
1 parent b750f93 commit 93a5619
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
namespace: openstack
spec:
serviceUser: glance
containerImage: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
databaseInstance: openstack
databaseUser: glance
customServiceConfig: |
[DEFAULT]
debug = true
glanceAPI:
containerImage: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
type: "single"
Expand Down
21 changes: 14 additions & 7 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,22 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
return ctrl.Result{}, nil
}

// apiDeployment represents the logic of deploying GlanceAPI instances specified
// in the main CR according to a given strategy (split vs single). It handles
// the deployment logic itself, as well as the output settings mirrored in the
// main Glance CR status
func (r *GlanceReconciler) apiDeployment(ctx context.Context, instance *glancev1.Glance, current glancev1.GlanceAPITemplate, helper *helper.Helper) error {

// By default internal and external points to diff instances, but we might
// want to override "external" in case of a "single" instance and skip the
// internal one
// want to override "external" with "single" in case APIType == "single":
// in this case we only deploy the External instance and skip the internal
// one
var internal string = glancev1.APIInternal
var external string = glancev1.APIExternal

// If we're deploying a "single" instance, we skip the GlanceAPI.Internal one,
// and we only deploy the External instance passing "glancev1.APISingle" to
// the GlanceAPI controller, so we can properly handle this use case (nad and
// If we're deploying a "single" instance, we skip GlanceAPI.Internal, and
// we only deploy the External instance passing "glancev1.APISingle" to the
// GlanceAPI controller, so we can properly handle this use case (nad and
// service creation).
if current.Type == "single" {
external = glancev1.APISingle
Expand All @@ -649,7 +654,8 @@ func (r *GlanceReconciler) apiDeployment(ctx context.Context, instance *glancev1
// Mirror single/external GlanceAPI status' APIEndpoints and ReadyCount to this parent CR
if glanceAPI.Status.APIEndpoints != nil {
instance.Status.APIEndpoints[string(endpoint.EndpointPublic)] = glanceAPI.Status.APIEndpoints[string(endpoint.EndpointPublic)]
// if we don't split, update apiEndpoint to include the internal service
// if we don't split, both apiEndpoints (public and internal) should be
// reflected to the main Glance CR
if current.Type == "single" {
instance.Status.APIEndpoints[string(endpoint.EndpointInternal)] = glanceAPI.Status.APIEndpoints[string(endpoint.EndpointInternal)]
}
Expand All @@ -659,8 +665,9 @@ func (r *GlanceReconciler) apiDeployment(ctx context.Context, instance *glancev1
// Get external GlanceAPI's condition status and compare it against priority of internal GlanceAPI's condition
apiCondition := glanceAPI.Status.Conditions.Mirror(glancev1.GlanceAPIReadyCondition)

// split is the default use case unless type: "single" is passed to the top
// level CR: in this case we deploy an additional glanceAPI instance (Internal)
if current.Type == "split" || len(current.Type) == 0 {
// Regardless of what the user may have set in GlanceAPIInternal.EndpointType,
// we force "internal" here by passing glancev1.APIInternal for the apiType arg
glanceAPI, op, err := r.apiDeploymentCreateOrUpdate(ctx, instance, current, internal, helper)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ var _ = Describe("Samples", func() {
}, timeout, interval).Should(Succeed())
})
})
When("glance_v1beta1_glance_single_instance.yaml sample is applied", func() {
When("glance_v1beta1_glance_single.yaml sample is applied", func() {
It("Glance is created", func() {
name := CreateGlanceFromSample("glance_v1beta1_glance_single_instance.yaml", glanceTest.Instance)
name := CreateGlanceFromSample("glance_v1beta1_glance_single.yaml", glanceTest.Instance)
GetGlance(name)
})
})
Expand Down
151 changes: 151 additions & 0 deletions test/kuttl/tests/glance_single/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#
# Check for:
# - Glance CR
# - GlanceAPI glance-single CR
# - GlanceAPI glance-single-api Deployment
# - glance-single-api Pod
# - glance-internal service
# - glance-public service
# - glance internal and public endpoints

apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
spec:
serviceUser: glance
containerImage: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
customServiceConfig: |
[DEFAULT]
debug = true
databaseInstance: openstack
databaseUser: glance
glanceAPI:
containerImage: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
debug:
service: false
replicas: 1
type: "single"
secret: osp-secret
storageRequest: 10G
status:
databaseHostname: openstack
glanceAPIExternalReadyCount: 1
---
apiVersion: glance.openstack.org/v1beta1
kind: GlanceAPI
metadata:
name: glance-single
spec:
apiType: single
containerImage: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
databaseUser: glance
databaseHostname: openstack
debug:
service: false
passwordSelectors:
database: GlanceDatabasePassword
service: GlancePassword
replicas: 1
status:
readyCount: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glance-single-api
spec:
replicas: 1
selector:
matchLabels:
service: glance-single
template:
metadata:
labels:
service: glance-single
spec:
containers:
- args:
- -c
- tail -n+1 -F /var/log/glance/glance-single.log
command:
- /bin/bash
image: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
name: glance-log
- args:
- -c
- /usr/sbin/httpd -DFOREGROUND
command:
- /bin/bash
image: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
name: glance-httpd
- args:
- -c
- /usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start
command:
- /bin/bash
image: quay.io/podified-antelope-centos9/openstack-glance-api:current-podified
name: glance-api
serviceAccount: glance-glance
serviceAccountName: glance-glance
status:
availableReplicas: 1
replicas: 1
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-single
status:
phase: Running
---
apiVersion: v1
kind: Service
metadata:
name: glance-internal
labels:
endpoint: internal
service: glance-single
spec:
ports:
- name: glance-internal
port: 9292
protocol: TCP
targetPort: 9292
selector:
service: glance-single
---
apiVersion: v1
kind: Service
metadata:
name: glance-public
labels:
endpoint: public
service: glance-single
spec:
ports:
- name: glance-public
port: 9292
protocol: TCP
targetPort: 9292
selector:
service: glance-single
---
# the actual addresses of the apiEndpoints are platform specific, so we can't rely on
# kuttl asserts to check them. This short script gathers the addresses and checks that
# the three endpoints are defined and their addresses follow the default pattern
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
namespaced: true
commands:
- script: |
template='{{.status.apiEndpoint.internal}}{{":"}}{{.status.apiEndpoint.public}}{{"\n"}}'
regex="http:\/\/glance-internal.$NAMESPACE.*:http:\/\/glance-public.$NAMESPACE.*"
apiEndpoints=$(oc get -n $NAMESPACE Glance glance -o go-template="$template")
matches=$(echo "$apiEndpoints" | sed -e "s?$regex??")
if [ -z "$matches" ]; then
exit 0
else
exit 1
fi
6 changes: 6 additions & 0 deletions test/kuttl/tests/glance_single/01-deploy_glance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
cp ../../../../config/samples/glance_v1beta1_glance_single.yaml deploy
oc kustomize deploy | oc apply -n $NAMESPACE -f -
27 changes: 27 additions & 0 deletions test/kuttl/tests/glance_single/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Check for:
# - Glance CR with 2 replicas for each GlanceAPI
# - GlanceAPI glance-external-api Deployment with 2 replicas
# - GlanceAPI glance-internal-api Deployment with 2 replicas


apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
spec:
glanceAPI:
replicas: 2
status:
glanceAPIExternalReadyCount: 2
#glanceAPIInternalReadyCount: 2
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glance-single-api
spec:
replicas: 2
status:
availableReplicas: 2
replicas: 2
5 changes: 5 additions & 0 deletions test/kuttl/tests/glance_single/02-scale-glanceapis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc patch Glance -n $NAMESPACE glance --type='json' -p='[{"op": "replace", "path": "/spec/glanceAPI/replicas", "value":2}]'
26 changes: 26 additions & 0 deletions test/kuttl/tests/glance_single/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Check for:
# - Glance CR with 1 replicas for each GlanceAPI
# - GlanceAPI glance-single-api Deployment with 1 replicas


apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
spec:
glanceAPI:
replicas: 1
status:
glanceAPIExternalReadyCount: 1
#glanceAPIInternalReadyCount: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glance-single-api
spec:
replicas: 1
status:
availableReplicas: 1
replicas: 1
5 changes: 5 additions & 0 deletions test/kuttl/tests/glance_single/03-scale-down-glanceapis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc patch Glance -n $NAMESPACE glance --type='json' -p='[{"op": "replace", "path": "/spec/glanceAPI/replicas", "value":1}]'
21 changes: 21 additions & 0 deletions test/kuttl/tests/glance_single/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Check for:
# - Glance CR with 0 replicas for each GlanceAPI
# - GlanceAPI glance-external-api Deployment with 0 replicas
# - GlanceAPI glance-internal-api Deployment with 0 replicas


apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
spec:
glanceAPI:
replicas: 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glance-single-api
spec:
replicas: 0
5 changes: 5 additions & 0 deletions test/kuttl/tests/glance_single/04-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-single
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc patch Glance -n $NAMESPACE glance --type='json' -p='[{"op": "replace", "path": "/spec/glanceAPI/replicas", "value":0}]'
6 changes: 6 additions & 0 deletions test/kuttl/tests/glance_single/05-cleanup-glance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc kustomize deploy | oc delete -n $NAMESPACE -f -
rm deploy/glance_v1beta1_glance_single.yaml
39 changes: 39 additions & 0 deletions test/kuttl/tests/glance_single/05-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Check for:
# - No Glance CR
# - No GlanceAPI glance-single CR
# - No GlanceAPI glance-single-api Deployment
# - No glance-single-api Pod
# - No glance-public service
# - No glance internal and public endpoints

apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
name: glance
---
apiVersion: glance.openstack.org/v1beta1
kind: GlanceAPI
metadata:
name: glance-single
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glance-single-api
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-single
---
apiVersion: v1
kind: Service
metadata:
name: glance-internal
---
apiVersion: v1
kind: Service
metadata:
name: glance-public
11 changes: 11 additions & 0 deletions test/kuttl/tests/glance_single/deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./glance_v1beta1_glance_single.yaml
patches:
- patch: |-
- op: replace
path: /spec/storageClass
value: local-storage
target:
kind: Glance

0 comments on commit 93a5619

Please sign in to comment.