88 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
99 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
1010 "github.com/openstack-k8s-operators/lib-common/modules/common/service"
11+ "github.com/openstack-k8s-operators/lib-common/modules/common/util"
1112 corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
1213 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -18,8 +19,11 @@ import (
1819
1920const (
2021 // svcSelector is used as selector to get the list of "Services" associated
21- // to a specific glanceAPI instance
22- svcSelector = "glanceAPI"
22+ // to a specific glanceAPI instance. It must be different from glanceAPI
23+ // label set by the service operator as in case of split glanceAPI type the
24+ // the label on public svc gets set to -external and internal instance svc
25+ // to -internal instead of the glance top level glanceType split
26+ svcSelector = "tlGlanceAPI"
2327)
2428
2529// ReconcileGlance -
@@ -55,7 +59,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
5559 if glanceAPI .Override .Service == nil {
5660 glanceAPI .Override .Service = map [service.Endpoint ]service.RoutedOverrideSpec {}
5761 }
58- glanceAPI .Override .Service [endpointType ] = AddServiceComponentLabel (
62+ glanceAPI .Override .Service [endpointType ] = AddServiceOpenStackOperatorLabel (
5963 glanceAPI .Override .Service [endpointType ], glance .Name )
6064
6165 svcOverride := glanceAPI .Override .Service [endpointType ]
@@ -71,32 +75,36 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
7175 instance .Spec .Glance .Template .GlanceAPIs [name ] = glanceAPI
7276 }
7377
74- if glance .Status .Conditions .IsTrue (glancev1 .GlanceAPIReadyCondition ) {
75- // initialize the main APIOverride struct
76- if instance .Spec .Glance .APIOverride == nil {
77- instance .Spec .Glance .APIOverride = map [string ]corev1beta1.Override {}
78- }
78+ // initialize the main APIOverride struct
79+ if instance .Spec .Glance .APIOverride == nil {
80+ instance .Spec .Glance .APIOverride = map [string ]corev1beta1.Override {}
81+ }
7982
80- var changed bool = false
81- for name , glanceAPI := range instance .Spec .Glance .Template .GlanceAPIs {
82- if _ , ok := instance .Spec .Glance .APIOverride [name ]; ! ok {
83- instance .Spec .Glance .APIOverride [name ] = corev1beta1.Override {}
84- }
85- // Retrieve the services by Label and filter on glanceAPI: for
86- // each instance we should get **only** the associated `SVCs`
87- // and not the whole list. As per the Glance design doc we know
88- // that a given instance name is made in the form: "<service>
89- // <apiName> <apiType>", so we build the filter accordingly
90- // to resolve the label as <service>-<apiName>
91- svcs , err := service .GetServicesListWithLabel (
92- ctx ,
93- helper ,
94- instance .Namespace ,
83+ var changed = false
84+ for name , glanceAPI := range instance .Spec .Glance .Template .GlanceAPIs {
85+ if _ , ok := instance .Spec .Glance .APIOverride [name ]; ! ok {
86+ instance .Spec .Glance .APIOverride [name ] = corev1beta1.Override {}
87+ }
88+ // Retrieve the services by Label and filter on glanceAPI: for
89+ // each instance we should get **only** the associated `SVCs`
90+ // and not the whole list. As per the Glance design doc we know
91+ // that a given instance name is made in the form: "<service>
92+ // <apiName> <apiType>", so we build the filter accordingly
93+ // to resolve the label as <service>-<apiName>
94+ svcs , err := service .GetServicesListWithLabel (
95+ ctx ,
96+ helper ,
97+ instance .Namespace ,
98+ util .MergeMaps (
99+ GetServiceOpenStackOperatorLabel (glance .Name ),
95100 getGlanceAPILabelMap (glance .Name , name , glanceAPI .Type ),
96- )
97- if err != nil {
98- return ctrl.Result {}, err
99- }
101+ ),
102+ )
103+ if err != nil {
104+ return ctrl.Result {}, err
105+ }
106+ // make sure to get to EndpointConfig when all service got created
107+ if len (svcs .Items ) == len (glanceAPI .Override .Service ) {
100108 endpointDetails , ctrlResult , err := EnsureEndpointConfig (
101109 ctx ,
102110 instance ,
@@ -111,23 +119,22 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
111119 if err != nil {
112120 return ctrlResult , err
113121 }
122+ // set service overrides
114123 glanceAPI .Override .Service = endpointDetails .GetEndpointServiceOverrides ()
115-
116124 // update TLS cert secret
117125 glanceAPI .TLS .API .Public .SecretName = endpointDetails .GetEndptCertSecret (service .EndpointPublic )
118126 glanceAPI .TLS .API .Internal .SecretName = endpointDetails .GetEndptCertSecret (service .EndpointInternal )
119- instance .Spec .Glance .Template .GlanceAPIs [name ] = glanceAPI
120127
121128 // let's keep track of changes for any instance, but return
122129 // only when the iteration on the whole APIList is over
123130 if (ctrlResult != ctrl.Result {}) {
124131 changed = true
125132 }
126133 }
127- // if one of the API changed, return
128- if changed {
129- return ctrl. Result {}, nil
130- }
134+ instance . Spec . Glance . Template . GlanceAPIs [ name ] = glanceAPI
135+ }
136+ if changed {
137+ return ctrl. Result {}, nil
131138 }
132139
133140 Log .Info ("Reconciling Glance" , "Glance.Namespace" , instance .Namespace , "Glance.Name" , "glance" )
0 commit comments