@ -26,7 +26,7 @@ var _ = BeforeSuite(func() {
}
}
} )
} )
var _ = Describe ( "local storage" , func ( ) {
var _ = Describe ( "local storage" , Ordered , func ( ) {
BeforeEach ( func ( ) {
BeforeEach ( func ( ) {
if testutil . IsExistingServer ( ) && ! testutil . ServerArgsPresent ( localStorageServerArgs ) {
if testutil . IsExistingServer ( ) && ! testutil . ServerArgsPresent ( localStorageServerArgs ) {
Skip ( "Test needs k3s server with: " + strings . Join ( localStorageServerArgs , " " ) )
Skip ( "Test needs k3s server with: " + strings . Join ( localStorageServerArgs , " " ) )
@ -39,9 +39,8 @@ var _ = Describe("local storage", func() {
} , "120s" , "5s" ) . Should ( Succeed ( ) )
} , "120s" , "5s" ) . Should ( Succeed ( ) )
} )
} )
It ( "creates a new pvc" , func ( ) {
It ( "creates a new pvc" , func ( ) {
result , err := testutil . K3sCmd ( "kubectl create -f ./testdata/localstorage_pvc.yaml" )
Expect ( testutil . K3sCmd ( "kubectl create -f ./testdata/localstorage_pvc.yaml" ) ) .
Expect ( result ) . To ( ContainSubstring ( "persistentvolumeclaim/local-path-pvc created" ) )
To ( ContainSubstring ( "persistentvolumeclaim/local-path-pvc created" ) )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
} )
} )
It ( "creates a new pod" , func ( ) {
It ( "creates a new pod" , func ( ) {
Expect ( testutil . K3sCmd ( "kubectl create -f ./testdata/localstorage_pod.yaml" ) ) .
Expect ( testutil . K3sCmd ( "kubectl create -f ./testdata/localstorage_pod.yaml" ) ) .
@ -62,7 +61,7 @@ var _ = Describe("local storage", func() {
var k3sStorage = "/var/lib/rancher/k3s/storage"
var k3sStorage = "/var/lib/rancher/k3s/storage"
fileStat , err := os . Stat ( k3sStorage )
fileStat , err := os . Stat ( k3sStorage )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
Expect ( fmt . Sprintf ( "%04o" , fileStat . Mode ( ) . Perm ( ) ) ) . To ( Equal ( "0701 " ) )
Expect ( fmt . Sprintf ( "%04o" , fileStat . Mode ( ) . Perm ( ) ) ) . To ( Equal ( "0700 " ) )
pvResult , err := testutil . K3sCmd ( "kubectl get --namespace=default pv" )
pvResult , err := testutil . K3sCmd ( "kubectl get --namespace=default pv" )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
@ -72,6 +71,20 @@ var _ = Describe("local storage", func() {
fileStat , err = os . Stat ( k3sStorage + "/" + volumeName )
fileStat , err = os . Stat ( k3sStorage + "/" + volumeName )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
Expect ( err ) . ToNot ( HaveOccurred ( ) )
Expect ( fmt . Sprintf ( "%04o" , fileStat . Mode ( ) . Perm ( ) ) ) . To ( Equal ( "0777" ) )
Expect ( fmt . Sprintf ( "%04o" , fileStat . Mode ( ) . Perm ( ) ) ) . To ( Equal ( "0777" ) )
Eventually ( func ( ) error {
_ , err = os . Stat ( k3sStorage + "/" + volumeName + "/file1" )
return err
} , "10s" , "1s" ) . Should ( Succeed ( ) )
Expect ( testutil . K3sCmd ( "kubectl --namespace=default exec volume-test -- stat -c %a /data/file1" ) ) .
To ( Equal ( "644\n" ) )
} )
It ( "allows non-root pods to write to the volume" , func ( ) {
Expect ( testutil . K3sCmd ( "kubectl --namespace=default exec volume-test -- touch /data/file2" ) ) .
To ( BeEmpty ( ) )
Expect ( testutil . K3sCmd ( "kubectl --namespace=default exec volume-test -- stat -c %a /data/file2" ) ) .
To ( Equal ( "644\n" ) )
} )
} )
It ( "deletes properly" , func ( ) {
It ( "deletes properly" , func ( ) {
Expect ( testutil . K3sCmd ( "kubectl delete --namespace=default --force pod volume-test" ) ) .
Expect ( testutil . K3sCmd ( "kubectl delete --namespace=default --force pod volume-test" ) ) .