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 Jan 10, 2022
1 parent 26d9fd4 commit 8f14756
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 107 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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.20220108032703-d7d63f4b6289
sigs.k8s.io/kustomize/api v0.8.11
sigs.k8s.io/kustomize/kyaml v0.13.1-0.20211203194734-cd2c6a1ad117
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,8 @@ 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.20220108032703-d7d63f4b6289 h1:4kv1Ge3sdzNPT96uRa5zU+vNczErzkoQYanbQmRgn60=
sigs.k8s.io/cli-utils v0.26.1-0.20220108032703-d7d63f4b6289/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
6 changes: 3 additions & 3 deletions internal/cmdmigrate/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ func TestKptMigrate_migrateObjs(t *testing.T) {
},
"One migrate object is valid": {
invObj: kptfileStr,
objs: []object.ObjMetadata{object.UnstructuredToObjMetaOrDie(pod1)},
objs: []object.ObjMetadata{object.UnstructuredToObjMetadata(pod1)},
isError: false,
},
"Multiple migrate objects are valid": {
invObj: kptfileStr,
objs: []object.ObjMetadata{
object.UnstructuredToObjMetaOrDie(pod1),
object.UnstructuredToObjMetaOrDie(pod2),
object.UnstructuredToObjMetadata(pod1),
object.UnstructuredToObjMetadata(pod2),
},
isError: false,
},
Expand Down
25 changes: 2 additions & 23 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 @@ -85,15 +76,13 @@ Details:
`

unknownTypesMsg = `
Error: {{ printf "%d" (len .err.GroupKinds) }} resource types could not be found in the cluster or as CRDs among the applied resources.
Error: {{ printf "%d" (len .err.GroupVersionKinds) }} resource types could not be found in the cluster or as CRDs among the applied resources.
Resource types:
{{- range .err.GroupKinds}}
{{- range .err.GroupVersionKinds}}
{{ 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
39 changes: 9 additions & 30 deletions internal/errors/resolver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ 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"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
)

func TestLiveErrorResolver(t *testing.T) {
Expand All @@ -34,39 +31,21 @@ func TestLiveErrorResolver(t *testing.T) {
}{
"nested timeoutError": {
err: &errors.Error{
Err: &taskrunner.TimeoutError{
Identifiers: []object.ObjMetadata{
Err: &manifestreader.UnknownTypesError{
GroupVersionKinds: []schema.GroupVersionKind{
{
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",
Group: "apps",
Version: "v1",
Kind: "Deployment",
},
},
},
},
expected: `
Error: Timeout after 3 seconds waiting for 1 out of 1 resources to reach condition AllCurrent:
Error: 1 resource types could not be found in the cluster or as CRDs among the applied resources.
Deployment/test InProgress this is a test
Resource types:
apps/v1, Kind=Deployment
`,
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/util/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func FetchFunctionImages() []string {
}

// fnName -> v<major>.<minor> -> catalogEntry
type catalogV2 map[string]map[string]struct{
type catalogV2 map[string]map[string]struct {
LatestPatchVersion string
Examples interface{}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/live/apply-crd-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (a *ApplyCRDTask) Action() event.ResourceAction {
}

func (a *ApplyCRDTask) Identifiers() object.ObjMetadataSet {
return object.UnstructuredsToObjMetasOrDie([]*unstructured.Unstructured{a.crd})
return object.UnstructuredSetToObjMetadataSet([]*unstructured.Unstructured{a.crd})
}

// NewApplyCRDTask returns a pointer to an ApplyCRDTask struct,
Expand Down 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) {}
14 changes: 8 additions & 6 deletions pkg/live/inventoryrg.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
"sigs.k8s.io/cli-utils/pkg/object"
utilfactory "sigs.k8s.io/cli-utils/pkg/util/factory"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -149,9 +150,10 @@ func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) {
Kind: strings.TrimSpace(kind),
}
klog.V(4).Infof("creating obj metadata: %s/%s/%s", namespace, name, groupKind)
objMeta, err := object.CreateObjMetadata(namespace, name, groupKind)
if err != nil {
return []object.ObjMetadata{}, err
objMeta := object.ObjMetadata{
GroupKind: groupKind,
Name: name,
Namespace: namespace,
}
objs = append(objs, objMeta)
}
Expand Down Expand Up @@ -266,7 +268,7 @@ func InstallResourceGroupCRD(factory cmdutil.Factory) error {
}
// Create the task to apply the ResourceGroup CRD.
applyRGTask := NewApplyCRDTask(factory, crd)
objs := object.UnstructuredsToObjMetasOrDie([]*unstructured.Unstructured{crd})
objs := object.UnstructuredSetToObjMetadataSet([]*unstructured.Unstructured{crd})
// Create the tasks to apply the ResourceGroup CRD.
tasks := []taskrunner.Task{
applyRGTask,
Expand All @@ -278,7 +280,7 @@ func InstallResourceGroupCRD(factory cmdutil.Factory) error {
for _, t := range tasks {
taskQueue <- t
}
statusPoller, err := utilfactory.NewStatusPoller(factory)
statusPoller, err := polling.NewStatusPollerFromFactory(factory, []engine.StatusReader{})
if err != nil {
handleError(eventChannel, err)
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/live/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLoad_LocalDisk(t *testing.T) {
testCases := map[string]struct {
pkg *pkgbuilder.RootPkg
namespace string
expectedObjs []object.ObjMetadata
expectedObjs object.ObjMetadataSet
expectedInv kptfile.Inventory
expectedErrMsg string
}{
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestLoad_LocalDisk(t *testing.T) {
}
assert.NoError(t, err)

objMetas := object.UnstructuredsToObjMetasOrDie(objs)
objMetas := object.UnstructuredSetToObjMetadataSet(objs)
sort.Slice(objMetas, func(i, j int) bool {
return objMetas[i].String() < objMetas[j].String()
})
Expand All @@ -199,7 +199,7 @@ func TestLoad_StdIn(t *testing.T) {
testCases := map[string]struct {
pkg *pkgbuilder.RootPkg
namespace string
expectedObjs []object.ObjMetadata
expectedObjs object.ObjMetadataSet
expectedInv kptfile.Inventory
expectedErrMsg string
}{
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestLoad_StdIn(t *testing.T) {
}
assert.NoError(t, err)

objMetas := object.UnstructuredsToObjMetasOrDie(objs)
objMetas := object.UnstructuredSetToObjMetadataSet(objs)
sort.Slice(objMetas, func(i, j int) bool {
return objMetas[i].String() < objMetas[j].String()
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/live/rgpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPathManifestReader_Read(t *testing.T) {
testCases := map[string]struct {
manifests map[string]string
namespace string
expectedObjs []object.ObjMetadata
expectedObjs object.ObjMetadataSet
expectedErrMsg string
}{
"Empty package is ok": {
Expand Down 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 Expand Up @@ -211,7 +211,7 @@ func TestPathManifestReader_Read(t *testing.T) {
}
assert.NoError(t, err)

readObjMetas := object.UnstructuredsToObjMetasOrDie(readObjs)
readObjMetas := object.UnstructuredSetToObjMetadataSet(readObjs)

sort.Slice(readObjMetas, func(i, j int) bool {
return readObjMetas[i].String() < readObjMetas[j].String()
Expand Down
Loading

0 comments on commit 8f14756

Please sign in to comment.