Skip to content

Commit 0f6d9f8

Browse files
committedJul 24, 2020
Remove EnqueueRequestForAnnotation handler from SDK
This commit removes pkg/handler/enqueue_annotation.go from SDK, and modifies helm/ansible to use EnqueueRequestForAnnotation handler implemented in Operator-lib.
1 parent ff73712 commit 0f6d9f8

File tree

10 files changed

+119
-166
lines changed

10 files changed

+119
-166
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
entries:
2+
- description: >
3+
Remove the implementation for `EnqueueRequestForAnnotation` handler from sdk repository, and
4+
reference it from operator-lib instead.
5+
kind: "change"
6+
7+
# Is this a breaking change?
8+
breaking: true
9+
10+
# Migration can be defined to automatically add a section to
11+
# the migration guide. This is required for breaking changes.
12+
migration:
13+
header: Move the implementation of `EnqueueRequestForAnnotation` handler
14+
body: >
15+
The implementation of `EnqueueRequestForAnnotation` handler has been removed from Operator SDK repository,
16+
and is now imported from Operator-lib.

‎go.mod

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ require (
1313
github.com/markbates/inflect v1.0.4
1414
github.com/mattn/go-isatty v0.0.12
1515
github.com/mitchellh/go-homedir v1.1.0
16-
github.com/onsi/ginkgo v1.12.0
17-
github.com/onsi/gomega v1.9.0
16+
github.com/onsi/ginkgo v1.12.1
17+
github.com/onsi/gomega v1.10.1
1818
github.com/operator-framework/api v0.3.8
19-
github.com/operator-framework/operator-lib v0.0.0-20200722145423-0ffd6fc49593
19+
github.com/operator-framework/operator-lib v0.0.0-20200723212032-525cb9a9ed70
2020
github.com/operator-framework/operator-registry v1.12.6-0.20200611222234-275301b779f8
2121
github.com/prometheus/client_golang v1.5.1
2222
github.com/rogpeppe/go-internal v1.5.0
@@ -30,18 +30,18 @@ require (
3030
go.uber.org/zap v1.14.1
3131
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b
3232
gomodules.xyz/jsonpatch/v3 v3.0.1
33-
gopkg.in/yaml.v2 v2.2.8
33+
gopkg.in/yaml.v2 v2.3.0
3434
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966
3535
helm.sh/helm/v3 v3.2.4
36-
k8s.io/api v0.18.2
37-
k8s.io/apiextensions-apiserver v0.18.2
38-
k8s.io/apimachinery v0.18.2
36+
k8s.io/api v0.18.4
37+
k8s.io/apiextensions-apiserver v0.18.4
38+
k8s.io/apimachinery v0.18.4
3939
k8s.io/cli-runtime v0.18.2
40-
k8s.io/client-go v0.18.2
40+
k8s.io/client-go v0.18.4
4141
k8s.io/klog v1.0.0
4242
k8s.io/kubectl v0.18.2
4343
rsc.io/letsencrypt v0.0.3 // indirect
44-
sigs.k8s.io/controller-runtime v0.6.0
44+
sigs.k8s.io/controller-runtime v0.6.1
4545
sigs.k8s.io/controller-tools v0.3.0
4646
sigs.k8s.io/kubebuilder v1.0.9-0.20200618125005-36aa113dbe99
4747
sigs.k8s.io/yaml v1.2.0

‎go.sum

+62-2
Large diffs are not rendered by default.

‎internal/generate/crd/crd_test.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,10 @@ spec:
300300
description: Memcached is the Schema for the memcacheds API
301301
properties:
302302
apiVersion:
303-
description: 'APIVersion defines the versioned schema of this representation
304-
of an object. Servers should convert recognized schemas to the latest
305-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
303+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
306304
type: string
307305
kind:
308-
description: 'Kind is a string value representing the REST resource this
309-
object represents. Servers may infer this from the endpoint the client
310-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
306+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
311307
type: string
312308
metadata:
313309
type: object
@@ -361,14 +357,10 @@ spec:
361357
description: Memcached is the Schema for the memcacheds API
362358
properties:
363359
apiVersion:
364-
description: 'APIVersion defines the versioned schema of this representation
365-
of an object. Servers should convert recognized schemas to the latest
366-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
360+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
367361
type: string
368362
kind:
369-
description: 'Kind is a string value representing the REST resource this
370-
object represents. Servers may infer this from the endpoint the client
371-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
363+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
372364
type: string
373365
metadata:
374366
type: object

‎pkg/ansible/proxy/cache_response.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"regexp"
2424
"strings"
2525

26+
libhandler "github.com/operator-framework/operator-lib/handler"
2627
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
2728
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
2829
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
29-
osdkHandler "github.com/operator-framework/operator-sdk/pkg/handler"
3030

3131
"k8s.io/apimachinery/pkg/api/meta"
3232
metainternalscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
@@ -224,7 +224,7 @@ func (c *cacheResponseHandler) recoverDependentWatches(req *http.Request, un *un
224224
}
225225
}
226226
}
227-
if typeString, ok := un.GetAnnotations()[osdkHandler.TypeAnnotation]; ok {
227+
if typeString, ok := un.GetAnnotations()[libhandler.TypeAnnotation]; ok {
228228
ownerGV, err := schema.ParseGroupVersion(ownerRef.APIVersion)
229229
if err != nil {
230230
m := fmt.Sprintf("could not get group version for: %v", ownerGV)

‎pkg/ansible/proxy/inject_owner.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"net/http"
2323
"net/http/httputil"
2424

25+
"github.com/operator-framework/operator-lib/handler"
2526
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
2627
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
2728
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
28-
"github.com/operator-framework/operator-sdk/pkg/handler"
2929

3030
"k8s.io/apimachinery/pkg/api/meta"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -146,7 +146,13 @@ func (i *injectOwnerReferenceHandler) ServeHTTP(w http.ResponseWriter, req *http
146146
if addOwnerRef {
147147
data.SetOwnerReferences(append(data.GetOwnerReferences(), owner.OwnerReference))
148148
} else {
149-
handler.SetOwnerAnnotation(data, ownerObject)
149+
err := handler.SetOwnerAnnotations(data, ownerObject)
150+
if err != nil {
151+
m := "Could not set owner annotations"
152+
log.Error(err, m)
153+
http.Error(w, m, http.StatusBadRequest)
154+
return
155+
}
150156
}
151157
newBody, err := json.Marshal(data.Object)
152158
if err != nil {

‎pkg/ansible/proxy/proxy.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import (
2929
"sync"
3030
"time"
3131

32+
libhandler "github.com/operator-framework/operator-lib/handler"
33+
"github.com/operator-framework/operator-lib/predicate"
34+
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
35+
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/kubeconfig"
36+
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
3237
"k8s.io/apimachinery/pkg/api/meta"
3338
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3439
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -38,12 +43,6 @@ import (
3843
"sigs.k8s.io/controller-runtime/pkg/cache"
3944
"sigs.k8s.io/controller-runtime/pkg/handler"
4045
"sigs.k8s.io/controller-runtime/pkg/source"
41-
42-
"github.com/operator-framework/operator-lib/predicate"
43-
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
44-
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/kubeconfig"
45-
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
46-
osdkHandler "github.com/operator-framework/operator-sdk/pkg/handler"
4746
)
4847

4948
// This is the default timeout to wait for the cache to respond
@@ -257,11 +256,14 @@ func addWatchToController(owner kubeconfig.NamespacedOwnerReference, cMap *contr
257256
return nil
258257
}
259258
awMap.Store(resource.GroupVersionKind())
260-
typeString := fmt.Sprintf("%v.%v", owner.Kind, ownerGV.Group)
259+
ownerGK := schema.GroupKind{
260+
Kind: owner.Kind,
261+
Group: ownerGV.Group,
262+
}
261263
log.Info("Watching child resource", "kind", resource.GroupVersionKind(),
262-
"enqueue_annotation_type", typeString)
264+
"enqueue_annotation_type", ownerGK.String())
263265
err = contents.Controller.Watch(&source.Kind{Type: resource},
264-
&osdkHandler.EnqueueRequestForAnnotation{Type: typeString}, predicate.DependentPredicate{})
266+
&libhandler.EnqueueRequestForAnnotation{Type: ownerGK}, predicate.DependentPredicate{})
265267
if err != nil {
266268
log.Error(err, "Failed to watch child resource",
267269
"kind", resource.GroupVersionKind(), "enqueue_kind", u.GroupVersionKind())

‎pkg/handler/enqueue_annotation.go

-127
This file was deleted.

‎pkg/helm/client/client.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"errors"
1919
"io"
2020

21+
"github.com/operator-framework/operator-lib/handler"
2122
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
22-
"github.com/operator-framework/operator-sdk/pkg/handler"
2323
"helm.sh/helm/v3/pkg/kube"
2424
"k8s.io/apimachinery/pkg/api/meta"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -148,7 +148,10 @@ func (c *ownerRefInjectingClient) Build(reader io.Reader, validate bool) (kube.R
148148
ownerRef := metav1.NewControllerRef(c.owner, c.owner.GroupVersionKind())
149149
u.SetOwnerReferences([]metav1.OwnerReference{*ownerRef})
150150
} else {
151-
handler.SetOwnerAnnotation(u, c.owner)
151+
err := handler.SetOwnerAnnotations(u, c.owner)
152+
if err != nil {
153+
return err
154+
}
152155
}
153156
return nil
154157
})

‎pkg/helm/controller/controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"sigs.k8s.io/controller-runtime/pkg/source"
3333
"sigs.k8s.io/yaml"
3434

35+
libhandler "github.com/operator-framework/operator-lib/handler"
3536
"github.com/operator-framework/operator-lib/predicate"
3637
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
3738
"github.com/operator-framework/operator-sdk/pkg/handler"
@@ -132,7 +133,7 @@ func watchDependentResources(mgr manager.Manager, r *HelmOperatorReconciler, c c
132133
return err
133134
}
134135
} else { // Setup watch using annotations.
135-
err = c.Watch(&source.Kind{Type: &u}, &handler.EnqueueRequestForAnnotation{Type: gvk.GroupKind().String()},
136+
err = c.Watch(&source.Kind{Type: &u}, &libhandler.EnqueueRequestForAnnotation{Type: gvk.GroupKind()},
136137
predicate.DependentPredicate{})
137138
if err != nil {
138139
return err

0 commit comments

Comments
 (0)