Skip to content

Commit

Permalink
Merge pull request kubernetes#84735 from liggitt/wardle-example-e2e
Browse files Browse the repository at this point in the history
wardle example e2e
  • Loading branch information
k8s-ci-robot authored Dec 17, 2019
2 parents a1fc96f + 8111bb3 commit 7fdefe5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
4 changes: 2 additions & 2 deletions staging/src/k8s.io/sample-apiserver/artifacts/example/rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ spec:
- name: wardle-server
# build from staging/src/k8s.io/sample-apiserver/artifacts/simple-image/Dockerfile
# or
# docker pull gcr.io/kubernetes-e2e-test-images/sample-apiserver:1.10
# docker tag gcr.io/kubernetes-e2e-test-images/sample-apiserver:1.10 kube-sample-apiserver:latest
# docker pull gcr.io/kubernetes-e2e-test-images/sample-apiserver:1.17
# docker tag gcr.io/kubernetes-e2e-test-images/sample-apiserver:1.17 kube-sample-apiserver:latest
image: kube-sample-apiserver:latest
imagePullPolicy: Never
args: [ "--etcd-servers=https://localhost:2379" ]
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/testdata/conformance.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test/e2e/apimachinery/aggregator.go: "Should be able to support the 1.10 Sample API Server using the current Aggregator"
test/e2e/apimachinery/aggregator.go: "Should be able to support the 1.17 Sample API Server using the current Aggregator"
test/e2e/apimachinery/crd_conversion_webhook.go: "should be able to convert from CR v1 to CR v2"
test/e2e/apimachinery/crd_conversion_webhook.go: "should be able to convert a non homogeneous list of CRs"
test/e2e/apimachinery/crd_publish_openapi.go: "works for CRD with validation schema"
Expand Down
56 changes: 32 additions & 24 deletions test/e2e/apimachinery/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
unstructuredv1 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -88,18 +89,18 @@ var _ = SIGDescribe("Aggregator", func() {

/*
Testname: aggregator-supports-the-sample-apiserver
Description: Ensure that the sample-apiserver code from 1.10 and compiled against 1.10
Description: Ensure that the sample-apiserver code from 1.17 and compiled against 1.17
will work on the current Aggregator/API-Server.
*/
framework.ConformanceIt("Should be able to support the 1.10 Sample API Server using the current Aggregator", func() {
// Testing a 1.10 version of the sample-apiserver
framework.ConformanceIt("Should be able to support the 1.17 Sample API Server using the current Aggregator", func() {
// Testing a 1.17 version of the sample-apiserver
TestSampleAPIServer(f, aggrclient, imageutils.GetE2EImage(imageutils.APIServer))
})
})

func cleanTest(client clientset.Interface, aggrclient *aggregatorclient.Clientset, namespace string) {
// delete the APIService first to avoid causing discovery errors
_ = aggrclient.ApiregistrationV1().APIServices().Delete("v1alpha1.wardle.k8s.io", nil)
_ = aggrclient.ApiregistrationV1().APIServices().Delete("v1alpha1.wardle.example.com", nil)

_ = client.AppsV1().Deployments(namespace).Delete("sample-apiserver-deployment", nil)
_ = client.CoreV1().Secrets(namespace).Delete("sample-apiserver-secret", nil)
Expand Down Expand Up @@ -325,21 +326,21 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl

// kubectl create -f apiservice.yaml
_, err = aggrclient.ApiregistrationV1().APIServices().Create(&apiregistrationv1.APIService{
ObjectMeta: metav1.ObjectMeta{Name: "v1alpha1.wardle.k8s.io"},
ObjectMeta: metav1.ObjectMeta{Name: "v1alpha1.wardle.example.com"},
Spec: apiregistrationv1.APIServiceSpec{
Service: &apiregistrationv1.ServiceReference{
Namespace: namespace,
Name: "sample-api",
Port: pointer.Int32Ptr(aggregatorServicePort),
},
Group: "wardle.k8s.io",
Group: "wardle.example.com",
Version: "v1alpha1",
CABundle: context.signingCert,
GroupPriorityMinimum: 2000,
VersionPriority: 200,
},
})
framework.ExpectNoError(err, "creating apiservice %s with namespace %s", "v1alpha1.wardle.k8s.io", namespace)
framework.ExpectNoError(err, "creating apiservice %s with namespace %s", "v1alpha1.wardle.example.com", namespace)

var (
currentAPIService *apiregistrationv1.APIService
Expand All @@ -348,10 +349,10 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl

err = pollTimed(100*time.Millisecond, 60*time.Second, func() (bool, error) {

currentAPIService, _ = aggrclient.ApiregistrationV1().APIServices().Get("v1alpha1.wardle.k8s.io", metav1.GetOptions{})
currentAPIService, _ = aggrclient.ApiregistrationV1().APIServices().Get("v1alpha1.wardle.example.com", metav1.GetOptions{})
currentPods, _ = client.CoreV1().Pods(namespace).List(metav1.ListOptions{})

request := restClient.Get().AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders")
request := restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders")
request.SetHeader("Accept", "application/json")
_, err := request.DoRaw()
if err != nil {
Expand Down Expand Up @@ -390,42 +391,49 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
flunderName := generateFlunderName("rest-flunder")

// kubectl create -f flunders-1.yaml -v 9
// curl -k -v -XPOST https://localhost/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders
// Request Body: {"apiVersion":"wardle.k8s.io/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
flunder := `{"apiVersion":"wardle.k8s.io/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"` + flunderName + `","namespace":"default"}}`
result := restClient.Post().AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders").Body([]byte(flunder)).Do()
// curl -k -v -XPOST https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
// Request Body: {"apiVersion":"wardle.example.com/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
flunder := `{"apiVersion":"wardle.example.com/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"` + flunderName + `","namespace":"default"}}`
result := restClient.Post().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").Body([]byte(flunder)).SetHeader("Accept", "application/json").Do()
framework.ExpectNoError(result.Error(), "creating a new flunders resource")
var statusCode int
result.StatusCode(&statusCode)
if statusCode != 201 {
framework.Failf("Flunders client creation response was status %d, not 201", statusCode)
}
u := &unstructured.Unstructured{}
if err := result.Into(u); err != nil {
framework.ExpectNoError(err, "reading created response")
}
framework.ExpectEqual(u.GetAPIVersion(), "wardle.example.com/v1alpha1")
framework.ExpectEqual(u.GetKind(), "Flunder")
framework.ExpectEqual(u.GetName(), flunderName)

pods, err := client.CoreV1().Pods(namespace).List(metav1.ListOptions{})
framework.ExpectNoError(err, "getting pods for flunders service")

// kubectl get flunders -v 9
// curl -k -v -XGET https://localhost/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders
contents, err := restClient.Get().AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
// curl -k -v -XGET https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
contents, err := restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
framework.ExpectNoError(err, "attempting to get a newly created flunders resource")
var flundersList samplev1alpha1.FlunderList
err = json.Unmarshal(contents, &flundersList)
validateErrorWithDebugInfo(f, err, pods, "Error in unmarshalling %T response from server %s", contents, "/apis/wardle.k8s.io/v1alpha1")
validateErrorWithDebugInfo(f, err, pods, "Error in unmarshalling %T response from server %s", contents, "/apis/wardle.example.com/v1alpha1")
if len(flundersList.Items) != 1 {
framework.Failf("failed to get back the correct flunders list %v", flundersList)
}

// kubectl delete flunder test-flunder -v 9
// curl -k -v -XDELETE https://35.193.112.40/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders/test-flunder
_, err = restClient.Delete().AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders/" + flunderName).DoRaw()
// curl -k -v -XDELETE https://35.193.112.40/apis/wardle.example.com/v1alpha1/namespaces/default/flunders/test-flunder
_, err = restClient.Delete().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders/" + flunderName).DoRaw()
validateErrorWithDebugInfo(f, err, pods, "attempting to delete a newly created flunders(%v) resource", flundersList.Items)

// kubectl get flunders -v 9
// curl -k -v -XGET https://localhost/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders
contents, err = restClient.Get().AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
// curl -k -v -XGET https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
contents, err = restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
framework.ExpectNoError(err, "confirming delete of a newly created flunders resource")
err = json.Unmarshal(contents, &flundersList)
validateErrorWithDebugInfo(f, err, pods, "Error in unmarshalling %T response from server %s", contents, "/apis/wardle.k8s.io/v1alpha1")
validateErrorWithDebugInfo(f, err, pods, "Error in unmarshalling %T response from server %s", contents, "/apis/wardle.example.com/v1alpha1")
if len(flundersList.Items) != 0 {
framework.Failf("failed to get back the correct deleted flunders list %v", flundersList)
}
Expand All @@ -436,19 +444,19 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
resources, discoveryErr := client.Discovery().ServerPreferredNamespacedResources()
groupVersionResources, err := discovery.GroupVersionResources(resources)
framework.ExpectNoError(err, "getting group version resources for dynamic client")
gvr := schema.GroupVersionResource{Group: "wardle.k8s.io", Version: "v1alpha1", Resource: "flunders"}
gvr := schema.GroupVersionResource{Group: "wardle.example.com", Version: "v1alpha1", Resource: "flunders"}
_, ok := groupVersionResources[gvr]
if !ok {
framework.Failf("could not find group version resource for dynamic client and wardle/flunders (discovery error: %v, discovery results: %#v)", discoveryErr, groupVersionResources)
}
dynamicClient := f.DynamicClient.Resource(gvr).Namespace(namespace)

// kubectl create -f flunders-1.yaml
// Request Body: {"apiVersion":"wardle.k8s.io/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
// Request Body: {"apiVersion":"wardle.example.com/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
testFlunder := samplev1alpha1.Flunder{
TypeMeta: metav1.TypeMeta{
Kind: "Flunder",
APIVersion: "wardle.k8s.io/v1alpha1",
APIVersion: "wardle.example.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{Name: flunderName},
Spec: samplev1alpha1.FlunderSpec{},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ var _ = SIGDescribe("Kubectl client", func() {
// tolerate discovery errors for non-k8s.io groups (like aggregated/crd groups)
continue
}
if gv.Group == "wardle.k8s.io" || gv.Group == "metrics.k8s.io" {
if gv.Group == "metrics.k8s.io" {
// tolerate discovery errors for known test k8s.io groups like aggregated/metrics groups
continue
}
Expand Down
20 changes: 11 additions & 9 deletions test/images/sample-apiserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM k8s.gcr.io/kube-cross:v1.10.4-1 as build_k8s_1_10_sample_apiserver
FROM k8s.gcr.io/kube-cross:v1.13.4-1 as build_k8s_1_17_sample_apiserver

ENV GOPATH /go
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
ENV PATH $GOPATH/bin:$PATH

# The e2e aggregator test was originally added in #50347 and is designed to test ability to run a 1.7
# sample-apiserver in newer releases. please see e2e test named "Should be able to support the 1.7 Sample
# API Server using the current Aggregator"
RUN go get -d k8s.io/sample-apiserver \
&& cd ${GOPATH}/src/k8s.io/sample-apiserver \
&& git checkout --track origin/release-1.10 \
&& CGO_ENABLED=0 GOOS=linux GOARCH=BASEARCH go install .

# The e2e aggregator test is designed to test ability to run sample-apiserver as an aggregated server.
# see e2e test named "Should be able to support the 1.17 Sample API Server using the current Aggregator"

# Build v1.17.0 to ensure the current release supports a prior version of the sample apiserver
# Get without building to populate module cache
RUN GO111MODULE=on go get -d k8s.io/[email protected]
# Get with OS/ARCH-specific env to build
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=BASEARCH go get k8s.io/[email protected]

# for arm, go install uses go/bin/linux_arm, so just find the file and copy it to the root so
# we can copy it out from this throw away container image from a standard location
RUN find /go/bin -name sample-apiserver -exec cp {} / \;

FROM BASEIMAGE
COPY --from=build_k8s_1_10_sample_apiserver /sample-apiserver /sample-apiserver
COPY --from=build_k8s_1_17_sample_apiserver /sample-apiserver /sample-apiserver

ENTRYPOINT ["/sample-apiserver"]
2 changes: 1 addition & 1 deletion test/images/sample-apiserver/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10
1.17
2 changes: 1 addition & 1 deletion test/utils/image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func initImageConfigs() map[int]Config {
configs[AgnhostPrivate] = Config{PrivateRegistry, "agnhost", "2.6"}
configs[AuthenticatedAlpine] = Config{gcAuthenticatedRegistry, "alpine", "3.7"}
configs[AuthenticatedWindowsNanoServer] = Config{gcAuthenticatedRegistry, "windows-nanoserver", "v1"}
configs[APIServer] = Config{e2eRegistry, "sample-apiserver", "1.10"}
configs[APIServer] = Config{e2eRegistry, "sample-apiserver", "1.17"}
configs[AppArmorLoader] = Config{e2eRegistry, "apparmor-loader", "1.0"}
configs[BusyBox] = Config{dockerLibraryRegistry, "busybox", "1.29"}
configs[CheckMetadataConcealment] = Config{e2eRegistry, "metadata-concealment", "1.2"}
Expand Down

0 comments on commit 7fdefe5

Please sign in to comment.