Skip to content

Commit ac5adf9

Browse files
committed
*: bump controller-runtime to v0.2.0-rc.0, update APIs
1 parent 7f575be commit ac5adf9

File tree

14 files changed

+97
-32
lines changed

14 files changed

+97
-32
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
- CSV config field `role-path` is now `role-paths` and takes a list of strings. Users can now specify multiple `Role` and `ClusterRole` manifests using `role-paths`. ([#1704](https://github.com/operator-framework/operator-sdk/pull/1704))
1616
- Upgrade Kubernetes version from `kubernetes-1.13.4` to `kubernetes-1.14.1`
1717
- Upgrade `github.com/operator-framework/operator-lifecycle-manager` version from `b8a4faf68e36feb6d99a6aec623b405e587b17b1` to `0.10.1`
18-
- Upgrade [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime) version from `v0.1.12` to `v0.2.0-beta.3`
18+
- Upgrade [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime) version from `v0.1.12` to `v0.2.0`
1919
- The package `sigs.k8s.io/controller-runtime/pkg/runtime/scheme` is deprecated, and contains no code. Replace this import with `sigs.k8s.io/controller-runtime/pkg/scheme` where relevant.
2020
- The package `sigs.k8s.io/controller-runtime/pkg/runtime/log` is deprecated. Replace this import with `sigs.k8s.io/controller-runtime/pkg/log` where relevant.
2121
- The package `sigs.k8s.io/controller-runtime/pkg/runtime/signals` is deprecated. Replace this import with `sigs.k8s.io/controller-runtime/pkg/manager/signals` where relevant.
22-
- [`sigs.k8s.io/controller-runtime/pkg/client.Client`](https://github.com/kubernetes-sigs/controller-runtime/blob/aaddbd9d9a89d8ff329a084aece23be0406e6467/pkg/client/interfaces.go#L101)'s `List()` method signature has been updated: `List(ctx context.Context, opts *client.ListOptions, list runtime.Object) error` is now [`List(ctx context.Context, list runtime.Object, opts ...client.ListOptionFunc) error`](https://github.com/kubernetes-sigs/controller-runtime/blob/aaddbd9d9a89d8ff329a084aece23be0406e6467/pkg/client/interfaces.go#L61). To migrate:
22+
<!-- TODO: change link tags when v0.2.0 stable is released -->
23+
- [`sigs.k8s.io/controller-runtime/pkg/client.Client`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/interfaces.go#L104)'s `List()` method signature has been updated: `List(ctx context.Context, opts *client.ListOptions, list runtime.Object) error` is now [`List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/interfaces.go#L61). To migrate:
2324
```go
2425
import (
2526
"context"
@@ -29,11 +30,15 @@
2930

3031
...
3132

32-
listOpts := &client.ListOptions{}
3333
// Old
34+
listOpts := &client.ListOptions{}
35+
listOpts.InNamespace("namespace")
3436
err = r.client.List(context.TODO(), listOps, podList)
3537
// New
36-
err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps))
38+
listOpts := []client.ListOption{
39+
client.InNamespace("namespace"),
40+
}
41+
err = r.client.List(context.TODO(), podList, listOpts...)
3742
```
3843
- CRD file names were previously of the form `<group>_<version>_<kind>_crd.yaml`. Now that CRD manifest `spec.version` is deprecated in favor of `spec.versions`, i.e. multiple versions can be specified in one CRD, CRD file names have the form `<full group>_<resource>_crd.yaml`. `<full group>` is the full group name of your CRD while `<group>` is the last subdomain of `<full group>`, ex. `foo.bar.com` vs `foo`. `<resource>` is the plural lower-case CRD Kind found at `spec.names.plural`.
3944

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ replace (
114114
github.com/operator-framework/operator-lifecycle-manager => github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190605231540-b8a4faf68e36
115115
k8s.io/helm => k8s.io/helm v2.14.1+incompatible
116116
k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0
117-
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3
117+
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0
118118
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde
119119
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ k8s.io/kubernetes v1.14.1/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
634634
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
635635
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
636636
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
637-
sigs.k8s.io/controller-runtime v0.2.0-beta.3 h1:K3dddu6/pOVORH2dBOnEbXif6R80oSDa4y/t1jhoh8s=
638-
sigs.k8s.io/controller-runtime v0.2.0-beta.3/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME=
637+
sigs.k8s.io/controller-runtime v0.2.0-rc.0 h1:49JLOielmXfrd44Cmk2c0eeIkQ/Vq4AvfqsZqya16/E=
638+
sigs.k8s.io/controller-runtime v0.2.0-rc.0/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME=
639639
sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde h1:ZkaHf5rNYzIB6CB82keKMQNv7xxkqT0ylOBdfJPfi+k=
640640
sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde/go.mod h1:ATWLRP3WGxuAN9HcT2LaKHReXIH+EZGzRuMHuxjXfhQ=
641641
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=

internal/pkg/scaffold/ansible/go_mod.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ replace (
6060
k8s.io/kubernetes => k8s.io/kubernetes v1.14.1
6161
)
6262
63-
// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can
64-
// resolve it correctly.
65-
replace github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286
63+
replace (
64+
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0
65+
// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can
66+
// resolve it correctly.
67+
github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286
68+
)
6669
`
6770

6871
func PrintGoMod() error {

internal/pkg/scaffold/ansible/gopkgtoml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const gopkgTomlTmpl = `[[constraint]]
5252
name = "k8s.io/client-go"
5353
version = "kubernetes-1.14.1"
5454
55+
[[override]]
56+
name = "sigs.k8s.io/controller-runtime"
57+
version = "=v0.2.0-rc.0"
58+
5559
[prune]
5660
go-tests = true
5761
unused-packages = true

internal/pkg/scaffold/go_mod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ replace (
6060
6161
replace (
6262
github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1
63-
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3
63+
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0
6464
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde
6565
// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can
6666
// resolve it correctly.

internal/pkg/scaffold/gopkgtoml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ required = [
7373
7474
[[override]]
7575
name = "sigs.k8s.io/controller-runtime"
76-
version = "=v0.2.0-beta.3"
76+
version = "=v0.2.0-rc.0"
7777
7878
# Required when resolving controller-runtime dependencies.
7979
[[override]]

internal/pkg/scaffold/helm/go_mod.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ replace (
8080
)
8181
8282
replace (
83+
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0
8384
github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1
8485
// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can
8586
// resolve it correctly.

internal/pkg/scaffold/helm/gopkgtoml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const gopkgTomlTmpl = `[[constraint]]
6464
name = "k8s.io/cli-runtime"
6565
version = "kubernetes-1.14.1"
6666
67+
[[override]]
68+
name = "sigs.k8s.io/controller-runtime"
69+
version = "=v0.2.0-rc.0"
70+
6771
# We need overrides for the following imports because dep can't resolve them
6872
# correctly. The easiest way to get this right is to use the versions that
6973
# k8s.io/helm uses. See https://github.com/helm/helm/blob/v2.14.1/glide.lock

internal/util/k8sutil/options.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package k8sutil
16+
17+
import (
18+
"k8s.io/apimachinery/pkg/fields"
19+
"sigs.k8s.io/controller-runtime/pkg/client"
20+
)
21+
22+
// MatchingFields implements the client.ListOption and client.DeleteAllOfOption
23+
// interfaces so fields.Selector can be used directly in client.List and
24+
// client.DeleteAllOf.
25+
type MatchingFields struct {
26+
Sel fields.Selector
27+
}
28+
29+
func (m MatchingFields) ApplyToList(opts *client.ListOptions) {
30+
opts.FieldSelector = m.Sel
31+
}
32+
33+
func (m MatchingFields) ApplyToDeleteAllOf(opts *client.DeleteAllOfOptions) {
34+
opts.FieldSelector = m.Sel
35+
}

pkg/ansible/proxy/cache_response.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ import (
2222
"net/http"
2323
"strings"
2424

25+
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
2526
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
2627
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
2728
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
2829
osdkHandler "github.com/operator-framework/operator-sdk/pkg/handler"
30+
2931
"k8s.io/apimachinery/pkg/api/meta"
3032
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
3133
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3234
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
35+
"k8s.io/apimachinery/pkg/fields"
36+
"k8s.io/apimachinery/pkg/labels"
3337
"k8s.io/apimachinery/pkg/runtime/schema"
3438
"k8s.io/apimachinery/pkg/util/sets"
3539
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -199,22 +203,29 @@ func (c *cacheResponseHandler) getListFromCache(r *requestfactory.RequestInfo, r
199203
log.Error(err, "Unable to decode list options from request")
200204
return nil, err
201205
}
202-
clientListOpts := &client.ListOptions{}
203-
clientListOpts.InNamespace(r.Namespace)
204-
if err := clientListOpts.SetLabelSelector(k8sListOpts.LabelSelector); err != nil {
205-
log.Error(err, "Unable to set label selectors for the client")
206-
return nil, err
206+
clientListOpts := []client.ListOption{
207+
client.InNamespace(r.Namespace),
208+
}
209+
if k8sListOpts.LabelSelector != "" {
210+
sel, err := labels.ConvertSelectorToLabelsMap(k8sListOpts.LabelSelector)
211+
if err != nil {
212+
log.Error(err, "Unable to convert label selectors for the client")
213+
return nil, err
214+
}
215+
clientListOpts = append(clientListOpts, client.MatchingLabels(sel))
207216
}
208217
if k8sListOpts.FieldSelector != "" {
209-
if err := clientListOpts.SetFieldSelector(k8sListOpts.FieldSelector); err != nil {
210-
log.Error(err, "Unable to set field selectors for the client")
218+
sel, err := fields.ParseSelector(k8sListOpts.FieldSelector)
219+
if err != nil {
220+
log.Error(err, "Unable to parse field selectors for the client")
211221
return nil, err
212222
}
223+
clientListOpts = append(clientListOpts, k8sutil.MatchingFields{Sel: sel})
213224
}
214225
k.Kind = k.Kind + "List"
215226
un := unstructured.UnstructuredList{}
216227
un.SetGroupVersionKind(k)
217-
err := c.informerCache.List(context.Background(), &un, client.UseListOptions(clientListOpts))
228+
err := c.informerCache.List(context.Background(), &un, clientListOpts...)
218229
if err != nil {
219230
// break here in case resource doesn't exist in cache but exists on APIserver
220231
// This is very unlikely but provides user with expected 404

pkg/test/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ var _ FrameworkClient = &frameworkClient{}
3232

3333
type FrameworkClient interface {
3434
Get(gCtx goctx.Context, key dynclient.ObjectKey, obj runtime.Object) error
35-
List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOptionFunc) error
35+
List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOption) error
3636
Create(gCtx goctx.Context, obj runtime.Object, cleanupOptions *CleanupOptions) error
37-
Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOptionFunc) error
37+
Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOption) error
3838
Update(gCtx goctx.Context, obj runtime.Object) error
3939
}
4040

@@ -93,11 +93,11 @@ func (f *frameworkClient) Get(gCtx goctx.Context, key dynclient.ObjectKey, obj r
9393
return f.Client.Get(gCtx, key, obj)
9494
}
9595

96-
func (f *frameworkClient) List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOptionFunc) error {
96+
func (f *frameworkClient) List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOption) error {
9797
return f.Client.List(gCtx, list, opts...)
9898
}
9999

100-
func (f *frameworkClient) Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOptionFunc) error {
100+
func (f *frameworkClient) Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOption) error {
101101
return f.Client.Delete(gCtx, obj, opts...)
102102
}
103103

test/test-framework/pkg/controller/memcached/memcached_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res
150150
// Update the Memcached status with the pod names
151151
// List the pods for this memcached's deployment
152152
podList := &corev1.PodList{}
153-
listOps := &client.ListOptions{}
154-
listOps.InNamespace(memcached.Namespace)
155-
listOps.MatchingLabels(labelsForMemcached(memcached.Name))
156-
err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps))
153+
listOps := []client.ListOption{
154+
client.InNamespace(memcached.Namespace),
155+
client.MatchingLabels(labelsForMemcached(memcached.Name)),
156+
}
157+
err = r.client.List(context.TODO(), podList, listOps...)
157158
if err != nil {
158159
reqLogger.Error(err, "Failed to list pods.", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name)
159160
return reconcile.Result{}, err

test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@ func (r *ReconcileMemcachedRS) Reconcile(request reconcile.Request) (reconcile.R
152152
// Update the Memcached status with the pod names
153153
// List the pods for this memcached's replicaSet
154154
podList := &corev1.PodList{}
155-
listOps := &client.ListOptions{}
156-
listOps.InNamespace(memcachedrs.Namespace)
157-
listOps.MatchingLabels(labelsForMemcached(memcachedrs.Name))
158-
err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps))
155+
listOps := []client.ListOption{
156+
client.InNamespace(memcachedrs.Namespace),
157+
client.MatchingLabels(labelsForMemcached(memcachedrs.Name)),
158+
}
159+
err = r.client.List(context.TODO(), podList, listOps...)
159160
if err != nil {
160161
reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcachedrs.Namespace, "Memcached.Name", memcachedrs.Name)
161162
return reconcile.Result{}, err

0 commit comments

Comments
 (0)