diff --git a/config/samples/glance_v1beta1_glance_single_instance.yaml b/config/samples/glance_v1beta1_glance_single.yaml similarity index 90% rename from config/samples/glance_v1beta1_glance_single_instance.yaml rename to config/samples/glance_v1beta1_glance_single.yaml index 77f632142..62b2e4a9d 100644 --- a/config/samples/glance_v1beta1_glance_single_instance.yaml +++ b/config/samples/glance_v1beta1_glance_single.yaml @@ -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" diff --git a/controllers/glance_controller.go b/controllers/glance_controller.go index 09b9b66ae..f46b40ab0 100644 --- a/controllers/glance_controller.go +++ b/controllers/glance_controller.go @@ -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 @@ -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)] } @@ -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 { diff --git a/test/functional/sample_test.go b/test/functional/sample_test.go index 38199821d..00a6de31c 100644 --- a/test/functional/sample_test.go +++ b/test/functional/sample_test.go @@ -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) }) }) diff --git a/test/kuttl/tests/glance_single/01-assert.yaml b/test/kuttl/tests/glance_single/01-assert.yaml new file mode 100644 index 000000000..7119bf3f2 --- /dev/null +++ b/test/kuttl/tests/glance_single/01-assert.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/01-deploy_glance.yaml b/test/kuttl/tests/glance_single/01-deploy_glance.yaml new file mode 100644 index 000000000..3de6742b1 --- /dev/null +++ b/test/kuttl/tests/glance_single/01-deploy_glance.yaml @@ -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 - diff --git a/test/kuttl/tests/glance_single/02-assert.yaml b/test/kuttl/tests/glance_single/02-assert.yaml new file mode 100644 index 000000000..b8aa6c6b4 --- /dev/null +++ b/test/kuttl/tests/glance_single/02-assert.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/02-scale-glanceapis.yaml b/test/kuttl/tests/glance_single/02-scale-glanceapis.yaml new file mode 100644 index 000000000..3f6e8bffc --- /dev/null +++ b/test/kuttl/tests/glance_single/02-scale-glanceapis.yaml @@ -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}]' diff --git a/test/kuttl/tests/glance_single/03-assert.yaml b/test/kuttl/tests/glance_single/03-assert.yaml new file mode 100644 index 000000000..9fb1d6c68 --- /dev/null +++ b/test/kuttl/tests/glance_single/03-assert.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/03-scale-down-glanceapis.yaml b/test/kuttl/tests/glance_single/03-scale-down-glanceapis.yaml new file mode 100644 index 000000000..9372c2652 --- /dev/null +++ b/test/kuttl/tests/glance_single/03-scale-down-glanceapis.yaml @@ -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}]' diff --git a/test/kuttl/tests/glance_single/04-assert.yaml b/test/kuttl/tests/glance_single/04-assert.yaml new file mode 100644 index 000000000..72e1a6d3b --- /dev/null +++ b/test/kuttl/tests/glance_single/04-assert.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/04-errors.yaml b/test/kuttl/tests/glance_single/04-errors.yaml new file mode 100644 index 000000000..b837cabcc --- /dev/null +++ b/test/kuttl/tests/glance_single/04-errors.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Pod +metadata: + labels: + service: glance-single diff --git a/test/kuttl/tests/glance_single/04-scale-down-zero-glanceapis.yaml b/test/kuttl/tests/glance_single/04-scale-down-zero-glanceapis.yaml new file mode 100644 index 000000000..0e247aad8 --- /dev/null +++ b/test/kuttl/tests/glance_single/04-scale-down-zero-glanceapis.yaml @@ -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}]' diff --git a/test/kuttl/tests/glance_single/05-cleanup-glance.yaml b/test/kuttl/tests/glance_single/05-cleanup-glance.yaml new file mode 100644 index 000000000..46acd7ac4 --- /dev/null +++ b/test/kuttl/tests/glance_single/05-cleanup-glance.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/05-errors.yaml b/test/kuttl/tests/glance_single/05-errors.yaml new file mode 100644 index 000000000..01d7da261 --- /dev/null +++ b/test/kuttl/tests/glance_single/05-errors.yaml @@ -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 diff --git a/test/kuttl/tests/glance_single/deploy/kustomization.yaml b/test/kuttl/tests/glance_single/deploy/kustomization.yaml new file mode 100644 index 000000000..a45bef385 --- /dev/null +++ b/test/kuttl/tests/glance_single/deploy/kustomization.yaml @@ -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