Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergicastro committed Nov 12, 2024
1 parent 63e87cb commit ebc0ac9
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 32 deletions.
58 changes: 55 additions & 3 deletions controllers/spec/enforcer/statefulset_spec/VolumeSpecEnforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ limitations under the License.
package statefulset_spec

import (
"reflect"

apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"reactive-tech.io/kubegres/controllers/ctx"
"reflect"
)

type VolumeSpecEnforcer struct {
Expand Down Expand Up @@ -52,9 +53,18 @@ func (r *VolumeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.StatefulSe
}
}

currentCustomVolumeMountsInit, hasInitContainer := r.getVolumeMountsFromInitContainer(statefulSet)
currentCustomVolumeMounts := r.getCurrentCustomVolumeMounts(statefulSet)
expectedCustomVolumeMounts := r.kubegresContext.Kubegres.Spec.Volume.VolumeMounts

if hasInitContainer && !r.compareVolumeMounts(currentCustomVolumeMountsInit, expectedCustomVolumeMounts) {
return StatefulSetSpecDifference{
SpecName: "Volume.VolumeMounts",
Current: r.volumeMountsToString(currentCustomVolumeMountsInit),
Expected: r.volumeMountsToString(expectedCustomVolumeMounts),
}
}

if !r.compareVolumeMounts(currentCustomVolumeMounts, expectedCustomVolumeMounts) {
return StatefulSetSpecDifference{
SpecName: "Volume.VolumeMounts",
Expand All @@ -70,6 +80,7 @@ func (r *VolumeSpecEnforcer) EnforceSpec(statefulSet *apps.StatefulSet) (wasSpec

r.removeCustomVolumes(statefulSet)
r.removeCustomVolumeMounts(statefulSet)
r.removeCustomVolumeMountsFromInitContainer(statefulSet)

if r.kubegresContext.Kubegres.Spec.Volume.Volumes != nil {
statefulSet.Spec.Template.Spec.Volumes = append(statefulSet.Spec.Template.Spec.Volumes, r.kubegresContext.Kubegres.Spec.Volume.Volumes...)
Expand All @@ -79,10 +90,14 @@ func (r *VolumeSpecEnforcer) EnforceSpec(statefulSet *apps.StatefulSet) (wasSpec
statefulSet.Spec.Template.Spec.Containers[0].VolumeMounts = append(statefulSet.Spec.Template.Spec.Containers[0].VolumeMounts, r.kubegresContext.Kubegres.Spec.Volume.VolumeMounts...)
}

if len(statefulSet.Spec.Template.Spec.InitContainers) > 0 && statefulSet.Spec.Template.Spec.InitContainers[0].VolumeMounts != nil {
statefulSet.Spec.Template.Spec.InitContainers[0].VolumeMounts = append(statefulSet.Spec.Template.Spec.InitContainers[0].VolumeMounts, r.kubegresContext.Kubegres.Spec.Volume.VolumeMounts...)
}

return true, nil
}

func (r *VolumeSpecEnforcer) OnSpecEnforcedSuccessfully(statefulSet *apps.StatefulSet) error {
func (r *VolumeSpecEnforcer) OnSpecEnforcedSuccessfully(*apps.StatefulSet) error {
return nil
}

Expand All @@ -109,7 +124,7 @@ func (r *VolumeSpecEnforcer) doesExpectedVolumeExist(expectedCustomVolume v1.Vol
return false
}

func (r *VolumeSpecEnforcer) compareVolumeMounts(currentCustomVolumeMounts []v1.VolumeMount, expectedCustomVolumeMounts []v1.VolumeMount) bool {
func (r *VolumeSpecEnforcer) compareVolumeMounts(currentCustomVolumeMounts, expectedCustomVolumeMounts []v1.VolumeMount) bool {

if len(expectedCustomVolumeMounts) != len(currentCustomVolumeMounts) {
return false
Expand Down Expand Up @@ -158,6 +173,23 @@ func (r *VolumeSpecEnforcer) getCurrentCustomVolumeMounts(statefulSet *apps.Stat
return customVolumeMounts
}

func (r *VolumeSpecEnforcer) getVolumeMountsFromInitContainer(statefulSet *apps.StatefulSet) ([]v1.VolumeMount, bool) {

if len(statefulSet.Spec.Template.Spec.InitContainers) == 0 {
return nil, false
}

initContainer := &statefulSet.Spec.Template.Spec.InitContainers[0]
var customVolumeMounts []v1.VolumeMount

for _, volumeMount := range initContainer.VolumeMounts {
if !r.kubegresContext.IsReservedVolumeName(volumeMount.Name) {
customVolumeMounts = append(customVolumeMounts, volumeMount)
}
}
return customVolumeMounts, true
}

func (r *VolumeSpecEnforcer) removeCustomVolumes(statefulSet *apps.StatefulSet) {

currentCustomVolumes := r.getCurrentCustomVolumes(statefulSet)
Expand Down Expand Up @@ -209,6 +241,26 @@ func (r *VolumeSpecEnforcer) removeCustomVolumeMounts(statefulSet *apps.Stateful
}
}

func (r *VolumeSpecEnforcer) removeCustomVolumeMountsFromInitContainer(statefulSet *apps.StatefulSet) {

currentCustomVolumeMounts, hasInit := r.getVolumeMountsFromInitContainer(statefulSet)
if !hasInit || len(currentCustomVolumeMounts) == 0 {
return
}

currentCustomVolumeMountsCopy := make([]v1.VolumeMount, len(currentCustomVolumeMounts))
copy(currentCustomVolumeMountsCopy, currentCustomVolumeMounts)

initContainer := &statefulSet.Spec.Template.Spec.InitContainers[0]

for _, customVolumeMount := range currentCustomVolumeMountsCopy {
index := r.getIndexOfVolumeMount(customVolumeMount, initContainer.VolumeMounts)
if index >= 0 {
initContainer.VolumeMounts = append(initContainer.VolumeMounts[:index], initContainer.VolumeMounts[index+1:]...)
}
}
}

func (r *VolumeSpecEnforcer) getIndexOfVolumeMount(volumeMountToSearch v1.VolumeMount, volumeMounts []v1.VolumeMount) int {
index := 0
for _, volumeMount := range volumeMounts {
Expand Down
119 changes: 92 additions & 27 deletions test/spec_customConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsShouldNotContainsCustomConfig()

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

test.thenDeployedKubegresSpecShouldBeSetTo(ctx.BaseConfigMapName)

Expand Down Expand Up @@ -117,11 +123,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapEmptyResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

log.Print("END OF: Test 'GIVEN new Kubegres is created with spec 'customConfig' set to a ConfigMap which is empty'")
})
Expand All @@ -141,11 +153,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapWithPostgresConfResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

log.Print("END OF: Test 'GIVEN new Kubegres is created with spec 'customConfig' set to a ConfigMap containing 'postgres.conf'")
})
Expand All @@ -165,11 +183,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapWithPrimaryInitScriptResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

log.Print("END OF: Test 'GIVEN new Kubegres is created with spec 'customConfig' set to a ConfigMap containing 'primary_init_script.sh''")
})
Expand All @@ -189,11 +213,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapWithPgHbaConfResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

log.Print("END OF: Test 'GIVEN new Kubegres is created with spec 'customConfig' set to a ConfigMap containing 'pg_hba.conf''")
})
Expand All @@ -220,11 +250,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapWithPostgresConfResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.CustomConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

test.dbQueryTestCases.ThenWeCanSqlQueryPrimaryDb()
test.dbQueryTestCases.ThenWeCanSqlQueryReplicaDb()
Expand All @@ -249,19 +285,25 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenPodsContainsCustomConfigWithResourceName(resourceConfigs.CustomConfigMapWithBackupDatabaseScriptResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

log.Print("END OF: Test 'GIVEN new Kubegres is created with backUp enabled and spec 'customConfig' set to a ConfigMap containing 'backup_database.sh''")
})
})

Context("GIVEN new Kubegres is created with backUp enabled and spec 'customConfig' set to base-config AND later it is updated to a configMap containing data-key 'backup_database.sh'", func() {

It("THEN the custom-config should be used for 'postgres.conf' AND the base-config should be used for 'postgres.conf', 'pg_hba.conf' and 'primary_init_script.sh'", func() {
It("THEN the custom-config should be used for 'backup_database.conf' AND the base-config should be used for 'postgres.conf', 'pg_hba.conf' and 'primary_init_script.sh'", func() {

log.Print("START OF: Test 'GIVEN new Kubegres is created with backUp enabled and spec 'customConfig' set to base-config AND later it is updated to a configMap containing data-key 'backup_database.sh''")

Expand All @@ -284,11 +326,17 @@ var _ = Describe("Setting Kubegres specs 'customConfig'", Label("group:2"), func

test.thenCronJobContainsConfigMap(resourceConfigs.CustomConfigMapWithBackupDatabaseScriptResourceName)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, primary)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryInitScript, true)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, primary)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPgHbaConf, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPostgresConf, false)
test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyCopyPrimaryDataToReplica, replica)

test.thenPodsContainsConfigTypeAssociatedToFile(ctx.BaseConfigMapVolumeName, states.ConfigMapDataKeyPrimaryCreateReplicaRole, primary)

test.dbQueryTestCases.ThenWeCanSqlQueryPrimaryDb()
test.dbQueryTestCases.ThenWeCanSqlQueryReplicaDb()
Expand Down Expand Up @@ -439,7 +487,14 @@ func (r *SpecCustomConfigTest) hasCustomConfigWithResourceName(statefulSetSpec v
return false
}

func (r *SpecCustomConfigTest) thenPodsContainsConfigTypeAssociatedToFile(expectedVolumeNameForConfigType, expectedConfigFile string, isOnlyPrimaryStatefulSet bool) bool {
type statefulSetType int

const (
primary statefulSetType = iota
replica
)

func (r *SpecCustomConfigTest) thenPodsContainsConfigTypeAssociatedToFile(expectedVolumeNameForConfigType, expectedConfigFile string, statefulSetType statefulSetType) bool {
return Eventually(func() bool {

kubegresResources, err := r.resourceRetriever.GetKubegresResources()
Expand All @@ -450,7 +505,10 @@ func (r *SpecCustomConfigTest) thenPodsContainsConfigTypeAssociatedToFile(expect

for _, resource := range kubegresResources.Resources {

if isOnlyPrimaryStatefulSet && !resource.IsPrimary {
switch {
case statefulSetType == primary && !resource.IsPrimary:
continue
case statefulSetType == replica && resource.IsPrimary:
continue
}

Expand Down Expand Up @@ -499,6 +557,13 @@ func (r *SpecCustomConfigTest) hasConfigTypeAssociatedToFile(statefulSetSpec v1.
return true
}
}
if len(statefulSetSpec.Template.Spec.InitContainers) > 0 {
for _, volumeMount := range statefulSetSpec.Template.Spec.InitContainers[0].VolumeMounts {
if volumeMount.Name == expectedVolumeNameForConfigType && volumeMount.SubPath == expectedConfigFile {
return true
}
}
}
return false
}

Expand Down
Loading

0 comments on commit ebc0ac9

Please sign in to comment.