Skip to content

Commit bb234f8

Browse files
Deprecated SDK impl of DynamicRESTMapper and replace its usage for controller-runtime impl (#2309)
* Deprecated SDK impl of DynamicRESTMapper * Replace SDK usage of DynamicRESTMapper for controller runtime one.
1 parent f9cb4c7 commit bb234f8

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
### Changed
88

9+
- 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))
910

1011
### Deprecated
1112

13+
- 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))
1214

1315
### Removed
1416

internal/olm/client/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"sync"
2525
"time"
2626

27-
"github.com/operator-framework/operator-sdk/pkg/restmapper"
28-
2927
"github.com/blang/semver"
3028
olmapiv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
3129
"github.com/pkg/errors"
@@ -41,6 +39,7 @@ import (
4139
"k8s.io/client-go/rest"
4240
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
4341
"sigs.k8s.io/controller-runtime/pkg/client"
42+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
4443
)
4544

4645
const OLMNamespace = "olm"
@@ -60,7 +59,7 @@ type Client struct {
6059
}
6160

6261
func ClientForConfig(cfg *rest.Config) (*Client, error) {
63-
rm, err := restmapper.NewDynamicRESTMapper(cfg)
62+
rm, err := apiutil.NewDynamicRESTMapper(cfg)
6463
if err != nil {
6564
return nil, errors.Wrap(err, "failed to create dynamic rest mapper")
6665
}

internal/scaffold/cmd.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import (
5656
"github.com/operator-framework/operator-sdk/pkg/leader"
5757
"github.com/operator-framework/operator-sdk/pkg/log/zap"
5858
"github.com/operator-framework/operator-sdk/pkg/metrics"
59-
"github.com/operator-framework/operator-sdk/pkg/restmapper"
6059
sdkVersion "github.com/operator-framework/operator-sdk/version"
6160
"github.com/spf13/pflag"
6261
v1 "k8s.io/api/core/v1"
@@ -129,7 +128,6 @@ func main() {
129128
// Create a new Cmd to provide shared dependencies and start components
130129
mgr, err := manager.New(cfg, manager.Options{
131130
Namespace: namespace,
132-
MapperProvider: restmapper.NewDynamicRESTMapper,
133131
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
134132
})
135133
if err != nil {

internal/scaffold/cmd_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import (
5555
"github.com/operator-framework/operator-sdk/pkg/leader"
5656
"github.com/operator-framework/operator-sdk/pkg/log/zap"
5757
"github.com/operator-framework/operator-sdk/pkg/metrics"
58-
"github.com/operator-framework/operator-sdk/pkg/restmapper"
5958
sdkVersion "github.com/operator-framework/operator-sdk/version"
6059
"github.com/spf13/pflag"
6160
v1 "k8s.io/api/core/v1"
@@ -128,7 +127,6 @@ func main() {
128127
// Create a new Cmd to provide shared dependencies and start components
129128
mgr, err := manager.New(cfg, manager.Options{
130129
Namespace: namespace,
131-
MapperProvider: restmapper.NewDynamicRESTMapper,
132130
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
133131
})
134132
if err != nil {

pkg/ansible/run.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
2828
"github.com/operator-framework/operator-sdk/pkg/leader"
2929
"github.com/operator-framework/operator-sdk/pkg/metrics"
30-
"github.com/operator-framework/operator-sdk/pkg/restmapper"
3130
"k8s.io/apimachinery/pkg/runtime/schema"
3231
"k8s.io/apimachinery/pkg/util/intstr"
3332
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -79,7 +78,6 @@ func Run(flags *aoflags.AnsibleOperatorFlags) error {
7978
// TODO: probably should expose the host & port as an environment variables
8079
mgr, err := manager.New(cfg, manager.Options{
8180
Namespace: namespace,
82-
MapperProvider: restmapper.NewDynamicRESTMapper,
8381
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
8482
})
8583
if err != nil {

pkg/restmapper/dynamicrestmapper.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
"k8s.io/client-go/restmapper"
2424
)
2525

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)