diff --git a/mocks/pkg/types/aws_resource_descriptor.go b/mocks/pkg/types/aws_resource_descriptor.go index ad73872..9b1e9bd 100644 --- a/mocks/pkg/types/aws_resource_descriptor.go +++ b/mocks/pkg/types/aws_resource_descriptor.go @@ -8,9 +8,9 @@ import ( mock "github.com/stretchr/testify/mock" - types "github.com/aws-controllers-k8s/runtime/pkg/types" + schema "k8s.io/apimachinery/pkg/runtime/schema" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "github.com/aws-controllers-k8s/runtime/pkg/types" ) // AWSResourceDescriptor is an autogenerated mock type for the AWSResourceDescriptor type @@ -50,17 +50,15 @@ func (_m *AWSResourceDescriptor) EmptyRuntimeObject() client.Object { return r0 } -// GroupKind provides a mock function with given fields: -func (_m *AWSResourceDescriptor) GroupKind() *v1.GroupKind { +// GroupVersionKind provides a mock function with given fields: +func (_m *AWSResourceDescriptor) GroupVersionKind() schema.GroupVersionKind { ret := _m.Called() - var r0 *v1.GroupKind - if rf, ok := ret.Get(0).(func() *v1.GroupKind); ok { + var r0 schema.GroupVersionKind + if rf, ok := ret.Get(0).(func() schema.GroupVersionKind); ok { r0 = rf() } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*v1.GroupKind) - } + r0 = ret.Get(0).(schema.GroupVersionKind) } return r0 diff --git a/mocks/pkg/types/aws_resource_reconciler.go b/mocks/pkg/types/aws_resource_reconciler.go index 22373bc..1a0702c 100644 --- a/mocks/pkg/types/aws_resource_reconciler.go +++ b/mocks/pkg/types/aws_resource_reconciler.go @@ -10,9 +10,9 @@ import ( reconcile "sigs.k8s.io/controller-runtime/pkg/reconcile" - types "github.com/aws-controllers-k8s/runtime/pkg/types" + schema "k8s.io/apimachinery/pkg/runtime/schema" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "github.com/aws-controllers-k8s/runtime/pkg/types" v1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" ) @@ -36,16 +36,16 @@ func (_m *AWSResourceReconciler) BindControllerManager(_a0 manager.Manager) erro return r0 } -// GroupKind provides a mock function with given fields: -func (_m *AWSResourceReconciler) GroupKind() *v1.GroupKind { +// GroupVersionKind provides a mock function with given fields: +func (_m *AWSResourceReconciler) GroupVersionKind() *schema.GroupVersionKind { ret := _m.Called() - var r0 *v1.GroupKind - if rf, ok := ret.Get(0).(func() *v1.GroupKind); ok { + var r0 *schema.GroupVersionKind + if rf, ok := ret.Get(0).(func() *schema.GroupVersionKind); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*v1.GroupKind) + r0 = ret.Get(0).(*schema.GroupVersionKind) } } diff --git a/mocks/pkg/types/field_export_reconciler.go b/mocks/pkg/types/field_export_reconciler.go index 8cfa6bb..903f84f 100644 --- a/mocks/pkg/types/field_export_reconciler.go +++ b/mocks/pkg/types/field_export_reconciler.go @@ -12,9 +12,9 @@ import ( reconcile "sigs.k8s.io/controller-runtime/pkg/reconcile" - types "github.com/aws-controllers-k8s/runtime/pkg/types" + schema "k8s.io/apimachinery/pkg/runtime/schema" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "github.com/aws-controllers-k8s/runtime/pkg/types" v1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" ) @@ -39,11 +39,11 @@ func (_m *FieldExportReconciler) BindControllerManager(_a0 manager.Manager) erro } // GetFieldExportsForResource provides a mock function with given fields: _a0, _a1, _a2 -func (_m *FieldExportReconciler) GetFieldExportsForResource(_a0 context.Context, _a1 v1.GroupKind, _a2 pkgtypes.NamespacedName) ([]v1alpha1.FieldExport, error) { +func (_m *FieldExportReconciler) GetFieldExportsForResource(_a0 context.Context, _a1 schema.GroupKind, _a2 pkgtypes.NamespacedName) ([]v1alpha1.FieldExport, error) { ret := _m.Called(_a0, _a1, _a2) var r0 []v1alpha1.FieldExport - if rf, ok := ret.Get(0).(func(context.Context, v1.GroupKind, pkgtypes.NamespacedName) []v1alpha1.FieldExport); ok { + if rf, ok := ret.Get(0).(func(context.Context, schema.GroupKind, pkgtypes.NamespacedName) []v1alpha1.FieldExport); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { @@ -52,7 +52,7 @@ func (_m *FieldExportReconciler) GetFieldExportsForResource(_a0 context.Context, } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, v1.GroupKind, pkgtypes.NamespacedName) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, schema.GroupKind, pkgtypes.NamespacedName) error); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) diff --git a/pkg/runtime/adoption_reconciler.go b/pkg/runtime/adoption_reconciler.go index c988cdc..a891ebe 100644 --- a/pkg/runtime/adoption_reconciler.go +++ b/pkg/runtime/adoption_reconciler.go @@ -89,7 +89,7 @@ func (r *adoptionReconciler) reconcile(ctx context.Context, req ctrlrt.Request) controllerRMF = v break } - if gk.Group != controllerRMF.ResourceDescriptor().GroupKind().Group { + if gk.Group != controllerRMF.ResourceDescriptor().GroupVersionKind().Group { ackrtlog.DebugAdoptedResource(r.log, res, "target resource API group is not of this service. no-op") return nil } @@ -112,11 +112,9 @@ func (r *adoptionReconciler) reconcile(ctx context.Context, req ctrlrt.Request) region := r.getRegion(res) roleARN := r.getRoleARN(acctID) endpointURL := r.getEndpointURL(res) + gvk := targetDescriptor.GroupVersionKind() - sess, err := r.sc.NewSession( - region, &endpointURL, roleARN, - targetDescriptor.EmptyRuntimeObject().GetObjectKind().GroupVersionKind(), - ) + sess, err := r.sc.NewSession(region, &endpointURL, roleARN, gvk) if err != nil { return err } diff --git a/pkg/runtime/field_export_reconciler.go b/pkg/runtime/field_export_reconciler.go index e56ce95..5986805 100644 --- a/pkg/runtime/field_export_reconciler.go +++ b/pkg/runtime/field_export_reconciler.go @@ -22,8 +22,8 @@ import ( jq "github.com/itchyny/gojq" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" ctrlrt "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -106,7 +106,7 @@ func (r *fieldExportReconciler) reconcileFieldExport(ctx context.Context, req ct controllerRMF = v break } - if sourceGK.Group != controllerRMF.ResourceDescriptor().GroupKind().Group { + if sourceGK.Group != controllerRMF.ResourceDescriptor().GroupVersionKind().Group { ackrtlog.DebugFieldExport(r.log, feObject, "target resource API group is not of this service. no-op") return nil } @@ -382,7 +382,7 @@ func (r *fieldExportReconciler) writeToSecret( func (r *fieldExportReconciler) GetFieldExportsForResource( ctx context.Context, - gk metav1.GroupKind, + gk schema.GroupKind, nsn types.NamespacedName, ) ([]ackv1alpha1.FieldExport, error) { listed := &ackv1alpha1.FieldExportList{} @@ -682,7 +682,7 @@ func (r *fieldExportResourceReconciler) reconcileSourceResource(ctx context.Cont // Get each of the exports referencing this AWS resource exports, err := r.GetFieldExportsForResource(ctx, - *r.rd.GroupKind(), + r.rd.GroupVersionKind().GroupKind(), types.NamespacedName{ Namespace: res.MetaObject().GetNamespace(), Name: res.MetaObject().GetName(), diff --git a/pkg/runtime/field_export_reconciler_test.go b/pkg/runtime/field_export_reconciler_test.go index 59735df..5205352 100644 --- a/pkg/runtime/field_export_reconciler_test.go +++ b/pkg/runtime/field_export_reconciler_test.go @@ -24,9 +24,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sobj "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" k8srtschema "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -94,8 +94,8 @@ func mockFieldExportReconcilerWithResourceDescriptor(rd *mocks.AWSResourceDescri func mockResourceDescriptor() *mocks.AWSResourceDescriptor { rd := &mocks.AWSResourceDescriptor{} - rd.On("GroupKind").Return( - &metav1.GroupKind{ + rd.On("GroupVersionKind").Return( + schema.GroupVersionKind{ Group: "bookstore.services.k8s.aws", Kind: "fakeBook", }, @@ -431,7 +431,7 @@ func TestFilterAllExports_HappyCase(t *testing.T) { } *list = mockList }) - gk := metav1.GroupKind{ + gk := schema.GroupKind{ Group: BookGVK.Group, Kind: BookGVK.Kind, } @@ -465,7 +465,7 @@ func TestSync_HappyCaseResourceNoExports(t *testing.T) { } *list = mockList }) - gk := metav1.GroupKind{ + gk := schema.GroupKind{ Group: BookGVK.Group, Kind: BookGVK.Kind, } diff --git a/pkg/runtime/reconciler.go b/pkg/runtime/reconciler.go index 54829e3..e3cb7e4 100644 --- a/pkg/runtime/reconciler.go +++ b/pkg/runtime/reconciler.go @@ -25,7 +25,7 @@ import ( "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ctrlrt "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -76,13 +76,14 @@ type resourceReconciler struct { resyncPeriod time.Duration } -// GroupKind returns the string containing the API group and kind reconciled by -// this reconciler -func (r *resourceReconciler) GroupKind() *metav1.GroupKind { +// GroupVersionKind returns the string containing the API group, version and +// kind reconciled by this reconciler +func (r *resourceReconciler) GroupVersionKind() *schema.GroupVersionKind { if r.rd == nil { return nil } - return r.rd.GroupKind() + gvk := r.rd.GroupVersionKind() + return &gvk } // BindControllerManager sets up the AWSResourceReconciler with an instance @@ -157,7 +158,7 @@ func (r *resourceReconciler) Reconcile(ctx context.Context, req ctrlrt.Request) region := r.getRegion(desired) roleARN := r.getRoleARN(acctID) endpointURL := r.getEndpointURL(desired) - gvk := desired.RuntimeObject().GetObjectKind().GroupVersionKind() + gvk := r.rd.GroupVersionKind() sess, err := r.sc.NewSession(region, &endpointURL, roleARN, gvk) if err != nil { return ctrlrt.Result{}, err @@ -170,7 +171,7 @@ func (r *resourceReconciler) Reconcile(ctx context.Context, req ctrlrt.Request) "region", region, // All the fields for a resource that do not change during reconciliation // can be initialized during resourceLogger creation - "kind", r.rd.GroupKind().Kind, + "kind", r.rd.GroupVersionKind().Kind, "namespace", req.Namespace, "name", req.Name, ) @@ -1106,7 +1107,7 @@ func getResyncPeriod(rmf acktypes.AWSResourceManagerFactory, cfg ackcfg.Config) // First, try to use a resource-specific resync period if provided in the resource // resync period configuration. - resourceKind := rmf.ResourceDescriptor().GroupKind().Kind + resourceKind := rmf.ResourceDescriptor().GroupVersionKind().Kind if duration, ok := drc[strings.ToLower(resourceKind)]; ok && duration > 0 { return time.Duration(duration) * time.Second } @@ -1158,7 +1159,7 @@ func NewReconcilerWithClient( rtLog := log.WithName("ackrt") resyncPeriod := getResyncPeriod(rmf, cfg) rtLog.V(1).Info("Initiating reconciler", - "reconciler kind", rmf.ResourceDescriptor().GroupKind().Kind, + "reconciler kind", rmf.ResourceDescriptor().GroupVersionKind().Kind, "resync period seconds", resyncPeriod.Seconds(), ) return &resourceReconciler{ diff --git a/pkg/runtime/reconciler_test.go b/pkg/runtime/reconciler_test.go index 9c45662..91427b1 100644 --- a/pkg/runtime/reconciler_test.go +++ b/pkg/runtime/reconciler_test.go @@ -24,8 +24,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sobj "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" k8srtschema "k8s.io/apimachinery/pkg/runtime/schema" ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -123,8 +123,8 @@ func managerFactoryMocks( *ackmocks.AWSResourceDescriptor, ) { rd := &ackmocks.AWSResourceDescriptor{} - rd.On("GroupKind").Return( - &metav1.GroupKind{ + rd.On("GroupVersionKind").Return( + schema.GroupVersionKind{ Group: "bookstore.services.k8s.aws", Kind: "fakeBook", }, diff --git a/pkg/runtime/registry.go b/pkg/runtime/registry.go index 979bd54..b8fe58b 100644 --- a/pkg/runtime/registry.go +++ b/pkg/runtime/registry.go @@ -44,7 +44,7 @@ func (r *Registry) GetResourceManagerFactories() []types.AWSResourceManagerFacto func (r *Registry) RegisterResourceManagerFactory(f types.AWSResourceManagerFactory) { r.Lock() defer r.Unlock() - r.resourceManagerFactories[f.ResourceDescriptor().GroupKind().String()] = f + r.resourceManagerFactories[f.ResourceDescriptor().GroupVersionKind().GroupKind().String()] = f } // NewRegistry returns a thread-safe Registry object diff --git a/pkg/runtime/registry_test.go b/pkg/runtime/registry_test.go index 259512f..7a56044 100644 --- a/pkg/runtime/registry_test.go +++ b/pkg/runtime/registry_test.go @@ -17,7 +17,7 @@ import ( "testing" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" @@ -28,8 +28,8 @@ func TestRegistry(t *testing.T) { require := require.New(t) rd := &mocks.AWSResourceDescriptor{} - rd.On("GroupKind").Return( - &metav1.GroupKind{ + rd.On("GroupVersionKind").Return( + schema.GroupVersionKind{ Group: "bookstore.services.k8s.aws", Kind: "Book", }, @@ -49,5 +49,5 @@ func TestRegistry(t *testing.T) { require.Contains(rmfs, rmf) rmf.AssertCalled(t, "ResourceDescriptor") - rd.AssertCalled(t, "GroupKind") + rd.AssertCalled(t, "GroupVersionKind") } diff --git a/pkg/runtime/service_controller.go b/pkg/runtime/service_controller.go index ccdeef5..9b108df 100644 --- a/pkg/runtime/service_controller.go +++ b/pkg/runtime/service_controller.go @@ -167,7 +167,7 @@ func (c *serviceController) WithResourceManagerFactories( } for _, rmf := range rmfs { - c.rmFactories[rmf.ResourceDescriptor().GroupKind().String()] = rmf + c.rmFactories[rmf.ResourceDescriptor().GroupVersionKind().GroupKind().String()] = rmf } return c } diff --git a/pkg/runtime/service_controller_test.go b/pkg/runtime/service_controller_test.go index e2bc672..e572751 100644 --- a/pkg/runtime/service_controller_test.go +++ b/pkg/runtime/service_controller_test.go @@ -131,8 +131,8 @@ func TestServiceController(t *testing.T) { require := require.New(t) rd := &mocks.AWSResourceDescriptor{} - rd.On("GroupKind").Return( - &metav1.GroupKind{ + rd.On("GroupVersionKind").Return( + schema.GroupVersionKind{ Group: "bookstore.services.k8s.aws", Kind: "fakeBook", }, @@ -180,7 +180,7 @@ func TestServiceController(t *testing.T) { foundfakeBookRecon := false for _, recon := range recons { - if recon.GroupKind().String() == "fakeBook.bookstore.services.k8s.aws" { + if recon.GroupVersionKind().GroupKind().String() == "fakeBook.bookstore.services.k8s.aws" { foundfakeBookRecon = true } } diff --git a/pkg/types/aws_resource_descriptor.go b/pkg/types/aws_resource_descriptor.go index c24a04c..0827849 100644 --- a/pkg/types/aws_resource_descriptor.go +++ b/pkg/types/aws_resource_descriptor.go @@ -14,7 +14,7 @@ package types import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" rtclient "sigs.k8s.io/controller-runtime/pkg/client" ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" @@ -25,9 +25,10 @@ import ( // prototype for that AWSResource, and the relationships between the // AWSResource and other AWSResources type AWSResourceDescriptor interface { - // GroupKind returns a Kubernetes metav1.GroupKind struct that describes - // the API Group and Kind of CRs described by the descriptor - GroupKind() *metav1.GroupKind + // GroupVersionKind returns a Kubernetes schema.GroupVersionKind struct that + // describes the API Group, Version and Kind of CRs described by the + // descriptor + GroupVersionKind() schema.GroupVersionKind // EmptyRuntimeObject returns an empty object prototype that may be used in // apimachinery and k8s client operations EmptyRuntimeObject() rtclient.Object diff --git a/pkg/types/aws_resource_reconciler.go b/pkg/types/aws_resource_reconciler.go index 28b17ee..435185c 100644 --- a/pkg/types/aws_resource_reconciler.go +++ b/pkg/types/aws_resource_reconciler.go @@ -16,7 +16,7 @@ package types import ( "context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ctrlrt "sigs.k8s.io/controller-runtime" ) @@ -34,10 +34,9 @@ type AWSResourceReconciler interface { // BindControllerManager sets up the AWSResourceReconciler with an instance // of an upstream controller-runtime.Manager BindControllerManager(ctrlrt.Manager) error - // GroupKind returns the - // sigs.k8s.io/apimachinery/pkg/apis/meta/v1.GroupKind containing the API - // group and kind reconciled by this reconciler - GroupKind() *metav1.GroupKind + // GroupKind returns the schema.GroupVersionKind containing the API group, + // version and kind reconciled by this reconciler + GroupVersionKind() *schema.GroupVersionKind // Sync ensures that the supplied AWSResource's backing API resource // matches the supplied desired state. // diff --git a/pkg/types/field_export_reconciler.go b/pkg/types/field_export_reconciler.go index 791c109..1e36dcc 100644 --- a/pkg/types/field_export_reconciler.go +++ b/pkg/types/field_export_reconciler.go @@ -17,7 +17,7 @@ import ( "context" ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" ctrlrt "sigs.k8s.io/controller-runtime" ) @@ -41,7 +41,7 @@ type FieldExportReconciler interface { // based on whether they contain a reference to the given AWS resource. GetFieldExportsForResource( context.Context, - metav1.GroupKind, + schema.GroupKind, types.NamespacedName, ) ([]ackv1alpha1.FieldExport, error) }