Skip to content

Commit

Permalink
add pvc e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Feb 1, 2022
1 parent 5ce87a4 commit 72577a3
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/config/pvc/pvc.yaml
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: knative-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
2 changes: 2 additions & 0 deletions test/e2e-common.sh
Expand Up @@ -55,6 +55,8 @@ export SYSTEM_NAMESPACE="${SYSTEM_NAMESPACE:-$(uuidgen | tr 'A-Z' 'a-z')}"
readonly REPLICAS=3
readonly BUCKETS=10

export USE_DEFAULT_STORAGE=${USE_DEFAULT_STORAGE:-1}

# Receives the latest serving version and searches for the same version with major and minor and searches for the latest patch
function latest_net_istio_version() {
local serving_version=$1
Expand Down
15 changes: 15 additions & 0 deletions test/e2e-tests.sh
Expand Up @@ -121,6 +121,21 @@ go_test_e2e -timeout=2m ./test/e2e/initcontainers ${TEST_OPTIONS} || failed=1
toggle_feature kubernetes.podspec-init-containers Disabled
toggle_feature kubernetes.podspec-volumes-emptydir Disabled

# RUN PVC tests with default storage class if available.
if (( USE_DEFAULT_STORAGE )) ; then
kubectl apply -f "${E2E_YAML_DIR}/test/config/pvc/pvc.yaml"
fi

toggle_feature kubernetes.podspec-persistent-volume-claim Enabled
toggle_feature kubernetes.podspec-persistent-volume-write Enabled
go_test_e2e -timeout=5m ./test/e2e/pvc ${TEST_OPTIONS} || failed=1
toggle_feature kubernetes.podspec-persistent-volume-write Disabled
toggle_feature kubernetes.podspec-persistent-volume-claim Disabled

if (( USE_DEFAULT_STORAGE )) ; then
kubectl delete -f "${E2E_YAML_DIR}/test/config/pvc/pvc.yaml"
fi

# Run HA tests separately as they're stopping core Knative Serving pods.
# Define short -spoofinterval to ensure frequent probing while stopping pods.
toggle_feature autocreateClusterDomainClaims true config-network || fail_test
Expand Down
73 changes: 73 additions & 0 deletions test/e2e/pvc/pvc_test.go
@@ -0,0 +1,73 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pvc

import (
"context"
"testing"

corev1 "k8s.io/api/core/v1"
pkgTest "knative.dev/pkg/test"
"knative.dev/pkg/test/spoof"
. "knative.dev/serving/pkg/testing/v1"
"knative.dev/serving/test"
v1test "knative.dev/serving/test/v1"
)

// TestPersistentVolumeClaims tests init containers support.
func TestPersistentVolumeClaims(t *testing.T) {
t.Parallel()
clients := test.Setup(t)

names := test.ResourceNames{
Service: test.ObjectNameForTest(t),
Image: test.EmptyDir,
}

test.EnsureTearDown(t, clients, &names)

t.Log("Creating a new Service")

withVolume := WithVolume("data", "/data", corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "knative-pv-claim",
ReadOnly: false,
},
})

resources, err := v1test.CreateServiceReady(t, clients, &names, withVolume)
if err != nil {
t.Fatalf("Failed to create initial Service: %v: %v", names.Service, err)
}

url := resources.Route.Status.URL.URL()
if _, err := pkgTest.CheckEndpointState(
context.Background(),
clients.KubeClient,
t.Logf,
url,
spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.EmptyDirText)),
"PVCText",
test.ServingFlags.ResolvableDomain,
test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS),
); err != nil {
t.Fatalf("The endpoint %s for Route %s didn't serve the expected text %q: %v", url, names.Route, test.EmptyDirText, err)
}
}
36 changes: 36 additions & 0 deletions test/test_images/pvc/service.yaml
@@ -0,0 +1,36 @@
# Copyright 2022 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
spec:
containers:
- image: ko://knative.dev/serving/test/test_images/emptydir
name: event-display
volumeMounts:
- mountPath: /data
name: mydata
readOnly: false
env:
- name: DATA_PATH
value: /data
volumes:
- name: mydata
persistentVolumeClaim:
claimName: knative-pv-claim
readOnly: false

0 comments on commit 72577a3

Please sign in to comment.