paused as ready now working

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
pull/13604/head
Austin Abro 9 months ago
parent 22af71f125
commit e18f22071d
No known key found for this signature in database
GPG Key ID: 92EB5159E403F9D6

@ -22,6 +22,7 @@ import (
"fmt" "fmt"
"time" "time"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1" batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator" "sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
@ -46,7 +47,7 @@ func (w *kstatusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Dur
return w.wait(resourceList, timeout, true) return w.wait(resourceList, timeout, true)
} }
func (w *kstatusWaiter) wait(resourceList ResourceList, timeout time.Duration, waitWithJobs bool) error { func (w *kstatusWaiter) wait(resourceList ResourceList, timeout time.Duration, waitForJobs bool) error {
ctx, cancel := context.WithTimeout(context.TODO(), timeout) ctx, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel() defer cancel()
cancelCtx, cancel := context.WithCancel(ctx) cancelCtx, cancel := context.WithCancel(ctx)
@ -54,9 +55,13 @@ func (w *kstatusWaiter) wait(resourceList ResourceList, timeout time.Duration, w
// TODO maybe a simpler way to transfer the objects // TODO maybe a simpler way to transfer the objects
runtimeObjs := []runtime.Object{} runtimeObjs := []runtime.Object{}
for _, resource := range resourceList { for _, resource := range resourceList {
switch AsVersioned(resource).(type) { switch value := AsVersioned(resource).(type) {
case *batchv1.Job: case *batchv1.Job:
if !waitWithJobs { if !waitForJobs {
continue
}
case *appsv1.Deployment:
if w.pausedAsReady && value.Spec.Paused {
continue continue
} }
} }

@ -23,6 +23,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
batchv1 "k8s.io/api/batch/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@ -80,6 +82,31 @@ status:
status: "True" status: "True"
` `
var pausedDeploymentYaml = `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: ns-1
generation: 1
spec:
paused: true
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.6
ports:
- containerPort: 80
`
func getGVR(t *testing.T, mapper meta.RESTMapper, obj *unstructured.Unstructured) schema.GroupVersionResource { func getGVR(t *testing.T, mapper meta.RESTMapper, obj *unstructured.Unstructured) schema.GroupVersionResource {
gvk := obj.GroupVersionKind() gvk := obj.GroupVersionKind()
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version) mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
@ -90,10 +117,11 @@ func getGVR(t *testing.T, mapper meta.RESTMapper, obj *unstructured.Unstructured
func TestKWaitJob(t *testing.T) { func TestKWaitJob(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []struct {
name string name string
objYamls []string objYamls []string
expectErrs []error expectErrs []error
waitForJobs bool waitForJobs bool
pausedAsReady bool
}{ }{
{ {
name: "Job is complete", name: "Job is complete",
@ -122,6 +150,12 @@ func TestKWaitJob(t *testing.T) {
objYamls: []string{podNoStatus, podCurrent}, objYamls: []string{podNoStatus, podCurrent},
expectErrs: []error{errors.New("in-progress-pod: Pod not ready, status: InProgress"), errors.New("context deadline exceeded")}, expectErrs: []error{errors.New("in-progress-pod: Pod not ready, status: InProgress"), errors.New("context deadline exceeded")},
}, },
{
name: "paused deployment passes",
objYamls: []string{pausedDeploymentYaml},
expectErrs: nil,
pausedAsReady: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
@ -131,11 +165,8 @@ func TestKWaitJob(t *testing.T) {
fakeClient := dynamicfake.NewSimpleDynamicClient(scheme.Scheme) fakeClient := dynamicfake.NewSimpleDynamicClient(scheme.Scheme)
fakeMapper := testutil.NewFakeRESTMapper( fakeMapper := testutil.NewFakeRESTMapper(
v1.SchemeGroupVersion.WithKind("Pod"), v1.SchemeGroupVersion.WithKind("Pod"),
schema.GroupVersionKind{ appsv1.SchemeGroupVersion.WithKind("Deployment"),
Group: "batch", batchv1.SchemeGroupVersion.WithKind("Job"),
Version: "v1",
Kind: "Job",
},
) )
objs := []runtime.Object{} objs := []runtime.Object{}
statusWatcher := watcher.NewDefaultStatusWatcher(fakeClient, fakeMapper) statusWatcher := watcher.NewDefaultStatusWatcher(fakeClient, fakeMapper)
@ -152,6 +183,7 @@ func TestKWaitJob(t *testing.T) {
kwaiter := kstatusWaiter{ kwaiter := kstatusWaiter{
sw: statusWatcher, sw: statusWatcher,
log: c.Log, log: c.Log,
pausedAsReady: tt.pausedAsReady,
} }
resourceList := ResourceList{} resourceList := ResourceList{}

Loading…
Cancel
Save