Skip to content

Commit

Permalink
Update cli-utils to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Dec 12, 2021
1 parent 3fb2497 commit dfad18a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 99 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 5 additions & 12 deletions internal/cmdapply/cmdapply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions internal/cmddestroy/cmddestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 9 additions & 7 deletions internal/cmdmigrate/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions internal/errors/resolver/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 = `
Expand Down Expand Up @@ -92,8 +83,6 @@ Resource types:
{{ printf "%s" .String }}
{{- end}}
`

TimeoutErrorExitCode = 3
)

// liveErrorResolver is an implementation of the ErrorResolver interface
Expand All @@ -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{
Expand Down
46 changes: 1 addition & 45 deletions internal/errors/resolver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/live/apply-crd-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
2 changes: 1 addition & 1 deletion pkg/live/rgpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/live/rgstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down

0 comments on commit dfad18a

Please sign in to comment.