Skip to content

Commit db12c2f

Browse files
Merge pull request #847 from Akrog/non-static-names
Use non static name for the Cinder and Glance CRs
2 parents 8df01b0 + e9cc254 commit db12c2f

5 files changed

Lines changed: 65 additions & 6 deletions

File tree

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

Lines changed: 6 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:
@@ -4525,6 +4528,9 @@ spec:
45254528
- memcachedInstance
45264529
- secret
45274530
type: object
4531+
uniquePodNames:
4532+
default: false
4533+
type: boolean
45284534
type: object
45294535
heat:
45304536
properties:

‎apis/core/v1beta1/openstackcontrolplane_types.go‎

Lines changed: 14 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
@@ -433,6 +440,13 @@ type CinderSection struct {
433440
// +operator-sdk:csv:customresourcedefinitions:type=spec
434441
// APIOverride, provides the ability to override the generated manifest of several child resources.
435442
APIOverride Override `json:"apiOverride,omitempty"`
443+
444+
// +kubebuilder:validation:Optional
445+
// +kubebuilder:default=false
446+
// UniquePodNames - Use a unique prefix for cinder CRs to have unique pod names.
447+
// Convenient to avoid podname (and thus hostname) collision between different deployments.
448+
// Useful for CI jobs as well as preproduction and production environments that use the same storage backend, etc.
449+
UniquePodNames bool `json:"uniquePodNames"`
436450
}
437451

438452
// GaleraSection defines the desired state of Galera services

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

Lines changed: 6 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:
@@ -4525,6 +4528,9 @@ spec:
45254528
- memcachedInstance
45264529
- secret
45274530
type: object
4531+
uniquePodNames:
4532+
default: false
4533+
type: boolean
45284534
type: object
45294535
heat:
45304536
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)

‎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)