Skip to content

Commit

Permalink
Set AppSelector to the main service Name
Browse files Browse the repository at this point in the history
If AppSelector does not reflect the general service name, it might
result hard to get all the resources associated to a given Glance
CR. For this reason this patch reworks the labels assignment to
align Glance with the work done in the other operators.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Dec 6, 2023
1 parent da826a4 commit 1e6225b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 38 deletions.
1 change: 0 additions & 1 deletion api/v1beta1/glance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (r *Glance) ValidateCreate() error {
}

//TODO:
// - Two glanceAPI with the same name can't be deployed
// - Check one of the items of the list is the one that should appear in the
// keystone catalog, otherwise raise an error because the field is not set!
return nil
Expand Down
5 changes: 3 additions & 2 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
//

//
err = r.generateServiceConfig(ctx, helper, instance, &configVars)
err = r.generateServiceConfig(ctx, helper, instance, &configVars, serviceLabels)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ServiceConfigReadyCondition,
Expand Down Expand Up @@ -820,8 +820,9 @@ func (r *GlanceReconciler) generateServiceConfig(
h *helper.Helper,
instance *glancev1.Glance,
envVars *map[string]env.Setter,
serviceLabels map[string]string,
) error {
labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), map[string]string{})
labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), serviceLabels)

ospSecret, _, err := secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
if err != nil {
Expand Down
21 changes: 11 additions & 10 deletions controllers/glanceapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,16 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage)
// run check OpenStack secret - end

//
// Create Secrets required as input for the Service and calculate an overall hash of hashes
//
// Generate serviceLabels that will be passed to all the Service related resource
// By doing this we can `oc get` all the resources associated to Glance making
// queries by label
serviceLabels := map[string]string{
common.AppSelector: glance.ServiceName,
common.ComponentSelector: glance.Component,
glance.GlanceAPIName: instance.Name,
}

err = r.generateServiceConfig(ctx, helper, instance, &configVars)
err = r.generateServiceConfig(ctx, helper, instance, &configVars, serviceLabels)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ServiceConfigReadyCondition,
Expand Down Expand Up @@ -521,11 +526,6 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
privileged = true
}
}

serviceLabels := map[string]string{
common.AppSelector: instance.Name,
}

var serviceAnnotations map[string]string
var ctrlResult ctrl.Result
// networks to attach to
Expand Down Expand Up @@ -633,9 +633,10 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
h *helper.Helper,
instance *glancev1.GlanceAPI,
envVars *map[string]env.Setter,
serviceLabels map[string]string,
) error {

labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), map[string]string{})
labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), serviceLabels)

// 02-config.conf
customData := map[string]string{glance.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig}
Expand Down
5 changes: 4 additions & 1 deletion pkg/glance/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const (
ServiceType = "image"
// DatabaseName -
DatabaseName = "glance"

// Component -
Component = "glance-api"
// GlanceAPIName -
GlanceAPIName = "glanceAPI"
// PvcLocal for a generic glanceAPI instance
PvcLocal PvcType = "local"
// PvcCache is used to define a PVC mounted for image caching purposes
Expand Down
6 changes: 3 additions & 3 deletions test/functional/glanceapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var _ = Describe("Glanceapi controller", func() {
})
It("exposes the service", func() {
apiInstance := th.GetService(glanceTest.GlancePublicSvc)
Expect(apiInstance.Labels["service"]).To(Equal("glance-default-external"))
Expect(apiInstance.Labels["service"]).To(Equal("glance"))
})
It("creates KeystoneEndpoint", func() {
keystoneEndpoint := keystone.GetKeystoneEndpoint(glanceTest.GlanceExternal)
Expand Down Expand Up @@ -244,7 +244,7 @@ var _ = Describe("Glanceapi controller", func() {
})
It("exposes the service - Internal", func() {
apiInstance := th.GetService(glanceTest.GlanceInternalSvc)
Expect(apiInstance.Labels["service"]).To(Equal("glance-default-internal"))
Expect(apiInstance.Labels["service"]).To(Equal("glance"))
})
It("creates KeystoneEndpoint - Internal", func() {
keystoneEndpoint := keystone.GetKeystoneEndpoint(glanceTest.GlanceInternal)
Expand Down Expand Up @@ -278,7 +278,7 @@ var _ = Describe("Glanceapi controller", func() {
})
It("exposes the service", func() {
apiInstance := th.GetService(glanceTest.GlanceSingleInternalSvc)
Expect(apiInstance.Labels["service"]).To(Equal("glance-default-single"))
Expect(apiInstance.Labels["service"]).To(Equal("glance"))
})
It("creates KeystoneEndpoint", func() {
keystoneEndpoint := keystone.GetKeystoneEndpoint(glanceTest.GlanceSingle)
Expand Down
14 changes: 7 additions & 7 deletions test/kuttl/tests/glance_single/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ spec:
replicas: 1
selector:
matchLabels:
service: glance-default-single
service: glance
template:
metadata:
labels:
service: glance-default-single
service: glance
spec:
containers:
- args:
Expand Down Expand Up @@ -92,7 +92,7 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-single
service: glance
status:
phase: Running
---
Expand All @@ -102,31 +102,31 @@ metadata:
name: glance-default-single-internal
labels:
endpoint: internal
service: glance-default-single
service: glance
spec:
ports:
- name: glance-default-single-internal
port: 9292
protocol: TCP
targetPort: 9292
selector:
service: glance-default-single
service: glance
---
apiVersion: v1
kind: Service
metadata:
name: glance-default-single-public
labels:
endpoint: public
service: glance-default-single
service: glance
spec:
ports:
- name: glance-default-single-public
port: 9292
protocol: TCP
targetPort: 9292
selector:
service: glance-default-single
service: glance
---
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/kuttl/tests/glance_single/04-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-single
service: glance
2 changes: 1 addition & 1 deletion test/kuttl/tests/glance_single/05-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-single
service: glance
---
apiVersion: v1
kind: Service
Expand Down
16 changes: 8 additions & 8 deletions test/kuttl/tests/glance_split/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ spec:
replicas: 1
selector:
matchLabels:
service: glance-default-external
service: glance
template:
metadata:
labels:
service: glance-default-external
service: glance
spec:
containers:
- args:
Expand Down Expand Up @@ -113,11 +113,11 @@ spec:
replicas: 1
selector:
matchLabels:
service: glance-default-internal
service: glance
template:
metadata:
labels:
service: glance-default-internal
service: glance
spec:
containers:
- args:
Expand Down Expand Up @@ -152,15 +152,15 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-external
service: glance
status:
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-internal
service: glance
status:
phase: Running
---
Expand All @@ -170,7 +170,7 @@ metadata:
name: glance-default-internal-internal
labels:
endpoint: internal
service: glance-default-internal
service: glance
spec:
ports:
- name: glance-default-internal-internal
Expand All @@ -186,7 +186,7 @@ metadata:
name: glance-default-external-public
labels:
endpoint: public
service: glance-default-external
service: glance
spec:
ports:
- name: glance-default-external-public
Expand Down
4 changes: 2 additions & 2 deletions test/kuttl/tests/glance_split/04-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-external
service: glance
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-internal
service: glance
4 changes: 2 additions & 2 deletions test/kuttl/tests/glance_split/05-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-external
service: glance
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: glance-default-internal
service: glance
---
apiVersion: v1
kind: Service
Expand Down

0 comments on commit 1e6225b

Please sign in to comment.