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"
"time"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/runtime"
"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)
}
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)
defer cancel()
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
runtimeObjs := []runtime.Object{}
for _, resource := range resourceList {
switch AsVersioned(resource).(type) {
switch value := AsVersioned(resource).(type) {
case *batchv1.Job:
if !waitWithJobs {
if !waitForJobs {
continue
}
case *appsv1.Deployment:
if w.pausedAsReady && value.Spec.Paused {
continue
}
}

@ -23,6 +23,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
batchv1 "k8s.io/api/batch/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@ -80,6 +82,31 @@ status:
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 {
gvk := obj.GroupVersionKind()
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
@ -94,6 +121,7 @@ func TestKWaitJob(t *testing.T) {
objYamls []string
expectErrs []error
waitForJobs bool
pausedAsReady bool
}{
{
name: "Job is complete",
@ -122,6 +150,12 @@ func TestKWaitJob(t *testing.T) {
objYamls: []string{podNoStatus, podCurrent},
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 {
@ -131,11 +165,8 @@ func TestKWaitJob(t *testing.T) {
fakeClient := dynamicfake.NewSimpleDynamicClient(scheme.Scheme)
fakeMapper := testutil.NewFakeRESTMapper(
v1.SchemeGroupVersion.WithKind("Pod"),
schema.GroupVersionKind{
Group: "batch",
Version: "v1",
Kind: "Job",
},
appsv1.SchemeGroupVersion.WithKind("Deployment"),
batchv1.SchemeGroupVersion.WithKind("Job"),
)
objs := []runtime.Object{}
statusWatcher := watcher.NewDefaultStatusWatcher(fakeClient, fakeMapper)
@ -152,6 +183,7 @@ func TestKWaitJob(t *testing.T) {
kwaiter := kstatusWaiter{
sw: statusWatcher,
log: c.Log,
pausedAsReady: tt.pausedAsReady,
}
resourceList := ResourceList{}

Loading…
Cancel
Save