Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Update controller-runtime to v0.8.3 #1415

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()

if err := app.NewWebhookCommand(signals.SetupSignalHandler()).Execute(); err != nil {
if err := app.NewWebhookCommand(signals.SetupSignalHandler().Done()).Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1) //nolint:gocritic
}
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module sigs.k8s.io/kubefed

go 1.14
go 1.16

require (
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v0.3.0 // indirect
github.com/go-logr/zapr v0.2.0 // indirect
github.com/json-iterator/go v1.1.10
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
Expand All @@ -17,17 +15,19 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.16.0 // indirect
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
k8s.io/api v0.20.2
k8s.io/apiextensions-apiserver v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/apiserver v0.20.2
k8s.io/client-go v0.20.2
k8s.io/component-base v0.20.2
k8s.io/klog/v2 v2.4.0
k8s.io/klog/v2 v2.8.0
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
k8s.io/kubectl v0.20.2
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
sigs.k8s.io/controller-runtime v0.6.3
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
sigs.k8s.io/controller-runtime v0.8.3
sigs.k8s.io/yaml v1.2.0
)

replace github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.4.1
238 changes: 32 additions & 206 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/apis/core/v1beta1/kubefedcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("KubefedCluster", func() {
},
}

key, _ = client.ObjectKeyFromObject(created)
key = client.ObjectKeyFromObject(created)

By("creating an API obj")
Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
Expand Down Expand Up @@ -78,7 +78,7 @@ var _ = Describe("KubefedCluster", func() {
},
}

key, _ = client.ObjectKeyFromObject(created)
key = client.ObjectKeyFromObject(created)

By("creating an API obj")
Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
Expand Down
5 changes: 1 addition & 4 deletions pkg/apis/core/v1beta1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.New(func(o *zap.Options) {
o.Development = true
o.DestWritter = GinkgoWriter
}))
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Expand Down
39 changes: 19 additions & 20 deletions pkg/client/generic/genericclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,28 @@ import (
"context"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/kubefed/pkg/client/generic/scheme"
)

type Client interface {
Create(ctx context.Context, obj runtime.Object) error
Get(ctx context.Context, obj runtime.Object, namespace, name string) error
Update(ctx context.Context, obj runtime.Object) error
Delete(ctx context.Context, obj runtime.Object, namespace, name string, opts ...client.DeleteOption) error
List(ctx context.Context, obj runtime.Object, namespace string, opts ...client.ListOption) error
UpdateStatus(ctx context.Context, obj runtime.Object) error
Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) error
Create(ctx context.Context, obj runtimeclient.Object) error
Get(ctx context.Context, obj runtimeclient.Object, namespace, name string) error
Update(ctx context.Context, obj runtimeclient.Object) error
Delete(ctx context.Context, obj runtimeclient.Object, namespace, name string, opts ...runtimeclient.DeleteOption) error
List(ctx context.Context, obj runtimeclient.ObjectList, namespace string, opts ...runtimeclient.ListOption) error
UpdateStatus(ctx context.Context, obj runtimeclient.Object) error
Patch(ctx context.Context, obj runtimeclient.Object, patch runtimeclient.Patch, opts ...runtimeclient.PatchOption) error
}

type genericClient struct {
client client.Client
client runtimeclient.Client
}

func New(config *rest.Config) (Client, error) {
client, err := client.New(config, client.Options{Scheme: scheme.Scheme})
client, err := runtimeclient.New(config, runtimeclient.Options{Scheme: scheme.Scheme})
return &genericClient{client}, err
}

Expand All @@ -60,19 +59,19 @@ func NewForConfigOrDieWithUserAgent(config *rest.Config, userAgent string) Clien
return NewForConfigOrDie(configCopy)
}

func (c *genericClient) Create(ctx context.Context, obj runtime.Object) error {
func (c *genericClient) Create(ctx context.Context, obj runtimeclient.Object) error {
return c.client.Create(ctx, obj)
}

func (c *genericClient) Get(ctx context.Context, obj runtime.Object, namespace, name string) error {
return c.client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, obj)
func (c *genericClient) Get(ctx context.Context, obj runtimeclient.Object, namespace, name string) error {
return c.client.Get(ctx, runtimeclient.ObjectKey{Namespace: namespace, Name: name}, obj)
}

func (c *genericClient) Update(ctx context.Context, obj runtime.Object) error {
func (c *genericClient) Update(ctx context.Context, obj runtimeclient.Object) error {
return c.client.Update(ctx, obj)
}

func (c *genericClient) Delete(ctx context.Context, obj runtime.Object, namespace, name string, opts ...client.DeleteOption) error {
func (c *genericClient) Delete(ctx context.Context, obj runtimeclient.Object, namespace, name string, opts ...runtimeclient.DeleteOption) error {
accessor, err := meta.Accessor(obj)
if err != nil {
return err
Expand All @@ -82,15 +81,15 @@ func (c *genericClient) Delete(ctx context.Context, obj runtime.Object, namespac
return c.client.Delete(ctx, obj, opts...)
}

func (c *genericClient) List(ctx context.Context, obj runtime.Object, namespace string, opts ...client.ListOption) error {
opts = append(opts, client.InNamespace(namespace))
func (c *genericClient) List(ctx context.Context, obj runtimeclient.ObjectList, namespace string, opts ...runtimeclient.ListOption) error {
opts = append(opts, runtimeclient.InNamespace(namespace))
return c.client.List(ctx, obj, opts...)
}

func (c *genericClient) UpdateStatus(ctx context.Context, obj runtime.Object) error {
func (c *genericClient) UpdateStatus(ctx context.Context, obj runtimeclient.Object) error {
return c.client.Status().Update(ctx, obj)
}

func (c *genericClient) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOption) error {
func (c *genericClient) Patch(ctx context.Context, obj runtimeclient.Object, patch runtimeclient.Patch, opts ...runtimeclient.PatchOption) error {
return c.client.Patch(ctx, obj, patch, opts...)
}
11 changes: 5 additions & 6 deletions pkg/controller/federatedtypeconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/runtime"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

corev1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -273,7 +272,7 @@ func (c *Controller) reconcile(qualifiedName util.QualifiedName) util.Reconcilia
return util.StatusAllOK
}

func (c *Controller) objCopyFromCache(key string) (pkgruntime.Object, error) {
func (c *Controller) objCopyFromCache(key string) (runtimeclient.Object, error) {
cachedObj, exist, err := c.store.GetByKey(key)
if err != nil {
wrappedErr := errors.Wrapf(err, "Failed to query FederatedTypeConfig store for %q", key)
Expand All @@ -283,7 +282,7 @@ func (c *Controller) objCopyFromCache(key string) (pkgruntime.Object, error) {
if !exist {
return nil, nil
}
return cachedObj.(pkgruntime.Object).DeepCopyObject(), nil
return cachedObj.(runtimeclient.Object).DeepCopyObject().(runtimeclient.Object), nil
}

func (c *Controller) shutDown() {
Expand Down Expand Up @@ -380,7 +379,7 @@ func (c *Controller) ensureFinalizer(tc *corev1b1.FederatedTypeConfig) (bool, er
return false, nil
}

patch := client.MergeFrom(tc.DeepCopy())
patch := runtimeclient.MergeFrom(tc.DeepCopy())
controllerutil.AddFinalizer(tc, finalizer)
return true, c.client.Patch(context.TODO(), tc, patch)
}
Expand All @@ -390,7 +389,7 @@ func (c *Controller) removeFinalizer(tc *corev1b1.FederatedTypeConfig) error {
return nil
}

patch := client.MergeFrom(tc.DeepCopy())
patch := runtimeclient.MergeFrom(tc.DeepCopy())
controllerutil.RemoveFinalizer(tc, finalizer)
return c.client.Patch(context.TODO(), tc, patch)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/kubefedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
kubeclient "k8s.io/client-go/kubernetes"
Expand All @@ -34,6 +33,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1"
genericclient "sigs.k8s.io/kubefed/pkg/client/generic"
Expand Down Expand Up @@ -260,7 +260,7 @@ func (cc *ClusterController) updateIndividualClusterStatus(cluster *fedv1b1.Kube
wg.Done()
}

func (cc *ClusterController) RecordError(cluster runtime.Object, errorCode string, err error) {
func (cc *ClusterController) RecordError(cluster runtimeclient.Object, errorCode string, err error) {
cc.eventRecorder.Eventf(cluster, corev1.EventTypeWarning, errorCode, err.Error())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var stopControllerCh chan struct{}
var config *util.ClusterHealthCheckConfig

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

testenv = &envtest.Environment{
CRDDirectoryPaths: []string{
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/schedulingpreference/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"time"

"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/runtime"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand All @@ -33,6 +31,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1"
"sigs.k8s.io/kubefed/pkg/controller/util"
Expand Down Expand Up @@ -113,7 +112,7 @@ func newSchedulingPreferenceController(config *util.ControllerConfig, scheduling

eventHandlers := schedulingtypes.SchedulerEventHandlers{
KubeFedEventHandler: s.worker.EnqueueObject,
ClusterEventHandler: func(obj pkgruntime.Object) {
ClusterEventHandler: func(obj runtimeclient.Object) {
qualifiedName := util.NewQualifiedName(obj)
s.worker.EnqueueForRetry(qualifiedName)
},
Expand Down Expand Up @@ -189,7 +188,7 @@ func (s *SchedulingPreferenceController) reconcileOnClusterChange() {
s.clusterDeliverer.DeliverAt(allClustersKey, nil, time.Now().Add(s.clusterAvailableDelay))
}
for _, obj := range s.store.List() {
qualifiedName := util.NewQualifiedName(obj.(pkgruntime.Object))
qualifiedName := util.NewQualifiedName(obj.(runtimeclient.Object))
s.worker.EnqueueWithDelay(qualifiedName, s.smallDelay)
}
}
Expand Down Expand Up @@ -222,7 +221,7 @@ func (s *SchedulingPreferenceController) reconcile(qualifiedName util.QualifiedN
return s.scheduler.Reconcile(obj, qualifiedName)
}

func (s *SchedulingPreferenceController) objFromCache(store cache.Store, kind, key string) (pkgruntime.Object, error) {
func (s *SchedulingPreferenceController) objFromCache(store cache.Store, kind, key string) (runtimeclient.Object, error) {
cachedObj, exist, err := store.GetByKey(key)
if err != nil {
wrappedErr := errors.Wrapf(err, "Failed to query store while reconciling RSP controller, triggered by %s named %q", kind, key)
Expand All @@ -232,5 +231,5 @@ func (s *SchedulingPreferenceController) objFromCache(store cache.Store, kind, k
if !exist {
return nil, nil
}
return cachedObj.(pkgruntime.Object).DeepCopyObject(), nil
return cachedObj.(runtimeclient.Object).DeepCopyObject().(runtimeclient.Object), nil
}
11 changes: 5 additions & 6 deletions pkg/controller/status/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import (
"time"

"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/kubefed/pkg/apis/core/typeconfig"
fedv1b1 "sigs.k8s.io/kubefed/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -147,7 +146,7 @@ func newKubeFedStatusController(controllerConfig *util.ControllerConfig, typeCon
controllerConfig,
client,
&targetAPIResource,
func(obj pkgruntime.Object) {
func(obj runtimeclient.Object) {
qualifiedName := util.NewQualifiedName(obj)
s.worker.EnqueueForRetry(qualifiedName)
},
Expand Down Expand Up @@ -229,7 +228,7 @@ func (s *KubeFedStatusController) reconcileOnClusterChange() {
s.clusterDeliverer.DeliverAt(allClustersKey, nil, time.Now().Add(s.clusterAvailableDelay))
}
for _, obj := range s.federatedStore.List() {
qualifiedName := util.NewQualifiedName(obj.(pkgruntime.Object))
qualifiedName := util.NewQualifiedName(obj.(runtimeclient.Object))
s.worker.EnqueueWithDelay(qualifiedName, s.smallDelay)
}
}
Expand Down Expand Up @@ -326,7 +325,7 @@ func (s *KubeFedStatusController) reconcile(qualifiedName util.QualifiedName) ut
return util.StatusAllOK
}

func (s *KubeFedStatusController) rawObjFromCache(store cache.Store, kind, key string) (pkgruntime.Object, error) {
func (s *KubeFedStatusController) rawObjFromCache(store cache.Store, kind, key string) (runtimeclient.Object, error) {
cachedObj, exist, err := store.GetByKey(key)
if err != nil {
wrappedErr := errors.Wrapf(err, "Failed to query %s store for %q", kind, key)
Expand All @@ -336,7 +335,7 @@ func (s *KubeFedStatusController) rawObjFromCache(store cache.Store, kind, key s
if !exist {
return nil, nil
}
return cachedObj.(pkgruntime.Object).DeepCopyObject(), nil
return cachedObj.(runtimeclient.Object).DeepCopyObject().(runtimeclient.Object), nil
}

func (s *KubeFedStatusController) objFromCache(store cache.Store, kind, key string) (*unstructured.Unstructured, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/sync/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package sync
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -77,7 +77,7 @@ func NewFederatedResourceAccessor(
typeConfig typeconfig.Interface,
fedNamespaceAPIResource *metav1.APIResource,
client genericclient.Client,
enqueueObj func(pkgruntime.Object),
enqueueObj func(runtimeclient.Object),
eventRecorder record.EventRecorder) (FederatedResourceAccessor, error) {
a := &resourceAccessor{
limitedScope: controllerConfig.LimitedScope(),
Expand Down Expand Up @@ -110,7 +110,7 @@ func NewFederatedResourceAccessor(
}

if typeConfig.GetNamespaced() {
fedNamespaceEnqueue := func(fedNamespaceObj pkgruntime.Object) {
fedNamespaceEnqueue := func(fedNamespaceObj runtimeclient.Object) {
// When a federated namespace changes, every resource in
// the namespace needs to be reconciled.
//
Expand All @@ -119,7 +119,7 @@ func NewFederatedResourceAccessor(
// placement for the federated namespace.
namespace := util.NewQualifiedName(fedNamespaceObj).Namespace
for _, rawObj := range a.federatedStore.List() {
obj := rawObj.(pkgruntime.Object)
obj := rawObj.(runtimeclient.Object)
qualifiedName := util.NewQualifiedName(obj)
if qualifiedName.Namespace == namespace {
enqueueObj(obj)
Expand Down
Loading