Skip to content

Commit

Permalink
Predict the GlanceAPI volumes order
Browse files Browse the repository at this point in the history
When TLS is enabled at Pod level (which is the new default introduced by
the openstack-operator), and a statefulset is created, a new revision is
rolled out because of the overrides passed by the OpenStack operator to
the service CR. In glance this introduced an additional issue: in case
of multiple APIs, an iteration is performed through the Spec instances,
and the TLS override is checked out for each endpoint. No one ensures
that the StatefulSet has the same order of the provided mountpoints, and
this might generate multiple (random) rollouts until it converges with
two subsequent revisions that keep the same order. To avoid multiple
restarts, this patch adds two utility functions to sort the Volumes and
the VolumeMounts passed to the GlanceAPI StatefulSet. By doing this we
can always predict the mount order and avoid unnecessary restarts.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Apr 15, 2024
1 parent 6b5994d commit 6a454d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/glance/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package glance

import (
"sort"
"strconv"

glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
Expand Down Expand Up @@ -329,3 +330,17 @@ func GetScriptVolumeMount() []corev1.VolumeMount {
},
}
}

// SortVolumeMounts - Sorts a list (by Name) of []corev1.VolumeMount
func SortVolumeMounts(vm []corev1.VolumeMount) {
sort.Slice(vm, func(i, j int) bool {
return vm[i].Name < vm[j].Name
})
}

// SortVolumes - Sorts a list (by Name) of []corev1.Volumes
func SortVolumes(vl []corev1.Volume) {
sort.Slice(vl, func(i, j int) bool {
return vl[i].Name < vl[j].Name
})
}
9 changes: 9 additions & 0 deletions pkg/glanceapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func StatefulSet(

extraVolPropagation := append(glance.GlanceAPIPropagation,
storage.PropagationType(glance.GetGlanceAPIName(instance.Name)))

httpdVolumeMount := glance.GetHttpdVolumeMount()

// Add the CA bundle to the apiVolumes and httpdVolumeMount
Expand Down Expand Up @@ -179,6 +180,14 @@ func StatefulSet(
}
}

// TLS-e: we need to predict the order of both Volumes and VolumeMounts to
// prevent any unwanted Pod restart and StatefulSet rollout due to an
// update on its revision
for _, vmount := range [][]corev1.VolumeMount{apiVolumeMounts, httpdVolumeMount} {
glance.SortVolumeMounts(vmount)
}
glance.SortVolumes(apiVolumes)

stsName := instance.Name
// The StatefulSet name **must** match with the headless service
// endpoint Name (see GetHeadlessService() function under controllers/
Expand Down

0 comments on commit 6a454d0

Please sign in to comment.