Skip to content

Commit 82e4f8f

Browse files
committed
Use non static name for the Cinder CR
When the openstack operator creates the cinder CR it always uses the "cinder" name and there is no way to change it. This means that the names of the pods, and therefore the reported hostname inside them, will always be the same for the backup service (cinder-backup-0). The same will happen for the cinder volume in 2 different deployment if they have the same key in the volumes map. This may be fine for some deployments, but it creates problems in others, because many cinder drivers expect the hostnames of the hosts attaching volumes to be unique. Because they expect them to be unique they use the hostname as a key to store information on the storage array such as the iSCSI initiator name or the HBAs addresses. If they are not unique there unexpected behavior can happen, like hosts being unable to attach. This is very common in CI systems, but is not limited to them as it can also happen in production deployments that are using the same storage arrays as their pre-production counterparts (even if it's different pools). In this patch the human operator has now a way to ask for unique pod names in cinder services using the `uniquePodNames` boolean field in the `cinder` section. When `uniquePodNames` is set to `true` the openstack-operator will name the `Cinder` CR using the first 6 characters of the `OpenStackControlPlane` UID, that way the pods for the cinder services will have a unique name. Pod name collision is still possible, but unlikely. Jira: OSPRH-7396
1 parent 2d315a0 commit 82e4f8f

4 files changed

Lines changed: 34 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
@@ -1661,6 +1661,9 @@ spec:
16611661
- rabbitMqClusterName
16621662
- secret
16631663
type: object
1664+
uniquePodNames:
1665+
default: false
1666+
type: boolean
16641667
type: object
16651668
designate:
16661669
properties:

‎apis/core/v1beta1/openstackcontrolplane_types.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ type CinderSection struct {
433433
// +operator-sdk:csv:customresourcedefinitions:type=spec
434434
// APIOverride, provides the ability to override the generated manifest of several child resources.
435435
APIOverride Override `json:"apiOverride,omitempty"`
436+
437+
// +kubebuilder:validation:Optional
438+
// +kubebuilder:default=false
439+
// UniquePodNames - Use a unique prefix for cinder CRs to have unique pod names.
440+
// Convenient to avoid podname (and thus hostname) collision between different deployments.
441+
// Useful for CI jobs as well as preproduction and production environments that use the same storage backend, etc.
442+
UniquePodNames bool `json:"uniquePodNames"`
436443
}
437444

438445
// GaleraSection defines the desired state of Galera services

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,9 @@ spec:
16611661
- rabbitMqClusterName
16621662
- secret
16631663
type: object
1664+
uniquePodNames:
1665+
default: false
1666+
type: boolean
16641667
type: object
16651668
designate:
16661669
properties:

‎pkg/openstack/cinder.go‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,27 @@ import (
2121

2222
// ReconcileCinder -
2323
func ReconcileCinder(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
24+
cinderName := "cinder"
25+
altCinderName := fmt.Sprintf("cinder-%s", instance.UID[:5])
26+
27+
if instance.Spec.Cinder.UniquePodNames {
28+
cinderName, altCinderName = altCinderName, cinderName
29+
}
30+
31+
// Ensure the alternate cinder CR doesn't exist, as the ramdomPodNames flag may have been toggled
2432
cinder := &cinderv1.Cinder{
2533
ObjectMeta: metav1.ObjectMeta{
26-
Name: "cinder",
34+
Name: altCinderName,
35+
Namespace: instance.Namespace,
36+
},
37+
}
38+
if res, err := EnsureDeleted(ctx, helper, cinder); err != nil {
39+
return res, err
40+
}
41+
42+
cinder = &cinderv1.Cinder{
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: cinderName,
2745
Namespace: instance.Namespace,
2846
},
2947
}
@@ -58,7 +76,7 @@ func ReconcileCinder(ctx context.Context, instance *corev1beta1.OpenStackControl
5876
}
5977

6078
// When component services got created check if there is the need to create a route
61-
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "cinder", Namespace: instance.Namespace}, cinder); err != nil {
79+
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: cinderName, Namespace: instance.Namespace}, cinder); err != nil {
6280
if !k8s_errors.IsNotFound(err) {
6381
return ctrl.Result{}, err
6482
}
@@ -106,7 +124,7 @@ func ReconcileCinder(ctx context.Context, instance *corev1beta1.OpenStackControl
106124
instance.Spec.Cinder.Template.CinderAPI.TLS.API.Internal.SecretName = endpointDetails.GetEndptCertSecret(service.EndpointInternal)
107125
}
108126

109-
Log.Info("Reconciling Cinder", "Cinder.Namespace", instance.Namespace, "Cinder.Name", "cinder")
127+
Log.Info("Reconciling Cinder", "Cinder.Namespace", instance.Namespace, "Cinder.Name", cinderName)
110128
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), cinder, func() error {
111129
instance.Spec.Cinder.Template.CinderSpecBase.DeepCopyInto(&cinder.Spec.CinderSpecBase)
112130
instance.Spec.Cinder.Template.CinderAPI.DeepCopyInto(&cinder.Spec.CinderAPI.CinderAPITemplateCore)

0 commit comments

Comments
 (0)