- [X] APISnoop org-flow: deleteCoreV1CollectionNamespacedPodTemplate.org
- [X] test approval issue: kubernetes/kubernetes#90746
- [ ] 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 'deleteCoreV1CollectionNamespacedPodTemplate'
ORDER BY kind,operation_id desc
LIMIT 25
;
operation_id | description | kind
---------------------------------------------+----------------------------------+-------------
deleteCoreV1CollectionNamespacedPodTemplate | delete collection of PodTemplate | PodTemplate
(1 row)
- Kubernetes API Reference Docs
- Kubernetes API: v1.18 Pod Template v1 core Delete Collection
- client-go - PodTemplate: DeleteCollection
- Create a set of 3 Pod Templates with a static label within a Namespace.
- Confirm that all 3 Pod Templates with the label in the Namespace are created.
- Delete the set of Namespaced Pod Templates with a label via DeleteCollection.
- Confirm that all Pod Templates with the label have been deleted.
package main
import (
// "encoding/json"
"fmt"
"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)
// DynamicClientSet, _ := dynamic.NewForConfig(config)
// podResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
// TEST BEGINS HERE
fmt.Println("create a set of Pod templates with a label")
podTemplateTestNames := [3]string{"test-podtemplate-1", "test-podtemplate-2", "test-podtemplate-3"}
for _, podTemplateTestName := range podTemplateTestNames {
_, err = ClientSet.CoreV1().PodTemplates("default").Create(&v1.PodTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: podTemplateTestName,
Labels: map[string]string{
"type": "Testing"},
},
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
{Name: "nginx", Image: "nginx"},
},
},
},
})
if err != nil {
fmt.Println("[error]", err)
return
}
fmt.Println("[status] created", podTemplateTestName)
}
fmt.Println("get a list of Pod templates with a label in the default namespace")
podTemplateList, err := ClientSet.CoreV1().PodTemplates("default").List(metav1.ListOptions{
LabelSelector: "type=Testing"})
fmt.Println("check that there are 3 Pod templates found")
fmt.Println("[status] Found", len(podTemplateList.Items), "Pod templates")
if len(podTemplateList.Items) != 3 {
fmt.Println("[error] Incorrect number of Pod templates found")
return
}
fmt.Println("delete Collection of Pod templates for the label in the default namespace")
_ = ClientSet.CoreV1().PodTemplates("default").DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: "type=Testing"})
fmt.Println("[status] DeleteCollection processed")
time.Sleep(2 * time.Second)
fmt.Println("get a list of Pod templates with a label in the default namespace")
podTemplateList, err = ClientSet.CoreV1().PodTemplates("default").List(metav1.ListOptions{
LabelSelector: "type=Testing"})
fmt.Println("check that there are no Pod templates found")
fmt.Println("[status] Found", len(podTemplateList.Items), "Pod templates")
if len(podTemplateList.Items) != 0 {
fmt.Println("[error] Incorrect number of Pod templates found")
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 | createCoreV1NamespacedPodTemplate | t | 3
live-test-writing | deleteCoreV1CollectionNamespacedPodTemplate | f | 1
live-test-writing | listCoreV1NamespacedPodTemplate | t | 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 | 189 | 1
(1 row)
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