Skip to content

Commit

Permalink
Update sigs.k8s.io/cli-utils to v0.27.0
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Jan 13, 2022
1 parent 66a8285 commit 22005fa
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 301 deletions.
24 changes: 20 additions & 4 deletions ssa/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,56 @@ go 1.17

require (
github.com/google/go-cmp v0.5.6
k8s.io/api v0.23.0
k8s.io/apimachinery v0.23.0
sigs.k8s.io/cli-utils v0.26.1
k8s.io/api v0.23.1
k8s.io/apimachinery v0.23.1
sigs.k8s.io/cli-utils v0.27.0
sigs.k8s.io/controller-runtime v0.11.0
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/spf13/cobra v1.2.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
Expand All @@ -53,8 +67,10 @@ require (
k8s.io/apiextensions-apiserver v0.23.0 // indirect
k8s.io/cli-runtime v0.23.0 // indirect
k8s.io/client-go v0.23.0 // indirect
k8s.io/component-base v0.23.0 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/kubectl v0.22.2 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/kustomize/api v0.10.1 // indirect
Expand Down
297 changes: 39 additions & 258 deletions ssa/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ssa/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
panic(err)
}

poller := polling.NewStatusPoller(kubeClient, restMapper)
poller := polling.NewStatusPoller(kubeClient, restMapper, nil)

manager = &ResourceManager{
client: kubeClient,
Expand Down
2 changes: 1 addition & 1 deletion ssa/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m *ResourceManager) GetOwnerLabels(name, namespace string) map[string]stri

func (m *ResourceManager) changeSetEntry(o *unstructured.Unstructured, action Action) *ChangeSetEntry {
return &ChangeSetEntry{
ObjMetadata: object.UnstructuredToObjMetaOrDie(o),
ObjMetadata: object.UnstructuredToObjMetadata(o),
GroupVersion: o.GroupVersionKind().Version,
Subject: FmtUnstructured(o),
Action: string(action),
Expand Down
22 changes: 1 addition & 21 deletions ssa/manager_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sort"
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -62,30 +60,12 @@ type ApplyCleanupOptions struct {
FieldManagers []FiledManager `json:"fieldManagers,omitempty"`
}

// DefaultApplyOptions returns the default apply options where force apply is disabled and the
// kubectl annotation, client-side and server-side field managers are removed from in-cluster objects.
// DefaultApplyOptions returns the default apply options where force apply is disabled.
func DefaultApplyOptions() ApplyOptions {
return ApplyOptions{
Force: false,
Exclusions: nil,
WaitTimeout: 60 * time.Second,
Cleanup: ApplyCleanupOptions{
Annotations: []string{corev1.LastAppliedConfigAnnotation},
FieldManagers: []FiledManager{
{
Name: "kubectl",
OperationType: metav1.ManagedFieldsOperationApply,
},
{
Name: "kubectl",
OperationType: metav1.ManagedFieldsOperationUpdate,
},
{
Name: "before-first-apply",
OperationType: metav1.ManagedFieldsOperationUpdate,
},
},
},
}
}

Expand Down
33 changes: 26 additions & 7 deletions ssa/manager_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (
"context"
"encoding/base64"
"fmt"
corev1 "k8s.io/api/core/v1"
"sort"
"testing"
"time"

"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -412,12 +413,31 @@ func TestApply_Exclusions(t *testing.T) {
})
}

func TestApply_ManagedFields(t *testing.T) {
func TestApply_Cleanup(t *testing.T) {
timeout := 10 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

id := generateName("fix")
applyOpts := DefaultApplyOptions()
applyOpts.Cleanup = ApplyCleanupOptions{
Annotations: []string{corev1.LastAppliedConfigAnnotation},
FieldManagers: []FiledManager{
{
Name: "kubectl",
OperationType: metav1.ManagedFieldsOperationApply,
},
{
Name: "kubectl",
OperationType: metav1.ManagedFieldsOperationUpdate,
},
{
Name: "before-first-apply",
OperationType: metav1.ManagedFieldsOperationUpdate,
},
},
}

id := generateName("cleanup")
objects, err := readManifest("testdata/test2.yaml", id)
if err != nil {
t.Fatal(err)
Expand All @@ -444,9 +464,8 @@ func TestApply_ManagedFields(t *testing.T) {
})

t.Run("removes kubectl client-side-apply manager and annotation", func(t *testing.T) {
opts := DefaultApplyOptions()
opts.Cleanup.Labels = []string{corev1.LastAppliedConfigAnnotation}
changeSet, err := manager.ApplyAllStaged(ctx, objects, opts)
applyOpts.Cleanup.Labels = []string{corev1.LastAppliedConfigAnnotation}
changeSet, err := manager.ApplyAllStaged(ctx, objects, applyOpts)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -494,7 +513,7 @@ func TestApply_ManagedFields(t *testing.T) {
t.Fatal(err)
}

changeSet, err := manager.ApplyAll(ctx, objects, DefaultApplyOptions())
changeSet, err := manager.ApplyAll(ctx, objects, applyOpts)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 1 addition & 5 deletions ssa/manager_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func DefaultWaitOptions() WaitOptions {

// Wait checks if the given set of objects has been fully reconciled.
func (m *ResourceManager) Wait(objects []*unstructured.Unstructured, opts WaitOptions) error {
objectsMeta, err := object.UnstructuredsToObjMetas(objects)
if err != nil {
return err
}

objectsMeta := object.UnstructuredSetToObjMetadataSet(objects)
if len(objectsMeta) == 0 {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions ssa/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ var _ sort.Interface = SortableUnstructureds{}
func (a SortableUnstructureds) Len() int { return len(a) }
func (a SortableUnstructureds) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortableUnstructureds) Less(i, j int) bool {
first := object.UnstructuredToObjMetaOrDie(a[i])
second := object.UnstructuredToObjMetaOrDie(a[j])
first := object.UnstructuredToObjMetadata(a[i])
second := object.UnstructuredToObjMetadata(a[j])
return less(first, second)
}

Expand Down
4 changes: 2 additions & 2 deletions ssa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func FmtObjMetadata(obj object.ObjMetadata) string {

// FmtUnstructured returns the object ID in the format <kind>/<namespace>/<name>.
func FmtUnstructured(obj *unstructured.Unstructured) string {
return FmtObjMetadata(object.UnstructuredToObjMetaOrDie(obj))
return FmtObjMetadata(object.UnstructuredToObjMetadata(obj))
}

// FmtUnstructuredList returns a line per object in the format <kind>/<namespace>/<name>.
func FmtUnstructuredList(objects []*unstructured.Unstructured) string {
var b strings.Builder
for _, obj := range objects {
b.WriteString(FmtObjMetadata(object.UnstructuredToObjMetaOrDie(obj)) + "\n")
b.WriteString(FmtObjMetadata(object.UnstructuredToObjMetadata(obj)) + "\n")
}
return strings.TrimSuffix(b.String(), "\n")
}
Expand Down

0 comments on commit 22005fa

Please sign in to comment.