Skip to content

Commit ba50016

Browse files
committed
Handle glance minor updates
Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent 912099a commit ba50016

6 files changed

Lines changed: 92 additions & 10 deletions

File tree

apis/core/v1beta1/openstackversion_types.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package v1beta1
1818

1919
import (
2020
"regexp"
21+
"strings"
22+
"golang.org/x/mod/semver"
23+
"fmt"
2124

2225
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2326
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
@@ -254,3 +257,38 @@ func GetOpenStackReleaseVersion(envVars []string) string {
254257
)
255258

256259
}
260+
261+
// GetDeployedSemVersion - returns the current deployed version. It can be used
262+
// to compare it against an available version and take decisions based on it
263+
func (v *OpenStackVersion) GetDeployedSemVer() string {
264+
if v.Status.DeployedVersion == nil {
265+
return ""
266+
}
267+
if strings.HasPrefix(*v.Status.DeployedVersion, "^v") {
268+
// we don't need to normalize the string
269+
return *v.Status.DeployedVersion
270+
}
271+
return fmt.Sprintf("v%s", *v.Status.DeployedVersion)
272+
}
273+
274+
// IsGreaterSemVer - returns true when deployedVersion is greater than the
275+
// targetVersion passed as input
276+
func (v *OpenStackVersion) IsGreaterSemVer(targetVer string) bool{
277+
deployedVersion := v.GetDeployedSemVer()
278+
// return false if there's no deployedVersion
279+
if deployedVersion == "" {
280+
return false
281+
}
282+
return semver.Compare(deployedVersion, targetVer) > 0
283+
}
284+
285+
// IsLowerSemVer - returns true when deployedVersion is lower than a targetVersion
286+
// that is used to compare it
287+
func (v *OpenStackVersion) IsLowerSemVer(targetVer string) bool{
288+
deployedVersion := v.GetDeployedSemVer()
289+
// return false if there's no deployedVersion
290+
if deployedVersion == "" {
291+
return false
292+
}
293+
return semver.Compare(deployedVersion, targetVer) < 0
294+
}

apis/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
go.uber.org/multierr v1.11.0 // indirect
3434
go.uber.org/zap v1.27.0 // indirect
3535
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
36+
golang.org/x/mod v0.20.0
3637
golang.org/x/tools v0.24.0 // indirect
3738
k8s.io/api v0.29.15
3839
k8s.io/apimachinery v0.29.15
@@ -115,3 +116,5 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202408300231
115116

116117
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.9.0_patches_tag)
117118
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 //allow-merging
119+
120+
replace github.com/openstack-k8s-operators/glance-operator/api => github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180

apis/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
1414
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1515
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
1616
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
17+
github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180 h1:crRHrF0uDIYm8es2Ya/ELO1el/uKOzY+NcdnEISQCLI=
18+
github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180/go.mod h1:dA/dH8jFvqX90KHPC9LN9RDOMRE+boriwwDjMMUJkL4=
1719
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1820
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1921
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
@@ -100,8 +102,6 @@ github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20250423054052-7
100102
github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20250423054052-76f811364c48/go.mod h1:wA+iwrJQzpsMslseJZgEgqdTGlrYytNX2XkI4SQQNLw=
101103
github.com/openstack-k8s-operators/designate-operator/api v0.6.1-0.20250422103124-9adfe79423df h1:+OMlbs1XNLVF6U8Xk0YmlofKlvDizt3YV+OQkxx9InY=
102104
github.com/openstack-k8s-operators/designate-operator/api v0.6.1-0.20250422103124-9adfe79423df/go.mod h1:KkjCmRFNnIKxJcWZC96bk3CsmZmT0nyGJzOCF6Qzvy8=
103-
github.com/openstack-k8s-operators/glance-operator/api v0.6.1-0.20250407064150-1cff0f51b44d h1:DivsLnqDoMFnAWOOkOCoj9ilCM+6pFXRjvz4fSFSvJw=
104-
github.com/openstack-k8s-operators/glance-operator/api v0.6.1-0.20250407064150-1cff0f51b44d/go.mod h1:IRp2nEGLIQj9gZSc5aMJr5Wec9yBhr//6y7W41ur4KQ=
105105
github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20250423034234-f96998c6fdac h1:HrBh3wx0po8AbTxH/+ZT6P51FQyvAssjQqhgPsbVE8Q=
106106
github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20250423034234-f96998c6fdac/go.mod h1:H7Cd+GRpWmm+Viqu2eqNMGhK7qTE7SpSVo6qz1Gksec=
107107
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20250421055257-62660c8c5cba h1:ZJSh4+IWoojgMeY2Pe2kaG3lLPPxT81X9tSEV2Ke3hM=
@@ -188,6 +188,8 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbR
188188
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
189189
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
190190
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
191+
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
192+
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
191193
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
192194
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
193195
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202408300231
127127

128128
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.9.0_patches_tag)
129129
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 //allow-merging
130+
131+
replace github.com/openstack-k8s-operators/glance-operator/api => github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
1414
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1515
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
1616
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
17+
github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180 h1:crRHrF0uDIYm8es2Ya/ELO1el/uKOzY+NcdnEISQCLI=
18+
github.com/fmount/glance-operator/api v0.1.2-0.20250502133016-1b9e7f5e4180/go.mod h1:dA/dH8jFvqX90KHPC9LN9RDOMRE+boriwwDjMMUJkL4=
1719
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1820
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1921
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
@@ -104,8 +106,6 @@ github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20250423054052-7
104106
github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20250423054052-76f811364c48/go.mod h1:wA+iwrJQzpsMslseJZgEgqdTGlrYytNX2XkI4SQQNLw=
105107
github.com/openstack-k8s-operators/designate-operator/api v0.6.1-0.20250422103124-9adfe79423df h1:+OMlbs1XNLVF6U8Xk0YmlofKlvDizt3YV+OQkxx9InY=
106108
github.com/openstack-k8s-operators/designate-operator/api v0.6.1-0.20250422103124-9adfe79423df/go.mod h1:KkjCmRFNnIKxJcWZC96bk3CsmZmT0nyGJzOCF6Qzvy8=
107-
github.com/openstack-k8s-operators/glance-operator/api v0.6.1-0.20250407064150-1cff0f51b44d h1:DivsLnqDoMFnAWOOkOCoj9ilCM+6pFXRjvz4fSFSvJw=
108-
github.com/openstack-k8s-operators/glance-operator/api v0.6.1-0.20250407064150-1cff0f51b44d/go.mod h1:IRp2nEGLIQj9gZSc5aMJr5Wec9yBhr//6y7W41ur4KQ=
109109
github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20250423034234-f96998c6fdac h1:HrBh3wx0po8AbTxH/+ZT6P51FQyvAssjQqhgPsbVE8Q=
110110
github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20250423034234-f96998c6fdac/go.mod h1:H7Cd+GRpWmm+Viqu2eqNMGhK7qTE7SpSVo6qz1Gksec=
111111
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20250421055257-62660c8c5cba h1:ZJSh4+IWoojgMeY2Pe2kaG3lLPPxT81X9tSEV2Ke3hM=

pkg/openstack/glance.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/apimachinery/pkg/types"
1616
ctrl "sigs.k8s.io/controller-runtime"
1717
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
18+
"strconv"
1819
)
1920

2021
const (
@@ -23,17 +24,32 @@ const (
2324
// label set by the service operator as in case of split glanceAPI type the
2425
// the label on public svc gets set to -external and internal instance svc
2526
// to -internal instead of the glance top level glanceType split
26-
svcSelector = "tlGlanceAPI"
27+
svcSelector = "tlGlanceAPI"
28+
targetVersion = "v18.0.9"
2729
)
2830

2931
// ReconcileGlance -
3032
func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
3133
glanceName, altGlanceName := instance.GetServiceName(corev1beta1.GlanceName, instance.Spec.Glance.UniquePodNames)
32-
// Ensure the alternate cinder CR doesn't exist, as the ramdomPodNames flag may have been toggled
34+
apiAnnotations := map[string]string{}
35+
36+
// Set WSGI annotation to either deploy GlanceAPI in wsgi mode or httpd +
37+
// ProxyPass
38+
//
39+
// - wsgi=true for both greenfield deployments and when a minor update is
40+
// performed from a version greater than v18.0.9
41+
//
42+
// - wsgi=false keeps the httpd + proxypass deployment method.
43+
// This is required when a minor update from a version < FR3 is performed
44+
apiAnnotations["wsgi"] = GlanceWSGIAnnotation(version, targetVersion)
45+
46+
// Ensure the alternate glance CR doesn't exist, as the ramdomPodNames flag may have
47+
// been toggled
3348
glance := &glancev1.Glance{
3449
ObjectMeta: metav1.ObjectMeta{
35-
Name: altGlanceName,
36-
Namespace: instance.Namespace,
50+
Name: altGlanceName,
51+
Namespace: instance.Namespace,
52+
Annotations: apiAnnotations,
3753
},
3854
}
3955
if res, err := EnsureDeleted(ctx, helper, glance); err != nil {
@@ -42,8 +58,9 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
4258

4359
glance = &glancev1.Glance{
4460
ObjectMeta: metav1.ObjectMeta{
45-
Name: glanceName,
46-
Namespace: instance.Namespace,
61+
Name: glanceName,
62+
Namespace: instance.Namespace,
63+
Annotations: apiAnnotations,
4764
},
4865
}
4966
Log := GetLogger(ctx)
@@ -171,6 +188,9 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
171188
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), glance, func() error {
172189
instance.Spec.Glance.Template.DeepCopyInto(&glance.Spec.GlanceSpecCore)
173190
glance.Spec.ContainerImage = *version.Status.ContainerImages.GlanceAPIImage
191+
// Set apiAnnotations in the Glance CR: this is currently used to
192+
// influence
193+
glance.SetAnnotations(apiAnnotations)
174194
if glance.Spec.Secret == "" {
175195
glance.Spec.Secret = instance.Spec.Secret
176196
}
@@ -243,3 +263,20 @@ func GlanceImageMatch(ctx context.Context, controlPlane *corev1beta1.OpenStackCo
243263

244264
return true
245265
}
266+
267+
// GlanceWSGIAnnotation -
268+
func GlanceWSGIAnnotation(version *corev1beta1.OpenStackVersion, targetVersion string) string {
269+
wsgi := true
270+
// if there is no deployed version, it is a greenfield scenario and we can
271+
// deploy in wsgi mode (which is the default)
272+
if version.Status.DeployedVersion == nil {
273+
return strconv.FormatBool(wsgi)
274+
}
275+
// Do not deploy Glance in wsgi mode, but keep http+ProxyPass model when the
276+
// version is lower than FR3 (18.0.10). This is required because the previous
277+
// Glance ContainerImage is incompatitble with WSGI.
278+
if version.IsLowerSemVer(targetVersion) {
279+
wsgi = false
280+
}
281+
return strconv.FormatBool(wsgi)
282+
}

0 commit comments

Comments
 (0)