Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/base/resource_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// resource_checks.go contains functions which check resources until they
// This file contains functions which check resources until they
// get into the state desired by the caller or time out.

package base
Expand All @@ -24,6 +24,7 @@ import (
"fmt"
"time"

"github.com/knative/eventing/test/base/resources"
"github.com/knative/pkg/apis"
duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1"
"go.opencensus.io/trace"
Expand All @@ -44,7 +45,7 @@ const (
// it is done, returns an error or timeout. desc will be used to
// name the metric that is emitted to track how long it took for
// the resource to get into the state checked by isResourceReady.
func WaitForResourceReady(dynamicClient dynamic.Interface, obj *MetaResource) error {
func WaitForResourceReady(dynamicClient dynamic.Interface, obj *resources.MetaResource) error {
metricName := fmt.Sprintf("WaitForResourceReady/%s/%s", obj.Namespace, obj.Name)
_, span := trace.StartSpan(context.Background(), metricName)
defer span.End()
Expand All @@ -56,7 +57,7 @@ func WaitForResourceReady(dynamicClient dynamic.Interface, obj *MetaResource) er
}

// WaitForResourcesReady waits until all the specified resources in the given namespace are ready.
func WaitForResourcesReady(dynamicClient dynamic.Interface, objList *MetaResourceList) error {
func WaitForResourcesReady(dynamicClient dynamic.Interface, objList *resources.MetaResourceList) error {
metricName := fmt.Sprintf("WaitForResourcesReady/%s", objList.Namespace)
_, span := trace.StartSpan(context.Background(), metricName)
defer span.End()
Expand Down
39 changes: 5 additions & 34 deletions test/base/generics.go → test/base/resource_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,27 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This file contains functions which get actual resources given the meta resource.

package base

import (
"github.com/knative/eventing/test/base/resources"
"github.com/knative/pkg/apis"
"github.com/knative/pkg/apis/duck"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/cache"
)

// MetaResource includes necessary meta data to retrieve the generic Kubernetes resource.
type MetaResource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}

// MetaResourceList includes necessary meta data to retrieve the generic Kubernetes resource list.
type MetaResourceList struct {
metav1.TypeMeta `json:",inline"`
Namespace string
}

// NewMetaResource returns a MetaResource built from the given name, namespace and typemeta.
func NewMetaResource(name, namespace string, typemeta *metav1.TypeMeta) *MetaResource {
return &MetaResource{
TypeMeta: *typemeta,
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
}

// NewMetaResourceList returns a MetaResourceList built from the given namespace and typemeta.
func NewMetaResourceList(namespace string, typemeta *metav1.TypeMeta) *MetaResourceList {
return &MetaResourceList{
TypeMeta: *typemeta,
Namespace: namespace,
}
}

// GetGenericObject returns a generic object representing a Kubernetes resource.
// Callers can cast this returned object to other objects that implement the corresponding duck-type.
func GetGenericObject(
dynamicClient dynamic.Interface,
obj *MetaResource,
obj *resources.MetaResource,
rtype apis.Listable,
) (runtime.Object, error) {
lister, err := getGenericLister(dynamicClient, obj.GroupVersionKind(), obj.Namespace, rtype)
Expand All @@ -76,7 +47,7 @@ func GetGenericObject(
// GetGenericObjectList returns a generic object list representing a list of Kubernetes resource.
func GetGenericObjectList(
dynamicClient dynamic.Interface,
objList *MetaResourceList,
objList *resources.MetaResourceList,
rtype apis.Listable,
) ([]runtime.Object, error) {
lister, err := getGenericLister(dynamicClient, objList.GroupVersionKind(), objList.Namespace, rtype)
Expand Down
5 changes: 3 additions & 2 deletions test/base/resource_inspectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// resource_inspectors.go contains functions which get property values for
// This file contains functions which get property values for
// resources provided by the caller.

package base

import (
"fmt"

"github.com/knative/eventing/test/base/resources"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
"k8s.io/client-go/dynamic"
)

// GetAddressableURI returns the uri for the given resource that implements Addressable duck-type.
func GetAddressableURI(dynamicClient dynamic.Interface, obj *MetaResource) (string, error) {
func GetAddressableURI(dynamicClient dynamic.Interface, obj *resources.MetaResource) (string, error) {
untyped, err := GetGenericObject(dynamicClient, obj, &duckv1alpha1.AddressableType{})
if err != nil {
return "", err
Expand Down
Loading