2017-02-01 00:45:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes 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.
|
|
|
|
*/
|
|
|
|
|
2017-02-03 13:41:32 +00:00
|
|
|
package e2e_federation
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
2017-02-03 13:41:32 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-02-01 00:45:59 +00:00
|
|
|
"k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset"
|
|
|
|
"k8s.io/kubernetes/pkg/api/v1"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2017-02-03 13:41:32 +00:00
|
|
|
fedframework "k8s.io/kubernetes/test/e2e_federation/framework"
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
FederationEventName = "federation-event"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Create/delete event api objects.
|
|
|
|
var _ = framework.KubeDescribe("Federation events [Feature:Federation]", func() {
|
2017-02-03 13:41:32 +00:00
|
|
|
f := fedframework.NewDefaultFederatedFramework("federation-event")
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
Describe("Event objects", func() {
|
|
|
|
AfterEach(func() {
|
2017-02-03 13:41:32 +00:00
|
|
|
fedframework.SkipUnlessFederated(f.ClientSet)
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
nsName := f.FederationNamespace.Name
|
|
|
|
// Delete registered events.
|
2017-02-03 13:41:32 +00:00
|
|
|
eventList, err := f.FederationClientset.Core().Events(nsName).List(metav1.ListOptions{})
|
2017-02-01 00:45:59 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
for _, event := range eventList.Items {
|
2017-02-03 13:41:32 +00:00
|
|
|
err := f.FederationClientset.Core().Events(nsName).Delete(event.Name, &metav1.DeleteOptions{})
|
2017-02-01 00:45:59 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should be created and deleted successfully", func() {
|
2017-02-03 13:41:32 +00:00
|
|
|
fedframework.SkipUnlessFederated(f.ClientSet)
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
nsName := f.FederationNamespace.Name
|
2017-02-03 13:41:32 +00:00
|
|
|
event := createEventOrFail(f.FederationClientset, nsName)
|
2017-02-01 00:45:59 +00:00
|
|
|
By(fmt.Sprintf("Creation of event %q in namespace %q succeeded. Deleting event.", event.Name, nsName))
|
|
|
|
// Cleanup
|
2017-02-03 13:41:32 +00:00
|
|
|
err := f.FederationClientset.Core().Events(nsName).Delete(event.Name, &metav1.DeleteOptions{})
|
2017-02-01 00:45:59 +00:00
|
|
|
framework.ExpectNoError(err, "Error deleting event %q in namespace %q", event.Name, event.Namespace)
|
|
|
|
By(fmt.Sprintf("Deletion of event %q in namespace %q succeeded.", event.Name, nsName))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
func createEventOrFail(clientset *federation_clientset.Clientset, namespace string) *v1.Event {
|
|
|
|
if clientset == nil || len(namespace) == 0 {
|
|
|
|
Fail(fmt.Sprintf("Internal error: invalid parameters passed to createEventOrFail: clientset: %v, namespace: %v", clientset, namespace))
|
|
|
|
}
|
|
|
|
By(fmt.Sprintf("Creating federated event %q in namespace %q", FederationEventName, namespace))
|
|
|
|
|
|
|
|
event := &v1.Event{
|
2017-02-03 13:41:32 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2017-02-01 00:45:59 +00:00
|
|
|
Name: FederationEventName,
|
|
|
|
Namespace: namespace,
|
|
|
|
},
|
|
|
|
InvolvedObject: v1.ObjectReference{
|
|
|
|
Kind: "Pod",
|
|
|
|
Name: "pod-name",
|
|
|
|
Namespace: namespace,
|
|
|
|
UID: "C934D34AFB20242",
|
|
|
|
APIVersion: "version",
|
|
|
|
},
|
|
|
|
Source: v1.EventSource{
|
|
|
|
Component: "kubelet",
|
|
|
|
Host: "kublet.node1",
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
Type: v1.EventTypeNormal,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := clientset.Core().Events(namespace).Create(event)
|
|
|
|
framework.ExpectNoError(err, "Creating event %q in namespace %q", event.Name, namespace)
|
|
|
|
By(fmt.Sprintf("Successfully created federated event %q in namespace %q", FederationEventName, namespace))
|
|
|
|
return event
|
|
|
|
}
|