Skip to content

Commit

Permalink
Remove EnqueueRequestForAnnotation handler from SDK
Browse files Browse the repository at this point in the history
This commit removes pkg/handler/enqueue_annotation.go from SDK,
and modifies helm/ansible to use EnqueueRequestForAnnotation handler
implemented in Operator-lib.
  • Loading branch information
varshaprasad96 committed Jul 24, 2020
1 parent ff73712 commit 726ec66
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 161 deletions.
8 changes: 8 additions & 0 deletions changelog/fragments/mv-EnqueueRequestForAnnotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
entries:
- description: >
Remove the implementation for `EnqueueRequestForAnnotation` handler from sdk repository, and
reference it from operator-lib instead.
kind: "change"
# Is this a breaking change?
breaking: false
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require (
github.com/markbates/inflect v1.0.4
github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/operator-framework/api v0.3.8
github.com/operator-framework/operator-lib v0.0.0-20200722145423-0ffd6fc49593
github.com/operator-framework/operator-lib v0.0.0-20200723212032-525cb9a9ed70
github.com/operator-framework/operator-registry v1.12.6-0.20200611222234-275301b779f8
github.com/prometheus/client_golang v1.5.1
github.com/rogpeppe/go-internal v1.5.0
Expand All @@ -30,18 +30,18 @@ require (
go.uber.org/zap v1.14.1
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b
gomodules.xyz/jsonpatch/v3 v3.0.1
gopkg.in/yaml.v2 v2.2.8
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966
helm.sh/helm/v3 v3.2.4
k8s.io/api v0.18.2
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.18.2
k8s.io/api v0.18.4
k8s.io/apiextensions-apiserver v0.18.4
k8s.io/apimachinery v0.18.4
k8s.io/cli-runtime v0.18.2
k8s.io/client-go v0.18.2
k8s.io/client-go v0.18.4
k8s.io/klog v1.0.0
k8s.io/kubectl v0.18.2
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.6.0
sigs.k8s.io/controller-runtime v0.6.1
sigs.k8s.io/controller-tools v0.3.0
sigs.k8s.io/kubebuilder v1.0.9-0.20200618125005-36aa113dbe99
sigs.k8s.io/yaml v1.2.0
Expand Down
64 changes: 62 additions & 2 deletions go.sum

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions internal/generate/crd/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,10 @@ spec:
description: Memcached is the Schema for the memcacheds API
properties:
apiVersion:
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'
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'
type: string
kind:
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'
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'
type: string
metadata:
type: object
Expand Down Expand Up @@ -361,14 +357,10 @@ spec:
description: Memcached is the Schema for the memcacheds API
properties:
apiVersion:
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'
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'
type: string
kind:
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'
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'
type: string
metadata:
type: object
Expand Down
4 changes: 2 additions & 2 deletions pkg/ansible/proxy/cache_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"regexp"
"strings"

libhandler "github.com/operator-framework/operator-lib/handler"
"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"
metainternalscheme "k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme"
Expand Down Expand Up @@ -224,7 +224,7 @@ func (c *cacheResponseHandler) recoverDependentWatches(req *http.Request, un *un
}
}
}
if typeString, ok := un.GetAnnotations()[osdkHandler.TypeAnnotation]; ok {
if typeString, ok := un.GetAnnotations()[libhandler.TypeAnnotation]; ok {
ownerGV, err := schema.ParseGroupVersion(ownerRef.APIVersion)
if err != nil {
m := fmt.Sprintf("could not get group version for: %v", ownerGV)
Expand Down
10 changes: 8 additions & 2 deletions pkg/ansible/proxy/inject_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"net/http"
"net/http/httputil"

"github.com/operator-framework/operator-lib/handler"
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
"github.com/operator-framework/operator-sdk/pkg/handler"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -146,7 +146,13 @@ func (i *injectOwnerReferenceHandler) ServeHTTP(w http.ResponseWriter, req *http
if addOwnerRef {
data.SetOwnerReferences(append(data.GetOwnerReferences(), owner.OwnerReference))
} else {
handler.SetOwnerAnnotation(data, ownerObject)
err := handler.SetOwnerAnnotations(data, ownerObject)
if err != nil {
m := "Could not set owner annotations"
log.Error(err, m)
http.Error(w, m, http.StatusBadRequest)
return
}
}
newBody, err := json.Marshal(data.Object)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions pkg/ansible/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"

libhandler "github.com/operator-framework/operator-lib/handler"
"github.com/operator-framework/operator-lib/predicate"
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap"
"github.com/operator-framework/operator-sdk/pkg/ansible/proxy/kubeconfig"
k8sRequest "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/requestfactory"
osdkHandler "github.com/operator-framework/operator-sdk/pkg/handler"
)

// This is the default timeout to wait for the cache to respond
Expand Down Expand Up @@ -257,11 +257,14 @@ func addWatchToController(owner kubeconfig.NamespacedOwnerReference, cMap *contr
return nil
}
awMap.Store(resource.GroupVersionKind())
typeString := fmt.Sprintf("%v.%v", owner.Kind, ownerGV.Group)
handlerType := schema.GroupKind{
Kind: owner.Kind,
Group: ownerGV.Group,
}
log.Info("Watching child resource", "kind", resource.GroupVersionKind(),
"enqueue_annotation_type", typeString)
"enqueue_annotation_type", handlerType.String())
err = contents.Controller.Watch(&source.Kind{Type: resource},
&osdkHandler.EnqueueRequestForAnnotation{Type: typeString}, predicate.DependentPredicate{})
&libhandler.EnqueueRequestForAnnotation{Type: handlerType}, predicate.DependentPredicate{})
if err != nil {
log.Error(err, "Failed to watch child resource",
"kind", resource.GroupVersionKind(), "enqueue_kind", u.GroupVersionKind())
Expand Down
127 changes: 0 additions & 127 deletions pkg/handler/enqueue_annotation.go

This file was deleted.

7 changes: 5 additions & 2 deletions pkg/helm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"errors"
"io"

"github.com/operator-framework/operator-lib/handler"
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/handler"
"helm.sh/helm/v3/pkg/kube"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -148,7 +148,10 @@ func (c *ownerRefInjectingClient) Build(reader io.Reader, validate bool) (kube.R
ownerRef := metav1.NewControllerRef(c.owner, c.owner.GroupVersionKind())
u.SetOwnerReferences([]metav1.OwnerReference{*ownerRef})
} else {
handler.SetOwnerAnnotation(u, c.owner)
err := handler.SetOwnerAnnotations(u, c.owner)
if err != nil {
return err
}
}
return nil
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/helm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"

libhandler "github.com/operator-framework/operator-lib/handler"
"github.com/operator-framework/operator-lib/predicate"
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/handler"
Expand Down Expand Up @@ -132,7 +133,7 @@ func watchDependentResources(mgr manager.Manager, r *HelmOperatorReconciler, c c
return err
}
} else { // Setup watch using annotations.
err = c.Watch(&source.Kind{Type: &u}, &handler.EnqueueRequestForAnnotation{Type: gvk.GroupKind().String()},
err = c.Watch(&source.Kind{Type: &u}, &libhandler.EnqueueRequestForAnnotation{Type: gvk.GroupKind()},
predicate.DependentPredicate{})
if err != nil {
return err
Expand Down

0 comments on commit 726ec66

Please sign in to comment.