From ac5adf9da4a39470a1e717c1ae2031fdb0cbdb43 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 19 Aug 2019 12:23:15 -0700 Subject: [PATCH 01/14] *: bump controller-runtime to v0.2.0-rc.0, update APIs --- CHANGELOG.md | 13 ++++--- go.mod | 2 +- go.sum | 4 +-- internal/pkg/scaffold/ansible/go_mod.go | 9 +++-- internal/pkg/scaffold/ansible/gopkgtoml.go | 4 +++ internal/pkg/scaffold/go_mod.go | 2 +- internal/pkg/scaffold/gopkgtoml.go | 2 +- internal/pkg/scaffold/helm/go_mod.go | 1 + internal/pkg/scaffold/helm/gopkgtoml.go | 4 +++ internal/util/k8sutil/options.go | 35 +++++++++++++++++++ pkg/ansible/proxy/cache_response.go | 27 +++++++++----- pkg/test/client.go | 8 ++--- .../memcached/memcached_controller.go | 9 ++--- .../memcachedrs/memcachedrs_controller.go | 9 ++--- 14 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 internal/util/k8sutil/options.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5529675252..8cbc586c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,12 @@ - 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)) - Upgrade Kubernetes version from `kubernetes-1.13.4` to `kubernetes-1.14.1` - Upgrade `github.com/operator-framework/operator-lifecycle-manager` version from `b8a4faf68e36feb6d99a6aec623b405e587b17b1` to `0.10.1` -- Upgrade [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime) version from `v0.1.12` to `v0.2.0-beta.3` +- Upgrade [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime) version from `v0.1.12` to `v0.2.0` - 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. - 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. - 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. - - [`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: + + - [`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: ```go import ( "context" @@ -29,11 +30,15 @@ ... - listOpts := &client.ListOptions{} // Old + listOpts := &client.ListOptions{} + listOpts.InNamespace("namespace") err = r.client.List(context.TODO(), listOps, podList) // New - err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps)) + listOpts := []client.ListOption{ + client.InNamespace("namespace"), + } + err = r.client.List(context.TODO(), podList, listOpts...) ``` - CRD file names were previously of the form `___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 `__crd.yaml`. `` is the full group name of your CRD while `` is the last subdomain of ``, ex. `foo.bar.com` vs `foo`. `` is the plural lower-case CRD Kind found at `spec.names.plural`. diff --git a/go.mod b/go.mod index 4e5cfa45b3..8215bcb3a9 100644 --- a/go.mod +++ b/go.mod @@ -114,6 +114,6 @@ replace ( github.com/operator-framework/operator-lifecycle-manager => github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190605231540-b8a4faf68e36 k8s.io/helm => k8s.io/helm v2.14.1+incompatible k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde ) diff --git a/go.sum b/go.sum index 266d625812..8d4105b69e 100644 --- a/go.sum +++ b/go.sum @@ -634,8 +634,8 @@ k8s.io/kubernetes v1.14.1/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= -sigs.k8s.io/controller-runtime v0.2.0-beta.3 h1:K3dddu6/pOVORH2dBOnEbXif6R80oSDa4y/t1jhoh8s= -sigs.k8s.io/controller-runtime v0.2.0-beta.3/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME= +sigs.k8s.io/controller-runtime v0.2.0-rc.0 h1:49JLOielmXfrd44Cmk2c0eeIkQ/Vq4AvfqsZqya16/E= +sigs.k8s.io/controller-runtime v0.2.0-rc.0/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME= sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde h1:ZkaHf5rNYzIB6CB82keKMQNv7xxkqT0ylOBdfJPfi+k= sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde/go.mod h1:ATWLRP3WGxuAN9HcT2LaKHReXIH+EZGzRuMHuxjXfhQ= sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0= diff --git a/internal/pkg/scaffold/ansible/go_mod.go b/internal/pkg/scaffold/ansible/go_mod.go index 145f9a1adf..d544b54fd0 100644 --- a/internal/pkg/scaffold/ansible/go_mod.go +++ b/internal/pkg/scaffold/ansible/go_mod.go @@ -60,9 +60,12 @@ replace ( k8s.io/kubernetes => k8s.io/kubernetes v1.14.1 ) -// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can -// resolve it correctly. -replace github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286 +replace ( + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 + // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can + // resolve it correctly. + github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286 +) ` func PrintGoMod() error { diff --git a/internal/pkg/scaffold/ansible/gopkgtoml.go b/internal/pkg/scaffold/ansible/gopkgtoml.go index 11ba07d5ad..efc50f9ae8 100644 --- a/internal/pkg/scaffold/ansible/gopkgtoml.go +++ b/internal/pkg/scaffold/ansible/gopkgtoml.go @@ -52,6 +52,10 @@ const gopkgTomlTmpl = `[[constraint]] name = "k8s.io/client-go" version = "kubernetes-1.14.1" +[[override]] + name = "sigs.k8s.io/controller-runtime" + version = "=v0.2.0-rc.0" + [prune] go-tests = true unused-packages = true diff --git a/internal/pkg/scaffold/go_mod.go b/internal/pkg/scaffold/go_mod.go index 1ed9b014ac..8a8b9392d1 100644 --- a/internal/pkg/scaffold/go_mod.go +++ b/internal/pkg/scaffold/go_mod.go @@ -60,7 +60,7 @@ replace ( replace ( github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. diff --git a/internal/pkg/scaffold/gopkgtoml.go b/internal/pkg/scaffold/gopkgtoml.go index 465b1d29fd..0ef628a3ca 100644 --- a/internal/pkg/scaffold/gopkgtoml.go +++ b/internal/pkg/scaffold/gopkgtoml.go @@ -73,7 +73,7 @@ required = [ [[override]] name = "sigs.k8s.io/controller-runtime" - version = "=v0.2.0-beta.3" + version = "=v0.2.0-rc.0" # Required when resolving controller-runtime dependencies. [[override]] diff --git a/internal/pkg/scaffold/helm/go_mod.go b/internal/pkg/scaffold/helm/go_mod.go index facfc1a120..ac207277b6 100644 --- a/internal/pkg/scaffold/helm/go_mod.go +++ b/internal/pkg/scaffold/helm/go_mod.go @@ -80,6 +80,7 @@ replace ( ) replace ( + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. diff --git a/internal/pkg/scaffold/helm/gopkgtoml.go b/internal/pkg/scaffold/helm/gopkgtoml.go index fc8cda54d1..d58f9cf285 100644 --- a/internal/pkg/scaffold/helm/gopkgtoml.go +++ b/internal/pkg/scaffold/helm/gopkgtoml.go @@ -64,6 +64,10 @@ const gopkgTomlTmpl = `[[constraint]] name = "k8s.io/cli-runtime" version = "kubernetes-1.14.1" +[[override]] + name = "sigs.k8s.io/controller-runtime" + version = "=v0.2.0-rc.0" + # We need overrides for the following imports because dep can't resolve them # correctly. The easiest way to get this right is to use the versions that # k8s.io/helm uses. See https://github.com/helm/helm/blob/v2.14.1/glide.lock diff --git a/internal/util/k8sutil/options.go b/internal/util/k8sutil/options.go new file mode 100644 index 0000000000..0c3eb86b37 --- /dev/null +++ b/internal/util/k8sutil/options.go @@ -0,0 +1,35 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package k8sutil + +import ( + "k8s.io/apimachinery/pkg/fields" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// MatchingFields implements the client.ListOption and client.DeleteAllOfOption +// interfaces so fields.Selector can be used directly in client.List and +// client.DeleteAllOf. +type MatchingFields struct { + Sel fields.Selector +} + +func (m MatchingFields) ApplyToList(opts *client.ListOptions) { + opts.FieldSelector = m.Sel +} + +func (m MatchingFields) ApplyToDeleteAllOf(opts *client.DeleteAllOfOptions) { + opts.FieldSelector = m.Sel +} diff --git a/pkg/ansible/proxy/cache_response.go b/pkg/ansible/proxy/cache_response.go index 3dbdca1a48..d181f29958 100644 --- a/pkg/ansible/proxy/cache_response.go +++ b/pkg/ansible/proxy/cache_response.go @@ -22,14 +22,18 @@ import ( "net/http" "strings" + "github.com/operator-framework/operator-sdk/internal/util/k8sutil" "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap" "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory" k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory" osdkHandler "github.com/operator-framework/operator-sdk/pkg/handler" + "k8s.io/apimachinery/pkg/api/meta" metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "sigs.k8s.io/controller-runtime/pkg/cache" @@ -199,22 +203,29 @@ func (c *cacheResponseHandler) getListFromCache(r *requestfactory.RequestInfo, r log.Error(err, "Unable to decode list options from request") return nil, err } - clientListOpts := &client.ListOptions{} - clientListOpts.InNamespace(r.Namespace) - if err := clientListOpts.SetLabelSelector(k8sListOpts.LabelSelector); err != nil { - log.Error(err, "Unable to set label selectors for the client") - return nil, err + clientListOpts := []client.ListOption{ + client.InNamespace(r.Namespace), + } + if k8sListOpts.LabelSelector != "" { + sel, err := labels.ConvertSelectorToLabelsMap(k8sListOpts.LabelSelector) + if err != nil { + log.Error(err, "Unable to convert label selectors for the client") + return nil, err + } + clientListOpts = append(clientListOpts, client.MatchingLabels(sel)) } if k8sListOpts.FieldSelector != "" { - if err := clientListOpts.SetFieldSelector(k8sListOpts.FieldSelector); err != nil { - log.Error(err, "Unable to set field selectors for the client") + sel, err := fields.ParseSelector(k8sListOpts.FieldSelector) + if err != nil { + log.Error(err, "Unable to parse field selectors for the client") return nil, err } + clientListOpts = append(clientListOpts, k8sutil.MatchingFields{Sel: sel}) } k.Kind = k.Kind + "List" un := unstructured.UnstructuredList{} un.SetGroupVersionKind(k) - err := c.informerCache.List(context.Background(), &un, client.UseListOptions(clientListOpts)) + err := c.informerCache.List(context.Background(), &un, clientListOpts...) if err != nil { // break here in case resource doesn't exist in cache but exists on APIserver // This is very unlikely but provides user with expected 404 diff --git a/pkg/test/client.go b/pkg/test/client.go index f02acd8899..89d6f3af47 100644 --- a/pkg/test/client.go +++ b/pkg/test/client.go @@ -32,9 +32,9 @@ var _ FrameworkClient = &frameworkClient{} type FrameworkClient interface { Get(gCtx goctx.Context, key dynclient.ObjectKey, obj runtime.Object) error - List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOptionFunc) error + List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOption) error Create(gCtx goctx.Context, obj runtime.Object, cleanupOptions *CleanupOptions) error - Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOptionFunc) error + Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOption) error Update(gCtx goctx.Context, obj runtime.Object) error } @@ -93,11 +93,11 @@ func (f *frameworkClient) Get(gCtx goctx.Context, key dynclient.ObjectKey, obj r return f.Client.Get(gCtx, key, obj) } -func (f *frameworkClient) List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOptionFunc) error { +func (f *frameworkClient) List(gCtx goctx.Context, list runtime.Object, opts ...dynclient.ListOption) error { return f.Client.List(gCtx, list, opts...) } -func (f *frameworkClient) Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOptionFunc) error { +func (f *frameworkClient) Delete(gCtx goctx.Context, obj runtime.Object, opts ...dynclient.DeleteOption) error { return f.Client.Delete(gCtx, obj, opts...) } diff --git a/test/test-framework/pkg/controller/memcached/memcached_controller.go b/test/test-framework/pkg/controller/memcached/memcached_controller.go index 59256dfe9e..a7b7fe43b0 100644 --- a/test/test-framework/pkg/controller/memcached/memcached_controller.go +++ b/test/test-framework/pkg/controller/memcached/memcached_controller.go @@ -150,10 +150,11 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res // Update the Memcached status with the pod names // List the pods for this memcached's deployment podList := &corev1.PodList{} - listOps := &client.ListOptions{} - listOps.InNamespace(memcached.Namespace) - listOps.MatchingLabels(labelsForMemcached(memcached.Name)) - err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps)) + listOps := []client.ListOption{ + client.InNamespace(memcached.Namespace), + client.MatchingLabels(labelsForMemcached(memcached.Name)), + } + err = r.client.List(context.TODO(), podList, listOps...) if err != nil { reqLogger.Error(err, "Failed to list pods.", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) return reconcile.Result{}, err diff --git a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go b/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go index 5b2edf2fd8..83fb68573d 100644 --- a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go +++ b/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go @@ -152,10 +152,11 @@ func (r *ReconcileMemcachedRS) Reconcile(request reconcile.Request) (reconcile.R // Update the Memcached status with the pod names // List the pods for this memcached's replicaSet podList := &corev1.PodList{} - listOps := &client.ListOptions{} - listOps.InNamespace(memcachedrs.Namespace) - listOps.MatchingLabels(labelsForMemcached(memcachedrs.Name)) - err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps)) + listOps := []client.ListOption{ + client.InNamespace(memcachedrs.Namespace), + client.MatchingLabels(labelsForMemcached(memcachedrs.Name)), + } + err = r.client.List(context.TODO(), podList, listOps...) if err != nil { reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcachedrs.Namespace, "Memcached.Name", memcachedrs.Name) return reconcile.Result{}, err From 184d4c23ff2e56ae3d0776772637aead89e2d6e3 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 19 Aug 2019 14:05:03 -0700 Subject: [PATCH 02/14] more updates to docs and code --- doc/user/client.md | 46 ++++++------------- .../memcached_controller.go.tmpl | 9 ++-- go.mod | 8 ++-- go.sum | 32 ++++++++++--- internal/util/k8sutil/options.go | 4 ++ .../_incluster-test-code/memcached_test.go | 22 +++++---- 6 files changed, 65 insertions(+), 56 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index f8cbbad329..6904bbfc65 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -134,32 +134,10 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ```Go // List retrieves a list of objects for a given namespace and list options // and stores the list in obj. -func (c Client) List(ctx context.Context, list runtime.Object, opts ...client.ListOptionFunc) error +func (c Client) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error ``` -A `client.ListOptionFunc` can be created either by using the provided [functional options](https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ListOptionFunc) or using `client.ListOptions`: - -```Go -type ListOptions struct { - // LabelSelector filters results by label. Use SetLabelSelector to - // set from raw string form. - LabelSelector labels.Selector - - // FieldSelector filters results by a particular field. In order - // to use this with cache-based implementations, restrict usage to - // a single field-value pair that's been added to the indexers. - FieldSelector fields.Selector - - // Namespace represents the namespace to list for, or empty for - // non-namespaced objects, or to list across all namespaces. - Namespace string - - // Raw represents raw ListOptions, as passed to the API server. Note - // that these may not be respected by all implementations of interface, - // and the LabelSelector and FieldSelector fields are ignored. - Raw *metav1.ListOptions -} -``` +A `client.ListOption` is an interface that sets [`client.ListOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L257) fields. A `client.ListOption` is created by using one of the provided implementations: [`LableSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L304), [`FieldSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L326), [`Namespace`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L339). Example: @@ -176,13 +154,15 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ... // Return all pods in the request namespace with a label of `app=` - opts := &client.ListOptions{} - opts.SetLabelSelector(fmt.Sprintf("app=%s", request.NamespacedName.Name)) - opts.InNamespace(request.NamespacedName.Namespace) - + // and is running. + opts := []client.ListOption{ + client.InNamespace(request.NamespacedName.Namespace), + client.MatchingLabels{"app", request.NamespacedName.Name}, + client.MatchingField("status.phase", "Running"), + } podList := &v1.PodList{} ctx := context.TODO() - err := r.client.List(ctx, podList, client.UseListOptions(listOps)) + err := r.client.List(ctx, podList, opts...) ... } @@ -417,10 +397,12 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e // Update the App status with the pod names. // List the pods for this app's deployment. + listOpts := []client.ListOption{ + client.InNamespace(app.Namespace), + client.MatchingLabels(labelsForApp(app.Name)), + } podList := &corev1.PodList{} - labelSelector := labels.SelectorFromSet(labelsForApp(app.Name)) - listOps := &client.ListOptions{Namespace: app.Namespace, LabelSelector: labelSelector} - if err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps)); err != nil { + if err = r.client.List(context.TODO(), podList, listOpts...); err != nil { return reconcile.Result{}, err } diff --git a/example/memcached-operator/memcached_controller.go.tmpl b/example/memcached-operator/memcached_controller.go.tmpl index 3e14f0704c..352412f9cc 100644 --- a/example/memcached-operator/memcached_controller.go.tmpl +++ b/example/memcached-operator/memcached_controller.go.tmpl @@ -141,11 +141,12 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res // Update the Memcached status with the pod names // List the pods for this memcached's deployment + listOpts := []client.ListOption{ + client.InNamespace(memcached.Namespace), + client.MatchingLabels(labelsForApp(memcached.Name)), + } podList := &corev1.PodList{} - labelSelector := labels.SelectorFromSet(labelsForMemcached(memcached.Name)) - listOps := &client.ListOptions{Namespace: memcached.Namespace, LabelSelector: labelSelector} - err = r.client.List(context.TODO(), podList, client.UseListOptions(listOps)) - if err != nil { + if err = r.client.List(context.TODO(), podList, listOpts...); err != nil { reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) return reconcile.Result{}, err } diff --git a/go.mod b/go.mod index 8215bcb3a9..bba6d765c2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( cloud.google.com/go v0.37.2 // indirect - contrib.go.opencensus.io/exporter/ocagent v0.4.11 // indirect + contrib.go.opencensus.io/exporter/ocagent v0.4.12 // indirect github.com/Azure/go-autorest v11.7.0+incompatible // indirect github.com/DATA-DOG/go-sqlmock v1.3.3 // indirect github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect @@ -27,6 +27,7 @@ require ( github.com/go-logr/logr v0.1.0 github.com/go-logr/zapr v0.1.1 github.com/go-openapi/swag v0.19.0 // indirect + github.com/go-sql-driver/mysql v1.4.1 // indirect github.com/gobuffalo/packr v1.30.1 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/google/uuid v1.1.1 // indirect @@ -50,9 +51,7 @@ require ( github.com/pelletier/go-toml v1.3.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.8.1 - github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 - github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect - github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872 // indirect + github.com/prometheus/client_golang v0.9.3 github.com/rogpeppe/go-internal v1.3.0 github.com/rubenv/sql-migrate v0.0.0-20190618074426-f4d34eae5a5c // indirect github.com/sergi/go-diff v1.0.0 @@ -72,6 +71,7 @@ require ( go.uber.org/zap v1.10.0 golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c + google.golang.org/api v0.3.2 // indirect google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect gopkg.in/gorp.v1 v1.7.2 // indirect gopkg.in/square/go-jose.v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index 8d4105b69e..7a8a478dc1 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.37.2 h1:4y4L7BdHenTfZL0HervofNTHh9Ad6mNX72cQvl+5eH0= cloud.google.com/go v0.37.2/go.mod h1:H8IAquKe2L30IxoupDgqTaQvKSwF/c8prYHynGIWQbA= -contrib.go.opencensus.io/exporter/ocagent v0.4.11 h1:Zwy9skaqR2igcEfSVYDuAsbpa33N0RPtnYTHEe2whPI= -contrib.go.opencensus.io/exporter/ocagent v0.4.11/go.mod h1:7ihiYRbdcVfW4m4wlXi9WRPdv79C0fStcjNlyE6ek9s= +contrib.go.opencensus.io/exporter/ocagent v0.4.12 h1:jGFvw3l57ViIVEPKKEUXPcLYIXJmQxLUh6ey1eJhwyc= +contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= @@ -28,6 +28,7 @@ github.com/Masterminds/sprig v0.0.0-20190301161902-9f8fceff796f h1:lGvI8+dm9Y/Qr github.com/Masterminds/sprig v0.0.0-20190301161902-9f8fceff796f/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.0.1/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= @@ -45,12 +46,15 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5 github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= github.com/census-instrumentation/opencensus-proto v0.2.0 h1:LzQXZOgg4CQfE6bFvXGM30YZL1WW/M337pXml+GrcZ4= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 h1:HD4PLRzjuCVW79mQ0/pdsalOLHJ+FaEoqJLxfltpb2U= github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -80,6 +84,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v0.7.3-0.20190409004836-2e1cfbca03da h1:9ouQ6UxUR99krN1mfiQP+ygP5mS9YSioeyXD01WcwLA= @@ -117,6 +122,7 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= @@ -153,6 +159,8 @@ github.com/go-openapi/swag v0.19.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/ github.com/go-openapi/validate v0.17.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ= github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= @@ -315,6 +323,7 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -359,20 +368,26 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0 h1:kUZDBDTdBVBYBj5Tmh2NZLlF60mfjA27rM34b+cVwNU= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.0 h1:7etb9YClo3a6HjLzfl6rIQaU+FDfi0VSX39io3aQ+DM= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872 h1:0aNv3xC7DmQoy1/x1sMh18g+fihWW68LL13i8ao9kl4= -github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084 h1:sofwID9zm4tzrgykg80hfFph1mryUeLRsUfoocVVmRY= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/robfig/cron v0.0.0-20170526150127-736158dc09e1/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -394,6 +409,7 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= @@ -439,8 +455,9 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A= go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M= -go.opencensus.io v0.20.0 h1:L/ARO58pdktB6dLmYI0zAyW1XnavEmGziFd0MKfxnck= -go.opencensus.io v0.20.0/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.20.2 h1:NAfh7zF0/3/HqtMvJNZ/RFrSlCE6ZTlHmKfhL/Dm1Jk= +go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -550,6 +567,9 @@ google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+ google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU= google.golang.org/api v0.3.0 h1:UIJY20OEo3+tK5MBlcdx37kmdH6EnRjGkW78mc6+EeA= google.golang.org/api v0.3.0/go.mod h1:IuvZyQh8jgscv8qWfQ4ABd8m7hEudgBFM/EdhA3BnXw= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/api v0.3.2 h1:iTp+3yyl/KOtxa/d1/JUE0GGSoR6FuW5udver22iwpw= +google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/internal/util/k8sutil/options.go b/internal/util/k8sutil/options.go index 0c3eb86b37..afa24858a9 100644 --- a/internal/util/k8sutil/options.go +++ b/internal/util/k8sutil/options.go @@ -26,10 +26,14 @@ type MatchingFields struct { Sel fields.Selector } +var _ client.ListOption = MatchingFields{} + func (m MatchingFields) ApplyToList(opts *client.ListOptions) { opts.FieldSelector = m.Sel } +var _ client.DeleteAllOfOption = MatchingFields{} + func (m MatchingFields) ApplyToDeleteAllOf(opts *client.DeleteAllOfOptions) { opts.FieldSelector = m.Sel } diff --git a/test/e2e/_incluster-test-code/memcached_test.go b/test/e2e/_incluster-test-code/memcached_test.go index 6e2e18dc14..b8988fe5fd 100644 --- a/test/e2e/_incluster-test-code/memcached_test.go +++ b/test/e2e/_incluster-test-code/memcached_test.go @@ -137,12 +137,13 @@ func verifyLeader(t *testing.T, namespace string, f *framework.Framework, labels owner := owners[0] // get operator pods + opts := []client.ListOption{ + client.InNamespace(namespace), + client.MatchingLabels(labels), + client.MatchingField("status.phase", "Running"), + } pods := &v1.PodList{} - opts := &client.ListOptions{} - opts.InNamespace(namespace) - opts.MatchingLabels(labels) - opts.MatchingField("status.phase", "Running") - err = f.Client.List(goctx.TODO(), pods, client.UseListOptions(opts)) + err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { return nil, err } @@ -420,12 +421,13 @@ func memcachedOperatorMetricsTest(t *testing.T, f *framework.Framework, ctx *fra func getMetrics(t *testing.T, f *framework.Framework, labels map[string]string, ns, port string) ([]byte, error) { // Get operator pod + opts := []client.ListOption{ + client.InNamespace(ns), + client.MatchingLabels(labels), + client.MatchingField("status.phase", "Running"), + } pods := &v1.PodList{} - opts := &client.ListOptions{} - opts.InNamespace(ns) - opts.MatchingLabels(labels) - opts.MatchingField("status.phase", "Running") - err := f.Client.List(goctx.TODO(), pods, client.UseListOptions(opts)) + err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { return nil, fmt.Errorf("failed to get pods: (%v)", err) } From 2a590052cf21f21fc6c150e540b6ecda5497aafc Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 19 Aug 2019 14:17:10 -0700 Subject: [PATCH 03/14] update client.Delete() usage --- doc/user/client.md | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index 6904bbfc65..c8e07caabc 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -271,39 +271,13 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ```Go // Delete deletes the given obj from Kubernetes cluster. -func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...DeleteOptionFunc) error -``` -A `client.DeleteOptionFunc` sets fields of `client.DeleteOptions` to configure a `Delete` call: -```Go -// DeleteOptionFunc is a function that mutates a DeleteOptions struct. -type DeleteOptionFunc func(*DeleteOptions) - -type DeleteOptions struct { - // GracePeriodSeconds is the duration in seconds before the object should be - // deleted. Value must be non-negative integer. The value zero indicates - // delete immediately. If this value is nil, the default grace period for the - // specified type will be used. - GracePeriodSeconds *int64 - - // Preconditions must be fulfilled before a deletion is carried out. If not - // possible, a 409 Conflict status will be returned. - Preconditions *metav1.Preconditions - - // PropagationPolicy determined whether and how garbage collection will be - // performed. Either this field or OrphanDependents may be set, but not both. - // The default policy is decided by the existing finalizer set in the - // metadata.finalizers and the resource-specific default policy. - // Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - - // allow the garbage collector to delete the dependents in the background; - // 'Foreground' - a cascading policy that deletes all dependents in the - // foreground. - PropagationPolicy *metav1.DeletionPropagation - - // Raw represents raw DeleteOptions, as passed to the API server. - Raw *metav1.DeleteOptions -} +func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error ``` + +A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L156) fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L216), [`Preconditions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L227), [`PropagationPolicy`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L238). + Example: + ```Go import ( "context" From d1f2408bf357f7ab0dc4d08f0998fe4eb229a5f4 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 19 Aug 2019 14:24:51 -0700 Subject: [PATCH 04/14] more updates --- doc/user/client.md | 4 ++-- example/memcached-operator/memcached_controller.go.tmpl | 2 +- test/e2e/_incluster-test-code/memcached_test.go | 4 ++-- .../pkg/controller/memcached/memcached_controller.go | 4 ++-- .../pkg/controller/memcachedrs/memcachedrs_controller.go | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index c8e07caabc..874b5376fc 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -155,12 +155,12 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e // Return all pods in the request namespace with a label of `app=` // and is running. + podList := &v1.PodList{} opts := []client.ListOption{ client.InNamespace(request.NamespacedName.Namespace), client.MatchingLabels{"app", request.NamespacedName.Name}, client.MatchingField("status.phase", "Running"), } - podList := &v1.PodList{} ctx := context.TODO() err := r.client.List(ctx, podList, opts...) @@ -371,11 +371,11 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e // Update the App status with the pod names. // List the pods for this app's deployment. + podList := &corev1.PodList{} listOpts := []client.ListOption{ client.InNamespace(app.Namespace), client.MatchingLabels(labelsForApp(app.Name)), } - podList := &corev1.PodList{} if err = r.client.List(context.TODO(), podList, listOpts...); err != nil { return reconcile.Result{}, err } diff --git a/example/memcached-operator/memcached_controller.go.tmpl b/example/memcached-operator/memcached_controller.go.tmpl index 352412f9cc..94998b74bc 100644 --- a/example/memcached-operator/memcached_controller.go.tmpl +++ b/example/memcached-operator/memcached_controller.go.tmpl @@ -141,11 +141,11 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res // Update the Memcached status with the pod names // List the pods for this memcached's deployment + podList := &corev1.PodList{} listOpts := []client.ListOption{ client.InNamespace(memcached.Namespace), client.MatchingLabels(labelsForApp(memcached.Name)), } - podList := &corev1.PodList{} if err = r.client.List(context.TODO(), podList, listOpts...); err != nil { reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) return reconcile.Result{}, err diff --git a/test/e2e/_incluster-test-code/memcached_test.go b/test/e2e/_incluster-test-code/memcached_test.go index b8988fe5fd..84d888b958 100644 --- a/test/e2e/_incluster-test-code/memcached_test.go +++ b/test/e2e/_incluster-test-code/memcached_test.go @@ -137,12 +137,12 @@ func verifyLeader(t *testing.T, namespace string, f *framework.Framework, labels owner := owners[0] // get operator pods + pods := &v1.PodList{} opts := []client.ListOption{ client.InNamespace(namespace), client.MatchingLabels(labels), client.MatchingField("status.phase", "Running"), } - pods := &v1.PodList{} err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { return nil, err @@ -421,12 +421,12 @@ func memcachedOperatorMetricsTest(t *testing.T, f *framework.Framework, ctx *fra func getMetrics(t *testing.T, f *framework.Framework, labels map[string]string, ns, port string) ([]byte, error) { // Get operator pod + pods := &v1.PodList{} opts := []client.ListOption{ client.InNamespace(ns), client.MatchingLabels(labels), client.MatchingField("status.phase", "Running"), } - pods := &v1.PodList{} err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { return nil, fmt.Errorf("failed to get pods: (%v)", err) diff --git a/test/test-framework/pkg/controller/memcached/memcached_controller.go b/test/test-framework/pkg/controller/memcached/memcached_controller.go index a7b7fe43b0..840bd29b7d 100644 --- a/test/test-framework/pkg/controller/memcached/memcached_controller.go +++ b/test/test-framework/pkg/controller/memcached/memcached_controller.go @@ -150,11 +150,11 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res // Update the Memcached status with the pod names // List the pods for this memcached's deployment podList := &corev1.PodList{} - listOps := []client.ListOption{ + listOpts := []client.ListOption{ client.InNamespace(memcached.Namespace), client.MatchingLabels(labelsForMemcached(memcached.Name)), } - err = r.client.List(context.TODO(), podList, listOps...) + err = r.client.List(context.TODO(), podList, listOpts...) if err != nil { reqLogger.Error(err, "Failed to list pods.", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) return reconcile.Result{}, err diff --git a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go b/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go index 83fb68573d..89b53a3a78 100644 --- a/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go +++ b/test/test-framework/pkg/controller/memcachedrs/memcachedrs_controller.go @@ -152,11 +152,11 @@ func (r *ReconcileMemcachedRS) Reconcile(request reconcile.Request) (reconcile.R // Update the Memcached status with the pod names // List the pods for this memcached's replicaSet podList := &corev1.PodList{} - listOps := []client.ListOption{ + listOpts := []client.ListOption{ client.InNamespace(memcachedrs.Namespace), client.MatchingLabels(labelsForMemcached(memcachedrs.Name)), } - err = r.client.List(context.TODO(), podList, listOps...) + err = r.client.List(context.TODO(), podList, listOpts...) if err != nil { reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcachedrs.Namespace, "Memcached.Name", memcachedrs.Name) return reconcile.Result{}, err From dd2798270d4ca361e87702c19b7a4e6993bf20b0 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 19 Aug 2019 15:09:28 -0700 Subject: [PATCH 05/14] e2e code fixes --- example/memcached-operator/memcached_controller.go.tmpl | 3 +-- test/e2e/_incluster-test-code/memcached_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/example/memcached-operator/memcached_controller.go.tmpl b/example/memcached-operator/memcached_controller.go.tmpl index 94998b74bc..a2e3495962 100644 --- a/example/memcached-operator/memcached_controller.go.tmpl +++ b/example/memcached-operator/memcached_controller.go.tmpl @@ -10,7 +10,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -144,7 +143,7 @@ func (r *ReconcileMemcached) Reconcile(request reconcile.Request) (reconcile.Res podList := &corev1.PodList{} listOpts := []client.ListOption{ client.InNamespace(memcached.Namespace), - client.MatchingLabels(labelsForApp(memcached.Name)), + client.MatchingLabels(labelsForMemcached(memcached.Name)), } if err = r.client.List(context.TODO(), podList, listOpts...); err != nil { reqLogger.Error(err, "Failed to list pods", "Memcached.Namespace", memcached.Namespace, "Memcached.Name", memcached.Name) diff --git a/test/e2e/_incluster-test-code/memcached_test.go b/test/e2e/_incluster-test-code/memcached_test.go index 84d888b958..b1641afb7f 100644 --- a/test/e2e/_incluster-test-code/memcached_test.go +++ b/test/e2e/_incluster-test-code/memcached_test.go @@ -427,7 +427,7 @@ func getMetrics(t *testing.T, f *framework.Framework, labels map[string]string, client.MatchingLabels(labels), client.MatchingField("status.phase", "Running"), } - err = f.Client.List(goctx.TODO(), pods, opts...) + err := f.Client.List(goctx.TODO(), pods, opts...) if err != nil { return nil, fmt.Errorf("failed to get pods: (%v)", err) } From 36996f72d29e91c47f7fd915d72de965521b182a Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Fri, 23 Aug 2019 11:19:51 -0700 Subject: [PATCH 06/14] bump rc.0 to stable release --- CHANGELOG.md | 3 +-- doc/user/client.md | 4 ++-- go.mod | 2 +- go.sum | 8 ++++---- internal/pkg/scaffold/ansible/go_mod.go | 2 +- internal/pkg/scaffold/ansible/gopkgtoml.go | 2 +- internal/pkg/scaffold/go_mod.go | 2 +- internal/pkg/scaffold/gopkgtoml.go | 2 +- internal/pkg/scaffold/helm/go_mod.go | 2 +- internal/pkg/scaffold/helm/gopkgtoml.go | 2 +- 10 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cbc586c83..d10310a223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,7 @@ - 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. - 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. - 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. - - - [`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: + - [`sigs.k8s.io/controller-runtime/pkg/client.Client`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.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/pkg/client/interfaces.go#L61). To migrate: ```go import ( "context" diff --git a/doc/user/client.md b/doc/user/client.md index 874b5376fc..250631daf3 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -137,7 +137,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error ``` -A `client.ListOption` is an interface that sets [`client.ListOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L257) fields. A `client.ListOption` is created by using one of the provided implementations: [`LableSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L304), [`FieldSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L326), [`Namespace`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L339). +A `client.ListOption` is an interface that sets [`client.ListOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L257) fields. A `client.ListOption` is created by using one of the provided implementations: [`LableSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L304), [`FieldSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L326), [`Namespace`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L339). Example: @@ -274,7 +274,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error ``` -A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L156) fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L216), [`Preconditions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L227), [`PropagationPolicy`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0-rc.0/pkg/client/options.go#L238). +A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L156) fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L216), [`Preconditions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L227), [`PropagationPolicy`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L238). Example: diff --git a/go.mod b/go.mod index bba6d765c2..fc4e433eec 100644 --- a/go.mod +++ b/go.mod @@ -114,6 +114,6 @@ replace ( github.com/operator-framework/operator-lifecycle-manager => github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190605231540-b8a4faf68e36 k8s.io/helm => k8s.io/helm v2.14.1+incompatible k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde ) diff --git a/go.sum b/go.sum index 7a8a478dc1..107ffa9e4d 100644 --- a/go.sum +++ b/go.sum @@ -559,8 +559,8 @@ golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190320215829-36c10c0a621f/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c h1:KfpJVdWhuRqNk4XVXzjXf2KAV4TBEP77SYdFGjeGuIE= golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -gomodules.xyz/jsonpatch/v2 v2.0.0 h1:lHNQverf0+Gm1TbSbVIDWVXOhZ2FpZopxRqpr2uIjs4= -gomodules.xyz/jsonpatch/v2 v2.0.0/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU= +gomodules.xyz/jsonpatch/v2 v2.0.1 h1:xyiBuvkD2g5n7cYzx6u2sxQvsAy4QJsZFCzGVdzOXZ0= +gomodules.xyz/jsonpatch/v2 v2.0.1/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= @@ -654,8 +654,8 @@ k8s.io/kubernetes v1.14.1/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= -sigs.k8s.io/controller-runtime v0.2.0-rc.0 h1:49JLOielmXfrd44Cmk2c0eeIkQ/Vq4AvfqsZqya16/E= -sigs.k8s.io/controller-runtime v0.2.0-rc.0/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME= +sigs.k8s.io/controller-runtime v0.2.0 h1:5gL30PXOisGZl+Osi4CmLhvMUj77BO3wJeouKF2va50= +sigs.k8s.io/controller-runtime v0.2.0/go.mod h1:ZHqrRDZi3f6BzONcvlUxkqCKgwasGk5FZrnSv9TVZF4= sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde h1:ZkaHf5rNYzIB6CB82keKMQNv7xxkqT0ylOBdfJPfi+k= sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde/go.mod h1:ATWLRP3WGxuAN9HcT2LaKHReXIH+EZGzRuMHuxjXfhQ= sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0= diff --git a/internal/pkg/scaffold/ansible/go_mod.go b/internal/pkg/scaffold/ansible/go_mod.go index d544b54fd0..dec8c0f12c 100644 --- a/internal/pkg/scaffold/ansible/go_mod.go +++ b/internal/pkg/scaffold/ansible/go_mod.go @@ -61,7 +61,7 @@ replace ( ) replace ( - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286 diff --git a/internal/pkg/scaffold/ansible/gopkgtoml.go b/internal/pkg/scaffold/ansible/gopkgtoml.go index efc50f9ae8..abe87cd14d 100644 --- a/internal/pkg/scaffold/ansible/gopkgtoml.go +++ b/internal/pkg/scaffold/ansible/gopkgtoml.go @@ -54,7 +54,7 @@ const gopkgTomlTmpl = `[[constraint]] [[override]] name = "sigs.k8s.io/controller-runtime" - version = "=v0.2.0-rc.0" + version = "=v0.2.0" [prune] go-tests = true diff --git a/internal/pkg/scaffold/go_mod.go b/internal/pkg/scaffold/go_mod.go index 8a8b9392d1..3328019a57 100644 --- a/internal/pkg/scaffold/go_mod.go +++ b/internal/pkg/scaffold/go_mod.go @@ -60,7 +60,7 @@ replace ( replace ( github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. diff --git a/internal/pkg/scaffold/gopkgtoml.go b/internal/pkg/scaffold/gopkgtoml.go index 0ef628a3ca..e6571bfc59 100644 --- a/internal/pkg/scaffold/gopkgtoml.go +++ b/internal/pkg/scaffold/gopkgtoml.go @@ -73,7 +73,7 @@ required = [ [[override]] name = "sigs.k8s.io/controller-runtime" - version = "=v0.2.0-rc.0" + version = "=v0.2.0" # Required when resolving controller-runtime dependencies. [[override]] diff --git a/internal/pkg/scaffold/helm/go_mod.go b/internal/pkg/scaffold/helm/go_mod.go index ac207277b6..11d5475c6b 100644 --- a/internal/pkg/scaffold/helm/go_mod.go +++ b/internal/pkg/scaffold/helm/go_mod.go @@ -80,7 +80,7 @@ replace ( ) replace ( - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-rc.0 + sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. diff --git a/internal/pkg/scaffold/helm/gopkgtoml.go b/internal/pkg/scaffold/helm/gopkgtoml.go index d58f9cf285..0ce6eb95c0 100644 --- a/internal/pkg/scaffold/helm/gopkgtoml.go +++ b/internal/pkg/scaffold/helm/gopkgtoml.go @@ -66,7 +66,7 @@ const gopkgTomlTmpl = `[[constraint]] [[override]] name = "sigs.k8s.io/controller-runtime" - version = "=v0.2.0-rc.0" + version = "=v0.2.0" # We need overrides for the following imports because dep can't resolve them # correctly. The easiest way to get this right is to use the versions that From 2265d5404da270bcd6bbbcd31d9522604890de67 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Fri, 23 Aug 2019 14:22:01 -0700 Subject: [PATCH 07/14] use require instead of replace for controller-runtime --- go.mod | 3 +-- go.sum | 1 + internal/pkg/scaffold/ansible/go_mod.go | 11 ++++------- internal/pkg/scaffold/go_mod.go | 3 +-- internal/pkg/scaffold/helm/go_mod.go | 3 +-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index fc4e433eec..2ee95106a2 100644 --- a/go.mod +++ b/go.mod @@ -89,7 +89,7 @@ require ( k8s.io/kube-openapi v0.0.0-20190401085232-94e1e7b7574c k8s.io/kube-state-metrics v1.6.0 k8s.io/kubernetes v1.14.2 - sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools v0.0.0-20190411181648-9d55346c2bde sigs.k8s.io/kustomize v2.0.3+incompatible // indirect vbom.ml/util v0.0.0-20180919145318-efcd4e0f9787 // indirect @@ -114,6 +114,5 @@ replace ( github.com/operator-framework/operator-lifecycle-manager => github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190605231540-b8a4faf68e36 k8s.io/helm => k8s.io/helm v2.14.1+incompatible k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde ) diff --git a/go.sum b/go.sum index 107ffa9e4d..b1efa6f08f 100644 --- a/go.sum +++ b/go.sum @@ -654,6 +654,7 @@ k8s.io/kubernetes v1.14.1/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y= k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= +sigs.k8s.io/controller-runtime v0.1.10/go.mod h1:HFAYoOh6XMV+jKF1UjFwrknPbowfyHEHHRdJMf2jMX8= sigs.k8s.io/controller-runtime v0.2.0 h1:5gL30PXOisGZl+Osi4CmLhvMUj77BO3wJeouKF2va50= sigs.k8s.io/controller-runtime v0.2.0/go.mod h1:ZHqrRDZi3f6BzONcvlUxkqCKgwasGk5FZrnSv9TVZF4= sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde h1:ZkaHf5rNYzIB6CB82keKMQNv7xxkqT0ylOBdfJPfi+k= diff --git a/internal/pkg/scaffold/ansible/go_mod.go b/internal/pkg/scaffold/ansible/go_mod.go index dec8c0f12c..b1a0fdc15e 100644 --- a/internal/pkg/scaffold/ansible/go_mod.go +++ b/internal/pkg/scaffold/ansible/go_mod.go @@ -47,7 +47,7 @@ require ( k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect - sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools v0.1.10 ) @@ -60,12 +60,9 @@ replace ( k8s.io/kubernetes => k8s.io/kubernetes v1.14.1 ) -replace ( - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 - // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can - // resolve it correctly. - github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286 -) +// Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can +// resolve it correctly. +replace github.com/prometheus/prometheus => github.com/prometheus/prometheus d20e84d0fb64aff2f62a977adc8cfb656da4e286 ` func PrintGoMod() error { diff --git a/internal/pkg/scaffold/go_mod.go b/internal/pkg/scaffold/go_mod.go index 3328019a57..911e4a4a2a 100644 --- a/internal/pkg/scaffold/go_mod.go +++ b/internal/pkg/scaffold/go_mod.go @@ -45,7 +45,7 @@ require ( k8s.io/apimachinery v0.0.0-20190612125636-6a5db36e93ad k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect - sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools v0.1.10 ) @@ -60,7 +60,6 @@ replace ( replace ( github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. diff --git a/internal/pkg/scaffold/helm/go_mod.go b/internal/pkg/scaffold/helm/go_mod.go index 11d5475c6b..0b771182a5 100644 --- a/internal/pkg/scaffold/helm/go_mod.go +++ b/internal/pkg/scaffold/helm/go_mod.go @@ -63,7 +63,7 @@ require ( k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible k8s.io/helm v2.14.1+incompatible // indirect k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect - sigs.k8s.io/controller-runtime v0.2.0-beta.3 + sigs.k8s.io/controller-runtime v0.2.0 sigs.k8s.io/controller-tools v0.1.10 ) @@ -80,7 +80,6 @@ replace ( ) replace ( - sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0 github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.31.1 // Pinned to v2.10.0 (kubernetes-1.14.1) so https://proxy.golang.org can // resolve it correctly. From 34703bfc9b261095cd69e9f8c3e3edd7b1ceeb1d Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Fri, 23 Aug 2019 14:22:30 -0700 Subject: [PATCH 08/14] use client.MatchingFields{} directly --- doc/user/client.md | 2 +- internal/util/k8sutil/options.go | 4 ++++ test/e2e/_incluster-test-code/memcached_test.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index 250631daf3..d4d4e5139d 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -159,7 +159,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e opts := []client.ListOption{ client.InNamespace(request.NamespacedName.Namespace), client.MatchingLabels{"app", request.NamespacedName.Name}, - client.MatchingField("status.phase", "Running"), + client.MatchingFields{"status.phase", "Running"}, } ctx := context.TODO() err := r.client.List(ctx, podList, opts...) diff --git a/internal/util/k8sutil/options.go b/internal/util/k8sutil/options.go index afa24858a9..5866205510 100644 --- a/internal/util/k8sutil/options.go +++ b/internal/util/k8sutil/options.go @@ -19,6 +19,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +// NOTE: use controller-runtime's version of MatchingFields if the following +// issue is accepted as a feature: +// https://github.com/kubernetes-sigs/controller-runtime/issues/576 + // MatchingFields implements the client.ListOption and client.DeleteAllOfOption // interfaces so fields.Selector can be used directly in client.List and // client.DeleteAllOf. diff --git a/test/e2e/_incluster-test-code/memcached_test.go b/test/e2e/_incluster-test-code/memcached_test.go index b1641afb7f..e7fb405611 100644 --- a/test/e2e/_incluster-test-code/memcached_test.go +++ b/test/e2e/_incluster-test-code/memcached_test.go @@ -141,7 +141,7 @@ func verifyLeader(t *testing.T, namespace string, f *framework.Framework, labels opts := []client.ListOption{ client.InNamespace(namespace), client.MatchingLabels(labels), - client.MatchingField("status.phase", "Running"), + client.MatchingFields{"status.phase", "Running"}, } err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { @@ -425,7 +425,7 @@ func getMetrics(t *testing.T, f *framework.Framework, labels map[string]string, opts := []client.ListOption{ client.InNamespace(ns), client.MatchingLabels(labels), - client.MatchingField("status.phase", "Running"), + client.MatchingFields{"status.phase", "Running"}, } err := f.Client.List(goctx.TODO(), pods, opts...) if err != nil { From 5a64d9b1cad17706b757198021b0a0829e3aee6b Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 26 Aug 2019 11:01:01 -0700 Subject: [PATCH 09/14] use map constructor instead of struct --- doc/user/client.md | 2 +- test/e2e/_incluster-test-code/memcached_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index d4d4e5139d..20d3b97d2b 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -159,7 +159,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e opts := []client.ListOption{ client.InNamespace(request.NamespacedName.Namespace), client.MatchingLabels{"app", request.NamespacedName.Name}, - client.MatchingFields{"status.phase", "Running"}, + client.MatchingFields{"status.phase": "Running"}, } ctx := context.TODO() err := r.client.List(ctx, podList, opts...) diff --git a/test/e2e/_incluster-test-code/memcached_test.go b/test/e2e/_incluster-test-code/memcached_test.go index e7fb405611..a7b3bea325 100644 --- a/test/e2e/_incluster-test-code/memcached_test.go +++ b/test/e2e/_incluster-test-code/memcached_test.go @@ -141,7 +141,7 @@ func verifyLeader(t *testing.T, namespace string, f *framework.Framework, labels opts := []client.ListOption{ client.InNamespace(namespace), client.MatchingLabels(labels), - client.MatchingFields{"status.phase", "Running"}, + client.MatchingFields{"status.phase": "Running"}, } err = f.Client.List(goctx.TODO(), pods, opts...) if err != nil { @@ -425,7 +425,7 @@ func getMetrics(t *testing.T, f *framework.Framework, labels map[string]string, opts := []client.ListOption{ client.InNamespace(ns), client.MatchingLabels(labels), - client.MatchingFields{"status.phase", "Running"}, + client.MatchingFields{"status.phase": "Running"}, } err := f.Client.List(goctx.TODO(), pods, opts...) if err != nil { From d9bc74957c89366aedad09af8e3570ba161c2677 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 27 Aug 2019 08:59:23 -0700 Subject: [PATCH 10/14] update runtime Client options and method signatures --- CHANGELOG.md | 1 + doc/user/client.md | 99 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d10310a223..aefdf6d9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - 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. - 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. - 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. + - All methods on [`sigs.k8s.io/controller-runtime/pkg/client.Client`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/interfaces.go#L104) (except for `Get()`) have been updated. Instead of each using a `struct`-typed or variadic functional option parameter, or having no option parameter, each now uses a variadic interface option parameter typed for each method. See `List()` below for an example. - [`sigs.k8s.io/controller-runtime/pkg/client.Client`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.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/pkg/client/interfaces.go#L61). To migrate: ```go import ( diff --git a/doc/user/client.md b/doc/user/client.md index 20d3b97d2b..183b449323 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -137,7 +137,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error ``` -A `client.ListOption` is an interface that sets [`client.ListOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L257) fields. A `client.ListOption` is created by using one of the provided implementations: [`LableSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L304), [`FieldSelector`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L326), [`Namespace`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L339). +A `client.ListOption` is an interface that sets [`client.ListOptions`][list-options] fields. A `client.ListOption` is created by using one of the provided implementations: [`MatchingLabels`][matchinglabels], [`MatchingFields`][matchingfields], [`InNamespace`][innamespace]. Example: @@ -168,14 +168,23 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e } ``` +[list-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ListOptions +[matchinglabels]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingLabels +[matchingfields]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingFields +[innamespace]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#InNamespace + #### Create ```Go // Create saves the object obj in the Kubernetes cluster. // Returns an error -func (c Client) Create(ctx context.Context, obj runtime.Object) error +func (c Client) Create(ctx context.Context, obj runtime.Object, opts ...client.CreateOption) error ``` + +A `client.CreateOption` is an interface that sets [`client.CreateOptions`][create-options] fields. A `client.CreateOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. + Example: + ```Go import ( "context" @@ -196,6 +205,8 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e } ``` +[create-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#CreateOptions + #### Update ```Go @@ -203,9 +214,13 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e // struct pointer so that obj can be updated with the content returned // by the API server. Update does *not* update the resource's status // subresource -func (c Client) Update(ctx context.Context, obj runtime.Object) error +func (c Client) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error ``` + +A `client.UpdateOption` is an interface that sets [`client.UpdateOptions`][update-options] fields. A `client.UpdateOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. + Example: + ```Go import ( "context" @@ -229,10 +244,54 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e } ``` +[update-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#UpdateOptions + +#### Patch + +```Go +// Patch patches the given obj in the Kubernetes cluster. obj must be a +// struct pointer so that obj can be updated with the content returned by the Server. +func (c Client) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.UpdateOption) error +``` + +A `client.PatchOption` is an interface that sets [`client.PatchOptions`][patch-options] fields. A `client.PatchOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. + +Example: + +```Go +import ( + "context" + "k8s.io/api/apps/v1" + "sigs.k8s.io/controller-runtime/pkg/reconcile" +) + +func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, error) { + ... + + dep := &v1.Deployment{} + err := r.client.Get(context.TODO(), request.NamespacedName, dep) + + ... + + ctx := context.TODO() + dep.Spec.Selector.MatchLabels["is_running"] = "true" + // A marge patch will preserve other fields modified at runtime. + patch := client.MergeFrom(dep) + err := r.client.Patch(ctx, dep, patch) + + ... +} +``` + +[patch-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PatchOption +[dryrunall]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DryRunAll +[forceownership]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ForceOwnership + ##### Updating Status Subresource -When updating the [status subresource][cr-status-subresource] from the client, -the StatusWriter must be used which can be gotten with `Status()` +When updating the [status subresource][cr-status-subresource] from the client, the [`StatusWriter`][statuswriter] must be used. The status subresource is retrieved with `Status()` and updated with `Update()` or patched with `Patch()`. + +`Update()` takes variadic `client.UpdateOption`'s, and `Patch()` takes variadic `client.PatchOption`'s. See [`Client.Update()`](#update) and [`Client.Patch()`](#patch) for more details. Generally these options are not needed. ##### Status @@ -253,19 +312,27 @@ import ( func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, error) { ... + ctx := context.TODO() mem := &cachev1alpha1.Memcached{} - err := r.client.Get(context.TODO(), request.NamespacedName, mem) + err := r.client.Get(ctx, request.NamespacedName, mem) ... - ctx := context.TODO() + // Update mem.Status.Nodes = []string{"pod1", "pod2"} err := r.client.Status().Update(ctx, mem) ... + + // Patch + patch := client.MergeFrom(mem) + err := r.client.Status().Patch(ctx, mem, patch) + + ... } ``` +[statuswriter]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#StatusWriter #### Delete @@ -274,7 +341,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error ``` -A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L156) fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L216), [`Preconditions`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L227), [`PropagationPolicy`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.2.0/pkg/client/options.go#L238). +A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`][delete-opts] fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`][graceperiodseconds], [`Preconditions`][preconditions], [`PropagationPolicy`][propagationpolicy]. Example: @@ -305,6 +372,22 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e } ``` +[delete-opts]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DeleteOptions +[graceperiodseconds]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#GracePeriodSeconds +[preconditions]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#Preconditions +[propagationpolicy]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PropagationPolicy + +#### Delete + +```Go +// DeleteAllOf deletes all objects of the given type matching the given options. +func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error +``` + +A `client.DeleteAllOfOption` is an interface that sets [`client.DeleteAllOfOptions`][deleteallof-opts] fields. A `client.DeleteAllOfOption` wraps a [`client.ListOption`](#list) and [`client.DeleteOption`](#delete). + +[deleteallof-opts]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DeleteAllOfOptions + ### Example usage ```Go From 09f34aadb10a4aeb46d3fcf8ab13ecb162ba95b0 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 27 Aug 2019 10:17:55 -0700 Subject: [PATCH 11/14] fix typo --- doc/user/client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/client.md b/doc/user/client.md index 183b449323..6cbd3a9236 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -275,7 +275,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ctx := context.TODO() dep.Spec.Selector.MatchLabels["is_running"] = "true" - // A marge patch will preserve other fields modified at runtime. + // A merge patch will preserve other fields modified at runtime. patch := client.MergeFrom(dep) err := r.client.Patch(ctx, dep, patch) From 71b9de5f8799189b7021bd075c16708ad8d455b2 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 29 Aug 2019 11:50:28 -0700 Subject: [PATCH 12/14] Update doc/user/client.md Co-Authored-By: Haseeb Tariq --- doc/user/client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/client.md b/doc/user/client.md index 6cbd3a9236..d04ac2b76d 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -154,7 +154,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ... // Return all pods in the request namespace with a label of `app=` - // and is running. + // and phase `Running`. podList := &v1.PodList{} opts := []client.ListOption{ client.InNamespace(request.NamespacedName.Namespace), From 1cf87bc02b3929e4ace9a3879bc7b6b39f512390 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 3 Sep 2019 10:32:34 -0700 Subject: [PATCH 13/14] Apply suggestions from code review Co-Authored-By: Haseeb Tariq --- doc/user/client.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/user/client.md b/doc/user/client.md index d04ac2b76d..30832886d8 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -137,7 +137,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) List(ctx context.Context, list runtime.Object, opts ...client.ListOption) error ``` -A `client.ListOption` is an interface that sets [`client.ListOptions`][list-options] fields. A `client.ListOption` is created by using one of the provided implementations: [`MatchingLabels`][matchinglabels], [`MatchingFields`][matchingfields], [`InNamespace`][innamespace]. +A `client.ListOption` is an interface that sets [`client.ListOptions`][list-options] fields. A `client.ListOption` is created by using one of the provided implementations: [`MatchingLabels`][matching-labels], [`MatchingFields`][matching-fields], [`InNamespace`][in-namespace]. Example: @@ -181,7 +181,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Create(ctx context.Context, obj runtime.Object, opts ...client.CreateOption) error ``` -A `client.CreateOption` is an interface that sets [`client.CreateOptions`][create-options] fields. A `client.CreateOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. +A `client.CreateOption` is an interface that sets [`client.CreateOptions`][create-options] fields. A `client.CreateOption` is created by using one of the provided implementations: [`DryRunAll`][dry-run-all], [`ForceOwnership`][force-ownership]. Generally these options are not needed. Example: @@ -262,6 +262,7 @@ Example: import ( "context" "k8s.io/api/apps/v1" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -332,7 +333,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e } ``` -[statuswriter]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#StatusWriter +[status-writer]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#StatusWriter #### Delete @@ -377,11 +378,11 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e [preconditions]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#Preconditions [propagationpolicy]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PropagationPolicy -#### Delete +#### DeleteAllOf ```Go // DeleteAllOf deletes all objects of the given type matching the given options. -func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error +func (c Client) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...client.DeleteAllOfOption) error ``` A `client.DeleteAllOfOption` is an interface that sets [`client.DeleteAllOfOptions`][deleteallof-opts] fields. A `client.DeleteAllOfOption` wraps a [`client.ListOption`](#list) and [`client.DeleteOption`](#delete). From 11386f334481679d4b66ca7ce13596eeee84f17f Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 3 Sep 2019 14:01:55 -0700 Subject: [PATCH 14/14] add CHANGELOG.md FrameworkClient breaking change and DeleteAllOf() example to doc/user/client.md --- CHANGELOG.md | 1 + doc/user/client.md | 52 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c480dc1b6..87a683b34d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ } err = r.client.List(context.TODO(), podList, listOpts...) ``` +- [`pkg/test.FrameworkClient`](https://github.com/operator-framework/operator-sdk/blob/master/pkg/test/client.go#L33) methods `List()` and `Delete()` have new signatures corresponding to the homonymous methods of `sigs.k8s.io/controller-runtime/pkg/client.Client`. - CRD file names were previously of the form `___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 `__crd.yaml`. `` is the full group name of your CRD while `` is the last subdomain of ``, ex. `foo.bar.com` vs `foo`. `` is the plural lower-case CRD Kind found at `spec.names.plural`. ### Deprecated diff --git a/doc/user/client.md b/doc/user/client.md index 30832886d8..747f247f6d 100644 --- a/doc/user/client.md +++ b/doc/user/client.md @@ -169,9 +169,9 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ``` [list-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ListOptions -[matchinglabels]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingLabels -[matchingfields]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingFields -[innamespace]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#InNamespace +[matching-labels]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingLabels +[matching-fields]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#MatchingFields +[in-namespace]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#InNamespace #### Create @@ -217,7 +217,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error ``` -A `client.UpdateOption` is an interface that sets [`client.UpdateOptions`][update-options] fields. A `client.UpdateOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. +A `client.UpdateOption` is an interface that sets [`client.UpdateOptions`][update-options] fields. A `client.UpdateOption` is created by using one of the provided implementations: [`DryRunAll`][dry-run-all], [`ForceOwnership`][force-ownership]. Generally these options are not needed. Example: @@ -254,7 +254,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.UpdateOption) error ``` -A `client.PatchOption` is an interface that sets [`client.PatchOptions`][patch-options] fields. A `client.PatchOption` is created by using one of the provided implementations: [`DryRunAll`][dryrunall], [`ForceOwnership`][forceownership]. Generally these options are not needed. +A `client.PatchOption` is an interface that sets [`client.PatchOptions`][patch-options] fields. A `client.PatchOption` is created by using one of the provided implementations: [`DryRunAll`][dry-run-all], [`ForceOwnership`][force-ownership]. Generally these options are not needed. Example: @@ -285,12 +285,12 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ``` [patch-options]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PatchOption -[dryrunall]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DryRunAll -[forceownership]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ForceOwnership +[dry-run-all]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DryRunAll +[force-ownership]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#ForceOwnership ##### Updating Status Subresource -When updating the [status subresource][cr-status-subresource] from the client, the [`StatusWriter`][statuswriter] must be used. The status subresource is retrieved with `Status()` and updated with `Update()` or patched with `Patch()`. +When updating the [status subresource][cr-status-subresource] from the client, the [`StatusWriter`][status-writer] must be used. The status subresource is retrieved with `Status()` and updated with `Update()` or patched with `Patch()`. `Update()` takes variadic `client.UpdateOption`'s, and `Patch()` takes variadic `client.PatchOption`'s. See [`Client.Update()`](#update) and [`Client.Patch()`](#patch) for more details. Generally these options are not needed. @@ -342,7 +342,7 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e func (c Client) Delete(ctx context.Context, obj runtime.Object, opts ...client.DeleteOption) error ``` -A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`][delete-opts] fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`][graceperiodseconds], [`Preconditions`][preconditions], [`PropagationPolicy`][propagationpolicy]. +A `client.DeleteOption` is an interface that sets [`client.DeleteOptions`][delete-opts] fields. A `client.DeleteOption` is created by using one of the provided implementations: [`GracePeriodSeconds`][grace-period-seconds], [`Preconditions`][preconditions], [`PropagationPolicy`][propagation-policy]. Example: @@ -374,9 +374,9 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e ``` [delete-opts]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DeleteOptions -[graceperiodseconds]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#GracePeriodSeconds +[grace-period-seconds]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#GracePeriodSeconds [preconditions]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#Preconditions -[propagationpolicy]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PropagationPolicy +[propagation-policy]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#PropagationPolicy #### DeleteAllOf @@ -387,6 +387,36 @@ func (c Client) DeleteAllOf(ctx context.Context, obj runtime.Object, opts ...cli A `client.DeleteAllOfOption` is an interface that sets [`client.DeleteAllOfOptions`][deleteallof-opts] fields. A `client.DeleteAllOfOption` wraps a [`client.ListOption`](#list) and [`client.DeleteOption`](#delete). +Example: + +```Go +import ( + "context" + "fmt" + "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/reconcile" +) + +func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, error) { + ... + + // Delete all pods in the request namespace with a label of `app=` + // and phase `Failed`. + pod := &v1.Pod{} + opts := []client.DeleteAllOfOption{ + client.InNamespace(request.NamespacedName.Namespace), + client.MatchingLabels{"app", request.NamespacedName.Name}, + client.MatchingFields{"status.phase": "Failed"}, + client.GracePeriodSeconds(5), + } + ctx := context.TODO() + err := r.client.DeleteAllOf(ctx, pod, opts...) + + ... +} +``` + [deleteallof-opts]:https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#DeleteAllOfOptions ### Example usage