use KindToResource now that it has been moved there
@@ -19,10 +19,10 @@ package subscription
import (
"context"
"fmt"
- "strings"
"github.com/golang/glog"
"github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
+ duckapis "github.com/knative/pkg/apis"
"github.com/knative/pkg/apis/duck"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
corev1 "k8s.io/api/core/v1"
@@ -30,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -225,7 +224,6 @@ func (r *reconciler) resolveFromChannelable(namespace string, ref *corev1.Object
// fetchObjectReference fetches an object based on ObjectReference.
func (r *reconciler) fetchObjectReference(namespace string, ref *corev1.ObjectReference) (duck.Marshalable, error) {
- // resourceClient, err := r.CreateResourceInterface2(r.restConfig, ref, namespace)
resourceClient, err := r.CreateResourceInterface(namespace, ref)
if err != nil {
glog.Warningf("failed to create dynamic client resource: %v", err)
@@ -283,29 +281,11 @@ func (r *reconciler) reconcileFromChannel(namespace string, subscribable corev1.
}
func (r *reconciler) CreateResourceInterface(namespace string, ref *corev1.ObjectReference) (dynamic.ResourceInterface, error) {
- gvk := ref.GroupVersionKind()
+ rc := r.dynamicClient.Resource(duckapis.KindToResource(ref.GroupVersionKind()))
- rc := r.dynamicClient.Resource(schema.GroupVersionResource{
- Group: gvk.Group,
- Version: gvk.Version,
- Resource: pluralizeKind(gvk.Kind),
- })
if rc == nil {
return nil, fmt.Errorf("failed to create dynamic client resource")
}
return rc.Namespace(namespace), nil
}
-
-// takes a kind and pluralizes it. This is super terrible, but I am
-// not aware of a generic way to do this.
-// I am not alone in thinking this and I haven't found a better solution:
-// This seems relevant:
-// https://github.com/kubernetes/kubernetes/issues/18622
-func pluralizeKind(kind string) string {
- ret := strings.ToLower(kind)
- if strings.HasSuffix(ret, "s") {
- return fmt.Sprintf("%ses", ret)
- }
- return fmt.Sprintf("%ss", ret)
-}
