Skip to content

Commit e9cc254

Browse files
committed
Use non static name for the Glance CR
When glance uses cinder as a backend it is also affected by the restrictions of needing unique pod names to have unique hostnames or risk the possibility of attachments not working as desired. The solution applied by this patch is the same as applied to cinder. Use the `uniquePodNames` field to generate a unique `Glance` name. This allows human operators ensure that the pod names in their deployment are unique. Jira: OSPRH-7396
1 parent 82e4f8f commit e9cc254

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎apis/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,6 +4528,9 @@ spec:
45284528
- memcachedInstance
45294529
- secret
45304530
type: object
4531+
uniquePodNames:
4532+
default: false
4533+
type: boolean
45314534
type: object
45324535
heat:
45334536
properties:

‎apis/core/v1beta1/openstackcontrolplane_types.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ type GlanceSection struct {
414414
// +operator-sdk:csv:customresourcedefinitions:type=spec
415415
// APIOverride, provides the ability to override the generated manifest of several child resources.
416416
APIOverride map[string]Override `json:"apiOverrides,omitempty"`
417+
418+
// +kubebuilder:validation:Optional
419+
// +kubebuilder:default=false
420+
// UniquePodNames - Use a unique prefix for glance CRs to have unique pod names.
421+
// Convenient to avoid podname (and thus hostname) collision between different deployments.
422+
// Useful for CI jobs as well as preproduction and production environments that use the same storage backend, etc.
423+
UniquePodNames bool `json:"uniquePodNames"`
417424
}
418425

419426
// CinderSection defines the desired state of Cinder service

‎config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,6 +4528,9 @@ spec:
45284528
- memcachedInstance
45294529
- secret
45304530
type: object
4531+
uniquePodNames:
4532+
default: false
4533+
type: boolean
45314534
type: object
45324535
heat:
45334536
properties:

‎pkg/openstack/glance.go‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,28 @@ const (
2828

2929
// ReconcileGlance -
3030
func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
31+
glanceName := "glance"
32+
altGlanceName := fmt.Sprintf("glance-%s", instance.UID[:5])
33+
if instance.Spec.Glance.UniquePodNames {
34+
glanceName, altGlanceName = altGlanceName, glanceName
35+
}
36+
// Ensure the alternate cinder CR doesn't exist, as the ramdomPodNames flag may have been toggled
3137
glance := &glancev1.Glance{
3238
ObjectMeta: metav1.ObjectMeta{
33-
Name: "glance",
39+
Name: altGlanceName,
3440
Namespace: instance.Namespace,
3541
},
3642
}
43+
if res, err := EnsureDeleted(ctx, helper, glance); err != nil {
44+
return res, err
45+
}
3746

47+
glance = &glancev1.Glance{
48+
ObjectMeta: metav1.ObjectMeta{
49+
Name: glanceName,
50+
Namespace: instance.Namespace,
51+
},
52+
}
3853
Log := GetLogger(ctx)
3954

4055
if !instance.Spec.Glance.Enabled {
@@ -52,7 +67,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
5267
}
5368

5469
// When component services got created check if there is the need to create a route
55-
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "glance", Namespace: instance.Namespace}, glance); err != nil {
70+
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: glanceName, Namespace: instance.Namespace}, glance); err != nil {
5671
if !k8s_errors.IsNotFound(err) {
5772
return ctrl.Result{}, err
5873
}
@@ -144,7 +159,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
144159
return ctrl.Result{}, nil
145160
}
146161

147-
Log.Info("Reconciling Glance", "Glance.Namespace", instance.Namespace, "Glance.Name", "glance")
162+
Log.Info("Reconciling Glance", "Glance.Namespace", instance.Namespace, "Glance.Name", glanceName)
148163
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), glance, func() error {
149164
instance.Spec.Glance.Template.DeepCopyInto(&glance.Spec.GlanceSpecCore)
150165
glance.Spec.ContainerImage = *version.Status.ContainerImages.GlanceAPIImage

0 commit comments

Comments
 (0)