|
|
|
@ -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"
|
|
|
|
@ -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)
|
|
|
|
@ -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
|
|
|
|
@ -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 {
|
|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
@ -436,7 +444,7 @@ 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)
|
|
|
|
@ -444,11 +452,11 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
|
|
|
|
|
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{},
|
|
|
|
|