Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6dcfca7
support fail fast in all creation methods
chizhg May 30, 2019
bebf9d3
add resources
chizhg May 30, 2019
2bace45
provisioner is not needed in Setup
chizhg May 30, 2019
a4dfe83
Merge branch 'EnableFailFastInResourceCreation' into AddTestForSources
chizhg May 30, 2019
c750a41
add test case for cronjobsource
chizhg May 30, 2019
b578679
fix README
chizhg May 30, 2019
3593eaf
Merge branch 'EnableFailFastInResourceCreation' into AddTestForSources
chizhg May 30, 2019
6d6416f
cron job source test is now working
chizhg May 30, 2019
34f41bb
add image for testing ContainerSource
chizhg May 30, 2019
f7e5385
serviceaccount is not required for cronjobsource
chizhg May 30, 2019
daa4632
Merge branch 'AddTestForCronJobSource' into AddTestForContainerSource
chizhg May 30, 2019
ca5fe7b
add an e2e test case for container source, still in progress
chizhg May 30, 2019
249cfb9
not sure why it's not working...
chizhg May 31, 2019
c46916a
fix minor commment error
chizhg May 31, 2019
18e9316
Merge branch 'AddTestForCronJobSource' into AddTestForContainerSource
chizhg May 31, 2019
33602f6
Update test/test_images/heartbeats/main.go
chizhg May 31, 2019
07abd21
run update-codegen
chizhg May 31, 2019
9e2cd0a
Merge branch 'AddTestForContainerSource' of git+ssh://github.com/Fred…
chizhg May 31, 2019
b6098da
remove debug print
chizhg May 31, 2019
23e787b
it's now working
chizhg May 31, 2019
bc78004
temp
chizhg Jun 1, 2019
c272c6e
done with cleanup
chizhg Jun 2, 2019
48f1f27
further cleanup
chizhg Jun 4, 2019
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
2 changes: 2 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions test/base/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2019 The Knative 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 base

import "github.com/knative/eventing/pkg/reconciler/namespace/resources"

const (
// DefaultBrokerName is the name of the Broker that is automatically created after the current namespace is labeled.
DefaultBrokerName = resources.DefaultBrokerName

// InMemoryProvisioner is the in-memory provisioner, which is also the default one.
InMemoryProvisioner = "in-memory"
// GCPPubSubProvisioner is the gcp-pubsub provisioner, which is under contrib/gcppubsub.
GCPPubSubProvisioner = "gcp-pubsub"
// KafkaProvisioner is the kafka provisioner, which is under contrib/kafka.
KafkaProvisioner = "kafka"
// NatssProvisioner is the natss provisioner, which is under contrib/natss
NatssProvisioner = "natss"
)

// API versions for the resources.
const (
EventingAPIVersion = "eventing.knative.dev/v1alpha1"
SourcesAPIVersion = "sources.eventing.knative.dev/v1alpha1"
MessagingAPIVersion = "messaging.knative.dev/v1alpha1"
)

// kind for eventing resources.
const (
// ChannelKind is the kind for Channel.
ChannelKind string = "Channel"
// SubscriptionKind is the kind for Subscription.
SubscriptionKind string = "Subscription"
// ClusterChannelProvisionerKind is the kind for ClusterChannelProvisioner.
ClusterChannelProvisionerKind string = "ClusterChannelProvisioner"

// BrokerKind is the kind for Broker.
BrokerKind string = "Broker"
// TriggerKind is the kind for Trigger.
TriggerKind string = "Trigger"
)

// kind for messaging resources.
const (
// InMemoryChannelKind is the kind for InMemoryChannel.
Comment thread
chizhg marked this conversation as resolved.
InMemoryChannelKind string = "InMemoryChannel"
// KafkaChannelKind is the kind for KafkaChannel.
KafkaChannelKind string = "KafkaChannel"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can still select that the e2e tests run on a set of given channels ? E.g. just kafka and in-mem >?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The flag will still be named as clusterChannelProvisioners until provisioner implementation is removed.

// NatssChannelKind string = "NatssChannel"
// GCPPubSubChannelKind string = "GCPPubSubChannel"
)

// kind for sources resources.
const (
// CronJobSourceKind is the kind for CronJobSource.
CronJobSourceKind string = "CronJobSource"
// ContainerSourceKind is the kind for ContainerSource.
ContainerSourceKind string = "ContainerSource"
// ApiServerSourceKind is the kind for ApiServerSource.
ApiServerSourceKind string = "ApiServerSource"
)
66 changes: 54 additions & 12 deletions test/base/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"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.
Expand All @@ -31,27 +34,66 @@ type MetaResource struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
}

// Meta returns a MetaResource built from the given name, namespace and kind.
func Meta(name, namespace, kind string) *MetaResource {
// 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,
},
TypeMeta: metav1.TypeMeta{
Kind: kind,
APIVersion: EventingAPIVersion,
},
}
}

// 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, rtype apis.Listable) (runtime.Object, error) {
// get the resource's name, namespace and gvr
name := obj.Name
namespace := obj.Namespace
gvk := obj.GroupVersionKind()
func GetGenericObject(
dynamicClient dynamic.Interface,
obj *MetaResource,
rtype apis.Listable,
) (runtime.Object, error) {
lister, err := getGenericLister(dynamicClient, obj.GroupVersionKind(), obj.Namespace, rtype)
if err != nil {
return nil, err
}
return lister.Get(obj.Name)
}

// GetGenericObjectList returns a generic object list representing a list of Kubernetes resource.
func GetGenericObjectList(
dynamicClient dynamic.Interface,
objList *MetaResourceList,
rtype apis.Listable,
) ([]runtime.Object, error) {
lister, err := getGenericLister(dynamicClient, objList.GroupVersionKind(), objList.Namespace, rtype)
if err != nil {
return nil, err
}
return lister.List(labels.Everything())
}

// getGenericLister returns a GenericNamespacedLister, which can be used to get resources in the namespace.
func getGenericLister(
dynamicClient dynamic.Interface,
gvk schema.GroupVersionKind,
namespace string,
rtype apis.Listable,
) (cache.GenericNamespaceLister, error) {
// get the resource's namespace and gvr
gvr, _ := meta.UnsafeGuessKindToResource(gvk)

stopChannel := make(chan struct{})
Expand All @@ -63,5 +105,5 @@ func GetGenericObject(dynamicClient dynamic.Interface, obj *MetaResource, rtype
if err != nil {
return nil, err
}
return lister.ByNamespace(namespace).Get(name)
return lister.ByNamespace(namespace), nil
}
28 changes: 23 additions & 5 deletions test/base/resource_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1"
"go.opencensus.io/trace"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
)
Expand All @@ -44,18 +45,35 @@ const (
// 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 {
metricName := fmt.Sprintf("WaitForResourceReady/%s", obj.Name)
metricName := fmt.Sprintf("WaitForResourceReady/%s/%s", obj.Namespace, obj.Name)
_, span := trace.StartSpan(context.Background(), metricName)
defer span.End()

return wait.PollImmediate(interval, timeout, func() (bool, error) {
return isResourceReady(dynamicClient, obj)
untyped, err := GetGenericObject(dynamicClient, obj, &duckv1beta1.KResource{})
return isResourceReady(untyped, err)
})
}

// WaitForResourcesReady waits until all the specified resources in the given namespace are ready.
func WaitForResourcesReady(dynamicClient dynamic.Interface, objList *MetaResourceList) error {
metricName := fmt.Sprintf("WaitForResourcesReady/%s", objList.Namespace)
_, span := trace.StartSpan(context.Background(), metricName)
defer span.End()

return wait.PollImmediate(interval, timeout, func() (bool, error) {
untypeds, err := GetGenericObjectList(dynamicClient, objList, &duckv1beta1.KResource{})
for _, untyped := range untypeds {
if isReady, err := isResourceReady(untyped, err); !isReady {
return isReady, err
}
}
return true, nil
})
}

// isResourceReady leverage duck-type to check if the given MetaResource is in ready state
func isResourceReady(dynamicClient dynamic.Interface, obj *MetaResource) (bool, error) {
untyped, err := GetGenericObject(dynamicClient, obj, &duckv1beta1.KResource{})
func isResourceReady(obj runtime.Object, err error) (bool, error) {
if k8serrors.IsNotFound(err) {
// Return false as we are not done yet.
// We swallow the error to keep on polling.
Expand All @@ -66,6 +84,6 @@ func isResourceReady(dynamicClient dynamic.Interface, obj *MetaResource) (bool,
return false, err
}

kr := untyped.(*duckv1beta1.KResource)
kr := obj.(*duckv1beta1.KResource)
return kr.Status.GetCondition(apis.ConditionReady).IsTrue(), nil
}
Loading