Skip to content

Commit

Permalink
Revert "e2e: confirm the cleanup of PVs with legacy affinity attributes"
Browse files Browse the repository at this point in the history
This reverts commit 59a15da.
  • Loading branch information
derekbit committed Oct 5, 2024
1 parent 750309a commit 0efb5e9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 86 deletions.
51 changes: 19 additions & 32 deletions test/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,38 @@ func TestPVCTestSuite(t *testing.T) {
func (p *PodTestSuite) TestPodWithHostPathVolume() {
p.kustomizeDir = "pod"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", hostPathVolumeType)
}

func (p *PodTestSuite) TestPodWithLocalVolume() {
p.kustomizeDir = "pod-with-local-volume"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), localVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", localVolumeType)
}

func (p *PodTestSuite) TestPodWithLocalVolumeDefault() {
p.kustomizeDir = "pod-with-default-local-volume"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), localVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", localVolumeType)
}

func (p *PodTestSuite) TestPodWithNodeAffinity() {
p.kustomizeDir = "pod-with-node-affinity"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", hostPathVolumeType)
}

func (p *PodTestSuite) TestPodWithRWOPVolume() {
p.kustomizeDir = "pod-with-rwop-volume"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), localVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", localVolumeType)
}

func (p *PodTestSuite) TestPodWithSecurityContext() {
p.kustomizeDir = "pod-with-security-context"
kustomizeDir := testdataFile(p.kustomizeDir)

runTest(p, []string{p.config.IMAGE}, waitCondition("podscheduled"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "podscheduled", hostPathVolumeType)

cmd := fmt.Sprintf(`kubectl get pod -l %s=%s -o=jsonpath='{.items[0].status.conditions[?(@.type=="Ready")].reason}'`, LabelKey, LabelValue)

Expand Down Expand Up @@ -142,33 +142,22 @@ loop:
func (p *PodTestSuite) TestPodWithSubpath() {
p.kustomizeDir = "pod-with-subpath"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", hostPathVolumeType)
}

func (p *PodTestSuite) xxTestPodWithMultipleStorageClasses() {
p.kustomizeDir = "multiple-storage-classes"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", hostPathVolumeType)
}

func (p *PodTestSuite) TestPodWithCustomPathPatternStorageClasses() {
p.kustomizeDir = "custom-path-pattern"

runTest(p, []string{p.config.IMAGE}, waitCondition("ready"), hostPathVolumeType)
runTest(p, []string{p.config.IMAGE}, "ready", hostPathVolumeType)
}

func (p *PodTestSuite) TestPodWithLegacyAffinityConstraint() {
// The helper pod should be correctly scheduled
p.kustomizeDir = "pv-with-legacy-affinity"

runTest(p, []string{p.config.IMAGE}, "kubectl wait pv pvc-to-clean-up --for delete --timeout=120s", "")
}

func waitCondition(waitCondition string) string {
return fmt.Sprintf("kubectl wait pod -l %s=%s --for condition=%s --timeout=120s", LabelKey, LabelValue, waitCondition)
}

func runTest(p *PodTestSuite, images []string, waitCmd, volumeType string) {
func runTest(p *PodTestSuite, images []string, waitCondition, volumeType string) {
kustomizeDir := testdataFile(p.kustomizeDir)

var cmds []string
Expand All @@ -182,7 +171,7 @@ func runTest(p *PodTestSuite, images []string, waitCmd, volumeType string) {
cmds,
fmt.Sprintf("kustomize edit add label %s:%s -f", LabelKey, LabelValue),
"kustomize build | kubectl apply -f -",
waitCmd,
fmt.Sprintf("kubectl wait pod -l %s=%s --for condition=%s --timeout=120s", LabelKey, LabelValue, waitCondition),
)

for _, cmd := range cmds {
Expand All @@ -199,15 +188,13 @@ func runTest(p *PodTestSuite, images []string, waitCmd, volumeType string) {
}
}

if volumeType != "" {
typeCheckCmd := fmt.Sprintf("kubectl get pv $(%s) -o jsonpath='{.spec.%s}'", "kubectl get pv -o jsonpath='{.items[0].metadata.name}'", volumeType)
c := createCmd(p.T(), typeCheckCmd, kustomizeDir, p.config.envs(), nil)
typeCheckOutput, err := c.CombinedOutput()
if err != nil {
p.FailNow("", "failed to check volume type: %v", err)
}
if len(typeCheckOutput) == 0 || !strings.Contains(string(typeCheckOutput), "path") {
p.FailNow("volume Type not correct")
}
typeCheckCmd := fmt.Sprintf("kubectl get pv $(%s) -o jsonpath='{.spec.%s}'", "kubectl get pv -o jsonpath='{.items[0].metadata.name}'", volumeType)
c := createCmd(p.T(), typeCheckCmd, kustomizeDir, p.config.envs(), nil)
typeCheckOutput, err := c.CombinedOutput()
if err != nil {
p.FailNow("", "failed to check volume type: %v", err)
}
if len(typeCheckOutput) == 0 || !strings.Contains(string(typeCheckOutput), "path") {
p.FailNow("volume Type not correct")
}
}
4 changes: 0 additions & 4 deletions test/testdata/kind-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ kind: Cluster
nodes:
- role: control-plane
- role: worker
labels:
kubernetes.io/hostname: kind-worker1.hostname
- role: worker
labels:
kubernetes.io/hostname: kind-worker2.hostname
2 changes: 1 addition & 1 deletion test/testdata/pod-with-node-affinity/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
- key: kubernetes.io/hostname
operator: In
values:
- kind-worker1.hostname
- kind-worker
10 changes: 0 additions & 10 deletions test/testdata/pv-with-legacy-affinity/kustomization.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions test/testdata/pv-with-legacy-affinity/pv.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func testdataFile(fields ...string) string {
func deleteKustomizeDeployment(t *testing.T, kustomizeDir string, envs []string) error {
_, err := runCmd(
t,
"kustomize build | kubectl delete --timeout=180s -f - -l 'test/avoid-cleanup!=true'",
"kustomize build | kubectl delete --timeout=180s -f -",
testdataFile(kustomizeDir),
envs,
nil,
Expand Down

0 comments on commit 0efb5e9

Please sign in to comment.