Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bbda54b3
Unverified
Commit
bbda54b3
authored
Apr 28, 2023
by
Brooks Newberry
Committed by
GitHub
Apr 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add longhorn storage test (#6445)
Signed-off-by:
Brooks Newberry
<
brooks@newberry.com
>
parent
0247794a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
210 additions
and
2 deletions
+210
-2
integration.go
tests/integration/integration.go
+26
-2
longhorn_int_test.go
tests/integration/longhorn/longhorn_int_test.go
+154
-0
longhorn.yaml
tests/integration/longhorn/testdata/longhorn.yaml
+0
-0
pod.yaml
tests/integration/longhorn/testdata/pod.yaml
+19
-0
pvc.yaml
tests/integration/longhorn/testdata/pvc.yaml
+11
-0
No files found.
tests/integration/integration.go
View file @
bbda54b3
...
...
@@ -162,12 +162,12 @@ func CheckDeployments(deployments []string) error {
return
nil
}
func
ParsePods
(
opts
metav1
.
ListOptions
)
([]
corev1
.
Pod
,
error
)
{
func
ParsePods
(
namespace
string
,
opts
metav1
.
ListOptions
)
([]
corev1
.
Pod
,
error
)
{
clientSet
,
err
:=
k8sClient
()
if
err
!=
nil
{
return
nil
,
err
}
pods
,
err
:=
clientSet
.
CoreV1
()
.
Pods
(
""
)
.
List
(
context
.
Background
(),
opts
)
pods
,
err
:=
clientSet
.
CoreV1
()
.
Pods
(
namespace
)
.
List
(
context
.
Background
(),
opts
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -188,6 +188,30 @@ func ParseNodes() ([]corev1.Node, error) {
return
nodes
.
Items
,
nil
}
func
GetPod
(
namespace
,
name
string
)
(
*
corev1
.
Pod
,
error
)
{
client
,
err
:=
k8sClient
()
if
err
!=
nil
{
return
nil
,
err
}
return
client
.
CoreV1
()
.
Pods
(
namespace
)
.
Get
(
context
.
Background
(),
name
,
metav1
.
GetOptions
{})
}
func
GetPersistentVolumeClaim
(
namespace
,
name
string
)
(
*
corev1
.
PersistentVolumeClaim
,
error
)
{
client
,
err
:=
k8sClient
()
if
err
!=
nil
{
return
nil
,
err
}
return
client
.
CoreV1
()
.
PersistentVolumeClaims
(
namespace
)
.
Get
(
context
.
Background
(),
name
,
metav1
.
GetOptions
{})
}
func
GetPersistentVolume
(
name
string
)
(
*
corev1
.
PersistentVolume
,
error
)
{
client
,
err
:=
k8sClient
()
if
err
!=
nil
{
return
nil
,
err
}
return
client
.
CoreV1
()
.
PersistentVolumes
()
.
Get
(
context
.
Background
(),
name
,
metav1
.
GetOptions
{})
}
func
FindStringInCmdAsync
(
scanner
*
bufio
.
Scanner
,
target
string
)
bool
{
for
scanner
.
Scan
()
{
if
strings
.
Contains
(
scanner
.
Text
(),
target
)
{
...
...
tests/integration/longhorn/longhorn_int_test.go
0 → 100644
View file @
bbda54b3
package
longhorn
import
(
"fmt"
"os/exec"
"strings"
"testing"
testutil
"github.com/k3s-io/k3s/tests/integration"
.
"github.com/onsi/ginkgo/v2"
.
"github.com/onsi/gomega"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
var
server
*
testutil
.
K3sServer
var
serverArgs
=
[]
string
{
"--cluster-init"
}
var
testLock
int
var
_
=
BeforeSuite
(
func
()
{
if
_
,
err
:=
exec
.
LookPath
(
"iscsiadm"
);
err
!=
nil
{
Skip
(
"Test needs open-iscsi to be installed"
)
}
else
if
!
testutil
.
IsExistingServer
()
{
var
err
error
testLock
,
err
=
testutil
.
K3sTestLock
()
Expect
(
err
)
.
ToNot
(
HaveOccurred
())
server
,
err
=
testutil
.
K3sStartServer
(
serverArgs
...
)
Expect
(
err
)
.
ToNot
(
HaveOccurred
())
}
})
var
_
=
Describe
(
"longhorn"
,
Ordered
,
func
()
{
BeforeEach
(
func
()
{
if
testutil
.
IsExistingServer
()
&&
!
testutil
.
ServerArgsPresent
(
serverArgs
)
{
Skip
(
"Test needs k3s server with: "
+
strings
.
Join
(
serverArgs
,
" "
))
}
})
When
(
"a new cluster is created"
,
func
()
{
It
(
"starts up with no problems"
,
func
()
{
Eventually
(
func
()
error
{
return
testutil
.
K3sDefaultDeployments
()
},
"120s"
,
"5s"
)
.
Should
(
Succeed
())
})
})
When
(
"longhorn is installed"
,
func
()
{
It
(
"installs components into the longhorn-system namespace"
,
func
()
{
result
,
err
:=
testutil
.
K3sCmd
(
"kubectl apply -f ./testdata/longhorn.yaml"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
result
)
.
To
(
ContainSubstring
(
"namespace/longhorn-system created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"daemonset.apps/longhorn-manager created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"deployment.apps/longhorn-driver-deployer created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"deployment.apps/longhorn-recovery-backend created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"deployment.apps/longhorn-ui created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"deployment.apps/longhorn-conversion-webhook created"
))
Expect
(
result
)
.
To
(
ContainSubstring
(
"deployment.apps/longhorn-admission-webhook created"
))
})
It
(
"starts the longhorn pods with no problems"
,
func
()
{
Eventually
(
func
()
error
{
pods
,
err
:=
testutil
.
ParsePods
(
"longhorn-system"
,
metav1
.
ListOptions
{})
if
err
!=
nil
{
return
err
}
for
_
,
pod
:=
range
pods
{
if
pod
.
Status
.
Phase
!=
"Running"
&&
pod
.
Status
.
Phase
!=
"Succeeded"
{
return
fmt
.
Errorf
(
"pod %s failing"
,
pod
.
Name
)
}
}
return
nil
},
"120s"
,
"5s"
)
.
Should
(
Succeed
())
})
})
When
(
"persistent volume claim is created"
,
func
()
{
It
(
"creates the pv and pvc"
,
func
()
{
result
,
err
:=
testutil
.
K3sCmd
(
"kubectl create -f ./testdata/pvc.yaml"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
result
)
.
To
(
ContainSubstring
(
"persistentvolumeclaim/longhorn-volv-pvc created"
))
Eventually
(
func
()
error
{
pvc
,
err
:=
testutil
.
GetPersistentVolumeClaim
(
"default"
,
"longhorn-volv-pvc"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get pvc longhorn-volv-pvc"
)
}
if
pvc
.
Status
.
Phase
!=
"Bound"
{
return
fmt
.
Errorf
(
"pvc longhorn-volv-pvc not bound"
)
}
pv
,
err
:=
testutil
.
GetPersistentVolume
(
pvc
.
Spec
.
VolumeName
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get pv %s"
,
pvc
.
Spec
.
VolumeName
)
}
if
pv
.
Status
.
Phase
!=
"Bound"
{
return
fmt
.
Errorf
(
"pv %s not bound"
,
pv
.
Name
)
}
return
nil
},
"300s"
,
"5s"
)
.
Should
(
Succeed
())
})
It
(
"creates a pod with the pvc"
,
func
()
{
result
,
err
:=
testutil
.
K3sCmd
(
"kubectl create -f ./testdata/pod.yaml"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
result
)
.
To
(
ContainSubstring
(
"pod/volume-test created"
))
Eventually
(
func
()
error
{
pod
,
err
:=
testutil
.
GetPod
(
"default"
,
"volume-test"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get pod volume-test"
)
}
if
pod
.
Status
.
Phase
!=
"Running"
{
return
fmt
.
Errorf
(
"pod volume-test
\"
%s
\"
reason:
\"
%s
\"
message
\"
%s
\"
"
,
pod
.
Status
.
Phase
,
pod
.
Status
.
Reason
,
pod
.
Status
.
Message
)
}
return
nil
},
"60s"
,
"5s"
)
.
Should
(
Succeed
())
})
})
When
(
"the pvc is deleted"
,
func
()
{
It
(
"the pv is deleted according to the default reclaim policy"
,
func
()
{
result
,
err
:=
testutil
.
K3sCmd
(
"kubectl delete pod volume-test"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
result
)
.
To
(
ContainSubstring
(
"pod
\"
volume-test
\"
deleted"
))
result
,
err
=
testutil
.
K3sCmd
(
"kubectl delete pvc longhorn-volv-pvc"
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
result
)
.
To
(
ContainSubstring
(
"persistentvolumeclaim
\"
longhorn-volv-pvc
\"
deleted"
))
Eventually
(
func
()
error
{
result
,
err
=
testutil
.
K3sCmd
(
"kubectl get pv"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed get persistent volumes"
)
}
if
!
strings
.
Contains
(
result
,
"No resources found"
)
{
return
fmt
.
Errorf
(
"persistent volumes still exist"
)
}
return
nil
},
"60s"
,
"5s"
)
.
Should
(
Succeed
())
})
})
})
var
failed
bool
var
_
=
AfterEach
(
func
()
{
failed
=
failed
||
CurrentSpecReport
()
.
Failed
()
})
var
_
=
AfterSuite
(
func
()
{
if
!
testutil
.
IsExistingServer
()
{
if
failed
{
testutil
.
K3sSaveLog
(
server
,
false
)
}
Expect
(
testutil
.
K3sKillServer
(
server
))
.
To
(
Succeed
())
Expect
(
testutil
.
K3sCleanup
(
testLock
,
""
))
.
To
(
Succeed
())
}
})
func
Test_IntegrationLonghorn
(
t
*
testing
.
T
)
{
RegisterFailHandler
(
Fail
)
RunSpecs
(
t
,
"Longhorn Suite"
)
}
tests/integration/longhorn/testdata/longhorn.yaml
0 → 100644
View file @
bbda54b3
This source diff could not be displayed because it is too large. You can
view the blob
instead.
tests/integration/longhorn/testdata/pod.yaml
0 → 100644
View file @
bbda54b3
apiVersion
:
v1
kind
:
Pod
metadata
:
name
:
volume-test
namespace
:
default
spec
:
containers
:
-
name
:
volume-test
image
:
nginx:stable-alpine
imagePullPolicy
:
IfNotPresent
volumeMounts
:
-
name
:
volv
mountPath
:
/data
ports
:
-
containerPort
:
80
volumes
:
-
name
:
volv
persistentVolumeClaim
:
claimName
:
longhorn-volv-pvc
tests/integration/longhorn/testdata/pvc.yaml
0 → 100644
View file @
bbda54b3
apiVersion
:
v1
kind
:
PersistentVolumeClaim
metadata
:
name
:
longhorn-volv-pvc
spec
:
accessModes
:
-
ReadWriteOnce
storageClassName
:
longhorn
resources
:
requests
:
storage
:
1Gi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment