mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Clean shutdown of disruption integration tests
This commit is contained in:
parent
03d0e2c338
commit
783da34f54
@ -358,7 +358,18 @@ func verifyGroupKind(controllerRef *metav1.OwnerReference, expectedKind string,
|
|||||||
|
|
||||||
func (dc *DisruptionController) Run(ctx context.Context) {
|
func (dc *DisruptionController) Run(ctx context.Context) {
|
||||||
defer utilruntime.HandleCrash()
|
defer utilruntime.HandleCrash()
|
||||||
|
|
||||||
|
// Start events processing pipeline.
|
||||||
|
if dc.kubeClient != nil {
|
||||||
|
klog.Infof("Sending events to api server.")
|
||||||
|
dc.broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: dc.kubeClient.CoreV1().Events("")})
|
||||||
|
} else {
|
||||||
|
klog.Infof("No api server defined - no events will be sent to API server.")
|
||||||
|
}
|
||||||
|
defer dc.broadcaster.Shutdown()
|
||||||
|
|
||||||
defer dc.queue.ShutDown()
|
defer dc.queue.ShutDown()
|
||||||
|
defer dc.recheckQueue.ShutDown()
|
||||||
|
|
||||||
klog.Infof("Starting disruption controller")
|
klog.Infof("Starting disruption controller")
|
||||||
defer klog.Infof("Shutting down disruption controller")
|
defer klog.Infof("Shutting down disruption controller")
|
||||||
@ -367,12 +378,6 @@ func (dc *DisruptionController) Run(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dc.kubeClient != nil {
|
|
||||||
klog.Infof("Sending events to api server.")
|
|
||||||
dc.broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: dc.kubeClient.CoreV1().Events("")})
|
|
||||||
} else {
|
|
||||||
klog.Infof("No api server defined - no events will be sent to API server.")
|
|
||||||
}
|
|
||||||
go wait.UntilWithContext(ctx, dc.worker, time.Second)
|
go wait.UntilWithContext(ctx, dc.worker, time.Second)
|
||||||
go wait.Until(dc.recheckWorker, time.Second, ctx.Done())
|
go wait.Until(dc.recheckWorker, time.Second, ctx.Done())
|
||||||
|
|
||||||
|
@ -101,7 +101,9 @@ func setup(t *testing.T) (*kubeapiservertesting.TestServer, *disruption.Disrupti
|
|||||||
func TestPDBWithScaleSubresource(t *testing.T) {
|
func TestPDBWithScaleSubresource(t *testing.T) {
|
||||||
s, pdbc, informers, clientSet, apiExtensionClient, dynamicClient := setup(t)
|
s, pdbc, informers, clientSet, apiExtensionClient, dynamicClient := setup(t)
|
||||||
defer s.TearDownFn()
|
defer s.TearDownFn()
|
||||||
ctx := context.TODO()
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
nsName := "pdb-scale-subresource"
|
nsName := "pdb-scale-subresource"
|
||||||
createNs(ctx, t, nsName, clientSet)
|
createNs(ctx, t, nsName, clientSet)
|
||||||
|
|
||||||
@ -187,16 +189,14 @@ func TestPDBWithScaleSubresource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptySelector(t *testing.T) {
|
func TestEmptySelector(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
createPDBFunc func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error
|
createPDBFunc func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error
|
||||||
expectedCurrentHealthy int32
|
expectedCurrentHealthy int32
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "v1beta1 should not target any pods",
|
name: "v1beta1 should not target any pods",
|
||||||
createPDBFunc: func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
createPDBFunc: func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
||||||
pdb := &v1beta1.PodDisruptionBudget{
|
pdb := &v1beta1.PodDisruptionBudget{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -213,7 +213,7 @@ func TestEmptySelector(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "v1 should target all pods",
|
name: "v1 should target all pods",
|
||||||
createPDBFunc: func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
createPDBFunc: func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
||||||
pdb := &policyv1.PodDisruptionBudget{
|
pdb := &policyv1.PodDisruptionBudget{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -235,6 +235,9 @@ func TestEmptySelector(t *testing.T) {
|
|||||||
s, pdbc, informers, clientSet, _, _ := setup(t)
|
s, pdbc, informers, clientSet, _, _ := setup(t)
|
||||||
defer s.TearDownFn()
|
defer s.TearDownFn()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
nsName := fmt.Sprintf("pdb-empty-selector-%d", i)
|
nsName := fmt.Sprintf("pdb-empty-selector-%d", i)
|
||||||
createNs(ctx, t, nsName, clientSet)
|
createNs(ctx, t, nsName, clientSet)
|
||||||
|
|
||||||
@ -252,7 +255,7 @@ func TestEmptySelector(t *testing.T) {
|
|||||||
waitToObservePods(t, informers.Core().V1().Pods().Informer(), 4, v1.PodRunning)
|
waitToObservePods(t, informers.Core().V1().Pods().Informer(), 4, v1.PodRunning)
|
||||||
|
|
||||||
pdbName := "test-pdb"
|
pdbName := "test-pdb"
|
||||||
if err := tc.createPDBFunc(clientSet, pdbName, nsName, minAvailable); err != nil {
|
if err := tc.createPDBFunc(ctx, clientSet, pdbName, nsName, minAvailable); err != nil {
|
||||||
t.Errorf("Error creating PodDisruptionBudget: %v", err)
|
t.Errorf("Error creating PodDisruptionBudget: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,16 +274,14 @@ func TestEmptySelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
createPDBFunc func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error
|
createPDBFunc func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error
|
||||||
expectedCurrentHealthy int32
|
expectedCurrentHealthy int32
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "pods with no labels can be targeted by v1 PDBs with empty selector",
|
name: "pods with no labels can be targeted by v1 PDBs with empty selector",
|
||||||
createPDBFunc: func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
createPDBFunc: func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
||||||
pdb := &policyv1.PodDisruptionBudget{
|
pdb := &policyv1.PodDisruptionBudget{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -297,7 +298,7 @@ func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pods with no labels can be targeted by v1 PDBs with DoesNotExist selector",
|
name: "pods with no labels can be targeted by v1 PDBs with DoesNotExist selector",
|
||||||
createPDBFunc: func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
createPDBFunc: func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
||||||
pdb := &policyv1.PodDisruptionBudget{
|
pdb := &policyv1.PodDisruptionBudget{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -321,7 +322,7 @@ func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pods with no labels can be targeted by v1beta1 PDBs with DoesNotExist selector",
|
name: "pods with no labels can be targeted by v1beta1 PDBs with DoesNotExist selector",
|
||||||
createPDBFunc: func(clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
createPDBFunc: func(ctx context.Context, clientSet clientset.Interface, name, nsName string, minAvailable intstr.IntOrString) error {
|
||||||
pdb := &v1beta1.PodDisruptionBudget{
|
pdb := &v1beta1.PodDisruptionBudget{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -350,6 +351,9 @@ func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
|||||||
s, pdbc, informers, clientSet, _, _ := setup(t)
|
s, pdbc, informers, clientSet, _, _ := setup(t)
|
||||||
defer s.TearDownFn()
|
defer s.TearDownFn()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
nsName := fmt.Sprintf("pdb-selectors-%d", i)
|
nsName := fmt.Sprintf("pdb-selectors-%d", i)
|
||||||
createNs(ctx, t, nsName, clientSet)
|
createNs(ctx, t, nsName, clientSet)
|
||||||
|
|
||||||
@ -360,7 +364,7 @@ func TestSelectorsForPodsWithoutLabels(t *testing.T) {
|
|||||||
|
|
||||||
// Create the PDB first and wait for it to settle.
|
// Create the PDB first and wait for it to settle.
|
||||||
pdbName := "test-pdb"
|
pdbName := "test-pdb"
|
||||||
if err := tc.createPDBFunc(clientSet, pdbName, nsName, minAvailable); err != nil {
|
if err := tc.createPDBFunc(ctx, clientSet, pdbName, nsName, minAvailable); err != nil {
|
||||||
t.Errorf("Error creating PodDisruptionBudget: %v", err)
|
t.Errorf("Error creating PodDisruptionBudget: %v", err)
|
||||||
}
|
}
|
||||||
waitPDBStable(ctx, t, clientSet, 0, nsName, pdbName)
|
waitPDBStable(ctx, t, clientSet, 0, nsName, pdbName)
|
||||||
@ -498,9 +502,15 @@ func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podN
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPatchCompatibility(t *testing.T) {
|
func TestPatchCompatibility(t *testing.T) {
|
||||||
s, _, _, clientSet, _, _ := setup(t)
|
s, pdbc, _, clientSet, _, _ := setup(t)
|
||||||
defer s.TearDownFn()
|
defer s.TearDownFn()
|
||||||
|
|
||||||
|
// Even though pdbc isn't used in this test, its creation is already
|
||||||
|
// spawning some goroutines. So we need to run it to ensure they won't leak.
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
pdbc.Run(ctx)
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
version string
|
version string
|
||||||
@ -634,5 +644,4 @@ func TestPatchCompatibility(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user