Skip to content

Commit 9fadd74

Browse files
authored
make GetProcessSettings not return volumeClaimTemplate for stateless … (#1965)
* make GetProcessSettings not return volumeClaimTemplate for stateless processes --------- Co-authored-by: Nicole Morales <[email protected]>
1 parent 5b3720b commit 9fadd74

File tree

4 files changed

+23
-84
lines changed

4 files changed

+23
-84
lines changed

api/v1beta2/foundationdbcluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ type ProcessSettings struct {
12661266
PodTemplate *corev1.PodTemplateSpec `json:"podTemplate,omitempty"`
12671267

12681268
// VolumeClaimTemplate allows customizing the persistent volume claim for the
1269-
// pod.
1269+
// pod. This will be ignored by the operator for stateless processes.
12701270
VolumeClaimTemplate *corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
12711271

12721272
// CustomParameters defines additional parameters to pass to the fdbserver
@@ -1289,7 +1289,7 @@ func (cluster *FoundationDBCluster) GetProcessSettings(processClass ProcessClass
12891289
if merged.PodTemplate == nil {
12901290
merged.PodTemplate = entry.PodTemplate
12911291
}
1292-
if merged.VolumeClaimTemplate == nil {
1292+
if merged.VolumeClaimTemplate == nil && processClass.IsStateful() { // stateless pods will not use a PVC
12931293
merged.VolumeClaimTemplate = entry.VolumeClaimTemplate
12941294
}
12951295
if merged.CustomParameters == nil {

docs/cluster_spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ ProcessSettings defines process-level settings.
437437
| Field | Description | Scheme | Required |
438438
| ----- | ----------- | ------ | -------- |
439439
| podTemplate | PodTemplate allows customizing the pod. If a container image with a tag is specified the operator will throw an error and stop processing the cluster. | *[corev1.PodTemplateSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#podtemplatespec-v1-core) | false |
440-
| volumeClaimTemplate | VolumeClaimTemplate allows customizing the persistent volume claim for the pod. | *[corev1.PersistentVolumeClaim](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#persistentvolumeclaim-v1-core) | false |
440+
| volumeClaimTemplate | VolumeClaimTemplate allows customizing the persistent volume claim for the pod. This will be ignored by the operator for stateless processes. | *[corev1.PersistentVolumeClaim](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#persistentvolumeclaim-v1-core) | false |
441441
| customParameters | CustomParameters defines additional parameters to pass to the fdbserver process. | FoundationDBCustomParameters | false |
442442

443443
[Back to TOC](#table-of-contents)

internal/pod_models.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func configureVolumesForContainers(cluster *fdbv1beta2.FoundationDBCluster, podS
320320
}
321321

322322
var mainVolumeSource corev1.VolumeSource
323-
if usePvc(cluster, processClass) {
323+
if processClass.IsStateful() {
324324
var volumeClaimSourceName string
325325
if volumeClaimTemplate != nil && volumeClaimTemplate.Name != "" {
326326
volumeClaimSourceName = fmt.Sprintf("%s-%s", podName, volumeClaimTemplate.Name)
@@ -721,24 +721,9 @@ func getEnvForMonitorConfigSubstitution(cluster *fdbv1beta2.FoundationDBCluster,
721721
return env
722722
}
723723

724-
// usePvc determines whether we should attach a PVC to a pod.
725-
func usePvc(cluster *fdbv1beta2.FoundationDBCluster, processClass fdbv1beta2.ProcessClass) bool {
726-
var storage *resource.Quantity
727-
processSettings := cluster.GetProcessSettings(processClass)
728-
729-
if processSettings.VolumeClaimTemplate != nil {
730-
requests := processSettings.VolumeClaimTemplate.Spec.Resources.Requests
731-
if requests != nil {
732-
storageCopy := requests[corev1.ResourceStorage]
733-
storage = &storageCopy
734-
}
735-
}
736-
return processClass.IsStateful() && (storage == nil || !storage.IsZero())
737-
}
738-
739724
// GetPvc builds a persistent volume claim for a FoundationDB process group.
740725
func GetPvc(cluster *fdbv1beta2.FoundationDBCluster, processGroup *fdbv1beta2.ProcessGroupStatus) (*corev1.PersistentVolumeClaim, error) {
741-
if !usePvc(cluster, processGroup.ProcessClass) {
726+
if !processGroup.ProcessClass.IsStateful() {
742727
return nil, nil
743728
}
744729

internal/pod_models_test.go

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,32 +1698,6 @@ var _ = Describe("pod_models", func() {
16981698
})
16991699
})
17001700

1701-
Context("with no volume", func() {
1702-
BeforeEach(func() {
1703-
cluster.Spec.Processes = map[fdbv1beta2.ProcessClass]fdbv1beta2.ProcessSettings{fdbv1beta2.ProcessClassGeneral: {VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
1704-
Spec: corev1.PersistentVolumeClaimSpec{
1705-
Resources: corev1.ResourceRequirements{
1706-
Requests: corev1.ResourceList{
1707-
corev1.ResourceStorage: resource.MustParse("0"),
1708-
},
1709-
},
1710-
},
1711-
}}}
1712-
err := NormalizeClusterSpec(cluster, DeprecationOptions{})
1713-
Expect(err).NotTo(HaveOccurred())
1714-
1715-
spec, err = GetPodSpec(cluster, GetProcessGroup(cluster, fdbv1beta2.ProcessClassStorage, 1))
1716-
Expect(err).NotTo(HaveOccurred())
1717-
})
1718-
1719-
It("should use an EmptyDir volume", func() {
1720-
Expect(spec.Volumes[0]).To(Equal(corev1.Volume{
1721-
Name: "data",
1722-
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
1723-
}))
1724-
})
1725-
})
1726-
17271701
Context("with a host-based fault domain", func() {
17281702
BeforeEach(func() {
17291703
cluster.Spec.FaultDomain = fdbv1beta2.FoundationDBClusterFaultDomain{}
@@ -2779,44 +2753,6 @@ var _ = Describe("pod_models", func() {
27792753
})
27802754
})
27812755

2782-
Context("with a volume size of 0", func() {
2783-
BeforeEach(func() {
2784-
cluster.Spec.Processes = map[fdbv1beta2.ProcessClass]fdbv1beta2.ProcessSettings{fdbv1beta2.ProcessClassGeneral: {VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
2785-
Spec: corev1.PersistentVolumeClaimSpec{
2786-
Resources: corev1.ResourceRequirements{
2787-
Requests: corev1.ResourceList{
2788-
corev1.ResourceStorage: resource.MustParse("0"),
2789-
},
2790-
},
2791-
},
2792-
}}}
2793-
pvc, err = GetPvc(cluster, GetProcessGroup(cluster, fdbv1beta2.ProcessClassStorage, 1))
2794-
Expect(err).NotTo(HaveOccurred())
2795-
})
2796-
2797-
It("should return a nil PVC", func() {
2798-
Expect(pvc).To(BeNil())
2799-
})
2800-
})
2801-
2802-
Context("with a custom storage class", func() {
2803-
var class string
2804-
BeforeEach(func() {
2805-
class = "local"
2806-
cluster.Spec.Processes = map[fdbv1beta2.ProcessClass]fdbv1beta2.ProcessSettings{fdbv1beta2.ProcessClassGeneral: {VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
2807-
Spec: corev1.PersistentVolumeClaimSpec{
2808-
StorageClassName: &class,
2809-
},
2810-
}}}
2811-
pvc, err = GetPvc(cluster, GetProcessGroup(cluster, fdbv1beta2.ProcessClassStorage, 1))
2812-
Expect(err).NotTo(HaveOccurred())
2813-
})
2814-
2815-
It("should set the storage class on the PVC", func() {
2816-
Expect(pvc.Spec.StorageClassName).To(Equal(&class))
2817-
})
2818-
})
2819-
28202756
Context("for a stateless process group", func() {
28212757
BeforeEach(func() {
28222758
pvc, err = GetPvc(cluster, GetProcessGroup(cluster, fdbv1beta2.ProcessClassStateless, 1))
@@ -2845,6 +2781,24 @@ var _ = Describe("pod_models", func() {
28452781
})
28462782
})
28472783

2784+
Context("with a custom storage class", func() {
2785+
var class string
2786+
BeforeEach(func() {
2787+
class = "local"
2788+
cluster.Spec.Processes = map[fdbv1beta2.ProcessClass]fdbv1beta2.ProcessSettings{fdbv1beta2.ProcessClassGeneral: {VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
2789+
Spec: corev1.PersistentVolumeClaimSpec{
2790+
StorageClassName: &class,
2791+
},
2792+
}}}
2793+
pvc, err = GetPvc(cluster, GetProcessGroup(cluster, fdbv1beta2.ProcessClassStorage, 1))
2794+
Expect(err).NotTo(HaveOccurred())
2795+
})
2796+
2797+
It("should set the storage class on the PVC", func() {
2798+
Expect(pvc.Spec.StorageClassName).To(Equal(&class))
2799+
})
2800+
})
2801+
28482802
Context("with an process group ID prefix", func() {
28492803
BeforeEach(func() {
28502804
cluster.Spec.ProcessGroupIDPrefix = "dc1"

0 commit comments

Comments
 (0)