Skip to content

Commit

Permalink
Use non static name for the Glance CR
Browse files Browse the repository at this point in the history
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 `randomPodNames` field to generate a unique `Glance` name.

This allows human operators ensure that the pod names in their
deployment are unique.

Jira: OSPRH-7396
  • Loading branch information
Akrog committed Jun 19, 2024
1 parent cab8026 commit 44c9c07
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3506,6 +3506,9 @@ spec:
enabled:
default: true
type: boolean
randomPodNames:
default: false
type: boolean
template:
properties:
apiTimeout:
Expand Down
7 changes: 7 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ type GlanceSection struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// APIOverride, provides the ability to override the generated manifest of several child resources.
APIOverride map[string]Override `json:"apiOverrides,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
// RandomPodNames - Use a unique prefix for glance CRs to have unique pod names.
// Convenient to avoid podname (and thus hostname) collision between different deployments.
// Useful for CI jobs as well as preproduction and production environments that use the same storage backend, etc.
RandomPodNames bool `json:"randomPodNames"`
}

// CinderSection defines the desired state of Cinder service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3506,6 +3506,9 @@ spec:
enabled:
default: true
type: boolean
randomPodNames:
default: false
type: boolean
template:
properties:
apiTimeout:
Expand Down
21 changes: 18 additions & 3 deletions pkg/openstack/glance.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,28 @@ const (

// ReconcileGlance -
func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
glanceName := "glance"
altGlanceName := fmt.Sprintf("glance-%s", instance.UID[:5])
if instance.Spec.Glance.RandomPodNames {
glanceName, altGlanceName = altGlanceName, glanceName
}
// Ensure the alternate cinder CR doesn't exist, as the ramdomPodNames flag may have been toggled
glance := &glancev1.Glance{
ObjectMeta: metav1.ObjectMeta{
Name: "glance",
Name: altGlanceName,
Namespace: instance.Namespace,
},
}
if res, err := EnsureDeleted(ctx, helper, glance); err != nil {
return res, err
}

glance = &glancev1.Glance{
ObjectMeta: metav1.ObjectMeta{
Name: glanceName,
Namespace: instance.Namespace,
},
}
Log := GetLogger(ctx)

if !instance.Spec.Glance.Enabled {
Expand All @@ -47,7 +62,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
}

// When component services got created check if there is the need to create a route
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "glance", Namespace: instance.Namespace}, glance); err != nil {
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: glanceName, Namespace: instance.Namespace}, glance); err != nil {
if !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -139,7 +154,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
return ctrl.Result{}, nil
}

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

0 comments on commit 44c9c07

Please sign in to comment.