- [X] APISnoop org-flow: deleteCoreV1CollectionNamespacedEventTest.org
- [X] Test approval issue: kubernetes/kubernetes#90619
- [ ] Test pr: kuberenetes/kubernetes#
- [ ] Two weeks soak start date: testgrid-link
- [ ] Two weeks soak end date:
- [ ] Test promotion pr: kubernetes/kubernetes#?
According to this APIsnoop query, there are still an endpoint which is untested.
SELECT
operation_id,
-- k8s_action,
-- path,
description,
kind
FROM untested_stable_core_endpoints
-- FROM untested_stable_endpoints
where path not like '%volume%'
-- and kind like ''
and operation_id ilike 'delete%CollectionNamespacedEvent'
ORDER BY kind,operation_id desc
LIMIT 25
;
operation_id | description | kind
---------------------------------------+----------------------------+-------
deleteCoreV1CollectionNamespacedEvent | delete collection of Event | Event
(1 row)
- Kubernetes API Reference Docs
- Kubernetes API: v1.18 /deleteCoreV1CollectionNamespacedEvent
- client-go - Event: DeleteCollection
- Create a set of 3 Events with a static label within a Namespace.
- Confirm that all 3 Events with the label in the Namespaces are created.
- Delete the set of Namespaced Events with a label via DeleteCollection.
- Confirm that all Events with the label have been deleted.
package main
import (
// "encoding/json"
"fmt"
"strconv"
// "time"
"flag"
"os"
v1 "k8s.io/api/core/v1"
// "k8s.io/client-go/dynamic"
// "k8s.io/apimachinery/pkg/runtime/schema"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
// "k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
// uses the current context in kubeconfig
kubeconfig := flag.String("kubeconfig", fmt.Sprintf("%v/%v/%v", os.Getenv("HOME"), ".kube", "config"), "(optional) absolute path to the kubeconfig file")
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
fmt.Println(err)
return
}
// make our work easier to find in the audit_event queries
config.UserAgent = "live-test-writing"
// creates the clientset
ClientSet, _ := kubernetes.NewForConfig(config)
// TEST BEGINS HERE
// create a set of event test names
eventTestName := [3]string{"test-event-1", "test-event-2", "test-event-3"}
// create a set of test events with a label in the default namespace
for i := range eventTestName {
eventMessage := "This is " + eventTestName[i]
_, err = ClientSet.CoreV1().Events("default").Create(&v1.Event{
ObjectMeta: metav1.ObjectMeta{
Name: eventTestName[i],
Labels: map[string]string{"type": "Testing"},
},
Message: eventMessage,
Reason: "Test",
Type: "Normal",
Count: 1,
})
if err != nil {
fmt.Println("[error]", err)
return
}
fmt.Println("[status] created", eventTestName[i])
// time.Sleep(3 * time.Second)
}
// get a list of Events with a label in the default namespace
eventsList, err := ClientSet.CoreV1().Events("default").List(metav1.ListOptions{
LabelSelector: "type=Testing"})
if err != nil {
fmt.Println("[error]", err)
return
}
// check that there are 3 events found
fmt.Println("[status] Found", strconv.Itoa(len(eventsList.Items)), "events")
if len(eventsList.Items) != 3 {
fmt.Println("[error] Incorrect number of Events found")
return
}
// delete Collection Events for the label in the default namespace
_ = ClientSet.CoreV1().Events("default").DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: "type=Testing"})
fmt.Println("[status] DeleteCollection processed")
// get a list of Events default namespace with the label
eventsList, err = ClientSet.CoreV1().Events("default").List(metav1.ListOptions{
LabelSelector: "type=Testing"})
if err != nil {
fmt.Println("[error]", err)
return
}
// check that there are zero events found
fmt.Println("[status] Found", strconv.Itoa(len(eventsList.Items)), "events")
if len(eventsList.Items) != 0 {
fmt.Println("[error] Still found an Event(s)")
return
}
// TEST ENDS HERE
fmt.Println("[status] complete")
}
Discover useragents:
select distinct useragent from audit_event where bucket='apisnoop' and useragent not like 'kube%' and useragent not like 'coredns%' and useragent not like 'kindnetd%' and useragent like 'live%';
useragent
-------------------
live-test-writing
(1 row)
List endpoints hit by the test:
select * from endpoints_hit_by_new_test where useragent like 'live%';
useragent | operation_id | hit_by_ete | hit_by_new_test
-------------------+---------------------------------------+------------+-----------------
live-test-writing | createCoreV1NamespacedEvent | f | 3
live-test-writing | deleteCoreV1CollectionNamespacedEvent | f | 1
live-test-writing | listCoreV1NamespacedEvent | f | 2
(3 rows)
Display endpoint coverage change:
select * from projected_change_in_coverage;
category | total_endpoints | old_coverage | new_coverage | change_in_number
---------------+-----------------+--------------+--------------+------------------
test_coverage | 445 | 188 | 191 | 3
(1 row)
Two other endpoints tested here have tests in progress to conformance already.
If a test with these calls gets merged, **test coverage will go up by 1 points**
This test is also created with the goal of conformance promotion.
/sig testing
/sig architecture
/area conformance