diff --git a/go.mod b/go.mod index 3e38758688..2744954762 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( k8s.io/kube-openapi v0.0.0-20211109043139-026bd182f079 // indirect k8s.io/kubectl v0.22.2 k8s.io/utils v0.0.0-20210820185131-d34e5cb4466e - sigs.k8s.io/cli-utils v0.26.1-0.20211020064957-d62b5c62002d + sigs.k8s.io/cli-utils v0.26.1-0.20211207234511-5b83428a278a sigs.k8s.io/kustomize/api v0.8.11 sigs.k8s.io/kustomize/kyaml v0.13.1-0.20211203194734-cd2c6a1ad117 ) diff --git a/go.sum b/go.sum index 9045149435..169834fbea 100644 --- a/go.sum +++ b/go.sum @@ -1027,8 +1027,10 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= -sigs.k8s.io/cli-utils v0.26.1-0.20211020064957-d62b5c62002d h1:yxJZ6HujyxXTLuHuZ8/HkzWy6g+eTpslhUzAzPpA9dE= -sigs.k8s.io/cli-utils v0.26.1-0.20211020064957-d62b5c62002d/go.mod h1:8ll2fyx+bzjbwmwUnKBQU+2LDbMDsxy44DiDZ+drALg= +sigs.k8s.io/cli-utils v0.26.1-0.20211111225114-39f77432ba99 h1:XXjbg+pG8zO2oWcH/UtF2wJwEpy6sYOkPOAaIR1N4qM= +sigs.k8s.io/cli-utils v0.26.1-0.20211111225114-39f77432ba99/go.mod h1:8ll2fyx+bzjbwmwUnKBQU+2LDbMDsxy44DiDZ+drALg= +sigs.k8s.io/cli-utils v0.26.1-0.20211207234511-5b83428a278a h1:zsrX4zkditxqJHXxZINpBrazDhWoLMqZwqRk0hRgkGM= +sigs.k8s.io/cli-utils v0.26.1-0.20211207234511-5b83428a278a/go.mod h1:8ll2fyx+bzjbwmwUnKBQU+2LDbMDsxy44DiDZ+drALg= sigs.k8s.io/controller-runtime v0.10.1 h1:+eLHgY/VrJWnfg6iXUqhCUqNXgPH1NZeP9drNAAgWlg= sigs.k8s.io/controller-runtime v0.10.1/go.mod h1:CQp8eyUQZ/Q7PJvnIrB6/hgfTC1kBkGylwsLgOQi1WY= sigs.k8s.io/kustomize/api v0.8.11 h1:LzQzlq6Z023b+mBtc6v72N2mSHYmN8x7ssgbf/hv0H8= diff --git a/internal/cmdapply/cmdapply.go b/internal/cmdapply/cmdapply.go index ffc4ff9d26..733469f1c7 100644 --- a/internal/cmdapply/cmdapply.go +++ b/internal/cmdapply/cmdapply.go @@ -35,7 +35,6 @@ import ( "sigs.k8s.io/cli-utils/pkg/apply" "sigs.k8s.io/cli-utils/pkg/common" "sigs.k8s.io/cli-utils/pkg/inventory" - status "sigs.k8s.io/cli-utils/pkg/util/factory" ) // NewRunner returns a command runner @@ -208,25 +207,19 @@ func runApply(r *Runner, invInfo inventory.InventoryInfo, objs []*unstructured.U // Run the applier. It will return a channel where we can receive updates // to keep track of progress and any issues. - poller, err := status.NewStatusPoller(r.factory) - if err != nil { - return err - } invClient, err := inventory.NewInventoryClient(r.factory, live.WrapInventoryObj, live.InvToUnstructuredFunc) if err != nil { return err } - applier, err := apply.NewApplier(r.factory, invClient, poller) + applier, err := apply.NewApplier(r.factory, invClient) if err != nil { return err } ch := applier.Run(r.ctx, invInfo, objs, apply.Options{ - ServerSideOptions: r.serverSideOptions, - PollInterval: r.period, - ReconcileTimeout: r.reconcileTimeout, - // If we are not waiting for status, tell the applier to not - // emit the events. - EmitStatusEvents: r.reconcileTimeout != time.Duration(0) || r.pruneTimeout != time.Duration(0), + ServerSideOptions: r.serverSideOptions, + PollInterval: r.period, + ReconcileTimeout: r.reconcileTimeout, + EmitStatusEvents: true, // We are always waiting for reconcile. DryRunStrategy: dryRunStrategy, PrunePropagationPolicy: r.prunePropPolicy, PruneTimeout: r.pruneTimeout, diff --git a/internal/cmddestroy/cmddestroy.go b/internal/cmddestroy/cmddestroy.go index 5ae7930e17..f658860e7f 100644 --- a/internal/cmddestroy/cmddestroy.go +++ b/internal/cmddestroy/cmddestroy.go @@ -31,7 +31,6 @@ import ( "sigs.k8s.io/cli-utils/pkg/apply" "sigs.k8s.io/cli-utils/pkg/common" "sigs.k8s.io/cli-utils/pkg/inventory" - status "sigs.k8s.io/cli-utils/pkg/util/factory" ) func NewRunner(ctx context.Context, factory util.Factory, @@ -154,21 +153,18 @@ func (r *Runner) runE(c *cobra.Command, args []string) error { func runDestroy(r *Runner, inv inventory.InventoryInfo, dryRunStrategy common.DryRunStrategy) error { // Run the destroyer. It will return a channel where we can receive updates // to keep track of progress and any issues. - poller, err := status.NewStatusPoller(r.factory) - if err != nil { - return err - } invClient, err := inventory.NewInventoryClient(r.factory, live.WrapInventoryObj, live.InvToUnstructuredFunc) if err != nil { return err } - destroyer, err := apply.NewDestroyer(r.factory, invClient, poller) + destroyer, err := apply.NewDestroyer(r.factory, invClient) if err != nil { return err } options := apply.DestroyerOptions{ - InventoryPolicy: r.inventoryPolicy, - DryRunStrategy: dryRunStrategy, + InventoryPolicy: r.inventoryPolicy, + DryRunStrategy: dryRunStrategy, + EmitStatusEvents: true, } ch := destroyer.Run(context.Background(), inv, options) diff --git a/internal/cmdmigrate/migratecmd.go b/internal/cmdmigrate/migratecmd.go index ff06693d70..51981dbf9f 100644 --- a/internal/cmdmigrate/migratecmd.go +++ b/internal/cmdmigrate/migratecmd.go @@ -231,16 +231,18 @@ func (mr *MigrateRunner) retrieveConfigMapInv(reader io.Reader, args []string) ( if err != nil { return nil, err } - cmInv, _, err := mr.cmLoader.InventoryInfo(objs) + cmInvObj, _, err := inventory.SplitUnstructureds(objs) if err != nil { + return nil, err + } + if cmInvObj == nil { // No ConfigMap inventory means the migration has already run before. - if _, ok := err.(inventory.NoInventoryObjError); ok { //nolint - fmt.Fprintln(mr.ioStreams.Out, "no ConfigMap inventory...completed") - } - } else { - fmt.Fprintf(mr.ioStreams.Out, "success (inventory-id: %s)\n", cmInv.ID()) + fmt.Fprintln(mr.ioStreams.Out, "no ConfigMap inventory...completed") + return nil, inventory.NoInventoryObjError{} } - return cmInv, err + cmInv := inventory.WrapInventoryInfoObj(cmInvObj) + fmt.Fprintf(mr.ioStreams.Out, "success (inventory-id: %s)\n", cmInv.ID()) + return cmInv, nil } // retrieveInvObjs returns the object references from the passed diff --git a/internal/errors/resolver/live.go b/internal/errors/resolver/live.go index 00f42ff892..8e61fffe72 100644 --- a/internal/errors/resolver/live.go +++ b/internal/errors/resolver/live.go @@ -19,7 +19,6 @@ import ( "github.com/GoogleContainerTools/kpt/internal/cmdutil" "github.com/GoogleContainerTools/kpt/internal/errors" "github.com/GoogleContainerTools/kpt/pkg/live" - "sigs.k8s.io/cli-utils/pkg/apply/taskrunner" "sigs.k8s.io/cli-utils/pkg/inventory" "sigs.k8s.io/cli-utils/pkg/manifestreader" ) @@ -42,14 +41,6 @@ package or automatically deleting omitted resources (pruning). Error: Package has multiple inventory object templates. The package should have one and only one inventory object template. -` - //nolint:lll - timeoutErrorMsg = ` -Error: Timeout after {{printf "%.0f" .err.Timeout.Seconds}} seconds waiting for {{printf "%d" (len .err.TimedOutResources)}} out of {{printf "%d" (len .err.Identifiers)}} resources to reach condition {{ .err.Condition}}:{{ printf "\n" }} - -{{- range .err.TimedOutResources}} -{{printf "%s/%s %s %s" .Identifier.GroupKind.Kind .Identifier.Name .Status .Message }} -{{- end}} ` resourceGroupCRDInstallErrorMsg = ` @@ -92,8 +83,6 @@ Resource types: {{ printf "%s" .String }} {{- end}} ` - - TimeoutErrorExitCode = 3 ) // liveErrorResolver is an implementation of the ErrorResolver interface @@ -119,16 +108,6 @@ func (*liveErrorResolver) Resolve(err error) (ResolvedResult, bool) { }, true } - var timeoutError *taskrunner.TimeoutError - if errors.As(err, &timeoutError) { - return ResolvedResult{ - Message: ExecuteTemplate(timeoutErrorMsg, map[string]interface{}{ - "err": *timeoutError, - }), - ExitCode: TimeoutErrorExitCode, - }, true - } - var resourceGroupCRDInstallError *cmdutil.ResourceGroupCRDInstallError if errors.As(err, &resourceGroupCRDInstallError) { return ResolvedResult{ diff --git a/internal/errors/resolver/live_test.go b/internal/errors/resolver/live_test.go index 08164610df..08b6c641e4 100644 --- a/internal/errors/resolver/live_test.go +++ b/internal/errors/resolver/live_test.go @@ -17,59 +17,15 @@ package resolver import ( "strings" "testing" - "time" - "github.com/GoogleContainerTools/kpt/internal/errors" "github.com/stretchr/testify/assert" - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/cli-utils/pkg/apply/taskrunner" - "sigs.k8s.io/cli-utils/pkg/kstatus/status" - "sigs.k8s.io/cli-utils/pkg/object" ) func TestLiveErrorResolver(t *testing.T) { testCases := map[string]struct { err error expected string - }{ - "nested timeoutError": { - err: &errors.Error{ - Err: &taskrunner.TimeoutError{ - Identifiers: []object.ObjMetadata{ - { - GroupKind: schema.GroupKind{ - Group: "apps", - Kind: "Deployment", - }, - Name: "test", - Namespace: "test-ns", - }, - }, - Condition: taskrunner.AllCurrent, - Timeout: 3 * time.Second, - TimedOutResources: []taskrunner.TimedOutResource{ - { - Identifier: object.ObjMetadata{ - GroupKind: schema.GroupKind{ - Group: "apps", - Kind: "Deployment", - }, - Name: "test", - Namespace: "test-ns", - }, - Status: status.InProgressStatus, - Message: "this is a test", - }, - }, - }, - }, - expected: ` -Error: Timeout after 3 seconds waiting for 1 out of 1 resources to reach condition AllCurrent: - -Deployment/test InProgress this is a test -`, - }, - } + }{} for tn, tc := range testCases { t.Run(tn, func(t *testing.T) { diff --git a/pkg/live/apply-crd-task.go b/pkg/live/apply-crd-task.go index 2a1399ea74..e9c05c5f15 100644 --- a/pkg/live/apply-crd-task.go +++ b/pkg/live/apply-crd-task.go @@ -89,4 +89,6 @@ func (a *ApplyCRDTask) Start(taskContext *taskrunner.TaskContext) { }() } -func (a *ApplyCRDTask) ClearTimeout() {} +func (a *ApplyCRDTask) Cancel(_ *taskrunner.TaskContext) {} + +func (a *ApplyCRDTask) StatusUpdate(_ *taskrunner.TaskContext, _ object.ObjMetadata) {} diff --git a/pkg/live/rgpath_test.go b/pkg/live/rgpath_test.go index 2e529e00cc..efb5fc1c6d 100644 --- a/pkg/live/rgpath_test.go +++ b/pkg/live/rgpath_test.go @@ -151,7 +151,7 @@ func TestPathManifestReader_Read(t *testing.T) { "cr.yaml": cr, }, namespace: "test-namespace", - expectedErrMsg: "unknown resource types: Custom.custom.io", + expectedErrMsg: "unknown resource types: custom.io/v1/Custom", }, "local-config is filtered out": { manifests: map[string]string{ diff --git a/pkg/live/rgstream_test.go b/pkg/live/rgstream_test.go index 15ddf9ad6c..32c3ecbce6 100644 --- a/pkg/live/rgstream_test.go +++ b/pkg/live/rgstream_test.go @@ -99,7 +99,7 @@ func TestResourceStreamManifestReader_Read(t *testing.T) { "cr.yaml": cr, }, namespace: "test-namespace", - expectedErrMsg: "unknown resource types: Custom.custom.io", + expectedErrMsg: "unknown resource types: custom.io/v1/Custom", }, }