Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't rely on volume order when finding PVC name #245

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions internal/fullnode/pod_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"sync"

"github.com/samber/lo"
cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1"
"github.com/strangelove-ventures/cosmos-operator/internal/healthcheck"
"github.com/strangelove-ventures/cosmos-operator/internal/kube"
Expand Down Expand Up @@ -172,6 +173,13 @@ func (b PodBuilder) Build() (*corev1.Pod, error) {
return pod, nil
}

const (
volChainHome = "vol-chain-home" // Stores live chain data and config files.
volTmp = "vol-tmp" // Stores temporary config files for manipulation later.
volConfig = "vol-config" // Items from ConfigMap.
volSystemTmp = "vol-system-tmp" // Necessary for statesync or else you may see the error: ERR State sync failed err="failed to create chunk queue: unable to create temp dir for state sync chunks: stat /tmp: no such file or directory" module=statesync
)

// WithOrdinal updates adds name and other metadata to the pod using "ordinal" which is the pod's
// ordered sequence. Pods have deterministic, consistent names similar to a StatefulSet instead of generated names.
func (b PodBuilder) WithOrdinal(ordinal int32) PodBuilder {
Expand All @@ -184,12 +192,6 @@ func (b PodBuilder) WithOrdinal(ordinal int32) PodBuilder {
pod.Name = name
pod.Spec.InitContainers = initContainers(b.crd, name)

const (
volChainHome = "vol-chain-home" // Stores live chain data and config files.
volTmp = "vol-tmp" // Stores temporary config files for manipulation later.
volConfig = "vol-config" // Items from ConfigMap.
volSystemTmp = "vol-system-tmp" // Necessary for statesync or else you may see the error: ERR State sync failed err="failed to create chunk queue: unable to create temp dir for state sync chunks: stat /tmp: no such file or directory" module=statesync
)
pod.Spec.Volumes = []corev1.Volume{
{
Name: volChainHome,
Expand Down Expand Up @@ -401,10 +403,12 @@ func podPatch(crd *cosmosv1.CosmosFullNode) *corev1.Pod {

// PVCName returns the primary PVC holding the chain data associated with the pod.
func PVCName(pod *corev1.Pod) string {
if vols := pod.Spec.Volumes; len(vols) > 0 {
if claim := vols[0].PersistentVolumeClaim; claim != nil {
return claim.ClaimName
}
found, ok := lo.Find(pod.Spec.Volumes, func(v corev1.Volume) bool { return v.Name == volChainHome })
if !ok {
return ""
}
if found.PersistentVolumeClaim == nil {
return ""
}
return ""
return found.PersistentVolumeClaim.ClaimName
}
5 changes: 5 additions & 0 deletions internal/fullnode/pod_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,5 +542,10 @@ func TestPVCName(t *testing.T) {
builder := NewPodBuilder(&crd)
pod, err := builder.WithOrdinal(5).Build()
require.NoError(t, err)

require.Equal(t, "pvc-osmosis-5", PVCName(pod))

pod.Spec.Volumes = append([]corev1.Volume{{Name: "foo"}}, pod.Spec.Volumes...)

require.Equal(t, "pvc-osmosis-5", PVCName(pod))
}