Skip to content

Commit

Permalink
Update cli-utils to v0.26.0 (#2550)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Oct 13, 2021
1 parent 3f23103 commit 9cd4aeb
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 25 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/klog/v2 v2.9.0
k8s.io/kubectl v0.21.1
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
sigs.k8s.io/cli-utils v0.25.1-0.20210702190410-c1a7c2d0409d
sigs.k8s.io/cli-utils v0.26.0
sigs.k8s.io/kustomize/api v0.8.10
sigs.k8s.io/kustomize/kyaml v0.11.2-0.20210920224623-c47fc4860720
)
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -566,6 +567,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spyzhov/ajson v0.4.2 h1:JMByd/jZApPKDvNsmO90X2WWGbmT2ahDFp73QhZbg3s=
github.com/spyzhov/ajson v0.4.2/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzyqMuVA=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down Expand Up @@ -769,8 +772,9 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
Expand Down Expand Up @@ -938,8 +942,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down Expand Up @@ -988,8 +993,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.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/cli-utils v0.25.1-0.20210702190410-c1a7c2d0409d h1:/JmSgB1dQKNcxbRviaIwTsoA4i0iLC9vJOsKMGSMG3w=
sigs.k8s.io/cli-utils v0.25.1-0.20210702190410-c1a7c2d0409d/go.mod h1:uYYtfiY5dsWTRISBLwuSLGwbasAm/gc4K8yvN8eGbYw=
sigs.k8s.io/cli-utils v0.26.0 h1:N1X1NVN19+daTihVimkSVNMgiVPIHG9OO3SJPh6SBQI=
sigs.k8s.io/cli-utils v0.26.0/go.mod h1:myCFn83XMe7vC1ZX5CEJJIY2cqsl6IxYI727mLW1mfE=
sigs.k8s.io/controller-runtime v0.9.0-beta.5.0.20210524185538-7181f1162e79 h1:unv8eVaIbf/1vh/ewJfHns6ffKF69fwUxZZpaxQOb7g=
sigs.k8s.io/controller-runtime v0.9.0-beta.5.0.20210524185538-7181f1162e79/go.mod h1:rgf+cBz72pYlKXDRNhI1WFQv/S86EMUV4/ySmsEYgHk=
sigs.k8s.io/kustomize/api v0.8.8/go.mod h1:He1zoK0nk43Pc6NlV085xDXDXTNprtcyKZVm3swsdNY=
Expand Down
17 changes: 11 additions & 6 deletions internal/cmdmigrate/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (mr *MigrateRunner) retrieveConfigMapInv(reader io.Reader, args []string) (
func (mr *MigrateRunner) retrieveInvObjs(cmInvClient inventory.InventoryClient,
invObj inventory.InventoryInfo) ([]object.ObjMetadata, error) {
fmt.Fprint(mr.ioStreams.Out, " retrieve ConfigMap inventory objs...")
cmObjs, err := cmInvClient.GetClusterObjs(invObj)
cmObjs, err := cmInvClient.GetClusterObjs(invObj, mr.dryRunStrategy())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func (mr *MigrateRunner) migrateObjs(rgInvClient inventory.InventoryClient,
return err
}

_, err = rgInvClient.Merge(invInfo, cmObjs)
_, err = rgInvClient.Merge(invInfo, cmObjs, mr.dryRunStrategy())
if err != nil {
return err
}
Expand All @@ -307,10 +307,7 @@ func (mr *MigrateRunner) migrateObjs(rgInvClient inventory.InventoryClient,
func (mr *MigrateRunner) deleteConfigMapInv(cmInvClient inventory.InventoryClient,
invObj inventory.InventoryInfo) error {
fmt.Fprint(mr.ioStreams.Out, " deleting old ConfigMap inventory object...")
if mr.dryRun {
cmInvClient.SetDryRunStrategy(common.DryRunClient)
}
if err := cmInvClient.DeleteInventoryObj(invObj); err != nil {
if err := cmInvClient.DeleteInventoryObj(invObj, mr.dryRunStrategy()); err != nil {
return err
}
fmt.Fprint(mr.ioStreams.Out, "success\n")
Expand Down Expand Up @@ -344,6 +341,14 @@ func (mr *MigrateRunner) deleteConfigMapFile() error {
return nil
}

// dryRunStrategy returns the strategy to use based on user config
func (mr *MigrateRunner) dryRunStrategy() common.DryRunStrategy {
if mr.dryRun {
return common.DryRunClient
}
return common.DryRunNone
}

// findResourceGroupInv returns the ResourceGroup inventory object from the
// passed slice of objects, or nil and and error if there is a problem.
func findResourceGroupInv(objs []*unstructured.Unstructured) (*unstructured.Unstructured, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmdmigrate/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestKptMigrate_migrateObjs(t *testing.T) {
}
assert.NoError(t, err)
// Retrieve the objects stored by the inventory client and validate.
migratedObjs, err := rgInvClient.GetClusterObjs(nil)
migratedObjs, err := rgInvClient.GetClusterObjs(nil, common.DryRunNone)
assert.NoError(t, err)
if len(tc.objs) != len(migratedObjs) {
t.Errorf("expected num migrated objs (%d), got (%d)", len(tc.objs), len(migratedObjs))
Expand Down
2 changes: 1 addition & 1 deletion pkg/live/apply-crd-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (a *ApplyCRDTask) Action() event.ResourceAction {
return event.ApplyAction
}

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

Expand Down
11 changes: 7 additions & 4 deletions pkg/live/inventoryrg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/apply/cache"
"sigs.k8s.io/cli-utils/pkg/apply/event"
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/common"
Expand Down Expand Up @@ -109,8 +110,8 @@ func (icm *InventoryResourceGroup) ID() string {

// Load is an Inventory interface function returning the set of
// object metadata from the wrapped ResourceGroup, or an error.
func (icm *InventoryResourceGroup) Load() ([]object.ObjMetadata, error) {
objs := []object.ObjMetadata{}
func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) {
objs := object.ObjMetadataSet{}
if icm.inv == nil {
return objs, fmt.Errorf("inventory info is nil")
}
Expand Down Expand Up @@ -160,7 +161,7 @@ func (icm *InventoryResourceGroup) Load() ([]object.ObjMetadata, error) {
// Store is an Inventory interface function implemented to store
// the object metadata in the wrapped ResourceGroup. Actual storing
// happens in "GetObject".
func (icm *InventoryResourceGroup) Store(objMetas []object.ObjMetadata) error {
func (icm *InventoryResourceGroup) Store(objMetas object.ObjMetadataSet) error {
icm.objMetas = objMetas
return nil
}
Expand Down Expand Up @@ -282,8 +283,10 @@ func InstallResourceGroupCRD(factory cmdutil.Factory) error {
handleError(eventChannel, err)
return
}
// Create a new cache map to hold the last known resource state & status
resourceCache := cache.NewResourceCacheMap()
// Run the task queue.
runner := taskrunner.NewTaskStatusRunner(objs, statusPoller)
runner := taskrunner.NewTaskStatusRunner(objs, statusPoller, resourceCache)
err = runner.Run(context.Background(), taskQueue, eventChannel, taskrunner.Options{
PollInterval: applyCRDPollInterval,
UseCache: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/live/inventoryrg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestLoadStore(t *testing.T) {
t.Fatalf("unexpected error %v received", err)
return
}
if !object.SetEquals(tc.objs, objs) {
if !objs.Equal(tc.objs) {
t.Fatalf("expected inventory objs (%v), got (%v)", tc.objs, objs)
}
})
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This directory contains the files that are copied from 3rd-party projects and mo
- `runfn`: KRM function runner
- `cmdconfig`: Files copied from [cmd/config] v0.9.9 library
- `commands`: Command files copied from [cmd/config]
- `cli-utils`: Files copied from [cli-utils] 8200fe56434dbb4fa897912524793af3c3384828 library
- `cli-utils`: Files copied from [cli-utils] v0.26.0 library
- `commands`: Command files copied from [cli-utils/cmd]

# Copyright and Licenses
Expand All @@ -24,4 +24,4 @@ The modifications made in the 3rd-party files may be contributed to upstream. Th
[kyaml]: https://github.com/kubernetes-sigs/kustomize/tree/8d72528eb5c73df80b20aae0a5e584c056879387/kyaml
[cmd/config]: https://github.com/kubernetes-sigs/kustomize/tree/b9c36caa1c5c6ee64926021841ea441773d0767c/cmd/config
[cli-utils]: https://github.com/kubernetes-sigs/cli-utils
[cli-utils/cmd]: https://github.com/kubernetes-sigs/cli-utils/tree/8200fe56434dbb4fa897912524793af3c3384828
[cli-utils/cmd]: https://github.com/kubernetes-sigs/cli-utils/tree/8b12ecd594e0bc4fa4b85ee6af3911ff33efd2aa/cmd
2 changes: 1 addition & 1 deletion thirdparty/cli-utils/printers/events/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (ef *formatter) FormatActionGroupEvent(age event.ActionGroupEvent, ags []ev
for id, se := range c.LatestStatus() {
// Only print information about objects that we actually care about
// for this wait task.
if found := object.ObjMetas(ag.Identifiers).Contains(id); found {
if found := ag.Identifiers.Contains(id); found {
ef.printResourceStatus(id, se)
}
}
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/cli-utils/printers/json/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (jf *formatter) FormatActionGroupEvent(age event.ActionGroupEvent, ags []ev
for id, se := range c.LatestStatus() {
// Only print information about objects that we actually care about
// for this wait task.
if found := object.ObjMetas(ag.Identifiers).Contains(id); found {
if found := ag.Identifiers.Contains(id); found {
if err := jf.printResourceStatus(se); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion thirdparty/cli-utils/status/cmdstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/slice"
"sigs.k8s.io/cli-utils/pkg/apply/poller"
"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/aggregator"
Expand Down Expand Up @@ -140,7 +141,7 @@ func (r *Runner) runE(c *cobra.Command, args []string) error {

// Based on the inventory template manifest we look up the inventory
// from the live state using the inventory client.
identifiers, err := invClient.GetClusterObjs(invInfo)
identifiers, err := invClient.GetClusterObjs(invInfo, common.DryRunNone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/cli-utils/status/cmdstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ type fakePoller struct {
events []pollevent.Event
}

func (f *fakePoller) Poll(ctx context.Context, _ []object.ObjMetadata,
func (f *fakePoller) Poll(ctx context.Context, _ object.ObjMetadataSet,
_ polling.Options) <-chan pollevent.Event {
eventChannel := make(chan pollevent.Event)
go func() {
Expand Down

0 comments on commit 9cd4aeb

Please sign in to comment.