Skip to content

Commit

Permalink
Deprecated SDK impl of DynamicRESTMapper and replace its usage for c…
Browse files Browse the repository at this point in the history
…ontroller-runtime impl (#2309)

* Deprecated SDK impl of DynamicRESTMapper
* Replace SDK usage of DynamicRESTMapper for controller runtime one.
  • Loading branch information
camilamacedo86 authored Dec 11, 2019
1 parent f9cb4c7 commit bb234f8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

### Changed

- Replace usage of `github.com/operator-framework/operator-sdk/pkg/restmapper.DynamicRESTMapper` with `sigs.k8s.io/controller-runtime/pkg/client/apiutil.DynamicRESTMapper`. ([#2309](https://github.com/operator-framework/operator-sdk/pull/2309))

### Deprecated

- Deprecated `github.com/operator-framework/operator-sdk/pkg/restmapper` in favor of the `DynamicRESTMapper` implementation in [controller-runtime](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/client/apiutil#NewDiscoveryRESTMapper). ([#2309](https://github.com/operator-framework/operator-sdk/pull/2309))

### Removed

Expand Down
5 changes: 2 additions & 3 deletions internal/olm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sync"
"time"

"github.com/operator-framework/operator-sdk/pkg/restmapper"

"github.com/blang/semver"
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/pkg/errors"
Expand All @@ -41,6 +39,7 @@ import (
"k8s.io/client-go/rest"
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

const OLMNamespace = "olm"
Expand All @@ -60,7 +59,7 @@ type Client struct {
}

func ClientForConfig(cfg *rest.Config) (*Client, error) {
rm, err := restmapper.NewDynamicRESTMapper(cfg)
rm, err := apiutil.NewDynamicRESTMapper(cfg)
if err != nil {
return nil, errors.Wrap(err, "failed to create dynamic rest mapper")
}
Expand Down
2 changes: 0 additions & 2 deletions internal/scaffold/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/log/zap"
"github.com/operator-framework/operator-sdk/pkg/metrics"
"github.com/operator-framework/operator-sdk/pkg/restmapper"
sdkVersion "github.com/operator-framework/operator-sdk/version"
"github.com/spf13/pflag"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -129,7 +128,6 @@ func main() {
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{
Namespace: namespace,
MapperProvider: restmapper.NewDynamicRESTMapper,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
})
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions internal/scaffold/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import (
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/log/zap"
"github.com/operator-framework/operator-sdk/pkg/metrics"
"github.com/operator-framework/operator-sdk/pkg/restmapper"
sdkVersion "github.com/operator-framework/operator-sdk/version"
"github.com/spf13/pflag"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -128,7 +127,6 @@ func main() {
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{
Namespace: namespace,
MapperProvider: restmapper.NewDynamicRESTMapper,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
})
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/ansible/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/metrics"
"github.com/operator-framework/operator-sdk/pkg/restmapper"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand Down Expand Up @@ -79,7 +78,6 @@ func Run(flags *aoflags.AnsibleOperatorFlags) error {
// TODO: probably should expose the host & port as an environment variables
mgr, err := manager.New(cfg, manager.Options{
Namespace: namespace,
MapperProvider: restmapper.NewDynamicRESTMapper,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
})
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions pkg/restmapper/dynamicrestmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"k8s.io/client-go/restmapper"
)

// Deprecated: DynamicRESTMapper exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
type DynamicRESTMapper struct {
client discovery.DiscoveryInterface
delegate meta.RESTMapper
Expand All @@ -32,6 +35,10 @@ type DynamicRESTMapper struct {
// types at runtime. This is in contrast to controller-manager's default RESTMapper, which
// only checks resource types at startup, and so can't handle the case of first creating a
// CRD and then creating an instance of that CRD.
//
// Deprecated: NewDynamicRESTMapper exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func NewDynamicRESTMapper(cfg *rest.Config) (meta.RESTMapper, error) {
client, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
Expand Down Expand Up @@ -67,6 +74,9 @@ func (drm *DynamicRESTMapper) reloadOnError(err error) bool {
return err == nil
}

// Deprecated: KindFor exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) {
gvk, err := drm.delegate.KindFor(resource)
if drm.reloadOnError(err) {
Expand All @@ -75,6 +85,9 @@ func (drm *DynamicRESTMapper) KindFor(resource schema.GroupVersionResource) (sch
return gvk, err
}

// Deprecated: KindsFor exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error) {
gvks, err := drm.delegate.KindsFor(resource)
if drm.reloadOnError(err) {
Expand All @@ -83,6 +96,9 @@ func (drm *DynamicRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]
return gvks, err
}

// Deprecated: ResourceFor exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error) {
gvr, err := drm.delegate.ResourceFor(input)
if drm.reloadOnError(err) {
Expand All @@ -91,6 +107,9 @@ func (drm *DynamicRESTMapper) ResourceFor(input schema.GroupVersionResource) (sc
return gvr, err
}

// Deprecated: ResourcesFor exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error) {
gvrs, err := drm.delegate.ResourcesFor(input)
if drm.reloadOnError(err) {
Expand All @@ -99,6 +118,9 @@ func (drm *DynamicRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([
return gvrs, err
}

// Deprecated: RESTMapping exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error) {
m, err := drm.delegate.RESTMapping(gk, versions...)
if drm.reloadOnError(err) {
Expand All @@ -107,6 +129,9 @@ func (drm *DynamicRESTMapper) RESTMapping(gk schema.GroupKind, versions ...strin
return m, err
}

// Deprecated: RESTMappings exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error) {
ms, err := drm.delegate.RESTMappings(gk, versions...)
if drm.reloadOnError(err) {
Expand All @@ -115,6 +140,9 @@ func (drm *DynamicRESTMapper) RESTMappings(gk schema.GroupKind, versions ...stri
return ms, err
}

// Deprecated: ResourceSingularizer exists for historical compatibility
// and should not be used. See that it was implemented in the controller-runtime.
// More info: https://github.com/kubernetes-sigs/controller-runtime/pull/554
func (drm *DynamicRESTMapper) ResourceSingularizer(resource string) (singular string, err error) {
s, err := drm.delegate.ResourceSingularizer(resource)
if drm.reloadOnError(err) {
Expand Down

0 comments on commit bb234f8

Please sign in to comment.