Skip to content

Commit 3d7f6e0

Browse files
authored
Merge pull request #15 from aniszosc/OSC-MIGRATION
Add e2e test for fsgroup
2 parents 1c70647 + 5e643b2 commit 3d7f6e0

File tree

6 files changed

+166
-4
lines changed

6 files changed

+166
-4
lines changed

CHANGELOG-0.x.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
# v0.0.10beta
2323
## Notable changes
2424
* Add fsGroupPolicy field to CSIDriver object and customize it with chart values
25+
26+
# v0.0.11beta
27+
## Notable changes
28+
* Add fsGroupPolicy specific e2e test

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20200520003142-237cc4f519e2/go.m
688688
github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs=
689689
github.com/opencontainers/selinux v1.5.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
690690
github.com/opencontainers/selinux v1.5.2/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
691+
github.com/outscale/osc-sdk-go/osc v0.0.0-20210317154930-f27e09c295b2 h1:gmvYTtBR5+erBu7PrPywmQhTSBN0b+PULYCB4rGjJUE=
692+
github.com/outscale/osc-sdk-go/osc v0.0.0-20210317154930-f27e09c295b2/go.mod h1:5AqqNH1X8zCHescKVlpSHRzrat1KCKDXqZoQPe8fY3A=
691693
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
692694
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
693695
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=

tests/e2e/dynamic_provisioning.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package e2e
1616

1717
import (
1818
"fmt"
19+
"log"
1920
"math/rand"
2021
"os"
2122
"strings"
@@ -426,6 +427,67 @@ var _ = Describe("[ebs-csi-e2e] [single-az] Dynamic Provisioning", func() {
426427
}
427428
test.Run(cs, ns)
428429
})
430+
431+
It("FSGROUP test should create a volume and check if pod security context is applied", func() {
432+
fsGroup := int64(5000)
433+
runAsGroup := int64(4000)
434+
runAsUser := int64(2000)
435+
podSecurityContext := v1.PodSecurityContext{
436+
RunAsUser: &runAsUser,
437+
RunAsGroup: &runAsGroup,
438+
FSGroup: &fsGroup,
439+
}
440+
podSc, err := podSecurityContext.Marshal()
441+
if err != nil {
442+
Fail(fmt.Sprintf("error encoding: %v, %v", podSecurityContext, err))
443+
}
444+
allowPrivilegeEscalation := false
445+
securityContext := v1.SecurityContext{
446+
AllowPrivilegeEscalation: &allowPrivilegeEscalation,
447+
}
448+
sc, err := securityContext.Marshal()
449+
if err != nil {
450+
Fail(fmt.Sprintf("error encoding: %v, %v", securityContext, err))
451+
}
452+
453+
pod := testsuites.PodDetails{
454+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data && while true; do echo running ; sleep 1; done",
455+
Volumes: []testsuites.VolumeDetails{
456+
{
457+
VolumeType: osccloud.VolumeTypeGP2,
458+
FSType: bsucsidriver.FSTypeExt4,
459+
ClaimSize: driver.MinimumSizeForVolumeType(osccloud.VolumeTypeGP2),
460+
VolumeMount: testsuites.VolumeMountDetails{
461+
NameGenerate: "test-volume-",
462+
MountPathGenerate: "/mnt/test-",
463+
},
464+
},
465+
},
466+
CustomizedPod: []string{
467+
string(podSc),
468+
string(sc),
469+
},
470+
}
471+
podCmds := []testsuites.PodCmds{
472+
{
473+
Cmd: []string{
474+
"stat",
475+
"-c",
476+
"%g",
477+
"/mnt/test-1",
478+
},
479+
ExpectedString: fmt.Sprintf("%d", fsGroup),
480+
},
481+
}
482+
test := testsuites.DynamicallyProvisionedCustomPodTest{
483+
CSIDriver: ebsDriver,
484+
Pod: pod,
485+
PodCmds: podCmds,
486+
}
487+
log.Printf("test: %+v\n", test)
488+
489+
test.Run(cs, ns, f)
490+
})
429491
})
430492

431493
var _ = Describe("[ebs-csi-e2e] [single-az] Snapshot", func() {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package testsuites
16+
17+
import (
18+
"fmt"
19+
"regexp"
20+
21+
. "github.com/onsi/ginkgo"
22+
v1 "k8s.io/api/core/v1"
23+
clientset "k8s.io/client-go/kubernetes"
24+
"k8s.io/kubernetes/test/e2e/framework"
25+
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
26+
27+
"github.com/outscale-dev/osc-bsu-csi-driver/tests/e2e/driver"
28+
)
29+
30+
type DynamicallyProvisionedCustomPodTest struct {
31+
CSIDriver driver.DynamicPVTestDriver
32+
Pod PodDetails
33+
PodCmds []PodCmds
34+
}
35+
36+
type PodCmds struct {
37+
Cmd []string
38+
ExpectedString string
39+
}
40+
41+
func customizePod(customizePod []string, deployment *TestDeployment) *TestDeployment {
42+
podSc := v1.PodSecurityContext{}
43+
sc := v1.SecurityContext{}
44+
for _, custom := range customizePod {
45+
fmt.Printf("custom: %+v\n", custom)
46+
err := podSc.Unmarshal([]byte(custom))
47+
if err == nil {
48+
fmt.Printf("add PodSecurityContext\n")
49+
deployment.deployment.Spec.Template.Spec.SecurityContext = &podSc
50+
} else {
51+
err := sc.Unmarshal([]byte(custom))
52+
if err == nil {
53+
fmt.Printf("add SecurityContext\n")
54+
deployment.deployment.Spec.Template.Spec.Containers[0].SecurityContext = &sc
55+
} else {
56+
fmt.Printf("ignore custom: %+v\n", custom)
57+
}
58+
}
59+
}
60+
return deployment
61+
}
62+
63+
func (t *DynamicallyProvisionedCustomPodTest) Run(client clientset.Interface, namespace *v1.Namespace, f *framework.Framework) {
64+
customImage := "busybox"
65+
tDeployment, cleanup := t.Pod.SetupDeployment(client, namespace, t.CSIDriver, customImage)
66+
// defer must be called here for resources not get removed before using them
67+
for i := range cleanup {
68+
defer cleanup[i]()
69+
}
70+
71+
By("customize Pod Deployment")
72+
fmt.Printf("Before tDeployment: %+v\n", tDeployment)
73+
customizePod(t.Pod.CustomizedPod, tDeployment)
74+
fmt.Printf("After tDeployment: %+v\n", tDeployment)
75+
76+
By("deploying the deployment")
77+
tDeployment.Create()
78+
79+
By("checking that the pod is running")
80+
tDeployment.WaitForPodReady()
81+
82+
pods, err := e2edeployment.GetPodsForDeployment(client, tDeployment.deployment)
83+
framework.ExpectNoError(err)
84+
singleSpacePattern := regexp.MustCompile(`\s+`)
85+
for _, podCmd := range t.PodCmds {
86+
By(fmt.Sprintf("Extended pod and volumes checks: %v", podCmd.Cmd))
87+
stdout, stderr, err := f.ExecCommandInContainerWithFullOutput(tDeployment.podName, pods.Items[0].Spec.Containers[0].Name, podCmd.Cmd...)
88+
fmt.Printf("stdout %v, stderr %v, err %v\n", stdout, stderr, err)
89+
if err != nil {
90+
panic(err.Error())
91+
}
92+
framework.ExpectEqual(singleSpacePattern.ReplaceAllString(stdout, " "), podCmd.ExpectedString)
93+
}
94+
}

tests/e2e/testsuites/dynamically_provisioned_resize_volume_tester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (t *DynamicallyProvisionedResizeVolumeTest) Run(client clientset.Interface,
4646
defer tpvc.Cleanup()
4747

4848
pvcName := tpvc.persistentVolumeClaim.Name
49-
pvc, err := client.CoreV1().PersistentVolumeClaims(namespace.Name).Get(context.TODO(), pvcName, metav1.GetOptions{})
49+
pvc, _ := client.CoreV1().PersistentVolumeClaims(namespace.Name).Get(context.TODO(), pvcName, metav1.GetOptions{})
5050
By(fmt.Sprintf("Get pvc name: %v", pvc.Name))
5151
originalSize := pvc.Spec.Resources.Requests["storage"]
5252
delta := resource.Quantity{}

tests/e2e/testsuites/specs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ import (
2828
)
2929

3030
type PodDetails struct {
31-
Cmd string
32-
Volumes []VolumeDetails
31+
Cmd string
32+
Volumes []VolumeDetails
33+
CustomizedPod []string
3334
}
3435

3536
type VolumeDetails struct {
@@ -131,7 +132,6 @@ func (pod *PodDetails) SetupDeployment(client clientset.Interface, namespace *v1
131132
cleanupFuncs = append(cleanupFuncs, tpvc.Cleanup)
132133
By("setting up the Deployment")
133134
tDeployment := NewTestDeployment(client, namespace, pod.Cmd, tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", volume.VolumeMount.NameGenerate, 1), fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, 1), volume.VolumeMount.ReadOnly, customImage...)
134-
135135
cleanupFuncs = append(cleanupFuncs, tDeployment.Cleanup)
136136
return tDeployment, cleanupFuncs
137137
}

0 commit comments

Comments
 (0)