diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 47d9e6d0738..69e5ccfd93b 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -45,9 +45,7 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - "knative.dev/eventing/pkg/apis/messaging" channeldefaultconfig "knative.dev/eventing/pkg/apis/messaging/config" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/pkg/apis/sources" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" @@ -64,10 +62,6 @@ var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ eventingv1beta1.SchemeGroupVersion.WithKind("EventType"): &eventingv1beta1.EventType{}, // For group messaging.knative.dev. - // v1alpha1 - messagingv1alpha1.SchemeGroupVersion.WithKind("InMemoryChannel"): &messagingv1alpha1.InMemoryChannel{}, - messagingv1alpha1.SchemeGroupVersion.WithKind("Channel"): &messagingv1alpha1.Channel{}, - messagingv1alpha1.SchemeGroupVersion.WithKind("Subscription"): &messagingv1alpha1.Subscription{}, // v1beta1 messagingv1beta1.SchemeGroupVersion.WithKind("InMemoryChannel"): &messagingv1beta1.InMemoryChannel{}, messagingv1beta1.SchemeGroupVersion.WithKind("Channel"): &messagingv1beta1.Channel{}, @@ -217,10 +211,8 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro } var ( - messagingv1alpha1_ = messagingv1alpha1.SchemeGroupVersion.Version - messagingv1beta1_ = messagingv1beta1.SchemeGroupVersion.Version - sourcesv1alpha1_ = sourcesv1alpha1.SchemeGroupVersion.Version - sourcesv1alpha2_ = sourcesv1alpha2.SchemeGroupVersion.Version + sourcesv1alpha1_ = sourcesv1alpha1.SchemeGroupVersion.Version + sourcesv1alpha2_ = sourcesv1alpha2.SchemeGroupVersion.Version ) return conversion.NewConversionController(ctx, @@ -229,23 +221,6 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro // Specify the types of custom resource definitions that should be converted map[schema.GroupKind]conversion.GroupKindConversion{ - // messaging - messagingv1beta1.Kind("Channel"): { - DefinitionName: messaging.ChannelsResource.String(), - HubVersion: messagingv1alpha1_, - Zygotes: map[string]conversion.ConvertibleObject{ - messagingv1alpha1_: &messagingv1alpha1.Channel{}, - messagingv1beta1_: &messagingv1beta1.Channel{}, - }, - }, - messagingv1beta1.Kind("InMemoryChannel"): { - DefinitionName: messaging.InMemoryChannelsResource.String(), - HubVersion: messagingv1alpha1_, - Zygotes: map[string]conversion.ConvertibleObject{ - messagingv1alpha1_: &messagingv1alpha1.InMemoryChannel{}, - messagingv1beta1_: &messagingv1beta1.InMemoryChannel{}, - }, - }, // Sources sourcesv1alpha2.Kind("ApiServerSource"): { DefinitionName: sources.ApiServerSourceResource.String(), diff --git a/config/channels/in-memory-channel/300-in-memory-channel.yaml b/config/channels/in-memory-channel/300-in-memory-channel.yaml index 3e215049108..b26096edb7d 100644 --- a/config/channels/in-memory-channel/300-in-memory-channel.yaml +++ b/config/channels/in-memory-channel/300-in-memory-channel.yaml @@ -66,7 +66,7 @@ spec: JSONPath: .metadata.creationTimestamp versions: - name: v1alpha1 - served: true + served: false storage: false - name: v1beta1 served: true diff --git a/config/core/resources/channel.yaml b/config/core/resources/channel.yaml index fc5d6ce1fbb..06524f64959 100644 --- a/config/core/resources/channel.yaml +++ b/config/core/resources/channel.yaml @@ -59,7 +59,7 @@ spec: JSONPath: .metadata.creationTimestamp versions: - name: v1alpha1 - served: true + served: false storage: false schema: openAPIV3Schema: diff --git a/config/core/resources/subscription.yaml b/config/core/resources/subscription.yaml index 39467c132e9..7ce78348560 100644 --- a/config/core/resources/subscription.yaml +++ b/config/core/resources/subscription.yaml @@ -141,7 +141,7 @@ spec: x-kubernetes-preserve-unknown-fields: true versions: - name: v1alpha1 - served: true + served: false storage: false - name: v1beta1 served: true diff --git a/docs/broker/example_brokers.yaml b/docs/broker/example_brokers.yaml index c97cf52dcd4..8ed6cdf2be5 100644 --- a/docs/broker/example_brokers.yaml +++ b/docs/broker/example_brokers.yaml @@ -17,7 +17,7 @@ --- # By not specifying a spec, the default Channel for the namespace will be used. -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1beta1 kind: Broker metadata: name: default @@ -28,13 +28,13 @@ metadata: # can be used, and thus guarantee the durability of the events that are sent to this # Broker, like here with Kafka: -apiVersion: eventing.knative.dev/v1alpha1 +apiVersion: eventing.knative.dev/v1beta1 kind: Broker metadata: name: kafka spec: channelTemplateSpec: - apiVersion: messaging.knative.dev/v1alpha1 + apiVersion: messaging.knative.dev/v1beta1 kind: KafkaChannel spec: numPartitions: 3 diff --git a/docs/delivery/imc-one-per-subcriber.yaml b/docs/delivery/imc-one-per-subcriber.yaml index e1b0fc33dfd..c6dfd0b3a40 100644 --- a/docs/delivery/imc-one-per-subcriber.yaml +++ b/docs/delivery/imc-one-per-subcriber.yaml @@ -1,4 +1,4 @@ -apiVersion: messaging.knative.dev/v1alpha1 +apiVersion: messaging.knative.dev/v1beta1 kind: InMemoryChannel metadata: name: imc @@ -8,9 +8,8 @@ spec: retry: 5 backoffPolicy: exponential backoffDelay: 3s - subscribable: # populated by Subscription - subscribers: - - subscriberURI: mysub.default.svc.cluster.local - delivery: - deadLetterSinkURI: mydls.default.svc.cluster.local + subscribers: + - subscriberURI: mysub.default.svc.cluster.local + delivery: + deadLetterSinkURI: mydls.default.svc.cluster.local diff --git a/docs/delivery/imc.yaml b/docs/delivery/imc.yaml index f5e0a72c51e..baf806b7009 100644 --- a/docs/delivery/imc.yaml +++ b/docs/delivery/imc.yaml @@ -1,17 +1,16 @@ -apiVersion: messaging.knative.dev/v1alpha1 +apiVersion: messaging.knative.dev/v1beta1 kind: InMemoryChannel metadata: name: imc spec: delivery: deadLetterSink: - apiVersion: serving.knative.dev/v1beta1 + apiVersion: serving.knative.dev/v1 kind: Service name: handle-error retry: 5 backoffPolicy: exponential backoffDelay: 3s - subscribable: # populated by Subscription - subscribers: - - subscriberURI: mysub.default.svc.cluster.local + subscribers: + - subscriberURI: mysub.default.svc.cluster.local diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index c752030541d..996656cc7f6 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -45,7 +45,7 @@ chmod +x ${CODEGEN_PKG}/generate-groups.sh # instead of the $GOPATH directly. For normal projects this can be dropped. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \ - "eventing:v1beta1 messaging:v1alpha1 messaging:v1beta1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 configs:v1alpha1" \ + "eventing:v1beta1 messaging:v1beta1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 configs:v1alpha1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt # Deep copy config @@ -65,7 +65,7 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \ chmod +x ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \ knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \ - "eventing:v1beta1 messaging:v1alpha1 messaging:v1beta1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 duck:v1alpha1 duck:v1beta1 configs:v1alpha1" \ + "eventing:v1beta1 messaging:v1beta1 flows:v1beta1 sources:v1alpha1 sources:v1alpha2 duck:v1alpha1 duck:v1beta1 configs:v1alpha1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt # Make sure our dependencies are up-to-date diff --git a/pkg/adapter/mtping/pingsource_test.go b/pkg/adapter/mtping/pingsource_test.go index c95ba2f19ad..706521cbdd7 100644 --- a/pkg/adapter/mtping/pingsource_test.go +++ b/pkg/adapter/mtping/pingsource_test.go @@ -56,7 +56,7 @@ var ( Name: sinkName, Namespace: testNS, Kind: "Channel", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, } diff --git a/pkg/apis/duck/v1alpha1/register.go b/pkg/apis/duck/v1alpha1/register.go new file mode 100644 index 00000000000..24e6c069b50 --- /dev/null +++ b/pkg/apis/duck/v1alpha1/register.go @@ -0,0 +1,46 @@ +/* + * Copyright 2020 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: "duck.knative.dev", Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Channelable{}, + &ChannelableList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/duck/v1alpha1/register_test.go b/pkg/apis/duck/v1alpha1/register_test.go new file mode 100644 index 00000000000..d3fa1372d13 --- /dev/null +++ b/pkg/apis/duck/v1alpha1/register_test.go @@ -0,0 +1,52 @@ +/* +Copyright 2020 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 v1alpha1 + +import ( + "testing" + + "github.com/google/go-cmp/cmp" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// Kind takes an unqualified resource and returns a Group qualified GroupKind +func TestKind(t *testing.T) { + want := schema.GroupKind{ + Group: "duck.knative.dev", + Kind: "kind", + } + + got := Kind("kind") + + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("unexpected resource (-want, +got) = %v", diff) + } +} + +// TestKnownTypes makes sure that expected types get added. +func TestKnownTypes(t *testing.T) { + scheme := runtime.NewScheme() + addKnownTypes(scheme) + types := scheme.KnownTypes(SchemeGroupVersion) + + for _, name := range []string{ + "Channelable", + "ChannelableList", + } { + if _, ok := types[name]; !ok { + t.Errorf("Did not find %q as registered type", name) + } + } + +} diff --git a/pkg/apis/eventing/v1beta1/test_helper.go b/pkg/apis/eventing/v1beta1/test_helper.go index c291f00d910..b8c26a23efe 100644 --- a/pkg/apis/eventing/v1beta1/test_helper.go +++ b/pkg/apis/eventing/v1beta1/test_helper.go @@ -20,7 +20,6 @@ import ( corev1 "k8s.io/api/core/v1" duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -31,15 +30,6 @@ type testHelper struct{} // TestHelper contains helpers for unit tests. var TestHelper = testHelper{} -// Moved to here from ../v1alpha1 while we migrate things... -func (testHelper) ReadySubscriptionStatusV1Alpha1() *messagingv1alpha1.SubscriptionStatus { - ss := &messagingv1alpha1.SubscriptionStatus{} - ss.MarkChannelReady() - ss.MarkReferencesResolved() - ss.MarkAddedToChannel() - return ss -} - func (testHelper) ReadySubscriptionCondition() *apis.Condition { return &apis.Condition{ Type: apis.ConditionReady, diff --git a/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go b/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go index 723aa409093..4cc8512315c 100644 --- a/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go +++ b/pkg/apis/flows/v1beta1/sequence_lifecycle_test.go @@ -72,7 +72,7 @@ func getChannelable(ready bool) *eventingduckv1beta1.Channelable { URL, _ := apis.ParseURL("http://example.com") c := eventingduckv1beta1.Channelable{ TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "InMemoryChannel", }, ObjectMeta: metav1.ObjectMeta{}, diff --git a/pkg/apis/messaging/v1alpha1/channel_conversion.go b/pkg/apis/messaging/v1alpha1/channel_conversion.go deleted file mode 100644 index 8afe33cc74a..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_conversion.go +++ /dev/null @@ -1,163 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "fmt" - - corev1 "k8s.io/api/core/v1" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - pkgduckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" -) - -// ConvertTo implements apis.Convertible -// Converts source (from v1alpha1.Channel) into v1beta1.Channel -func (source *Channel) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *v1beta1.Channel: - sink.ObjectMeta = source.ObjectMeta - source.Status.ConvertTo(ctx, &sink.Status) - return source.Spec.ConvertTo(ctx, &sink.Spec) - default: - return fmt.Errorf("unknown version, got: %T", sink) - } -} - -// ConvertTo helps implement apis.Convertible -func (source *ChannelSpec) ConvertTo(ctx context.Context, sink *v1beta1.ChannelSpec) error { - sink.ChannelTemplate = source.ChannelTemplate - sink.ChannelableSpec.Delivery = source.Delivery - if source.Subscribable != nil { - sink.ChannelableSpec.Subscribers = make([]duckv1beta1.SubscriberSpec, len(source.Subscribable.Subscribers)) - for i, s := range source.Subscribable.Subscribers { - sink.ChannelableSpec.Subscribers[i] = duckv1beta1.SubscriberSpec{ - UID: s.UID, - Generation: s.Generation, - SubscriberURI: s.SubscriberURI, - ReplyURI: s.ReplyURI, - } - // If the source has delivery, use it. - if s.Delivery != nil { - sink.ChannelableSpec.Subscribers[i].Delivery = s.Delivery - } else { - // If however, there's a Deprecated DeadLetterSinkURI, convert that up - // to DeliverySpec. - sink.ChannelableSpec.Subscribers[i].Delivery = &duckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - URI: s.DeadLetterSinkURI, - }, - } - } - } - } - return nil -} - -// ConvertTo helps implement apis.Convertible -func (source *ChannelStatus) ConvertTo(ctx context.Context, sink *v1beta1.ChannelStatus) { - source.Status.ConvertTo(ctx, &sink.Status) - if source.AddressStatus.Address != nil { - sink.AddressStatus.Address = &duckv1.Addressable{} - source.AddressStatus.Address.ConvertTo(ctx, sink.AddressStatus.Address) - } - if source.SubscribableTypeStatus.SubscribableStatus != nil && - len(source.SubscribableTypeStatus.SubscribableStatus.Subscribers) > 0 { - sink.SubscribableStatus.Subscribers = make([]duckv1beta1.SubscriberStatus, len(source.SubscribableTypeStatus.SubscribableStatus.Subscribers)) - for i, ss := range source.SubscribableTypeStatus.SubscribableStatus.Subscribers { - sink.SubscribableStatus.Subscribers[i] = duckv1beta1.SubscriberStatus{ - UID: ss.UID, - ObservedGeneration: ss.ObservedGeneration, - Ready: ss.Ready, - Message: ss.Message, - } - } - } - if source.Channel != nil { - sink.Channel = &duckv1.KReference{ - Kind: source.Channel.Kind, - APIVersion: source.Channel.APIVersion, - Name: source.Channel.Name, - Namespace: source.Channel.Namespace, - } - } -} - -// ConvertFrom implements apis.Convertible. -// Converts obj v1beta1.Channel into v1alpha1.Channel -func (sink *Channel) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *v1beta1.Channel: - sink.ObjectMeta = source.ObjectMeta - sink.Status.ConvertFrom(ctx, source.Status) - sink.Spec.ConvertFrom(ctx, source.Spec) - return nil - default: - return fmt.Errorf("unknown version, got: %T", source) - } -} - -// ConvertFrom helps implement apis.Convertible -func (sink *ChannelSpec) ConvertFrom(ctx context.Context, source v1beta1.ChannelSpec) { - sink.ChannelTemplate = source.ChannelTemplate - sink.Delivery = source.ChannelableSpec.Delivery - if len(source.ChannelableSpec.Subscribers) > 0 { - sink.Subscribable = &eventingduck.Subscribable{ - Subscribers: make([]eventingduck.SubscriberSpec, len(source.ChannelableSpec.Subscribers)), - } - for i, s := range source.ChannelableSpec.Subscribers { - sink.Subscribable.Subscribers[i] = eventingduck.SubscriberSpec{ - UID: s.UID, - Generation: s.Generation, - SubscriberURI: s.SubscriberURI, - ReplyURI: s.ReplyURI, - Delivery: s.Delivery, - } - } - } -} - -// ConvertFrom helps implement apis.Convertible -func (sink *ChannelStatus) ConvertFrom(ctx context.Context, source v1beta1.ChannelStatus) error { - source.Status.ConvertTo(ctx, &sink.Status) - if source.AddressStatus.Address != nil { - sink.AddressStatus.Address = &pkgduckv1alpha1.Addressable{} - if err := sink.AddressStatus.Address.ConvertFrom(ctx, source.AddressStatus.Address); err != nil { - return err - } - } - if len(source.SubscribableStatus.Subscribers) > 0 { - sink.SubscribableTypeStatus.SubscribableStatus = &duckv1alpha1.SubscribableStatus{ - Subscribers: make([]duckv1beta1.SubscriberStatus, len(source.SubscribableStatus.Subscribers)), - } - copy(sink.SubscribableTypeStatus.SubscribableStatus.Subscribers, source.SubscribableStatus.Subscribers) - } - if source.Channel != nil { - sink.Channel = &corev1.ObjectReference{ - Kind: source.Channel.Kind, - APIVersion: source.Channel.APIVersion, - Name: source.Channel.Name, - Namespace: source.Channel.Namespace, - } - } - return nil -} diff --git a/pkg/apis/messaging/v1alpha1/channel_conversion_test.go b/pkg/apis/messaging/v1alpha1/channel_conversion_test.go deleted file mode 100644 index 8fa30d81479..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_conversion_test.go +++ /dev/null @@ -1,321 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -func TestChannelConversionBadType(t *testing.T) { - good, bad := &Channel{}, &Subscription{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -// Test v1alpha1 -> v1beta1 -> v1alpha1 -func TestChannelConversion(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.Channel{}} - - linear := eventingduckv1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *Channel - }{{ - name: "min configuration", - in: &Channel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: ChannelSpec{}, - Status: ChannelStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{}, - }, - }, - }, - }, { - name: "full configuration", - in: &Channel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: metav1.TypeMeta{ - Kind: "channelKind", - APIVersion: "channelAPIVersion", - }, - // TODO: Add Spec... - }, - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - // DeadLetterSinkURI: apis.HTTP("dlc.reply.example.com"), - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("dls"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - Status: ChannelStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - Conditions: duckv1.Conditions{{ - Type: "Ready", - Status: "True", - }}, - }, - AddressStatus: duckv1alpha1.AddressStatus{ - Address: &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: apis.HTTP("addressstatus.example.com"), - }, - Hostname: "addressstatus.example.com", - }, - }, - SubscribableTypeStatus: eventingduck.SubscribableTypeStatus{ - SubscribableStatus: &eventingduck.SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - Channel: &corev1.ObjectReference{ - Kind: "u-channel-kind", - APIVersion: "u-channel-apiversion", - Name: "u-channel-name", - Namespace: "u-channel-namespace", - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &Channel{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -// Test v1alpha1 -> v1beta1 -> v1alpha1 -func TestChannelConversionWithV1Beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&Channel{}} - - linear := eventingduckv1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *v1beta1.Channel - }{{ - name: "min", - in: &v1beta1.Channel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: v1beta1.ChannelSpec{}, - Status: v1beta1.ChannelStatus{ - ChannelableStatus: eventingduckv1beta1.ChannelableStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{}, - }, - }, - }, - }, - }, { - name: "full configuration", - in: &v1beta1.Channel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: v1beta1.ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: metav1.TypeMeta{ - Kind: "channelKind", - APIVersion: "channelAPIVersion", - }, - // TODO: Add Spec... - }, - ChannelableSpec: eventingduckv1beta1.ChannelableSpec{ - SubscribableSpec: eventingduckv1beta1.SubscribableSpec{ - Subscribers: []eventingduckv1beta1.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - // DeadLetterSinkURI: apis.HTTP("dlc.reply.example.com"), - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("dls"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - Status: v1beta1.ChannelStatus{ - ChannelableStatus: eventingduckv1beta1.ChannelableStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - Conditions: duckv1.Conditions{{ - Type: "Ready", - Status: "True", - }}, - }, - AddressStatus: duckv1.AddressStatus{ - Address: &duckv1.Addressable{ - URL: apis.HTTP("addressstatus.example.com"), - }, - }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - Channel: &duckv1.KReference{ - Kind: "u-channel-kind", - APIVersion: "u-channel-apiversion", - Name: "u-channel-name", - Namespace: "u-channel-namespace", - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := version.ConvertFrom(context.Background(), test.in); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &v1beta1.Channel{} - if err := ver.ConvertTo(context.Background(), got); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/messaging/v1alpha1/channel_defaults.go b/pkg/apis/messaging/v1alpha1/channel_defaults.go deleted file mode 100644 index f1df81f691e..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_defaults.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - - "knative.dev/eventing/pkg/apis/messaging/config" - v1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" -) - -func (c *Channel) SetDefaults(ctx context.Context) { - if c != nil && c.Spec.ChannelTemplate == nil { - cfg := config.FromContextOrDefaults(ctx) - defaultChannel, err := cfg.ChannelDefaults.GetChannelConfig(apis.ParentMeta(ctx).Namespace) - if err == nil { - c.Spec.ChannelTemplate = &v1beta1.ChannelTemplateSpec{ - TypeMeta: defaultChannel.TypeMeta, - Spec: defaultChannel.Spec, - } - } - } - c.Spec.SetDefaults(ctx) -} - -func (cs *ChannelSpec) SetDefaults(ctx context.Context) {} diff --git a/pkg/apis/messaging/v1alpha1/channel_defaults_test.go b/pkg/apis/messaging/v1alpha1/channel_defaults_test.go deleted file mode 100644 index 5efc8123e23..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_defaults_test.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "testing" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/google/go-cmp/cmp" - "knative.dev/eventing/pkg/apis/messaging/config" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" -) - -var ( - configDefaultChannelTemplate = &config.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - APIVersion: SchemeGroupVersion.String(), - Kind: "InMemoryChannel", - }, - } - defaultChannelTemplate = &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - APIVersion: SchemeGroupVersion.String(), - Kind: "InMemoryChannel", - }, - } -) - -func TestChannelSetDefaults(t *testing.T) { - testCases := map[string]struct { - nilChannelDefaulter bool - channelTemplate *config.ChannelTemplateSpec - initial Channel - expected Channel - }{ - "nil ChannelDefaulter": { - nilChannelDefaulter: true, - expected: Channel{}, - }, - "unset ChannelDefaulter": { - expected: Channel{}, - }, - "set ChannelDefaulter": { - channelTemplate: configDefaultChannelTemplate, - expected: Channel{ - Spec: ChannelSpec{ - ChannelTemplate: defaultChannelTemplate, - }, - }, - }, - "template already specified": { - channelTemplate: configDefaultChannelTemplate, - initial: Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - APIVersion: SchemeGroupVersion.String(), - Kind: "OtherChannel", - }, - }, - }, - }, - expected: Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - APIVersion: SchemeGroupVersion.String(), - Kind: "OtherChannel", - }, - }, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - ctx := context.Background() - if !tc.nilChannelDefaulter { - ctx = config.ToContext(ctx, &config.Config{ - ChannelDefaults: &config.ChannelDefaults{ - ClusterDefault: tc.channelTemplate, - }, - }) - } - tc.initial.SetDefaults(ctx) - if diff := cmp.Diff(tc.expected, tc.initial); diff != "" { - t.Fatalf("Unexpected defaults (-want, +got): %s", diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/channel_lifecycle.go b/pkg/apis/messaging/v1alpha1/channel_lifecycle.go deleted file mode 100644 index c3b4377833c..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_lifecycle.go +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck/v1alpha1" -) - -var chCondSet = apis.NewLivingConditionSet(ChannelConditionBackingChannelReady, ChannelConditionAddressable) - -const ( - // ChannelConditionReady has status True when all subconditions below have been set to True. - ChannelConditionReady = apis.ConditionReady - - // ChannelConditionBackingChannelReady has status True when the backing Channel CRD is ready. - ChannelConditionBackingChannelReady apis.ConditionType = "BackingChannelReady" - - // ChannelConditionAddressable has status true when this Channel meets - // the Addressable contract and has a non-empty hostname. - ChannelConditionAddressable apis.ConditionType = "Addressable" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (cs *ChannelStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return chCondSet.Manage(cs).GetCondition(t) -} - -// GetTopLevelCondition returns the top level Condition. -func (cs *ChannelStatus) GetTopLevelCondition() *apis.Condition { - return chCondSet.Manage(cs).GetTopLevelCondition() -} - -// IsReady returns true if the resource is ready overall. -func (cs *ChannelStatus) IsReady() bool { - return chCondSet.Manage(cs).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (cs *ChannelStatus) InitializeConditions() { - chCondSet.Manage(cs).InitializeConditions() -} - -func (cs *ChannelStatus) SetAddress(address *v1alpha1.Addressable) { - if cs.Address == nil { - cs.Address = &v1alpha1.Addressable{} - } - if address != nil && address.URL != nil { - cs.Address.Hostname = address.URL.Host - cs.Address.URL = address.URL - chCondSet.Manage(cs).MarkTrue(ChannelConditionAddressable) - } else { - cs.Address.Hostname = "" - cs.Address.URL = nil - chCondSet.Manage(cs).MarkFalse(ChannelConditionAddressable, "EmptyHostname", "hostname is the empty string") - } -} - -func (cs *ChannelStatus) MarkBackingChannelFailed(reason, messageFormat string, messageA ...interface{}) { - chCondSet.Manage(cs).MarkFalse(ChannelConditionBackingChannelReady, reason, messageFormat, messageA...) -} - -func (cs *ChannelStatus) MarkBackingChannelUnknown(reason, messageFormat string, messageA ...interface{}) { - chCondSet.Manage(cs).MarkUnknown(ChannelConditionBackingChannelReady, reason, messageFormat, messageA...) -} - -func (cs *ChannelStatus) MarkBackingChannelNotConfigured() { - chCondSet.Manage(cs).MarkUnknown(ChannelConditionBackingChannelReady, - "BackingChannelNotConfigured", "BackingChannel has not yet been reconciled.") -} - -func (cs *ChannelStatus) MarkBackingChannelReady() { - chCondSet.Manage(cs).MarkTrue(ChannelConditionBackingChannelReady) -} - -func (cs *ChannelStatus) PropagateStatuses(chs *eventingduck.ChannelableStatus) { - // TODO: Once you can get a Ready status from Channelable in a generic way, use it here. - readyCondition := chs.Status.GetCondition(apis.ConditionReady) - if readyCondition == nil { - cs.MarkBackingChannelNotConfigured() - } else { - switch { - case readyCondition.Status == corev1.ConditionUnknown: - cs.MarkBackingChannelUnknown(readyCondition.Reason, readyCondition.Message) - case readyCondition.Status == corev1.ConditionTrue: - cs.MarkBackingChannelReady() - case readyCondition.Status == corev1.ConditionFalse: - cs.MarkBackingChannelFailed(readyCondition.Reason, readyCondition.Message) - default: - cs.MarkBackingChannelUnknown("BackingChannelUnknown", "The status of BackingChannel is invalid: %v", readyCondition.Status) - } - } - // Set the address and update the Addressable conditions. - cs.SetAddress(chs.AddressStatus.Address) - // Set the subscribable status. - if subscribableTypeStatus := chs.GetSubscribableTypeStatus(); subscribableTypeStatus != nil { - cs.SetSubscribableTypeStatus(*subscribableTypeStatus) - } -} diff --git a/pkg/apis/messaging/v1alpha1/channel_lifecycle_test.go b/pkg/apis/messaging/v1alpha1/channel_lifecycle_test.go deleted file mode 100644 index df7a138fc4b..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_lifecycle_test.go +++ /dev/null @@ -1,402 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -var ( - validAddress = &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - } - urlNotSetAddress = &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{}, - Hostname: "test-domain", - } -) - -func TestChannelGetCondition(t *testing.T) { - tests := []struct { - name string - cs *ChannelStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "single condition", - cs: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - condReady, - }, - }, - }, - condQuery: apis.ConditionReady, - want: &condReady, - }, { - name: "unknown condition", - cs: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - condReady, - }, - }, - }, - condQuery: apis.ConditionType("foo"), - want: nil, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.cs.GetCondition(test.condQuery) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} - -func TestChannelInitializeConditions(t *testing.T) { - tests := []struct { - name string - cs *ChannelStatus - want *ChannelStatus - }{{ - name: "empty", - cs: &ChannelStatus{}, - want: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionUnknown, - }, { - Type: ChannelConditionBackingChannelReady, - Status: corev1.ConditionUnknown, - }, { - Type: ChannelConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one false", - cs: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionFalse, - }}, - }, - }, - want: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionFalse, - }, { - Type: ChannelConditionBackingChannelReady, - Status: corev1.ConditionUnknown, - }, { - Type: ChannelConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one true", - cs: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionBackingChannelReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - want: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionUnknown, - }, { - Type: ChannelConditionBackingChannelReady, - Status: corev1.ConditionTrue, - }, { - Type: ChannelConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - test.cs.InitializeConditions() - ignore := cmpopts.IgnoreFields( - apis.Condition{}, - "LastTransitionTime", "Message", "Reason", "Severity") - if diff := cmp.Diff(test.want, test.cs, ignore); diff != "" { - t.Errorf("unexpected conditions (-want, +got) = %v", diff) - } - }) - } -} - -func TestChannelConditionStatus(t *testing.T) { - tests := []struct { - name string - address *duckv1alpha1.Addressable - backingChannelStatus corev1.ConditionStatus - wantConditionStatus corev1.ConditionStatus - }{{ - name: "all happy", - address: validAddress, - backingChannelStatus: corev1.ConditionTrue, - wantConditionStatus: corev1.ConditionTrue, - }, { - name: "address not set", - address: &duckv1alpha1.Addressable{}, - backingChannelStatus: corev1.ConditionTrue, - wantConditionStatus: corev1.ConditionFalse, - }, - { - name: "address without url", - address: urlNotSetAddress, - backingChannelStatus: corev1.ConditionTrue, - wantConditionStatus: corev1.ConditionFalse, - }, { - name: "backing channel with unknown status", - address: validAddress, - backingChannelStatus: corev1.ConditionUnknown, - wantConditionStatus: corev1.ConditionUnknown, - }, { - name: "backing channel with false status", - address: validAddress, - backingChannelStatus: corev1.ConditionFalse, - wantConditionStatus: corev1.ConditionFalse, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - cs := &ChannelStatus{} - cs.InitializeConditions() - cs.SetAddress(test.address) - if test.backingChannelStatus == corev1.ConditionTrue { - cs.MarkBackingChannelReady() - } else if test.backingChannelStatus == corev1.ConditionFalse { - cs.MarkBackingChannelFailed("ChannelFailure", "testing") - } else { - cs.MarkBackingChannelUnknown("ChannelUnknown", "testing") - } - got := cs.GetTopLevelCondition().Status - if test.wantConditionStatus != got { - t.Errorf("unexpected readiness: want %v, got %v", test.wantConditionStatus, got) - } - }) - } -} - -func TestChannelSetAddressable(t *testing.T) { - testCases := map[string]struct { - address *duckv1alpha1.Addressable - want *ChannelStatus - }{ - "nil url": { - want: &ChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionFalse, - }, { - // Note that Ready is here because when the condition is marked False, duck - // automatically sets Ready to false. - Type: ChannelConditionReady, - Status: corev1.ConditionFalse, - }}, - }, - AddressStatus: duckv1alpha1.AddressStatus{Address: &duckv1alpha1.Addressable{}}, - }, - }, - "has domain - unknown": { - address: &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - want: &ChannelStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: ChannelConditionAddressable, - Status: corev1.ConditionTrue, - }, { - // Note: Ready is here because when the condition - // is marked True, duck automatically sets Ready to - // Unknown because of missing ChannelConditionBackingChannelReady. - Type: ChannelConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - cs := &ChannelStatus{} - cs.SetAddress(tc.address) - ignore := cmpopts.IgnoreFields( - apis.Condition{}, - "LastTransitionTime", "Message", "Reason", "Severity") - if diff := cmp.Diff(tc.want, cs, ignore); diff != "" { - t.Errorf("unexpected conditions (-want, +got) = %v", diff) - } - }) - } -} - -func TestChannelPropagateStatuses(t *testing.T) { - testCases := map[string]struct { - channelableStatus *v1alpha1.ChannelableStatus - wantConditionStatus corev1.ConditionStatus - }{ - "address set": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: validAddress, - }, - }, - wantConditionStatus: corev1.ConditionUnknown, - }, - "address not set": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: &duckv1alpha1.Addressable{}, - }, - }, - wantConditionStatus: corev1.ConditionFalse, - }, - "url not set": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: urlNotSetAddress, - }, - }, - wantConditionStatus: corev1.ConditionFalse, - }, - "all set": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: validAddress, - }, - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: apis.ConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - wantConditionStatus: corev1.ConditionTrue, - }, - "backing channel with unknown status": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: validAddress, - }, - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - wantConditionStatus: corev1.ConditionUnknown, - }, - "no condition ready in backing channel": { - channelableStatus: &v1alpha1.ChannelableStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: validAddress, - }, - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }}, - }, - }, - wantConditionStatus: corev1.ConditionUnknown, - }, - "test subscribableTypeStatus is set": { - channelableStatus: &v1alpha1.ChannelableStatus{ - SubscribableTypeStatus: v1alpha1.SubscribableTypeStatus{ - SubscribableStatus: &v1alpha1.SubscribableStatus{ - // Populate ALL fields - Subscribers: []eventingduckv1beta1.SubscriberStatus{{ - UID: "2f9b5e8e-deb6-11e8-9f32-f2801f1b9fd1", - ObservedGeneration: 1, - Ready: corev1.ConditionTrue, - Message: "Some message", - }, { - UID: "34c5aec8-deb6-11e8-9f32-f2801f1b9fd1", - ObservedGeneration: 2, - Ready: corev1.ConditionFalse, - Message: "Some message", - }}, - }, - }, - }, - wantConditionStatus: corev1.ConditionFalse, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - cs := &ChannelStatus{} - cs.PropagateStatuses(tc.channelableStatus) - got := cs.GetTopLevelCondition().Status - if tc.wantConditionStatus != got { - t.Errorf("unexpected readiness: want %v, got %v", tc.wantConditionStatus, got) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/channel_types.go b/pkg/apis/messaging/v1alpha1/channel_types.go deleted file mode 100644 index 46bc6aad162..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_types.go +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/duck/v1beta1" - messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - "knative.dev/pkg/kmeta" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Channel represents a generic Channel. It is normally used when we want a Channel, but don't need a specific Channel implementation. -type Channel struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec defines the desired state of the Channel. - Spec ChannelSpec `json:"spec,omitempty"` - - // Status represents the current state of the Channel. This data may be out of - // date. - // +optional - Status ChannelStatus `json:"status,omitempty"` -} - -var ( - // Check that Channel can be validated and defaulted. - _ apis.Validatable = (*Channel)(nil) - _ apis.Defaultable = (*Channel)(nil) - - // Check that Channel can return its spec untyped. - _ apis.HasSpec = (*Channel)(nil) - - _ runtime.Object = (*Channel)(nil) - - // Check that we can create OwnerReferences to a Channel. - _ kmeta.OwnerRefable = (*Channel)(nil) -) - -// ChannelSpec defines which subscribers have expressed interest in receiving events from this Channel. -// It also defines the ChannelTemplate to use in order to create the CRD Channel backing this Channel. -type ChannelSpec struct { - - // ChannelTemplate specifies which Channel CRD to use to create the CRD Channel backing this Channel. - // This is immutable after creation. Normally this is set by the Channel defaulter, not directly by the user. - ChannelTemplate *messagingv1beta1.ChannelTemplateSpec `json:"channelTemplate"` - - // Channel conforms to Duck type Subscribable. - Subscribable *eventingduck.Subscribable `json:"subscribable,omitempty"` - - // Delivery options. - Delivery *v1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// ChannelStatus represents the current state of a Channel. -type ChannelStatus struct { - // inherits duck/v1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1.Status `json:",inline"` - - // Channel is Addressable. It currently exposes the endpoint as a - // fully-qualified DNS name which will distribute traffic over the - // provided targets from inside the cluster. - // - // It generally has the form {channel}.{namespace}.svc.{cluster domain name} - duckv1alpha1.AddressStatus `json:",inline"` - - // Subscribers is populated with the statuses of each of the Channelable's subscribers. - eventingduck.SubscribableTypeStatus `json:",inline"` - - // Channel is an ObjectReference to the Channel CRD backing this Channel. - Channel *corev1.ObjectReference `json:"channel,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// ChannelList is a collection of Channels. -type ChannelList struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ListMeta `json:"metadata,omitempty"` - Items []Channel `json:"items"` -} - -// GetGroupVersionKind returns GroupVersionKind for Channels. -func (dc *Channel) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("Channel") -} - -// GetUntypedSpec returns the spec of the Channel. -func (c *Channel) GetUntypedSpec() interface{} { - return c.Spec -} diff --git a/pkg/apis/messaging/v1alpha1/channel_types_test.go b/pkg/apis/messaging/v1alpha1/channel_types_test.go deleted file mode 100644 index 075b34691fd..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_types_test.go +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 v1alpha1 - -import "testing" - -func TestChannel_GetGroupVersionKind(t *testing.T) { - c := Channel{} - gvk := c.GetGroupVersionKind() - if gvk.Kind != "Channel" { - t.Errorf("Should be Channel.") - } -} diff --git a/pkg/apis/messaging/v1alpha1/channel_validation.go b/pkg/apis/messaging/v1alpha1/channel_validation.go deleted file mode 100644 index 67f295e2762..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_validation.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - - "github.com/google/go-cmp/cmp/cmpopts" - "knative.dev/pkg/kmp" - - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" -) - -func (c *Channel) Validate(ctx context.Context) *apis.FieldError { - return c.Spec.Validate(ctx).ViaField("spec") -} - -func (cs *ChannelSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - if cs.ChannelTemplate == nil { - // The Channel defaulter is expected to set this, not the users. - errs = errs.Also(apis.ErrMissingField("channelTemplate")) - } else if cte := v1beta1.IsValidChannelTemplate(cs.ChannelTemplate); cte != nil { - errs = errs.Also(cte.ViaField("channelTemplate")) - } - - if cs.Subscribable != nil && len(cs.Subscribable.Subscribers) > 0 { - errs = errs.Also(apis.ErrDisallowedFields("subscribers").ViaField("subscribable")) - } - - return errs -} - -func (c *Channel) CheckImmutableFields(ctx context.Context, original *Channel) *apis.FieldError { - if original == nil { - return nil - } - - ignoreArguments := cmpopts.IgnoreFields(ChannelSpec{}, "Subscribable") - if diff, err := kmp.ShortDiff(original.Spec, c.Spec, ignoreArguments); err != nil { - return &apis.FieldError{ - Message: "Failed to diff Channel", - Paths: []string{"spec"}, - Details: err.Error(), - } - } else if diff != "" { - return &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - } - } - return nil -} diff --git a/pkg/apis/messaging/v1alpha1/channel_validation_test.go b/pkg/apis/messaging/v1alpha1/channel_validation_test.go deleted file mode 100644 index d0ad67c00d7..00000000000 --- a/pkg/apis/messaging/v1alpha1/channel_validation_test.go +++ /dev/null @@ -1,229 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" -) - -func TestChannelValidation(t *testing.T) { - tests := []CRDTest{{ - name: "empty", - cr: &Channel{ - Spec: ChannelSpec{}, - }, - want: apis.ErrMissingField("spec.channelTemplate"), - }, { - name: "channel template with no kind", - cr: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - APIVersion: SchemeGroupVersion.String(), - }, - }}, - }, - want: apis.ErrMissingField("spec.channelTemplate.kind"), - }, { - name: "channel template with no apiVersion", - cr: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - }, - }}, - }, - want: apis.ErrMissingField("spec.channelTemplate.apiVersion"), - }, { - name: "invalid subscribers array, not allowed", - cr: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - }, - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{ - SubscriberURI: apis.HTTP("subscriberendpoint"), - ReplyURI: apis.HTTP("resultendpoint"), - }}, - }}, - }, - want: apis.ErrDisallowedFields("spec.subscribable.subscribers"), - }, { - name: "nil channelTemplate and disallowed subscriber", - cr: &Channel{ - Spec: ChannelSpec{ - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{ - SubscriberURI: apis.HTTP("subscriberendpoint"), - ReplyURI: apis.HTTP("replyendpoint"), - }, {}}, - }}, - }, - want: func() *apis.FieldError { - var errs *apis.FieldError - fe := apis.ErrMissingField("spec.channelTemplate") - errs = errs.Also(fe) - errs = errs.Also(apis.ErrDisallowedFields("spec.subscribable.subscribers")) - return errs - }(), - }} - - doValidateTest(t, tests) -} - -func TestChannelImmutableFields(t *testing.T) { - tests := []struct { - name string - current *Channel - original *Channel - want *apis.FieldError - }{{ - name: "good (no change)", - current: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - Spec: &runtime.RawExtension{ - Raw: []byte(`"foo":"baz"`), - }, - }, - }, - }, - original: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - Spec: &runtime.RawExtension{ - Raw: []byte(`"foo":"baz"`), - }, - }, - }, - }, - want: nil, - }, { - name: "new nil is ok", - current: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - Spec: &runtime.RawExtension{ - Raw: []byte(`"foo":"baz"`), - }, - }, - }, - }, - original: nil, - want: nil, - }, { - name: "bad (channelTemplate change)", - current: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "OtherChannel", - APIVersion: SchemeGroupVersion.String(), - }, - Spec: &runtime.RawExtension{ - Raw: []byte(`"foo":"baz"`), - }, - }, - }, - }, - original: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - Spec: &runtime.RawExtension{ - Raw: []byte(`"foo":"baz"`), - }, - }, - }, - }, - want: &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: `{v1alpha1.ChannelSpec}.ChannelTemplate.TypeMeta.Kind: - -: "InMemoryChannel" - +: "OtherChannel" -`, - }, - }, { - name: "good (subscribable change)", - current: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - }, - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{ - SubscriberURI: apis.HTTP("subscriberendpoint"), - ReplyURI: apis.HTTP("replyendpoint"), - }}, - }, - }, - }, - original: &Channel{ - Spec: ChannelSpec{ - ChannelTemplate: &v1beta1.ChannelTemplateSpec{ - TypeMeta: v1.TypeMeta{ - Kind: "InMemoryChannel", - APIVersion: SchemeGroupVersion.String(), - }, - }, - }, - }, - want: nil, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.current.CheckImmutableFields(context.TODO(), test.original) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("CheckImmutableFields (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/crd_validation_test.go b/pkg/apis/messaging/v1alpha1/crd_validation_test.go deleted file mode 100644 index fb6c349a6a6..00000000000 --- a/pkg/apis/messaging/v1alpha1/crd_validation_test.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "knative.dev/pkg/apis" - "knative.dev/pkg/webhook/resourcesemantics" -) - -type CRDTest struct { - name string - cr resourcesemantics.GenericCRD - want *apis.FieldError -} - -func doValidateTest(t *testing.T, tests []CRDTest) { - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.cr.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: validate (-want, +got) = %v", test.name, diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/doc.go b/pkg/apis/messaging/v1alpha1/doc.go deleted file mode 100644 index 64e1d2ec055..00000000000 --- a/pkg/apis/messaging/v1alpha1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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 v1alpha1 is the v1alpha1 version of the API. -// +k8s:deepcopy-gen=package -// +groupName=messaging.knative.dev -package v1alpha1 diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion.go deleted file mode 100644 index 9cb1c5abac2..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion.go +++ /dev/null @@ -1,131 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "fmt" - - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - pkgduckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" -) - -// ConvertTo implements apis.Convertible -// Converts source (from v1alpha1.InMemoryChannel) into v1beta1.InMemoryChannel -func (source *InMemoryChannel) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *v1beta1.InMemoryChannel: - sink.ObjectMeta = source.ObjectMeta - if sink.Annotations == nil { - sink.Annotations = make(map[string]string) - } - sink.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1beta1" - source.Status.ConvertTo(ctx, &sink.Status) - return source.Spec.ConvertTo(ctx, &sink.Spec) - default: - return fmt.Errorf("unknown version, got: %T", sink) - } -} - -// ConvertTo helps implement apis.Convertible -func (source *InMemoryChannelSpec) ConvertTo(ctx context.Context, sink *v1beta1.InMemoryChannelSpec) error { - sink.Delivery = source.Delivery - if source.Subscribable != nil { - sink.Subscribers = make([]duckv1beta1.SubscriberSpec, len(source.Subscribable.Subscribers)) - for i, s := range source.Subscribable.Subscribers { - s.ConvertTo(ctx, &sink.Subscribers[i]) - } - } - return nil -} - -// ConvertTo helps implement apis.Convertible -func (source *InMemoryChannelStatus) ConvertTo(ctx context.Context, sink *v1beta1.InMemoryChannelStatus) { - source.Status.ConvertTo(ctx, &sink.Status) - if source.AddressStatus.Address != nil { - sink.AddressStatus.Address = &duckv1.Addressable{} - source.AddressStatus.Address.ConvertTo(ctx, sink.AddressStatus.Address) - } - if source.SubscribableTypeStatus.SubscribableStatus != nil && - len(source.SubscribableTypeStatus.SubscribableStatus.Subscribers) > 0 { - sink.SubscribableStatus.Subscribers = make([]duckv1beta1.SubscriberStatus, len(source.SubscribableTypeStatus.SubscribableStatus.Subscribers)) - for i, ss := range source.SubscribableTypeStatus.SubscribableStatus.Subscribers { - sink.SubscribableStatus.Subscribers[i] = duckv1beta1.SubscriberStatus{ - UID: ss.UID, - ObservedGeneration: ss.ObservedGeneration, - Ready: ss.Ready, - Message: ss.Message, - } - } - } -} - -// ConvertFrom implements apis.Convertible. -// Converts obj v1beta1.InMemoryChannel into v1alpha1.InMemoryChannel -func (sink *InMemoryChannel) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *v1beta1.InMemoryChannel: - sink.ObjectMeta = source.ObjectMeta - sink.Status.ConvertFrom(ctx, source.Status) - sink.Spec.ConvertFrom(ctx, source.Spec) - if sink.Annotations == nil { - sink.Annotations = make(map[string]string) - } - sink.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1alpha1" - return nil - default: - return fmt.Errorf("unknown version, got: %T", source) - } -} - -// ConvertFrom helps implement apis.Convertible -func (sink *InMemoryChannelSpec) ConvertFrom(ctx context.Context, source v1beta1.InMemoryChannelSpec) { - sink.Delivery = source.Delivery - if len(source.Subscribers) > 0 { - sink.Subscribable = &eventingduck.Subscribable{ - Subscribers: make([]eventingduck.SubscriberSpec, len(source.Subscribers)), - } - for i, s := range source.Subscribers { - sink.Subscribable.Subscribers[i].ConvertFrom(ctx, s) - } - } -} - -// ConvertFrom helps implement apis.Convertible -func (sink *InMemoryChannelStatus) ConvertFrom(ctx context.Context, source v1beta1.InMemoryChannelStatus) error { - source.Status.ConvertTo(ctx, &sink.Status) - if source.AddressStatus.Address != nil { - sink.AddressStatus.Address = &pkgduckv1alpha1.Addressable{} - if err := sink.AddressStatus.Address.ConvertFrom(ctx, source.AddressStatus.Address); err != nil { - return err - } - } - if len(source.SubscribableStatus.Subscribers) > 0 { - sink.SubscribableTypeStatus.SubscribableStatus = &duckv1alpha1.SubscribableStatus{ - Subscribers: make([]duckv1beta1.SubscriberStatus, len(source.SubscribableStatus.Subscribers)), - } - copy(sink.SubscribableTypeStatus.SubscribableStatus.Subscribers, source.SubscribableStatus.Subscribers) - } - return nil -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion_test.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion_test.go deleted file mode 100644 index c1e6b5410d2..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_conversion_test.go +++ /dev/null @@ -1,308 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -func TestInMemoryChannelConversionBadType(t *testing.T) { - good, bad := &InMemoryChannel{}, &Subscription{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -// Test v1alpha1 -> v1beta1 -> v1alpha1 -func TestInMemoryChannelConversion(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.InMemoryChannel{}} - - linear := eventingduckv1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *InMemoryChannel - }{{ - name: "min configuration", - in: &InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: InMemoryChannelSpec{}, - Status: InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{}, - }, - }, - }, - }, { - name: "full configuration", - in: &InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: InMemoryChannelSpec{ - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - DeadLetterSinkURI: apis.HTTP("subscriber.dls.example.com"), - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("dls"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - Status: InMemoryChannelStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - Conditions: duckv1.Conditions{{ - Type: "Ready", - Status: "True", - }}, - }, - AddressStatus: duckv1alpha1.AddressStatus{ - Address: &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: apis.HTTP("addressstatus.example.com"), - }, - Hostname: "addressstatus.example.com", - }, - }, - SubscribableTypeStatus: eventingduck.SubscribableTypeStatus{ - SubscribableStatus: &eventingduck.SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &InMemoryChannel{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - // Make sure the annotation specifies the correct duck. - if test.in.Annotations == nil { - test.in.Annotations = make(map[string]string) - } - test.in.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1alpha1" - - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} - -// Test v1beta1 -> v1alpha1 -> v1beta1 -func TestInMemoryChannelConversionWithV1Beta1(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&InMemoryChannel{}} - - linear := eventingduckv1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *v1beta1.InMemoryChannel - }{{ - name: "min", - in: &v1beta1.InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: v1beta1.InMemoryChannelSpec{}, - Status: v1beta1.InMemoryChannelStatus{ - ChannelableStatus: eventingduckv1beta1.ChannelableStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{}, - }, - }, - }, - }, - }, { - name: "full configuration", - in: &v1beta1.InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: "channel-name", - Namespace: "channel-ns", - Generation: 17, - }, - Spec: v1beta1.InMemoryChannelSpec{ - ChannelableSpec: eventingduckv1beta1.ChannelableSpec{ - SubscribableSpec: eventingduckv1beta1.SubscribableSpec{ - Subscribers: []eventingduckv1beta1.SubscriberSpec{ - { - UID: "uid-1", - Generation: 7, - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - // DeadLetterSinkURI: apis.HTTP("dlc.reply.example.com"), - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("subscriber.dls.example.com"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - }, - Delivery: &eventingduckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("dls"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - }, - Status: v1beta1.InMemoryChannelStatus{ - ChannelableStatus: eventingduckv1beta1.ChannelableStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - Conditions: duckv1.Conditions{{ - Type: "Ready", - Status: "True", - }}, - }, - AddressStatus: duckv1.AddressStatus{ - Address: &duckv1.Addressable{ - URL: apis.HTTP("addressstatus.example.com"), - }, - }, - SubscribableStatus: eventingduckv1beta1.SubscribableStatus{ - Subscribers: []eventingduckv1beta1.SubscriberStatus{ - { - UID: "status-uid-1", - ObservedGeneration: 99, - Ready: corev1.ConditionTrue, - Message: "msg", - }, - }, - }, - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := version.ConvertFrom(context.Background(), test.in); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &v1beta1.InMemoryChannel{} - if err := ver.ConvertTo(context.Background(), got); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - // Make sure the annotation specifies the correct duck. - if test.in.Annotations == nil { - test.in.Annotations = make(map[string]string) - } - test.in.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1beta1" - - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_defaults.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_defaults.go deleted file mode 100644 index df806f17b70..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_defaults.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - - "knative.dev/eventing/pkg/apis/messaging" -) - -func (imc *InMemoryChannel) SetDefaults(ctx context.Context) { - imc.Spec.SetDefaults(ctx) - - // Set the duck subscription to the stored version of the duck - // we support. Reason for this is that the stored version will - // not get a chance to get modified, but for newer versions - // conversion webhook will be able to take a crack at it and - // can modify it to match the duck shape. - if imc.Annotations == nil { - imc.Annotations = make(map[string]string) - } - if _, ok := imc.Annotations[messaging.SubscribableDuckVersionAnnotation]; !ok { - imc.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1beta1" - } -} - -func (imcs *InMemoryChannelSpec) SetDefaults(ctx context.Context) { - // TODO: Nothing to default here... -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle.go deleted file mode 100644 index a9f1259e84a..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle.go +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck/v1alpha1" -) - -var imcCondSet = apis.NewLivingConditionSet(InMemoryChannelConditionDispatcherReady, InMemoryChannelConditionServiceReady, InMemoryChannelConditionEndpointsReady, InMemoryChannelConditionAddressable, InMemoryChannelConditionChannelServiceReady) - -const ( - // InMemoryChannelConditionReady has status True when all subconditions below have been set to True. - InMemoryChannelConditionReady = apis.ConditionReady - - // InMemoryChannelConditionDispatcherReady has status True when a Dispatcher deployment is ready - // Keyed off appsv1.DeploymentAvaialble, which means minimum available replicas required are up - // and running for at least minReadySeconds. - InMemoryChannelConditionDispatcherReady apis.ConditionType = "DispatcherReady" - - // InMemoryChannelConditionServiceReady has status True when a k8s Service is ready. This - // basically just means it exists because there's no meaningful status in Service. See Endpoints - // below. - InMemoryChannelConditionServiceReady apis.ConditionType = "ServiceReady" - - // InMemoryChannelConditionEndpointsReady has status True when a k8s Service Endpoints are backed - // by at least one endpoint. - InMemoryChannelConditionEndpointsReady apis.ConditionType = "EndpointsReady" - - // InMemoryChannelConditionAddressable has status true when this InMemoryChannel meets - // the Addressable contract and has a non-empty hostname. - InMemoryChannelConditionAddressable apis.ConditionType = "Addressable" - - // InMemoryChannelConditionServiceReady has status True when a k8s Service representing the channel is ready. - // Because this uses ExternalName, there are no endpoints to check. - InMemoryChannelConditionChannelServiceReady apis.ConditionType = "ChannelServiceReady" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (imcs *InMemoryChannelStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return imcCondSet.Manage(imcs).GetCondition(t) -} - -// IsReady returns true if the resource is ready overall. -func (imcs *InMemoryChannelStatus) IsReady() bool { - return imcCondSet.Manage(imcs).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (imcs *InMemoryChannelStatus) InitializeConditions() { - imcCondSet.Manage(imcs).InitializeConditions() -} - -// TODO: Use the new beta duck types. -func (imcs *InMemoryChannelStatus) SetAddress(url *apis.URL) { - if imcs.Address == nil { - imcs.Address = &v1alpha1.Addressable{} - } - if url != nil { - imcs.Address.Hostname = url.Host - imcs.Address.URL = url - imcCondSet.Manage(imcs).MarkTrue(InMemoryChannelConditionAddressable) - } else { - imcs.Address.Hostname = "" - imcs.Address.URL = nil - imcCondSet.Manage(imcs).MarkFalse(InMemoryChannelConditionAddressable, "emptyHostname", "hostname is the empty string") - } -} - -func (imcs *InMemoryChannelStatus) MarkDispatcherFailed(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkFalse(InMemoryChannelConditionDispatcherReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkDispatcherUnknown(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkUnknown(InMemoryChannelConditionDispatcherReady, reason, messageFormat, messageA...) -} - -// TODO: Unify this with the ones from Eventing. Say: Broker, Trigger. -func (imcs *InMemoryChannelStatus) PropagateDispatcherStatus(ds *appsv1.DeploymentStatus) { - for _, cond := range ds.Conditions { - if cond.Type == appsv1.DeploymentAvailable { - if cond.Status == corev1.ConditionTrue { - imcCondSet.Manage(imcs).MarkTrue(InMemoryChannelConditionDispatcherReady) - } else if cond.Status == corev1.ConditionFalse { - imcs.MarkDispatcherFailed("DispatcherDeploymentFalse", "The status of Dispatcher Deployment is False: %s : %s", cond.Reason, cond.Message) - } else if cond.Status == corev1.ConditionUnknown { - imcs.MarkDispatcherUnknown("DispatcherDeploymentUnknown", "The status of Dispatcher Deployment is Unknown: %s : %s", cond.Reason, cond.Message) - } - } - } -} - -func (imcs *InMemoryChannelStatus) MarkServiceFailed(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkFalse(InMemoryChannelConditionServiceReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkServiceUnknown(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkUnknown(InMemoryChannelConditionServiceReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkServiceTrue() { - imcCondSet.Manage(imcs).MarkTrue(InMemoryChannelConditionServiceReady) -} - -func (imcs *InMemoryChannelStatus) MarkChannelServiceFailed(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkFalse(InMemoryChannelConditionChannelServiceReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkChannelServiceUnknown(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkUnknown(InMemoryChannelConditionChannelServiceReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkChannelServiceTrue() { - imcCondSet.Manage(imcs).MarkTrue(InMemoryChannelConditionChannelServiceReady) -} - -func (imcs *InMemoryChannelStatus) MarkEndpointsFailed(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkFalse(InMemoryChannelConditionEndpointsReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkEndpointsUnknown(reason, messageFormat string, messageA ...interface{}) { - imcCondSet.Manage(imcs).MarkUnknown(InMemoryChannelConditionEndpointsReady, reason, messageFormat, messageA...) -} - -func (imcs *InMemoryChannelStatus) MarkEndpointsTrue() { - imcCondSet.Manage(imcs).MarkTrue(InMemoryChannelConditionEndpointsReady) -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle_test.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle_test.go deleted file mode 100644 index 999b83324c1..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_lifecycle_test.go +++ /dev/null @@ -1,360 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -var condReady = apis.Condition{ - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionTrue, -} - -var condDispatcherNotReady = apis.Condition{ - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionFalse, -} - -var deploymentConditionReady = appsv1.DeploymentCondition{ - Type: appsv1.DeploymentAvailable, - Status: corev1.ConditionTrue, -} - -var deploymentConditionNotReady = appsv1.DeploymentCondition{ - Type: appsv1.DeploymentAvailable, - Status: corev1.ConditionFalse, -} - -var deploymentStatusReady = &appsv1.DeploymentStatus{Conditions: []appsv1.DeploymentCondition{deploymentConditionReady}} -var deploymentStatusNotReady = &appsv1.DeploymentStatus{Conditions: []appsv1.DeploymentCondition{deploymentConditionNotReady}} - -var ignoreAllButTypeAndStatus = cmpopts.IgnoreFields( - apis.Condition{}, - "LastTransitionTime", "Message", "Reason", "Severity") - -func TestInMemoryChannelGetCondition(t *testing.T) { - tests := []struct { - name string - cs *InMemoryChannelStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "single condition", - cs: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - condReady, - }, - }, - }, - condQuery: apis.ConditionReady, - want: &condReady, - }, { - name: "unknown condition", - cs: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - condReady, - condDispatcherNotReady, - }, - }, - }, - condQuery: apis.ConditionType("foo"), - want: nil, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.cs.GetCondition(test.condQuery) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} - -func TestInMemoryChannelInitializeConditions(t *testing.T) { - tests := []struct { - name string - cs *InMemoryChannelStatus - want *InMemoryChannelStatus - }{{ - name: "empty", - cs: &InMemoryChannelStatus{}, - want: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionAddressable, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionChannelServiceReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionEndpointsReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionServiceReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one false", - cs: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionFalse, - }}, - }, - }, - want: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionAddressable, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionChannelServiceReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionFalse, - }, { - Type: InMemoryChannelConditionEndpointsReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionServiceReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one true", - cs: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - want: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionAddressable, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionChannelServiceReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionDispatcherReady, - Status: corev1.ConditionTrue, - }, { - Type: InMemoryChannelConditionEndpointsReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: InMemoryChannelConditionServiceReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - test.cs.InitializeConditions() - if diff := cmp.Diff(test.want, test.cs, ignoreAllButTypeAndStatus); diff != "" { - t.Errorf("unexpected conditions (-want, +got) = %v", diff) - } - }) - } -} - -func TestInMemoryChannelIsReady(t *testing.T) { - tests := []struct { - name string - markServiceReady bool - markChannelServiceReady bool - setAddress bool - markEndpointsReady bool - wantReady bool - dispatcherStatus *appsv1.DeploymentStatus - }{{ - name: "all happy", - markServiceReady: true, - markChannelServiceReady: true, - markEndpointsReady: true, - dispatcherStatus: deploymentStatusReady, - setAddress: true, - wantReady: true, - }, { - name: "service not ready", - markServiceReady: false, - markChannelServiceReady: false, - markEndpointsReady: true, - dispatcherStatus: deploymentStatusReady, - setAddress: true, - wantReady: false, - }, { - name: "endpoints not ready", - markServiceReady: true, - markChannelServiceReady: false, - markEndpointsReady: false, - dispatcherStatus: deploymentStatusReady, - setAddress: true, - wantReady: false, - }, { - name: "deployment not ready", - markServiceReady: true, - markEndpointsReady: true, - markChannelServiceReady: false, - dispatcherStatus: deploymentStatusNotReady, - setAddress: true, - wantReady: false, - }, { - name: "address not set", - markServiceReady: true, - markChannelServiceReady: false, - markEndpointsReady: true, - dispatcherStatus: deploymentStatusReady, - setAddress: false, - wantReady: false, - }, { - name: "channel service not ready", - markServiceReady: true, - markChannelServiceReady: false, - markEndpointsReady: true, - dispatcherStatus: deploymentStatusReady, - setAddress: true, - wantReady: false, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - cs := &InMemoryChannelStatus{} - cs.InitializeConditions() - if test.markServiceReady { - cs.MarkServiceTrue() - } else { - cs.MarkServiceFailed("NotReadyService", "testing") - } - if test.markChannelServiceReady { - cs.MarkChannelServiceTrue() - } else { - cs.MarkChannelServiceFailed("NotReadyChannelService", "testing") - } - if test.setAddress { - cs.SetAddress(&apis.URL{Scheme: "http", Host: "foo.bar"}) - } - if test.markEndpointsReady { - cs.MarkEndpointsTrue() - } else { - cs.MarkEndpointsFailed("NotReadyEndpoints", "testing") - } - if test.dispatcherStatus != nil { - cs.PropagateDispatcherStatus(test.dispatcherStatus) - } else { - cs.MarkDispatcherFailed("NotReadyDispatcher", "testing") - } - got := cs.IsReady() - if test.wantReady != got { - t.Errorf("unexpected readiness: want %v, got %v", test.wantReady, got) - } - }) - } -} - -func TestInMemoryChannelStatus_SetAddressable(t *testing.T) { - testCases := map[string]struct { - url *apis.URL - want *InMemoryChannelStatus - }{ - "empty string": { - want: &InMemoryChannelStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionAddressable, - Status: corev1.ConditionFalse, - }, { - // Note that Ready is here because when the condition is marked False, duck - // automatically sets Ready to false. - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionFalse, - }}, - }, - AddressStatus: duckv1alpha1.AddressStatus{Address: &duckv1alpha1.Addressable{}}, - }, - }, - "has domain - unknown": { - url: &apis.URL{Scheme: "http", Host: "test-domain"}, - want: &InMemoryChannelStatus{ - AddressStatus: duckv1alpha1.AddressStatus{ - Address: &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: "test-domain", - }, - }, - Hostname: "test-domain", - }, - }, - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: InMemoryChannelConditionAddressable, - Status: corev1.ConditionTrue, - }, { - // Note: Ready is here because when the condition - // is marked True, duck automatically sets Ready to - // Unknown because of missing ChannelConditionBackingChannelReady. - Type: InMemoryChannelConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - cs := &InMemoryChannelStatus{} - cs.SetAddress(tc.url) - if diff := cmp.Diff(tc.want, cs, ignoreAllButTypeAndStatus); diff != "" { - t.Errorf("unexpected conditions (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_types.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_types.go deleted file mode 100644 index b7f3e73a980..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_types.go +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - "knative.dev/pkg/kmeta" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// InMemoryChannel is a resource representing an in memory channel -type InMemoryChannel struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec defines the desired state of the Channel. - Spec InMemoryChannelSpec `json:"spec,omitempty"` - - // Status represents the current state of the Channel. This data may be out of - // date. - // +optional - Status InMemoryChannelStatus `json:"status,omitempty"` -} - -var ( - // Check that InMemoryChannel can be validated and defaulted. - _ apis.Validatable = (*InMemoryChannel)(nil) - _ apis.Defaultable = (*InMemoryChannel)(nil) - - // Check that InMemoryChannel can return its spec untyped. - _ apis.HasSpec = (*InMemoryChannel)(nil) - - _ runtime.Object = (*InMemoryChannel)(nil) - - // Check that we can create OwnerReferences to an InMemoryChannel. - _ kmeta.OwnerRefable = (*InMemoryChannel)(nil) -) - -// InMemoryChannelSpec defines which subscribers have expressed interest in -// receiving events from this InMemoryChannel. -// arguments for a Channel. -type InMemoryChannelSpec struct { - // Channel conforms to Duck type Subscribable. - Subscribable *eventingduck.Subscribable `json:"subscribable,omitempty"` - - // For round tripping (v1beta1 <-> v1alpha1> - Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// ChannelStatus represents the current state of a Channel. -type InMemoryChannelStatus struct { - // inherits duck/v1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1.Status `json:",inline"` - - // InMemoryChannel is Addressable. It currently exposes the endpoint as a - // fully-qualified DNS name which will distribute traffic over the - // provided targets from inside the cluster. - // - // It generally has the form {channel}.{namespace}.svc.{cluster domain name} - duckv1alpha1.AddressStatus `json:",inline"` - - // Subscribers is populated with the statuses of each of the Channelable's subscribers. - eventingduck.SubscribableTypeStatus `json:",inline"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// InMemoryChannelList is a collection of in-memory channels. -type InMemoryChannelList struct { - metav1.TypeMeta `json:",inline"` - // +optional - metav1.ListMeta `json:"metadata,omitempty"` - Items []InMemoryChannel `json:"items"` -} - -// GetGroupVersionKind returns GroupVersionKind for InMemoryChannels -func (imc *InMemoryChannel) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("InMemoryChannel") -} - -// GetUntypedSpec returns the spec of the InMemoryChannel. -func (i *InMemoryChannel) GetUntypedSpec() interface{} { - return i.Spec -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_types_test.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_types_test.go deleted file mode 100644 index 84e5f81e951..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_types_test.go +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 v1alpha1 - -import "testing" - -func TestInMemoryChannel_GetGroupVersionKind(t *testing.T) { - imc := InMemoryChannel{} - gvk := imc.GetGroupVersionKind() - if gvk.Kind != "InMemoryChannel" { - t.Errorf("Should be InMemoryChannel.") - } -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_validation.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_validation.go deleted file mode 100644 index f133d2ef258..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_validation.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -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 v1alpha1 - -import ( - "context" - "fmt" - - "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/pkg/apis" -) - -func (imc *InMemoryChannel) Validate(ctx context.Context) *apis.FieldError { - errs := imc.Spec.Validate(ctx).ViaField("spec") - - // Validate annotations - if imc.Annotations != nil { - if scope, ok := imc.Annotations[eventing.ScopeAnnotationKey]; ok { - if scope != eventing.ScopeNamespace && scope != eventing.ScopeCluster { - iv := apis.ErrInvalidValue(scope, "") - iv.Details = "expected either 'cluster' or 'namespace'" - errs = errs.Also(iv.ViaFieldKey("annotations", eventing.ScopeAnnotationKey).ViaField("metadata")) - } - } - } - - return errs -} - -func (imcs *InMemoryChannelSpec) Validate(ctx context.Context) *apis.FieldError { - var errs *apis.FieldError - - if imcs.Subscribable != nil { - for i, subscriber := range imcs.Subscribable.Subscribers { - if subscriber.ReplyURI == nil && subscriber.SubscriberURI == nil { - fe := apis.ErrMissingField("replyURI", "subscriberURI") - fe.Details = "expected at least one of, got none" - errs = errs.Also(fe.ViaField(fmt.Sprintf("subscriber[%d]", i)).ViaField("subscribable")) - } - } - } - - return errs -} diff --git a/pkg/apis/messaging/v1alpha1/in_memory_channel_validation_test.go b/pkg/apis/messaging/v1alpha1/in_memory_channel_validation_test.go deleted file mode 100644 index dd49a096081..00000000000 --- a/pkg/apis/messaging/v1alpha1/in_memory_channel_validation_test.go +++ /dev/null @@ -1,100 +0,0 @@ -/* -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 v1alpha1 - -import ( - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" - "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/pkg/apis" -) - -func TestInMemoryChannelValidation(t *testing.T) { - tests := []CRDTest{{ - name: "empty", - cr: &InMemoryChannel{ - Spec: InMemoryChannelSpec{}, - }, - want: nil, - }, { - name: "valid subscribers array", - cr: &InMemoryChannel{ - Spec: InMemoryChannelSpec{ - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{ - SubscriberURI: apis.HTTP("subscriberendpoint"), - ReplyURI: apis.HTTP("resultendpoint"), - }}, - }}, - }, - want: nil, - }, { - name: "empty subscriber at index 1", - cr: &InMemoryChannel{ - Spec: InMemoryChannelSpec{ - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{ - SubscriberURI: apis.HTTP("subscriberendpoint"), - ReplyURI: apis.HTTP("replyendpoint"), - }, {}}, - }}, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("spec.subscribable.subscriber[1].replyURI", "spec.subscribable.subscriber[1].subscriberURI") - fe.Details = "expected at least one of, got none" - return fe - }(), - }, { - name: "2 empty subscribers", - cr: &InMemoryChannel{ - Spec: InMemoryChannelSpec{ - Subscribable: &eventingduck.Subscribable{ - Subscribers: []eventingduck.SubscriberSpec{{}, {}}, - }, - }, - }, - want: func() *apis.FieldError { - var errs *apis.FieldError - fe := apis.ErrMissingField("spec.subscribable.subscriber[0].replyURI", "spec.subscribable.subscriber[0].subscriberURI") - fe.Details = "expected at least one of, got none" - errs = errs.Also(fe) - fe = apis.ErrMissingField("spec.subscribable.subscriber[1].replyURI", "spec.subscribable.subscriber[1].subscriberURI") - fe.Details = "expected at least one of, got none" - errs = errs.Also(fe) - return errs - }(), - }, { - name: "invalid scope annotation", - cr: &InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - eventing.ScopeAnnotationKey: "notvalid", - }, - }, - Spec: InMemoryChannelSpec{}, - }, - want: func() *apis.FieldError { - fe := apis.ErrInvalidValue("notvalid", "metadata.annotations.[eventing.knative.dev/scope]") - fe.Details = "expected either 'cluster' or 'namespace'" - return fe - }(), - }} - - doValidateTest(t, tests) -} diff --git a/pkg/apis/messaging/v1alpha1/register.go b/pkg/apis/messaging/v1alpha1/register.go deleted file mode 100644 index cefb6151272..00000000000 --- a/pkg/apis/messaging/v1alpha1/register.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 v1alpha1 - -import ( - "knative.dev/eventing/pkg/apis/messaging" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: messaging.GroupName, Version: "v1alpha1"} - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -var ( - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme -) - -// Adds the list of known types to Scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &InMemoryChannel{}, - &InMemoryChannelList{}, - &Subscription{}, - &SubscriptionList{}, - &Channel{}, - &ChannelList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation.go b/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation.go deleted file mode 100644 index 87dc0b05df4..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "reflect" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" -) - -func isChannelEmpty(f corev1.ObjectReference) bool { - return equality.Semantic.DeepEqual(f, corev1.ObjectReference{}) -} - -// Valid if it is a valid object reference. -func isValidChannel(f corev1.ObjectReference) *apis.FieldError { - return IsValidObjectReference(f) -} - -func IsValidObjectReference(f corev1.ObjectReference) *apis.FieldError { - return checkRequiredObjectReferenceFields(f). - Also(checkDisallowedObjectReferenceFields(f)) -} - -// Check the corev1.ObjectReference to make sure it has the required fields. They -// are not checked for anything more except that they are set. -func checkRequiredObjectReferenceFields(f corev1.ObjectReference) *apis.FieldError { - var errs *apis.FieldError - if f.Name == "" { - errs = errs.Also(apis.ErrMissingField("name")) - } - if f.APIVersion == "" { - errs = errs.Also(apis.ErrMissingField("apiVersion")) - } - if f.Kind == "" { - errs = errs.Also(apis.ErrMissingField("kind")) - } - return errs -} - -// Check the corev1.ObjectReference to make sure it only has the following fields set: -// Name, Kind, APIVersion -// If any other fields are set and is not the Zero value, returns an apis.FieldError -// with the fieldpaths for all those fields. -func checkDisallowedObjectReferenceFields(f corev1.ObjectReference) *apis.FieldError { - disallowedFields := []string{} - // See if there are any fields that have been set that should not be. - // TODO: Hoist this kind of stuff into pkg repository. - s := reflect.ValueOf(f) - typeOf := s.Type() - for i := 0; i < s.NumField(); i++ { - field := s.Field(i) - fieldName := typeOf.Field(i).Name - if fieldName == "Name" || fieldName == "Kind" || fieldName == "APIVersion" { - continue - } - if !cmp.Equal(field.Interface(), reflect.Zero(field.Type()).Interface()) { - disallowedFields = append(disallowedFields, fieldName) - } - } - if len(disallowedFields) > 0 { - fe := apis.ErrDisallowedFields(disallowedFields...) - fe.Details = "only name, apiVersion and kind are supported fields" - return fe - } - return nil - -} diff --git a/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation_test.go b/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation_test.go deleted file mode 100644 index 28a9f5d26a2..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscribable_channelable_validation_test.go +++ /dev/null @@ -1,150 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" -) - -var validationTests = []struct { - name string - ref corev1.ObjectReference - want *apis.FieldError -}{ - { - name: "valid object ref", - ref: corev1.ObjectReference{ - Name: "boaty-mcboatface", - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "MyChannel", - }, - want: nil, - }, - { - name: "invalid object ref", - ref: corev1.ObjectReference{ - Name: "boaty-mcboatface", - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "", - }, - want: apis.ErrMissingField("kind"), - }, -} - -func TestIsChannelEmpty(t *testing.T) { - name := "non empty" - t.Run(name, func(t *testing.T) { - r := corev1.ObjectReference{ - Name: "boaty-mcboatface", - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "Channel", - } - if isChannelEmpty(r) { - t.Errorf("%s: isChannelEmpty(%s) should be false", name, r) - } - }) - - name = "empty" - t.Run(name, func(t *testing.T) { - r := corev1.ObjectReference{} - if !isChannelEmpty(r) { - t.Errorf("%s: isChannelEmpty(%s) should be true", name, r) - } - }) -} - -func TestIsValidChannel(t *testing.T) { - for _, test := range validationTests { - t.Run(test.name, func(t *testing.T) { - got := isValidChannel(test.ref) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: validation (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestIsValidObjectReference(t *testing.T) { - tests := []struct { - name string - ref corev1.ObjectReference - want []*apis.FieldError - }{ - { - name: "missing api version and kind", - ref: corev1.ObjectReference{ - Name: "boaty-mcboatface", - APIVersion: "", - Kind: "", - }, - want: []*apis.FieldError{ - apis.ErrMissingField("apiVersion"), - apis.ErrMissingField("kind"), - }, - }, - { - name: "missing name", - ref: corev1.ObjectReference{ - Name: "", - APIVersion: "eventing.knative.dev/v1alpha1", - Kind: "Strait", - }, - want: []*apis.FieldError{ - apis.ErrMissingField("name"), - }, - }, - { - name: "missing all", - ref: corev1.ObjectReference{ - Name: "", - APIVersion: "", - Kind: "", - }, - want: []*apis.FieldError{ - apis.ErrMissingField("name"), - apis.ErrMissingField("apiVersion"), - apis.ErrMissingField("kind"), - }, - }, - { - name: "missing none", - ref: corev1.ObjectReference{ - Name: "kind", - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "Channel", - }, - want: []*apis.FieldError{}, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - allWanted := &apis.FieldError{} - for _, fe := range test.want { - allWanted = allWanted.Also(fe) - } - got := IsValidObjectReference(test.ref) - if diff := cmp.Diff(allWanted.Error(), got.Error()); diff != "" { - t.Errorf("%s: validation (-want, +got) = %v", test.name, diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_conversion.go b/pkg/apis/messaging/v1alpha1/subscription_conversion.go deleted file mode 100644 index e54e6123494..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_conversion.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "fmt" - - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" -) - -// ConvertTo implements apis.Convertible. -// Converts source (from v1alpha1.Subscription) into v1beta1.Subscription -func (source *Subscription) ConvertTo(ctx context.Context, obj apis.Convertible) error { - switch sink := obj.(type) { - case *v1beta1.Subscription: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.Channel = source.Spec.Channel - sink.Spec.Delivery = source.Spec.Delivery - sink.Spec.Subscriber = source.Spec.Subscriber - sink.Spec.Reply = source.Spec.Reply - - sink.Status.Status = source.Status.Status - sink.Status.PhysicalSubscription.SubscriberURI = source.Status.PhysicalSubscription.SubscriberURI - sink.Status.PhysicalSubscription.ReplyURI = source.Status.PhysicalSubscription.ReplyURI - sink.Status.PhysicalSubscription.DeadLetterSinkURI = source.Status.PhysicalSubscription.DeadLetterSinkURI - return nil - default: - return fmt.Errorf("Unknown conversion, got: %T", sink) - - } -} - -// ConvertFrom implements apis.Convertible. -// Converts obj from v1beta1.Subscription into v1alpha1.Subscription -func (sink *Subscription) ConvertFrom(ctx context.Context, obj apis.Convertible) error { - switch source := obj.(type) { - case *v1beta1.Subscription: - sink.ObjectMeta = source.ObjectMeta - sink.Spec.Channel = source.Spec.Channel - sink.Spec.Delivery = source.Spec.Delivery - sink.Spec.Subscriber = source.Spec.Subscriber - sink.Spec.Reply = source.Spec.Reply - - sink.Status.Status = source.Status.Status - sink.Status.PhysicalSubscription.SubscriberURI = source.Status.PhysicalSubscription.SubscriberURI - sink.Status.PhysicalSubscription.ReplyURI = source.Status.PhysicalSubscription.ReplyURI - sink.Status.PhysicalSubscription.DeadLetterSinkURI = source.Status.PhysicalSubscription.DeadLetterSinkURI - - return nil - default: - return fmt.Errorf("Unknown conversion, got: %T", source) - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_conversion_test.go b/pkg/apis/messaging/v1alpha1/subscription_conversion_test.go deleted file mode 100644 index eae08d49556..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_conversion_test.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright 2020 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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func TestSubscriptionConversionBadType(t *testing.T) { - good, bad := &Subscription{}, &Channel{} - - if err := good.ConvertTo(context.Background(), bad); err == nil { - t.Errorf("ConvertTo() = %#v, wanted error", bad) - } - - if err := good.ConvertFrom(context.Background(), bad); err == nil { - t.Errorf("ConvertFrom() = %#v, wanted error", good) - } -} - -func TestSubscriptionConversion(t *testing.T) { - // Just one for now, just adding the for loop for ease of future changes. - versions := []apis.Convertible{&v1beta1.Subscription{}} - - linear := duckv1beta1.BackoffPolicyLinear - - tests := []struct { - name string - in *Subscription - }{{ - name: "min configuration", - in: &Subscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: "broker-name", - Namespace: "broker-ns", - Generation: 17, - }, - Spec: SubscriptionSpec{}, - }, - }, { - name: "full configuration", - in: &Subscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: "broker-name", - Namespace: "broker-ns", - Generation: 17, - }, - Spec: SubscriptionSpec{ - Channel: corev1.ObjectReference{ - Kind: "channelKind", - Namespace: "channelNamespace", - Name: "channelName", - APIVersion: "channelAPIVersion", - }, - Delivery: &duckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Kind: "dlKind", - Namespace: "dlNamespace", - Name: "dlName", - APIVersion: "dlAPIVersion", - }, - URI: apis.HTTP("dls"), - }, - Retry: pointer.Int32Ptr(5), - BackoffPolicy: &linear, - BackoffDelay: pointer.StringPtr("5s"), - }, - }, - Status: SubscriptionStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - Conditions: duckv1.Conditions{{ - Type: "Ready", - Status: "True", - }}, - }, - PhysicalSubscription: SubscriptionStatusPhysicalSubscription{ - SubscriberURI: apis.HTTP("subscriber.example.com"), - ReplyURI: apis.HTTP("reply.example.com"), - DeadLetterSinkURI: apis.HTTP("dlc.example.com"), - }, - }, - }, - }} - for _, test := range tests { - for _, version := range versions { - t.Run(test.name, func(t *testing.T) { - ver := version - if err := test.in.ConvertTo(context.Background(), ver); err != nil { - t.Errorf("ConvertTo() = %v", err) - } - got := &Subscription{} - if err := got.ConvertFrom(context.Background(), ver); err != nil { - t.Errorf("ConvertFrom() = %v", err) - } - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) - } - }) - } - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_defaults.go b/pkg/apis/messaging/v1alpha1/subscription_defaults.go deleted file mode 100644 index f0be767f6e0..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_defaults.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "context" - - "knative.dev/pkg/apis" -) - -func (s *Subscription) SetDefaults(ctx context.Context) { - withNS := apis.WithinParent(ctx, s.ObjectMeta) - s.Spec.SetDefaults(withNS) -} - -func (ss *SubscriptionSpec) SetDefaults(ctx context.Context) { - // Default NS to Subscriber and Reply - if ss.Subscriber != nil { - ss.Subscriber.SetDefaults(ctx) - } - if ss.Reply != nil { - ss.Reply.SetDefaults(ctx) - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_defaults_test.go b/pkg/apis/messaging/v1alpha1/subscription_defaults_test.go deleted file mode 100644 index c661ceaf61e..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_defaults_test.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "context" - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -const ( - testNS = "testnamespace" -) - -// No-op test because method does nothing. -func TestSubscriptionDefaultsEmpty(t *testing.T) { - s := Subscription{} - s.SetDefaults(context.Background()) -} - -func TestDefaultSubscriber(t *testing.T) { - s := Subscription{ObjectMeta: metav1.ObjectMeta{Namespace: testNS}, - Spec: SubscriptionSpec{ - Subscriber: &duckv1.Destination{Ref: &duckv1.KReference{}}, - }, - } - s.SetDefaults(context.Background()) - if s.Spec.Subscriber.Ref.Namespace != testNS { - t.Errorf("Got: %s wanted %s", s.Spec.Subscriber.Ref.Namespace, testNS) - } -} - -func TestDefaultReply(t *testing.T) { - s := Subscription{ObjectMeta: metav1.ObjectMeta{Namespace: testNS}, - Spec: SubscriptionSpec{ - Reply: &duckv1.Destination{Ref: &duckv1.KReference{}}, - }, - } - s.SetDefaults(context.Background()) - if s.Spec.Reply.Ref.Namespace != testNS { - t.Errorf("Got: %s wanted %s", s.Spec.Reply.Ref.Namespace, testNS) - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_lifecycle.go b/pkg/apis/messaging/v1alpha1/subscription_lifecycle.go deleted file mode 100644 index 63a3ff7c2aa..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_lifecycle.go +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 v1alpha1 - -import ( - "knative.dev/pkg/apis" -) - -// subCondSet is a condition set with Ready as the happy condition and -// ReferencesResolved and ChannelReady as the dependent conditions. -var SubCondSet = apis.NewLivingConditionSet(SubscriptionConditionReferencesResolved, SubscriptionConditionAddedToChannel, SubscriptionConditionChannelReady) - -const ( - // SubscriptionConditionReady has status True when all subconditions below have been set to True. - SubscriptionConditionReady = apis.ConditionReady - // SubscriptionConditionReferencesResolved has status True when all the specified references have been successfully - // resolved. - SubscriptionConditionReferencesResolved apis.ConditionType = "ReferencesResolved" - - // SubscriptionConditionAddedToChannel has status True when controller has successfully added a - // subscription to the spec.channel resource. - SubscriptionConditionAddedToChannel apis.ConditionType = "AddedToChannel" - - // SubscriptionConditionChannelReady has status True when the channel has marked the subscriber as 'ready' - SubscriptionConditionChannelReady apis.ConditionType = "ChannelReady" -) - -// GetCondition returns the condition currently associated with the given type, or nil. -func (ss *SubscriptionStatus) GetCondition(t apis.ConditionType) *apis.Condition { - return SubCondSet.Manage(ss).GetCondition(t) -} - -// IsReady returns true if the resource is ready overall. -func (ss *SubscriptionStatus) IsReady() bool { - return SubCondSet.Manage(ss).IsHappy() -} - -// IsAddedToChannel returns true if SubscriptionConditionAddedToChannel is true -func (ss *SubscriptionStatus) IsAddedToChannel() bool { - return ss.GetCondition(SubscriptionConditionAddedToChannel).IsTrue() -} - -// AreReferencesResolved returns true if SubscriptionConditionReferencesResolved is true -func (ss *SubscriptionStatus) AreReferencesResolved() bool { - return ss.GetCondition(SubscriptionConditionReferencesResolved).IsTrue() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (ss *SubscriptionStatus) InitializeConditions() { - SubCondSet.Manage(ss).InitializeConditions() -} - -// MarkReferencesResolved sets the ReferencesResolved condition to True state. -func (ss *SubscriptionStatus) MarkReferencesResolved() { - SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionReferencesResolved) -} - -// MarkChannelReady sets the ChannelReady condition to True state. -func (ss *SubscriptionStatus) MarkChannelReady() { - SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionChannelReady) -} - -// MarkAddedToChannel sets the AddedToChannel condition to True state. -func (ss *SubscriptionStatus) MarkAddedToChannel() { - SubCondSet.Manage(ss).MarkTrue(SubscriptionConditionAddedToChannel) -} - -// MarkReferencesNotResolved sets the ReferencesResolved condition to False state. -func (ss *SubscriptionStatus) MarkReferencesNotResolved(reason, messageFormat string, messageA ...interface{}) { - SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionReferencesResolved, reason, messageFormat, messageA...) -} - -// MarkReferencesResolvedUnknown sets the ReferencesResolved condition to Unknown state. -func (ss *SubscriptionStatus) MarkReferencesResolvedUnknown(reason, messageFormat string, messageA ...interface{}) { - SubCondSet.Manage(ss).MarkUnknown(SubscriptionConditionReferencesResolved, reason, messageFormat, messageA...) -} - -// MarkChannelFailed sets the ChannelReady condition to False state. -func (ss *SubscriptionStatus) MarkChannelFailed(reason, messageFormat string, messageA ...interface{}) { - SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionChannelReady, reason, messageFormat, messageA...) -} - -// MarkChannelUnknown sets the ChannelReady condition to Unknown state. -func (ss *SubscriptionStatus) MarkChannelUnknown(reason, messageFormat string, messageA ...interface{}) { - SubCondSet.Manage(ss).MarkUnknown(SubscriptionConditionChannelReady, reason, messageFormat, messageA...) -} - -// MarkNotAddedToChannel sets the AddedToChannel condition to False state. -func (ss *SubscriptionStatus) MarkNotAddedToChannel(reason, messageFormat string, messageA ...interface{}) { - SubCondSet.Manage(ss).MarkFalse(SubscriptionConditionAddedToChannel, reason, messageFormat, messageA...) -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_lifecycle_test.go b/pkg/apis/messaging/v1alpha1/subscription_lifecycle_test.go deleted file mode 100644 index 7126e560bae..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_lifecycle_test.go +++ /dev/null @@ -1,267 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "testing" - - "knative.dev/pkg/apis" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -var subscriptionConditionReady = apis.Condition{ - Type: SubscriptionConditionReady, - Status: corev1.ConditionTrue, -} - -var subscriptionConditionReferencesResolved = apis.Condition{ - Type: SubscriptionConditionReferencesResolved, - Status: corev1.ConditionFalse, -} - -var subscriptionConditionChannelReady = apis.Condition{ - Type: SubscriptionConditionChannelReady, - Status: corev1.ConditionTrue, -} - -func TestSubscriptionGetCondition(t *testing.T) { - tests := []struct { - name string - ss *SubscriptionStatus - condQuery apis.ConditionType - want *apis.Condition - }{{ - name: "single condition", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - subscriptionConditionReady, - }, - }, - }, - condQuery: apis.ConditionReady, - want: &subscriptionConditionReady, - }, { - name: "multiple conditions", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - subscriptionConditionReady, - subscriptionConditionReferencesResolved, - }, - }, - }, - condQuery: SubscriptionConditionReferencesResolved, - want: &subscriptionConditionReferencesResolved, - }, { - name: "multiple conditions, condition true", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - subscriptionConditionReady, - subscriptionConditionChannelReady, - }, - }, - }, - condQuery: SubscriptionConditionChannelReady, - want: &subscriptionConditionChannelReady, - }, { - name: "unknown condition", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - subscriptionConditionReady, - subscriptionConditionReferencesResolved, - }, - }, - }, - condQuery: apis.ConditionType("foo"), - want: nil, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.ss.GetCondition(test.condQuery) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} - -func TestSubscriptionInitializeConditions(t *testing.T) { - tests := []struct { - name string - ss *SubscriptionStatus - want *SubscriptionStatus - }{{ - name: "empty", - ss: &SubscriptionStatus{}, - want: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: SubscriptionConditionAddedToChannel, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionChannelReady, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionReferencesResolved, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one false", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: SubscriptionConditionChannelReady, - Status: corev1.ConditionFalse, - }}, - }, - }, - want: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: SubscriptionConditionAddedToChannel, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionChannelReady, - Status: corev1.ConditionFalse, - }, { - Type: SubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionReferencesResolved, - Status: corev1.ConditionUnknown, - }}, - }, - }, - }, { - name: "one true", - ss: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: SubscriptionConditionReferencesResolved, - Status: corev1.ConditionTrue, - }}, - }, - }, - want: &SubscriptionStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{{ - Type: SubscriptionConditionAddedToChannel, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionChannelReady, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionReady, - Status: corev1.ConditionUnknown, - }, { - Type: SubscriptionConditionReferencesResolved, - Status: corev1.ConditionTrue, - }}, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - test.ss.InitializeConditions() - if diff := cmp.Diff(test.want, test.ss, ignoreAllButTypeAndStatus); diff != "" { - t.Errorf("unexpected conditions (-want, +got) = %v", diff) - } - }) - } -} - -func TestSubscriptionIsReady(t *testing.T) { - tests := []struct { - name string - markResolved bool - markChannelReady bool - wantReady bool - markAddedToChannel bool - }{{ - name: "all happy", - markResolved: true, - markChannelReady: true, - markAddedToChannel: true, - wantReady: true, - }, { - name: "one sad - markResolved", - markResolved: false, - markChannelReady: true, - markAddedToChannel: true, - wantReady: false, - }, { - name: "one sad - markChannelReady", - markResolved: true, - markChannelReady: false, - markAddedToChannel: true, - wantReady: false, - }, { - name: "one sad - markAddedToChannel", - markResolved: true, - markChannelReady: true, - markAddedToChannel: false, - wantReady: false, - }, { - name: "other sad", - markResolved: true, - markChannelReady: false, - wantReady: false, - }, { - name: "all sad", - markResolved: false, - markChannelReady: false, - markAddedToChannel: false, - wantReady: false, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ss := &SubscriptionStatus{} - if test.markResolved { - ss.MarkReferencesResolved() - if !ss.AreReferencesResolved() { - t.Errorf("References marked resolved, but not reflected in AreReferencesResolved") - } - } - if test.markChannelReady { - ss.MarkChannelReady() - } - if test.markAddedToChannel { - ss.MarkAddedToChannel() - if !ss.IsAddedToChannel() { - t.Errorf("Channel added, but not reflected in IsAddedToChannel") - } - } - got := ss.IsReady() - if test.wantReady != got { - t.Errorf("unexpected readiness: want %v, got %v", test.wantReady, got) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_types.go b/pkg/apis/messaging/v1alpha1/subscription_types.go deleted file mode 100644 index 37dad658389..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_types.go +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2018 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/kmeta" - - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:defaulter-gen=true - -// Subscription routes events received on a Channel to a DNS name and -// corresponds to the subscriptions.channels.knative.dev CRD. -type Subscription struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec SubscriptionSpec `json:"spec"` - Status SubscriptionStatus `json:"status,omitempty"` -} - -var ( - // Check that Subscription can be validated, can be defaulted, and has immutable fields. - _ apis.Validatable = (*Subscription)(nil) - _ apis.Defaultable = (*Subscription)(nil) - - // Check that Subscription can return its spec untyped. - _ apis.HasSpec = (*Subscription)(nil) - - _ runtime.Object = (*Subscription)(nil) - - // Check that we can create OwnerReferences to a Subscription. - _ kmeta.OwnerRefable = (*Subscription)(nil) -) - -// SubscriptionSpec specifies the Channel for incoming events, a Subscriber target -// for processing those events and where to put the result of the processing. Only -// From (where the events are coming from) is always required. You can optionally -// only Process the events (results in no output events) by leaving out the Result. -// You can also perform an identity transformation on the incoming events by leaving -// out the Subscriber and only specifying Result. -// -// The following are all valid specifications: -// channel --[subscriber]--> reply -// Sink, no outgoing events: -// channel -- subscriber -// no-op function (identity transformation): -// channel --> reply -type SubscriptionSpec struct { - // TODO By enabling the status subresource metadata.generation should increment - // thus making this property obsolete. - // - // We should be able to drop this property with a CRD conversion webhook - // in the future - // - // +optional - DeprecatedGeneration int64 `json:"generation,omitempty"` - - // Reference to a channel that will be used to create the subscription - // for receiving events. The channel must have spec.subscriptions - // list which will then be modified accordingly. - // - // You can specify only the following fields of the ObjectReference: - // - Kind - // - APIVersion - // - Name - // The resource pointed by this ObjectReference must meet the Subscribable contract - // with a pointer to the Subscribable duck type. If the resource does not meet this contract, - // it will be reflected in the Subscription's status. - - // This field is immutable. We have no good answer on what happens to - // the events that are currently in the channel being consumed from - // and what the semantics there should be. For now, you can always - // delete the Subscription and recreate it to point to a different - // channel, giving the user more control over what semantics should - // be used (drain the channel first, possibly have events dropped, - // etc.) - Channel corev1.ObjectReference `json:"channel"` - - // Subscriber is reference to (optional) function for processing events. - // Events from the Channel will be delivered here and replies are - // sent to a Destination as specified by the Reply. - // +optional - Subscriber *duckv1.Destination `json:"subscriber,omitempty"` - - // Reply specifies (optionally) how to handle events returned from - // the Subscriber target. - // +optional - Reply *duckv1.Destination `json:"reply,omitempty"` - - // Delivery configuration - // +optional - Delivery *eventingduckv1beta1.DeliverySpec `json:"delivery,omitempty"` -} - -// SubscriptionStatus (computed) for a subscription -type SubscriptionStatus struct { - // inherits duck/v1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1.Status `json:",inline"` - - // PhysicalSubscription is the fully resolved values that this Subscription represents. - PhysicalSubscription SubscriptionStatusPhysicalSubscription `json:"physicalSubscription,omitempty"` -} - -// SubscriptionStatusPhysicalSubscription represents the fully resolved values for this -// Subscription. -type SubscriptionStatusPhysicalSubscription struct { - // SubscriberURI is the fully resolved URI for spec.subscriber. - SubscriberURI *apis.URL `json:"subscriberURI,omitempty"` - - // ReplyURI is the fully resolved URI for the spec.reply. - ReplyURI *apis.URL `json:"replyURI,omitempty"` - - // ReplyURI is the fully resolved URI for the spec.delivery.deadLetterSink. - DeadLetterSinkURI *apis.URL `json:"deadLetterSinkURI,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// SubscriptionList returned in list operations -type SubscriptionList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []Subscription `json:"items"` -} - -// GetGroupVersionKind returns GroupVersionKind for Subscriptions -func (t *Subscription) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("Subscription") -} - -// GetUntypedSpec returns the spec of the Subscription. -func (s *Subscription) GetUntypedSpec() interface{} { - return s.Spec -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_types_test.go b/pkg/apis/messaging/v1alpha1/subscription_types_test.go deleted file mode 100644 index 6baef0e17a4..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_types_test.go +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 v1alpha1 - -import "testing" - -func TestSubscription_GetGroupVersionKind(t *testing.T) { - c := Subscription{} - gvk := c.GetGroupVersionKind() - if gvk.Kind != "Subscription" { - t.Errorf("Should be Subscription.") - } -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_validation.go b/pkg/apis/messaging/v1alpha1/subscription_validation.go deleted file mode 100644 index 1040ceffe93..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_validation.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2018 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 v1alpha1 - -import ( - "context" - - "github.com/google/go-cmp/cmp/cmpopts" - "k8s.io/apimachinery/pkg/api/equality" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/kmp" -) - -func (s *Subscription) Validate(ctx context.Context) *apis.FieldError { - return s.Spec.Validate(ctx).ViaField("spec") -} - -func (ss *SubscriptionSpec) Validate(ctx context.Context) *apis.FieldError { - // We require always Channel. - // Also at least one of 'subscriber' and 'reply' must be defined (non-nil and non-empty). - - var errs *apis.FieldError - if isChannelEmpty(ss.Channel) { - fe := apis.ErrMissingField("channel") - fe.Details = "the Subscription must reference a channel" - return fe - } else if fe := isValidChannel(ss.Channel); fe != nil { - errs = errs.Also(fe.ViaField("channel")) - } - - missingSubscriber := isDestinationNilOrEmpty(ss.Subscriber) - missingReply := isDestinationNilOrEmpty(ss.Reply) - if missingSubscriber && missingReply { - fe := apis.ErrMissingField("reply", "subscriber") - fe.Details = "the Subscription must reference at least one of (reply or a subscriber)" - errs = errs.Also(fe) - } - - if !missingSubscriber { - if fe := ss.Subscriber.Validate(ctx); fe != nil { - errs = errs.Also(fe.ViaField("subscriber")) - } - } - - if !missingReply { - if fe := ss.Reply.Validate(ctx); fe != nil { - errs = errs.Also(fe.ViaField("reply")) - } - } - - return errs -} - -func isDestinationNilOrEmpty(d *duckv1.Destination) bool { - return d == nil || equality.Semantic.DeepEqual(d, &duckv1.Destination{}) -} - -func (s *Subscription) CheckImmutableFields(ctx context.Context, original *Subscription) *apis.FieldError { - if original == nil { - return nil - } - - // Only Subscriber and Reply are mutable. - ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Reply") - if diff, err := kmp.ShortDiff(original.Spec, s.Spec, ignoreArguments); err != nil { - return &apis.FieldError{ - Message: "Failed to diff Subscription", - Paths: []string{"spec"}, - Details: err.Error(), - } - } else if diff != "" { - return &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - } - } - return nil -} diff --git a/pkg/apis/messaging/v1alpha1/subscription_validation_test.go b/pkg/apis/messaging/v1alpha1/subscription_validation_test.go deleted file mode 100644 index 7725b599f23..00000000000 --- a/pkg/apis/messaging/v1alpha1/subscription_validation_test.go +++ /dev/null @@ -1,442 +0,0 @@ -/* -Copyright 2018 The Knative Authors. All Rights Reserved. -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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -const ( - channelKind = "MyChannel" - channelAPIVersion = "eventing.knative.dev/v1alpha1" - routeKind = "Route" - routeAPIVersion = "serving.knative.dev/v1alpha1" - channelName = "subscribedChannel" - replyChannelName = "toChannel" - subscriberName = "subscriber" - namespace = "namespace" -) - -func getValidChannelRef() corev1.ObjectReference { - return corev1.ObjectReference{ - // Namespace: namespace, - Name: channelName, - Kind: channelKind, - APIVersion: channelAPIVersion, - } -} - -func getValidReply() *duckv1.Destination { - return &duckv1.Destination{ - Ref: &duckv1.KReference{ - Namespace: namespace, - Name: replyChannelName, - Kind: channelKind, - APIVersion: channelAPIVersion, - }, - } -} - -func getValidDestination() *duckv1.Destination { - return &duckv1.Destination{ - Ref: &duckv1.KReference{ - Namespace: namespace, - Name: subscriberName, - Kind: routeKind, - APIVersion: routeAPIVersion, - }, - } -} - -func TestSubscriptionValidation(t *testing.T) { - name := "empty channel" - c := &Subscription{ - Spec: SubscriptionSpec{ - Channel: corev1.ObjectReference{}, - }, - } - want := &apis.FieldError{ - Paths: []string{"spec.channel"}, - Message: "missing field(s)", - Details: "the Subscription must reference a channel", - } - - t.Run(name, func(t *testing.T) { - got := c.Validate(context.TODO()) - if diff := cmp.Diff(want.Error(), got.Error()); diff != "" { - t.Errorf("Subscription.Validate (-want, +got) = %v", diff) - } - }) - -} - -func TestSubscriptionSpecValidation(t *testing.T) { - tests := []struct { - name string - c *SubscriptionSpec - want *apis.FieldError - }{{ - name: "valid", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - want: nil, - }, { - name: "valid with reply", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - Reply: getValidReply(), - }, - want: nil, - }, { - name: "empty Channel", - c: &SubscriptionSpec{ - Channel: corev1.ObjectReference{}, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("channel") - fe.Details = "the Subscription must reference a channel" - return fe - }(), - }, { - name: "missing name in Channel", - c: &SubscriptionSpec{ - Channel: corev1.ObjectReference{ - Kind: channelKind, - APIVersion: channelAPIVersion, - }, - Subscriber: getValidDestination(), - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("channel.name") - return fe - }(), - }, { - name: "missing Subscriber and Reply", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("reply", "subscriber") - fe.Details = "the Subscription must reference at least one of (reply or a subscriber)" - return fe - }(), - }, { - name: "empty Subscriber and Reply", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: &duckv1.Destination{}, - Reply: &duckv1.Destination{}, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("reply", "subscriber") - fe.Details = "the Subscription must reference at least one of (reply or a subscriber)" - return fe - }(), - }, { - name: "missing Reply", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - want: nil, - }, { - name: "empty Reply", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - Reply: &duckv1.Destination{}, - }, - want: nil, - }, { - name: "missing Subscriber", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Reply: getValidReply(), - }, - want: nil, - }, { - name: "empty Subscriber", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: &duckv1.Destination{}, - Reply: getValidReply(), - }, - want: nil, - }, { - name: "missing name in channel, and missing subscriber, reply", - c: &SubscriptionSpec{ - Channel: corev1.ObjectReference{ - Kind: channelKind, - APIVersion: channelAPIVersion, - }, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("reply", "subscriber") - fe.Details = "the Subscription must reference at least one of (reply or a subscriber)" - return apis.ErrMissingField("channel.name").Also(fe) - }(), - }, { - name: "empty", - c: &SubscriptionSpec{}, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("channel") - fe.Details = "the Subscription must reference a channel" - return fe - }(), - }, { - name: "missing name in Subscriber.Ref", - c: &SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: &duckv1.Destination{ - Ref: &duckv1.KReference{ - Namespace: namespace, - Kind: channelKind, - APIVersion: channelAPIVersion, - }, - }, - }, - want: apis.ErrMissingField("subscriber.ref.name"), - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.c.Validate(context.TODO()) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("%s: validateChannel (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestSubscriptionImmutable(t *testing.T) { - newChannel := getValidChannelRef() - newChannel.Name = "newChannel" - - newSubscriber := getValidDestination() - newSubscriber.Ref.Name = "newSubscriber" - - newReply := getValidReply() - newReply.Ref.Name = "newReplyChannel" - - tests := []struct { - name string - c *Subscription - og *Subscription - want *apis.FieldError - }{{ - name: "valid", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - }, - }, - want: nil, - }, { - name: "new nil is ok", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - }, - og: nil, - want: nil, - }, { - name: "valid, new Subscriber", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: newSubscriber, - }, - }, - want: nil, - }, { - name: "valid, new Reply", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Reply: getValidReply(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Reply: newReply, - }, - }, - want: nil, - }, { - name: "valid, have Reply, remove and replace with Subscriber", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Reply: getValidReply(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - }, - want: nil, - }, { - name: "valid, have Subscriber, remove and replace with Reply", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Subscriber: getValidDestination(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - Reply: getValidReply(), - }, - }, - want: nil, - }, { - name: "Channel changed", - c: &Subscription{ - Spec: SubscriptionSpec{ - Channel: getValidChannelRef(), - }, - }, - og: &Subscription{ - Spec: SubscriptionSpec{ - Channel: newChannel, - }, - }, - want: &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: `{v1alpha1.SubscriptionSpec}.Channel.Name: - -: "newChannel" - +: "subscribedChannel" -`, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.c.CheckImmutableFields(context.TODO(), test.og) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("CheckImmutableFields (-want, +got) = %v", diff) - } - }) - } -} - -func TestValidChannel(t *testing.T) { - tests := []struct { - name string - c corev1.ObjectReference - want *apis.FieldError - }{{ - name: "valid", - c: corev1.ObjectReference{ - Name: channelName, - APIVersion: channelAPIVersion, - Kind: channelKind, - }, - want: nil, - }, { - name: "missing name", - c: corev1.ObjectReference{ - APIVersion: channelAPIVersion, - Kind: channelKind, - }, - want: func() *apis.FieldError { - fe := apis.ErrMissingField("name") - return fe - }(), - }, { - name: "missing apiVersion", - c: corev1.ObjectReference{ - Name: channelName, - Kind: channelKind, - }, - want: func() *apis.FieldError { - return apis.ErrMissingField("apiVersion") - }(), - }, { - name: "extra field, namespace", - c: corev1.ObjectReference{ - Name: channelName, - APIVersion: channelAPIVersion, - Kind: channelKind, - Namespace: "secretnamespace", - }, - want: func() *apis.FieldError { - fe := apis.ErrDisallowedFields("Namespace") - fe.Details = "only name, apiVersion and kind are supported fields" - return fe - }(), - }, { - name: "extra field, namespace and resourceVersion", - c: corev1.ObjectReference{ - Name: channelName, - APIVersion: channelAPIVersion, - Kind: channelKind, - Namespace: "secretnamespace", - ResourceVersion: "myresourceversion", - }, - want: func() *apis.FieldError { - fe := apis.ErrDisallowedFields("Namespace", "ResourceVersion") - fe.Details = "only name, apiVersion and kind are supported fields" - return fe - }(), - }, { - // Make sure that if an empty field for namespace is given, it's treated as not there. - name: "valid extra field, namespace empty", - c: corev1.ObjectReference{ - Name: channelName, - APIVersion: channelAPIVersion, - Kind: channelKind, - Namespace: "", - }, - want: nil, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := isValidChannel(test.c) - if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" { - t.Errorf("isValidChannel (-want, +got) = %v", diff) - } - }) - } -} diff --git a/pkg/apis/messaging/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/messaging/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index d3b16cd1689..00000000000 --- a/pkg/apis/messaging/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,395 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 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. -*/ - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1 "k8s.io/api/core/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - v1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - apis "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Channel) DeepCopyInto(out *Channel) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Channel. -func (in *Channel) DeepCopy() *Channel { - if in == nil { - return nil - } - out := new(Channel) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Channel) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelList) DeepCopyInto(out *ChannelList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Channel, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelList. -func (in *ChannelList) DeepCopy() *ChannelList { - if in == nil { - return nil - } - out := new(ChannelList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ChannelList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelSpec) DeepCopyInto(out *ChannelSpec) { - *out = *in - if in.ChannelTemplate != nil { - in, out := &in.ChannelTemplate, &out.ChannelTemplate - *out = new(v1beta1.ChannelTemplateSpec) - (*in).DeepCopyInto(*out) - } - if in.Subscribable != nil { - in, out := &in.Subscribable, &out.Subscribable - *out = new(duckv1alpha1.Subscribable) - (*in).DeepCopyInto(*out) - } - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(duckv1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelSpec. -func (in *ChannelSpec) DeepCopy() *ChannelSpec { - if in == nil { - return nil - } - out := new(ChannelSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ChannelStatus) DeepCopyInto(out *ChannelStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.AddressStatus.DeepCopyInto(&out.AddressStatus) - in.SubscribableTypeStatus.DeepCopyInto(&out.SubscribableTypeStatus) - if in.Channel != nil { - in, out := &in.Channel, &out.Channel - *out = new(v1.ObjectReference) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChannelStatus. -func (in *ChannelStatus) DeepCopy() *ChannelStatus { - if in == nil { - return nil - } - out := new(ChannelStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *InMemoryChannel) DeepCopyInto(out *InMemoryChannel) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InMemoryChannel. -func (in *InMemoryChannel) DeepCopy() *InMemoryChannel { - if in == nil { - return nil - } - out := new(InMemoryChannel) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *InMemoryChannel) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *InMemoryChannelList) DeepCopyInto(out *InMemoryChannelList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]InMemoryChannel, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InMemoryChannelList. -func (in *InMemoryChannelList) DeepCopy() *InMemoryChannelList { - if in == nil { - return nil - } - out := new(InMemoryChannelList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *InMemoryChannelList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *InMemoryChannelSpec) DeepCopyInto(out *InMemoryChannelSpec) { - *out = *in - if in.Subscribable != nil { - in, out := &in.Subscribable, &out.Subscribable - *out = new(duckv1alpha1.Subscribable) - (*in).DeepCopyInto(*out) - } - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(duckv1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InMemoryChannelSpec. -func (in *InMemoryChannelSpec) DeepCopy() *InMemoryChannelSpec { - if in == nil { - return nil - } - out := new(InMemoryChannelSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *InMemoryChannelStatus) DeepCopyInto(out *InMemoryChannelStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.AddressStatus.DeepCopyInto(&out.AddressStatus) - in.SubscribableTypeStatus.DeepCopyInto(&out.SubscribableTypeStatus) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InMemoryChannelStatus. -func (in *InMemoryChannelStatus) DeepCopy() *InMemoryChannelStatus { - if in == nil { - return nil - } - out := new(InMemoryChannelStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Subscription) DeepCopyInto(out *Subscription) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Subscription. -func (in *Subscription) DeepCopy() *Subscription { - if in == nil { - return nil - } - out := new(Subscription) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Subscription) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionList) DeepCopyInto(out *SubscriptionList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Subscription, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionList. -func (in *SubscriptionList) DeepCopy() *SubscriptionList { - if in == nil { - return nil - } - out := new(SubscriptionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SubscriptionList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionSpec) DeepCopyInto(out *SubscriptionSpec) { - *out = *in - out.Channel = in.Channel - if in.Subscriber != nil { - in, out := &in.Subscriber, &out.Subscriber - *out = new(duckv1.Destination) - (*in).DeepCopyInto(*out) - } - if in.Reply != nil { - in, out := &in.Reply, &out.Reply - *out = new(duckv1.Destination) - (*in).DeepCopyInto(*out) - } - if in.Delivery != nil { - in, out := &in.Delivery, &out.Delivery - *out = new(duckv1beta1.DeliverySpec) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionSpec. -func (in *SubscriptionSpec) DeepCopy() *SubscriptionSpec { - if in == nil { - return nil - } - out := new(SubscriptionSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionStatus) DeepCopyInto(out *SubscriptionStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - in.PhysicalSubscription.DeepCopyInto(&out.PhysicalSubscription) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatus. -func (in *SubscriptionStatus) DeepCopy() *SubscriptionStatus { - if in == nil { - return nil - } - out := new(SubscriptionStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SubscriptionStatusPhysicalSubscription) DeepCopyInto(out *SubscriptionStatusPhysicalSubscription) { - *out = *in - if in.SubscriberURI != nil { - in, out := &in.SubscriberURI, &out.SubscriberURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.ReplyURI != nil { - in, out := &in.ReplyURI, &out.ReplyURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.DeadLetterSinkURI != nil { - in, out := &in.DeadLetterSinkURI, &out.DeadLetterSinkURI - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubscriptionStatusPhysicalSubscription. -func (in *SubscriptionStatusPhysicalSubscription) DeepCopy() *SubscriptionStatusPhysicalSubscription { - if in == nil { - return nil - } - out := new(SubscriptionStatusPhysicalSubscription) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/apis/messaging/v1beta1/channel_defaults.go b/pkg/apis/messaging/v1beta1/channel_defaults.go index b1f94f48bdd..83ac2336661 100644 --- a/pkg/apis/messaging/v1beta1/channel_defaults.go +++ b/pkg/apis/messaging/v1beta1/channel_defaults.go @@ -19,11 +19,19 @@ package v1beta1 import ( "context" + "knative.dev/eventing/pkg/apis/messaging" "knative.dev/eventing/pkg/apis/messaging/config" "knative.dev/pkg/apis" ) func (c *Channel) SetDefaults(ctx context.Context) { + if c.Annotations == nil { + c.Annotations = make(map[string]string) + } + if _, ok := c.Annotations[messaging.SubscribableDuckVersionAnnotation]; !ok { + c.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1beta1" + } + c.Spec.SetDefaults(apis.WithinParent(ctx, c.ObjectMeta)) } diff --git a/pkg/apis/messaging/v1beta1/channel_defaults_test.go b/pkg/apis/messaging/v1beta1/channel_defaults_test.go index e012bf6662e..a32b252c76f 100644 --- a/pkg/apis/messaging/v1beta1/channel_defaults_test.go +++ b/pkg/apis/messaging/v1beta1/channel_defaults_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/eventing/pkg/apis/messaging/config" @@ -50,14 +51,15 @@ func TestChannelSetDefaults(t *testing.T) { }{ "nil ChannelDefaulter": { nilChannelDefaulter: true, - expected: Channel{}, + expected: Channel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}}, }, "unset ChannelDefaulter": { - expected: Channel{}, + expected: Channel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}}, }, "set ChannelDefaulter": { channelTemplate: defaultChannelTemplate, expected: Channel{ + ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}, Spec: ChannelSpec{ ChannelTemplate: ourDefaultChannelTemplate, }, @@ -76,6 +78,7 @@ func TestChannelSetDefaults(t *testing.T) { }, }, expected: Channel{ + ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}, Spec: ChannelSpec{ ChannelTemplate: &ChannelTemplateSpec{ TypeMeta: v1.TypeMeta{ diff --git a/pkg/apis/messaging/v1beta1/in_memory_channel_defaults_test.go b/pkg/apis/messaging/v1beta1/in_memory_channel_defaults_test.go new file mode 100644 index 00000000000..33953f5a3f6 --- /dev/null +++ b/pkg/apis/messaging/v1beta1/in_memory_channel_defaults_test.go @@ -0,0 +1,56 @@ +/* +Copyright 2020 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 v1beta1 + +import ( + "context" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/pkg/apis/messaging/config" + + "github.com/google/go-cmp/cmp" +) + +func TestInMemoryChannelSetDefaults(t *testing.T) { + testCases := map[string]struct { + channelTemplate *config.ChannelTemplateSpec + initial InMemoryChannel + expected InMemoryChannel + }{ + "nil gets annotations": { + initial: InMemoryChannel{}, + expected: InMemoryChannel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}}, + }, + "empty gets annotations": { + initial: InMemoryChannel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, + expected: InMemoryChannel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1"}}}, + }, + "non-empty gets added ChannelDefaulter": { + initial: InMemoryChannel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"somethingelse": "yup"}}}, + expected: InMemoryChannel{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"messaging.knative.dev/subscribable": "v1beta1", "somethingelse": "yup"}}}, + }, + } + for n, tc := range testCases { + t.Run(n, func(t *testing.T) { + tc.initial.SetDefaults(context.Background()) + if diff := cmp.Diff(tc.expected, tc.initial); diff != "" { + t.Fatalf("Unexpected defaults (-want, +got): %s", diff) + } + }) + } +} diff --git a/pkg/apis/messaging/v1beta1/subscribable_channelable_validation_test.go b/pkg/apis/messaging/v1beta1/subscribable_channelable_validation_test.go index c306217e21a..bbcc156646e 100644 --- a/pkg/apis/messaging/v1beta1/subscribable_channelable_validation_test.go +++ b/pkg/apis/messaging/v1beta1/subscribable_channelable_validation_test.go @@ -54,7 +54,7 @@ func TestIsChannelEmpty(t *testing.T) { t.Run(name, func(t *testing.T) { r := corev1.ObjectReference{ Name: "boaty-mcboatface", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Channel", } if isChannelEmpty(r) { @@ -104,7 +104,7 @@ func TestIsValidObjectReference(t *testing.T) { name: "missing name", ref: corev1.ObjectReference{ Name: "", - APIVersion: "eventing.knative.dev/v1alpha1", + APIVersion: "eventing.knative.dev/v1beta1", Kind: "Strait", }, want: []*apis.FieldError{ @@ -128,7 +128,7 @@ func TestIsValidObjectReference(t *testing.T) { name: "missing none", ref: corev1.ObjectReference{ Name: "kind", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", Kind: "Channel", }, want: []*apis.FieldError{}, diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index c9ece7db1aa..7b5f994fcd5 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -27,7 +27,6 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/configs/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2" @@ -38,7 +37,6 @@ type Interface interface { ConfigsV1alpha1() configsv1alpha1.ConfigsV1alpha1Interface EventingV1beta1() eventingv1beta1.EventingV1beta1Interface FlowsV1beta1() flowsv1beta1.FlowsV1beta1Interface - MessagingV1alpha1() messagingv1alpha1.MessagingV1alpha1Interface MessagingV1beta1() messagingv1beta1.MessagingV1beta1Interface SourcesV1alpha1() sourcesv1alpha1.SourcesV1alpha1Interface SourcesV1alpha2() sourcesv1alpha2.SourcesV1alpha2Interface @@ -48,13 +46,12 @@ type Interface interface { // version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient - configsV1alpha1 *configsv1alpha1.ConfigsV1alpha1Client - eventingV1beta1 *eventingv1beta1.EventingV1beta1Client - flowsV1beta1 *flowsv1beta1.FlowsV1beta1Client - messagingV1alpha1 *messagingv1alpha1.MessagingV1alpha1Client - messagingV1beta1 *messagingv1beta1.MessagingV1beta1Client - sourcesV1alpha1 *sourcesv1alpha1.SourcesV1alpha1Client - sourcesV1alpha2 *sourcesv1alpha2.SourcesV1alpha2Client + configsV1alpha1 *configsv1alpha1.ConfigsV1alpha1Client + eventingV1beta1 *eventingv1beta1.EventingV1beta1Client + flowsV1beta1 *flowsv1beta1.FlowsV1beta1Client + messagingV1beta1 *messagingv1beta1.MessagingV1beta1Client + sourcesV1alpha1 *sourcesv1alpha1.SourcesV1alpha1Client + sourcesV1alpha2 *sourcesv1alpha2.SourcesV1alpha2Client } // ConfigsV1alpha1 retrieves the ConfigsV1alpha1Client @@ -72,11 +69,6 @@ func (c *Clientset) FlowsV1beta1() flowsv1beta1.FlowsV1beta1Interface { return c.flowsV1beta1 } -// MessagingV1alpha1 retrieves the MessagingV1alpha1Client -func (c *Clientset) MessagingV1alpha1() messagingv1alpha1.MessagingV1alpha1Interface { - return c.messagingV1alpha1 -} - // MessagingV1beta1 retrieves the MessagingV1beta1Client func (c *Clientset) MessagingV1beta1() messagingv1beta1.MessagingV1beta1Interface { return c.messagingV1beta1 @@ -125,10 +117,6 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } - cs.messagingV1alpha1, err = messagingv1alpha1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } cs.messagingV1beta1, err = messagingv1beta1.NewForConfig(&configShallowCopy) if err != nil { return nil, err @@ -156,7 +144,6 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { cs.configsV1alpha1 = configsv1alpha1.NewForConfigOrDie(c) cs.eventingV1beta1 = eventingv1beta1.NewForConfigOrDie(c) cs.flowsV1beta1 = flowsv1beta1.NewForConfigOrDie(c) - cs.messagingV1alpha1 = messagingv1alpha1.NewForConfigOrDie(c) cs.messagingV1beta1 = messagingv1beta1.NewForConfigOrDie(c) cs.sourcesV1alpha1 = sourcesv1alpha1.NewForConfigOrDie(c) cs.sourcesV1alpha2 = sourcesv1alpha2.NewForConfigOrDie(c) @@ -171,7 +158,6 @@ func New(c rest.Interface) *Clientset { cs.configsV1alpha1 = configsv1alpha1.New(c) cs.eventingV1beta1 = eventingv1beta1.New(c) cs.flowsV1beta1 = flowsv1beta1.New(c) - cs.messagingV1alpha1 = messagingv1alpha1.New(c) cs.messagingV1beta1 = messagingv1beta1.New(c) cs.sourcesV1alpha1 = sourcesv1alpha1.New(c) cs.sourcesV1alpha2 = sourcesv1alpha2.New(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index d5e222b3943..5f55ecc9095 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -31,8 +31,6 @@ import ( fakeeventingv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1beta1/fake" flowsv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/flows/v1beta1" fakeflowsv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/flows/v1beta1/fake" - messagingv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" - fakemessagingv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake" messagingv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1beta1" fakemessagingv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1beta1/fake" sourcesv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha1" @@ -103,11 +101,6 @@ func (c *Clientset) FlowsV1beta1() flowsv1beta1.FlowsV1beta1Interface { return &fakeflowsv1beta1.FakeFlowsV1beta1{Fake: &c.Fake} } -// MessagingV1alpha1 retrieves the MessagingV1alpha1Client -func (c *Clientset) MessagingV1alpha1() messagingv1alpha1.MessagingV1alpha1Interface { - return &fakemessagingv1alpha1.FakeMessagingV1alpha1{Fake: &c.Fake} -} - // MessagingV1beta1 retrieves the MessagingV1beta1Client func (c *Clientset) MessagingV1beta1() messagingv1beta1.MessagingV1beta1Interface { return &fakemessagingv1beta1.FakeMessagingV1beta1{Fake: &c.Fake} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 6355408ee30..6b46a004e41 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -27,7 +27,6 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" @@ -40,7 +39,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ configsv1alpha1.AddToScheme, eventingv1beta1.AddToScheme, flowsv1beta1.AddToScheme, - messagingv1alpha1.AddToScheme, messagingv1beta1.AddToScheme, sourcesv1alpha1.AddToScheme, sourcesv1alpha2.AddToScheme, diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index fcc072c37b4..76c104bc5bc 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -27,7 +27,6 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" @@ -40,7 +39,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ configsv1alpha1.AddToScheme, eventingv1beta1.AddToScheme, flowsv1beta1.AddToScheme, - messagingv1alpha1.AddToScheme, messagingv1beta1.AddToScheme, sourcesv1alpha1.AddToScheme, sourcesv1alpha2.AddToScheme, diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/channel.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/channel.go deleted file mode 100644 index 257e742a071..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/channel.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - scheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" -) - -// ChannelsGetter has a method to return a ChannelInterface. -// A group's client should implement this interface. -type ChannelsGetter interface { - Channels(namespace string) ChannelInterface -} - -// ChannelInterface has methods to work with Channel resources. -type ChannelInterface interface { - Create(*v1alpha1.Channel) (*v1alpha1.Channel, error) - Update(*v1alpha1.Channel) (*v1alpha1.Channel, error) - UpdateStatus(*v1alpha1.Channel) (*v1alpha1.Channel, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.Channel, error) - List(opts v1.ListOptions) (*v1alpha1.ChannelList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) - ChannelExpansion -} - -// channels implements ChannelInterface -type channels struct { - client rest.Interface - ns string -} - -// newChannels returns a Channels -func newChannels(c *MessagingV1alpha1Client, namespace string) *channels { - return &channels{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. -func (c *channels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { - result = &v1alpha1.Channel{} - err = c.client.Get(). - Namespace(c.ns). - Resource("channels"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Channels that match those selectors. -func (c *channels) List(opts v1.ListOptions) (result *v1alpha1.ChannelList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.ChannelList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("channels"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested channels. -func (c *channels) Watch(opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("channels"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch() -} - -// Create takes the representation of a channel and creates it. Returns the server's representation of the channel, and an error, if there is any. -func (c *channels) Create(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { - result = &v1alpha1.Channel{} - err = c.client.Post(). - Namespace(c.ns). - Resource("channels"). - Body(channel). - Do(). - Into(result) - return -} - -// Update takes the representation of a channel and updates it. Returns the server's representation of the channel, and an error, if there is any. -func (c *channels) Update(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { - result = &v1alpha1.Channel{} - err = c.client.Put(). - Namespace(c.ns). - Resource("channels"). - Name(channel.Name). - Body(channel). - Do(). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - -func (c *channels) UpdateStatus(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { - result = &v1alpha1.Channel{} - err = c.client.Put(). - Namespace(c.ns). - Resource("channels"). - Name(channel.Name). - SubResource("status"). - Body(channel). - Do(). - Into(result) - return -} - -// Delete takes name of the channel and deletes it. Returns an error if one occurs. -func (c *channels) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("channels"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *channels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - var timeout time.Duration - if listOptions.TimeoutSeconds != nil { - timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("channels"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Timeout(timeout). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched channel. -func (c *channels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) { - result = &v1alpha1.Channel{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("channels"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/doc.go deleted file mode 100644 index 41e872fe9a9..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/doc.go deleted file mode 100644 index c7f6e65cab8..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_channel.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_channel.go deleted file mode 100644 index 87a431aaf7f..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_channel.go +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// FakeChannels implements ChannelInterface -type FakeChannels struct { - Fake *FakeMessagingV1alpha1 - ns string -} - -var channelsResource = schema.GroupVersionResource{Group: "messaging.knative.dev", Version: "v1alpha1", Resource: "channels"} - -var channelsKind = schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1alpha1", Kind: "Channel"} - -// Get takes name of the channel, and returns the corresponding channel object, and an error if there is any. -func (c *FakeChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.Channel, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(channelsResource, c.ns, name), &v1alpha1.Channel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Channel), err -} - -// List takes label and field selectors, and returns the list of Channels that match those selectors. -func (c *FakeChannels) List(opts v1.ListOptions) (result *v1alpha1.ChannelList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(channelsResource, channelsKind, c.ns, opts), &v1alpha1.ChannelList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.ChannelList{ListMeta: obj.(*v1alpha1.ChannelList).ListMeta} - for _, item := range obj.(*v1alpha1.ChannelList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested channels. -func (c *FakeChannels) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(channelsResource, c.ns, opts)) - -} - -// Create takes the representation of a channel and creates it. Returns the server's representation of the channel, and an error, if there is any. -func (c *FakeChannels) Create(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(channelsResource, c.ns, channel), &v1alpha1.Channel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Channel), err -} - -// Update takes the representation of a channel and updates it. Returns the server's representation of the channel, and an error, if there is any. -func (c *FakeChannels) Update(channel *v1alpha1.Channel) (result *v1alpha1.Channel, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(channelsResource, c.ns, channel), &v1alpha1.Channel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Channel), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeChannels) UpdateStatus(channel *v1alpha1.Channel) (*v1alpha1.Channel, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(channelsResource, "status", c.ns, channel), &v1alpha1.Channel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Channel), err -} - -// Delete takes name of the channel and deletes it. Returns an error if one occurs. -func (c *FakeChannels) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(channelsResource, c.ns, name), &v1alpha1.Channel{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeChannels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(channelsResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.ChannelList{}) - return err -} - -// Patch applies the patch and returns the patched channel. -func (c *FakeChannels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Channel, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(channelsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Channel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Channel), err -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_inmemorychannel.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_inmemorychannel.go deleted file mode 100644 index a765a7e6ff9..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_inmemorychannel.go +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// FakeInMemoryChannels implements InMemoryChannelInterface -type FakeInMemoryChannels struct { - Fake *FakeMessagingV1alpha1 - ns string -} - -var inmemorychannelsResource = schema.GroupVersionResource{Group: "messaging.knative.dev", Version: "v1alpha1", Resource: "inmemorychannels"} - -var inmemorychannelsKind = schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1alpha1", Kind: "InMemoryChannel"} - -// Get takes name of the inMemoryChannel, and returns the corresponding inMemoryChannel object, and an error if there is any. -func (c *FakeInMemoryChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.InMemoryChannel, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(inmemorychannelsResource, c.ns, name), &v1alpha1.InMemoryChannel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.InMemoryChannel), err -} - -// List takes label and field selectors, and returns the list of InMemoryChannels that match those selectors. -func (c *FakeInMemoryChannels) List(opts v1.ListOptions) (result *v1alpha1.InMemoryChannelList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(inmemorychannelsResource, inmemorychannelsKind, c.ns, opts), &v1alpha1.InMemoryChannelList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.InMemoryChannelList{ListMeta: obj.(*v1alpha1.InMemoryChannelList).ListMeta} - for _, item := range obj.(*v1alpha1.InMemoryChannelList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested inMemoryChannels. -func (c *FakeInMemoryChannels) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(inmemorychannelsResource, c.ns, opts)) - -} - -// Create takes the representation of a inMemoryChannel and creates it. Returns the server's representation of the inMemoryChannel, and an error, if there is any. -func (c *FakeInMemoryChannels) Create(inMemoryChannel *v1alpha1.InMemoryChannel) (result *v1alpha1.InMemoryChannel, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(inmemorychannelsResource, c.ns, inMemoryChannel), &v1alpha1.InMemoryChannel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.InMemoryChannel), err -} - -// Update takes the representation of a inMemoryChannel and updates it. Returns the server's representation of the inMemoryChannel, and an error, if there is any. -func (c *FakeInMemoryChannels) Update(inMemoryChannel *v1alpha1.InMemoryChannel) (result *v1alpha1.InMemoryChannel, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(inmemorychannelsResource, c.ns, inMemoryChannel), &v1alpha1.InMemoryChannel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.InMemoryChannel), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeInMemoryChannels) UpdateStatus(inMemoryChannel *v1alpha1.InMemoryChannel) (*v1alpha1.InMemoryChannel, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(inmemorychannelsResource, "status", c.ns, inMemoryChannel), &v1alpha1.InMemoryChannel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.InMemoryChannel), err -} - -// Delete takes name of the inMemoryChannel and deletes it. Returns an error if one occurs. -func (c *FakeInMemoryChannels) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(inmemorychannelsResource, c.ns, name), &v1alpha1.InMemoryChannel{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeInMemoryChannels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(inmemorychannelsResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.InMemoryChannelList{}) - return err -} - -// Patch applies the patch and returns the patched inMemoryChannel. -func (c *FakeInMemoryChannels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.InMemoryChannel, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(inmemorychannelsResource, c.ns, name, pt, data, subresources...), &v1alpha1.InMemoryChannel{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.InMemoryChannel), err -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_messaging_client.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_messaging_client.go deleted file mode 100644 index 57eb9208df7..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_messaging_client.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" -) - -type FakeMessagingV1alpha1 struct { - *testing.Fake -} - -func (c *FakeMessagingV1alpha1) Channels(namespace string) v1alpha1.ChannelInterface { - return &FakeChannels{c, namespace} -} - -func (c *FakeMessagingV1alpha1) InMemoryChannels(namespace string) v1alpha1.InMemoryChannelInterface { - return &FakeInMemoryChannels{c, namespace} -} - -func (c *FakeMessagingV1alpha1) Subscriptions(namespace string) v1alpha1.SubscriptionInterface { - return &FakeSubscriptions{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeMessagingV1alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_subscription.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_subscription.go deleted file mode 100644 index dcac6110bf1..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/fake/fake_subscription.go +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// FakeSubscriptions implements SubscriptionInterface -type FakeSubscriptions struct { - Fake *FakeMessagingV1alpha1 - ns string -} - -var subscriptionsResource = schema.GroupVersionResource{Group: "messaging.knative.dev", Version: "v1alpha1", Resource: "subscriptions"} - -var subscriptionsKind = schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1alpha1", Kind: "Subscription"} - -// Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. -func (c *FakeSubscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(subscriptionsResource, c.ns, name), &v1alpha1.Subscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Subscription), err -} - -// List takes label and field selectors, and returns the list of Subscriptions that match those selectors. -func (c *FakeSubscriptions) List(opts v1.ListOptions) (result *v1alpha1.SubscriptionList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(subscriptionsResource, subscriptionsKind, c.ns, opts), &v1alpha1.SubscriptionList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.SubscriptionList{ListMeta: obj.(*v1alpha1.SubscriptionList).ListMeta} - for _, item := range obj.(*v1alpha1.SubscriptionList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested subscriptions. -func (c *FakeSubscriptions) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(subscriptionsResource, c.ns, opts)) - -} - -// Create takes the representation of a subscription and creates it. Returns the server's representation of the subscription, and an error, if there is any. -func (c *FakeSubscriptions) Create(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(subscriptionsResource, c.ns, subscription), &v1alpha1.Subscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Subscription), err -} - -// Update takes the representation of a subscription and updates it. Returns the server's representation of the subscription, and an error, if there is any. -func (c *FakeSubscriptions) Update(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(subscriptionsResource, c.ns, subscription), &v1alpha1.Subscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Subscription), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeSubscriptions) UpdateStatus(subscription *v1alpha1.Subscription) (*v1alpha1.Subscription, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(subscriptionsResource, "status", c.ns, subscription), &v1alpha1.Subscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Subscription), err -} - -// Delete takes name of the subscription and deletes it. Returns an error if one occurs. -func (c *FakeSubscriptions) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(subscriptionsResource, c.ns, name), &v1alpha1.Subscription{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeSubscriptions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(subscriptionsResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.SubscriptionList{}) - return err -} - -// Patch applies the patch and returns the patched subscription. -func (c *FakeSubscriptions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(subscriptionsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Subscription{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.Subscription), err -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/generated_expansion.go deleted file mode 100644 index 4aac50827c6..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/generated_expansion.go +++ /dev/null @@ -1,25 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -type ChannelExpansion interface{} - -type InMemoryChannelExpansion interface{} - -type SubscriptionExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/inmemorychannel.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/inmemorychannel.go deleted file mode 100644 index 01ef2007ec6..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/inmemorychannel.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - scheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" -) - -// InMemoryChannelsGetter has a method to return a InMemoryChannelInterface. -// A group's client should implement this interface. -type InMemoryChannelsGetter interface { - InMemoryChannels(namespace string) InMemoryChannelInterface -} - -// InMemoryChannelInterface has methods to work with InMemoryChannel resources. -type InMemoryChannelInterface interface { - Create(*v1alpha1.InMemoryChannel) (*v1alpha1.InMemoryChannel, error) - Update(*v1alpha1.InMemoryChannel) (*v1alpha1.InMemoryChannel, error) - UpdateStatus(*v1alpha1.InMemoryChannel) (*v1alpha1.InMemoryChannel, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.InMemoryChannel, error) - List(opts v1.ListOptions) (*v1alpha1.InMemoryChannelList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.InMemoryChannel, err error) - InMemoryChannelExpansion -} - -// inMemoryChannels implements InMemoryChannelInterface -type inMemoryChannels struct { - client rest.Interface - ns string -} - -// newInMemoryChannels returns a InMemoryChannels -func newInMemoryChannels(c *MessagingV1alpha1Client, namespace string) *inMemoryChannels { - return &inMemoryChannels{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the inMemoryChannel, and returns the corresponding inMemoryChannel object, and an error if there is any. -func (c *inMemoryChannels) Get(name string, options v1.GetOptions) (result *v1alpha1.InMemoryChannel, err error) { - result = &v1alpha1.InMemoryChannel{} - err = c.client.Get(). - Namespace(c.ns). - Resource("inmemorychannels"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of InMemoryChannels that match those selectors. -func (c *inMemoryChannels) List(opts v1.ListOptions) (result *v1alpha1.InMemoryChannelList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.InMemoryChannelList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("inmemorychannels"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested inMemoryChannels. -func (c *inMemoryChannels) Watch(opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("inmemorychannels"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch() -} - -// Create takes the representation of a inMemoryChannel and creates it. Returns the server's representation of the inMemoryChannel, and an error, if there is any. -func (c *inMemoryChannels) Create(inMemoryChannel *v1alpha1.InMemoryChannel) (result *v1alpha1.InMemoryChannel, err error) { - result = &v1alpha1.InMemoryChannel{} - err = c.client.Post(). - Namespace(c.ns). - Resource("inmemorychannels"). - Body(inMemoryChannel). - Do(). - Into(result) - return -} - -// Update takes the representation of a inMemoryChannel and updates it. Returns the server's representation of the inMemoryChannel, and an error, if there is any. -func (c *inMemoryChannels) Update(inMemoryChannel *v1alpha1.InMemoryChannel) (result *v1alpha1.InMemoryChannel, err error) { - result = &v1alpha1.InMemoryChannel{} - err = c.client.Put(). - Namespace(c.ns). - Resource("inmemorychannels"). - Name(inMemoryChannel.Name). - Body(inMemoryChannel). - Do(). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - -func (c *inMemoryChannels) UpdateStatus(inMemoryChannel *v1alpha1.InMemoryChannel) (result *v1alpha1.InMemoryChannel, err error) { - result = &v1alpha1.InMemoryChannel{} - err = c.client.Put(). - Namespace(c.ns). - Resource("inmemorychannels"). - Name(inMemoryChannel.Name). - SubResource("status"). - Body(inMemoryChannel). - Do(). - Into(result) - return -} - -// Delete takes name of the inMemoryChannel and deletes it. Returns an error if one occurs. -func (c *inMemoryChannels) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("inmemorychannels"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *inMemoryChannels) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - var timeout time.Duration - if listOptions.TimeoutSeconds != nil { - timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("inmemorychannels"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Timeout(timeout). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched inMemoryChannel. -func (c *inMemoryChannels) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.InMemoryChannel, err error) { - result = &v1alpha1.InMemoryChannel{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("inmemorychannels"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/messaging_client.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/messaging_client.go deleted file mode 100644 index c08836105d2..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/messaging_client.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - "knative.dev/eventing/pkg/client/clientset/versioned/scheme" -) - -type MessagingV1alpha1Interface interface { - RESTClient() rest.Interface - ChannelsGetter - InMemoryChannelsGetter - SubscriptionsGetter -} - -// MessagingV1alpha1Client is used to interact with features provided by the messaging.knative.dev group. -type MessagingV1alpha1Client struct { - restClient rest.Interface -} - -func (c *MessagingV1alpha1Client) Channels(namespace string) ChannelInterface { - return newChannels(c, namespace) -} - -func (c *MessagingV1alpha1Client) InMemoryChannels(namespace string) InMemoryChannelInterface { - return newInMemoryChannels(c, namespace) -} - -func (c *MessagingV1alpha1Client) Subscriptions(namespace string) SubscriptionInterface { - return newSubscriptions(c, namespace) -} - -// NewForConfig creates a new MessagingV1alpha1Client for the given config. -func NewForConfig(c *rest.Config) (*MessagingV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientFor(&config) - if err != nil { - return nil, err - } - return &MessagingV1alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new MessagingV1alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *MessagingV1alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new MessagingV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *MessagingV1alpha1Client { - return &MessagingV1alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *MessagingV1alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/subscription.go b/pkg/client/clientset/versioned/typed/messaging/v1alpha1/subscription.go deleted file mode 100644 index f2fc016d7d7..00000000000 --- a/pkg/client/clientset/versioned/typed/messaging/v1alpha1/subscription.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - scheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" -) - -// SubscriptionsGetter has a method to return a SubscriptionInterface. -// A group's client should implement this interface. -type SubscriptionsGetter interface { - Subscriptions(namespace string) SubscriptionInterface -} - -// SubscriptionInterface has methods to work with Subscription resources. -type SubscriptionInterface interface { - Create(*v1alpha1.Subscription) (*v1alpha1.Subscription, error) - Update(*v1alpha1.Subscription) (*v1alpha1.Subscription, error) - UpdateStatus(*v1alpha1.Subscription) (*v1alpha1.Subscription, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.Subscription, error) - List(opts v1.ListOptions) (*v1alpha1.SubscriptionList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) - SubscriptionExpansion -} - -// subscriptions implements SubscriptionInterface -type subscriptions struct { - client rest.Interface - ns string -} - -// newSubscriptions returns a Subscriptions -func newSubscriptions(c *MessagingV1alpha1Client, namespace string) *subscriptions { - return &subscriptions{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the subscription, and returns the corresponding subscription object, and an error if there is any. -func (c *subscriptions) Get(name string, options v1.GetOptions) (result *v1alpha1.Subscription, err error) { - result = &v1alpha1.Subscription{} - err = c.client.Get(). - Namespace(c.ns). - Resource("subscriptions"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Subscriptions that match those selectors. -func (c *subscriptions) List(opts v1.ListOptions) (result *v1alpha1.SubscriptionList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.SubscriptionList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("subscriptions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested subscriptions. -func (c *subscriptions) Watch(opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("subscriptions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch() -} - -// Create takes the representation of a subscription and creates it. Returns the server's representation of the subscription, and an error, if there is any. -func (c *subscriptions) Create(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { - result = &v1alpha1.Subscription{} - err = c.client.Post(). - Namespace(c.ns). - Resource("subscriptions"). - Body(subscription). - Do(). - Into(result) - return -} - -// Update takes the representation of a subscription and updates it. Returns the server's representation of the subscription, and an error, if there is any. -func (c *subscriptions) Update(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { - result = &v1alpha1.Subscription{} - err = c.client.Put(). - Namespace(c.ns). - Resource("subscriptions"). - Name(subscription.Name). - Body(subscription). - Do(). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - -func (c *subscriptions) UpdateStatus(subscription *v1alpha1.Subscription) (result *v1alpha1.Subscription, err error) { - result = &v1alpha1.Subscription{} - err = c.client.Put(). - Namespace(c.ns). - Resource("subscriptions"). - Name(subscription.Name). - SubResource("status"). - Body(subscription). - Do(). - Into(result) - return -} - -// Delete takes name of the subscription and deletes it. Returns an error if one occurs. -func (c *subscriptions) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("subscriptions"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *subscriptions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - var timeout time.Duration - if listOptions.TimeoutSeconds != nil { - timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("subscriptions"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Timeout(timeout). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched subscription. -func (c *subscriptions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Subscription, err error) { - result = &v1alpha1.Subscription{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("subscriptions"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index ed80e126d6e..c91f5c47581 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -26,7 +26,6 @@ import ( v1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" v1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" @@ -76,14 +75,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case flowsv1beta1.SchemeGroupVersion.WithResource("sequences"): return &genericInformer{resource: resource.GroupResource(), informer: f.Flows().V1beta1().Sequences().Informer()}, nil - // Group=messaging.knative.dev, Version=v1alpha1 - case messagingv1alpha1.SchemeGroupVersion.WithResource("channels"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Messaging().V1alpha1().Channels().Informer()}, nil - case messagingv1alpha1.SchemeGroupVersion.WithResource("inmemorychannels"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Messaging().V1alpha1().InMemoryChannels().Informer()}, nil - case messagingv1alpha1.SchemeGroupVersion.WithResource("subscriptions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Messaging().V1alpha1().Subscriptions().Informer()}, nil - // Group=messaging.knative.dev, Version=v1beta1 case messagingv1beta1.SchemeGroupVersion.WithResource("channels"): return &genericInformer{resource: resource.GroupResource(), informer: f.Messaging().V1beta1().Channels().Informer()}, nil diff --git a/pkg/client/informers/externalversions/messaging/interface.go b/pkg/client/informers/externalversions/messaging/interface.go index f821e966e03..f1fb58aee2d 100644 --- a/pkg/client/informers/externalversions/messaging/interface.go +++ b/pkg/client/informers/externalversions/messaging/interface.go @@ -20,14 +20,11 @@ package messaging import ( internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1" v1beta1 "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1beta1" ) // Interface provides access to each of this group's versions. type Interface interface { - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.Interface } @@ -43,11 +40,6 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} - // V1beta1 returns a new v1beta1.Interface. func (g *group) V1beta1() v1beta1.Interface { return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) diff --git a/pkg/client/informers/externalversions/messaging/v1alpha1/channel.go b/pkg/client/informers/externalversions/messaging/v1alpha1/channel.go deleted file mode 100644 index 98fb1261fd7..00000000000 --- a/pkg/client/informers/externalversions/messaging/v1alpha1/channel.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - versioned "knative.dev/eventing/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" -) - -// ChannelInformer provides access to a shared informer and lister for -// Channels. -type ChannelInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.ChannelLister -} - -type channelInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewChannelInformer constructs a new informer for Channel type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredChannelInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredChannelInformer constructs a new informer for Channel type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().Channels(namespace).List(options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().Channels(namespace).Watch(options) - }, - }, - &messagingv1alpha1.Channel{}, - resyncPeriod, - indexers, - ) -} - -func (f *channelInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredChannelInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *channelInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&messagingv1alpha1.Channel{}, f.defaultInformer) -} - -func (f *channelInformer) Lister() v1alpha1.ChannelLister { - return v1alpha1.NewChannelLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/messaging/v1alpha1/inmemorychannel.go b/pkg/client/informers/externalversions/messaging/v1alpha1/inmemorychannel.go deleted file mode 100644 index 3f8979b75c5..00000000000 --- a/pkg/client/informers/externalversions/messaging/v1alpha1/inmemorychannel.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - versioned "knative.dev/eventing/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" -) - -// InMemoryChannelInformer provides access to a shared informer and lister for -// InMemoryChannels. -type InMemoryChannelInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.InMemoryChannelLister -} - -type inMemoryChannelInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewInMemoryChannelInformer constructs a new informer for InMemoryChannel type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewInMemoryChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredInMemoryChannelInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredInMemoryChannelInformer constructs a new informer for InMemoryChannel type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredInMemoryChannelInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().InMemoryChannels(namespace).List(options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().InMemoryChannels(namespace).Watch(options) - }, - }, - &messagingv1alpha1.InMemoryChannel{}, - resyncPeriod, - indexers, - ) -} - -func (f *inMemoryChannelInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredInMemoryChannelInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *inMemoryChannelInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&messagingv1alpha1.InMemoryChannel{}, f.defaultInformer) -} - -func (f *inMemoryChannelInformer) Lister() v1alpha1.InMemoryChannelLister { - return v1alpha1.NewInMemoryChannelLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/messaging/v1alpha1/interface.go b/pkg/client/informers/externalversions/messaging/v1alpha1/interface.go deleted file mode 100644 index 5c99cf8fd4a..00000000000 --- a/pkg/client/informers/externalversions/messaging/v1alpha1/interface.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // Channels returns a ChannelInformer. - Channels() ChannelInformer - // InMemoryChannels returns a InMemoryChannelInformer. - InMemoryChannels() InMemoryChannelInformer - // Subscriptions returns a SubscriptionInformer. - Subscriptions() SubscriptionInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// Channels returns a ChannelInformer. -func (v *version) Channels() ChannelInformer { - return &channelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// InMemoryChannels returns a InMemoryChannelInformer. -func (v *version) InMemoryChannels() InMemoryChannelInformer { - return &inMemoryChannelInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// Subscriptions returns a SubscriptionInformer. -func (v *version) Subscriptions() SubscriptionInformer { - return &subscriptionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/informers/externalversions/messaging/v1alpha1/subscription.go b/pkg/client/informers/externalversions/messaging/v1alpha1/subscription.go deleted file mode 100644 index 2ca12039697..00000000000 --- a/pkg/client/informers/externalversions/messaging/v1alpha1/subscription.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - versioned "knative.dev/eventing/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/eventing/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" -) - -// SubscriptionInformer provides access to a shared informer and lister for -// Subscriptions. -type SubscriptionInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.SubscriptionLister -} - -type subscriptionInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewSubscriptionInformer constructs a new informer for Subscription type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewSubscriptionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredSubscriptionInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredSubscriptionInformer constructs a new informer for Subscription type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredSubscriptionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().Subscriptions(namespace).List(options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.MessagingV1alpha1().Subscriptions(namespace).Watch(options) - }, - }, - &messagingv1alpha1.Subscription{}, - resyncPeriod, - indexers, - ) -} - -func (f *subscriptionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredSubscriptionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *subscriptionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&messagingv1alpha1.Subscription{}, f.defaultInformer) -} - -func (f *subscriptionInformer) Lister() v1alpha1.SubscriptionLister { - return v1alpha1.NewSubscriptionLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/channel/channel.go b/pkg/client/injection/informers/messaging/v1alpha1/channel/channel.go deleted file mode 100644 index 34822535b73..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/channel/channel.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package channel - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1" - factory "knative.dev/eventing/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Messaging().V1alpha1().Channels() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.ChannelInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1.ChannelInformer from context.") - } - return untyped.(v1alpha1.ChannelInformer) -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/channel/fake/fake.go b/pkg/client/injection/informers/messaging/v1alpha1/channel/fake/fake.go deleted file mode 100644 index 0a301337d60..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/channel/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "knative.dev/eventing/pkg/client/injection/informers/factory/fake" - channel "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/channel" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = channel.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Messaging().V1alpha1().Channels() - return context.WithValue(ctx, channel.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/fake/fake.go b/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/fake/fake.go deleted file mode 100644 index a6ff55ec490..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "knative.dev/eventing/pkg/client/injection/informers/factory/fake" - inmemorychannel "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = inmemorychannel.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Messaging().V1alpha1().InMemoryChannels() - return context.WithValue(ctx, inmemorychannel.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/inmemorychannel.go b/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/inmemorychannel.go deleted file mode 100644 index 30fd9c861e4..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/inmemorychannel.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package inmemorychannel - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1" - factory "knative.dev/eventing/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Messaging().V1alpha1().InMemoryChannels() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.InMemoryChannelInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1.InMemoryChannelInformer from context.") - } - return untyped.(v1alpha1.InMemoryChannelInformer) -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/subscription/fake/fake.go b/pkg/client/injection/informers/messaging/v1alpha1/subscription/fake/fake.go deleted file mode 100644 index 4e884761025..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/subscription/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - fake "knative.dev/eventing/pkg/client/injection/informers/factory/fake" - subscription "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/subscription" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = subscription.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Messaging().V1alpha1().Subscriptions() - return context.WithValue(ctx, subscription.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/messaging/v1alpha1/subscription/subscription.go b/pkg/client/injection/informers/messaging/v1alpha1/subscription/subscription.go deleted file mode 100644 index 37738d93275..00000000000 --- a/pkg/client/injection/informers/messaging/v1alpha1/subscription/subscription.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package subscription - -import ( - context "context" - - v1alpha1 "knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1" - factory "knative.dev/eventing/pkg/client/injection/informers/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Messaging().V1alpha1().Subscriptions() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.SubscriptionInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/eventing/pkg/client/informers/externalversions/messaging/v1alpha1.SubscriptionInformer from context.") - } - return untyped.(v1alpha1.SubscriptionInformer) -} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/controller.go b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/controller.go new file mode 100644 index 00000000000..9038c2777f0 --- /dev/null +++ b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/controller.go @@ -0,0 +1,118 @@ +/* +Copyright 2020 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. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package apiserversource + +import ( + context "context" + fmt "fmt" + reflect "reflect" + strings "strings" + + corev1 "k8s.io/api/core/v1" + watch "k8s.io/apimachinery/pkg/watch" + scheme "k8s.io/client-go/kubernetes/scheme" + v1 "k8s.io/client-go/kubernetes/typed/core/v1" + record "k8s.io/client-go/tools/record" + versionedscheme "knative.dev/eventing/pkg/client/clientset/versioned/scheme" + client "knative.dev/eventing/pkg/client/injection/client" + apiserversource "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha1/apiserversource" + kubeclient "knative.dev/pkg/client/injection/kube/client" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" +) + +const ( + defaultControllerAgentName = "apiserversource-controller" + defaultFinalizerName = "apiserversources.sources.knative.dev" +) + +// NewImpl returns a controller.Impl that handles queuing and feeding work from +// the queue through an implementation of controller.Reconciler, delegating to +// the provided Interface and optional Finalizer methods. OptionsFn is used to return +// controller.Options to be used but the internal reconciler. +func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsFn) *controller.Impl { + logger := logging.FromContext(ctx) + + // Check the options function input. It should be 0 or 1. + if len(optionsFns) > 1 { + logger.Fatalf("up to one options function is supported, found %d", len(optionsFns)) + } + + apiserversourceInformer := apiserversource.Get(ctx) + + rec := &reconcilerImpl{ + Client: client.Get(ctx), + Lister: apiserversourceInformer.Lister(), + reconciler: r, + finalizerName: defaultFinalizerName, + } + + t := reflect.TypeOf(r).Elem() + queueName := fmt.Sprintf("%s.%s", strings.ReplaceAll(t.PkgPath(), "/", "-"), t.Name()) + + impl := controller.NewImpl(rec, logger, queueName) + agentName := defaultControllerAgentName + + // Pass impl to the options. Save any optional results. + for _, fn := range optionsFns { + opts := fn(impl) + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + if opts.AgentName != "" { + agentName = opts.AgentName + } + } + + rec.Recorder = createRecorder(ctx, agentName) + + return impl +} + +func createRecorder(ctx context.Context, agentName string) record.EventRecorder { + logger := logging.FromContext(ctx) + + recorder := controller.GetEventRecorder(ctx) + if recorder == nil { + // Create event broadcaster + logger.Debug("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + watches := []watch.Interface{ + eventBroadcaster.StartLogging(logger.Named("event-broadcaster").Infof), + eventBroadcaster.StartRecordingToSink( + &v1.EventSinkImpl{Interface: kubeclient.Get(ctx).CoreV1().Events("")}), + } + recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: agentName}) + go func() { + <-ctx.Done() + for _, w := range watches { + w.Stop() + } + }() + } + + return recorder +} + +func init() { + versionedscheme.AddToScheme(scheme.Scheme) +} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/reconciler.go b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/reconciler.go new file mode 100644 index 00000000000..43a6e9523f4 --- /dev/null +++ b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/reconciler.go @@ -0,0 +1,352 @@ +/* +Copyright 2020 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. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package apiserversource + +import ( + context "context" + json "encoding/json" + reflect "reflect" + + zap "go.uber.org/zap" + v1 "k8s.io/api/core/v1" + equality "k8s.io/apimachinery/pkg/api/equality" + errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + sets "k8s.io/apimachinery/pkg/util/sets" + cache "k8s.io/client-go/tools/cache" + record "k8s.io/client-go/tools/record" + v1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" + versioned "knative.dev/eventing/pkg/client/clientset/versioned" + sourcesv1alpha1 "knative.dev/eventing/pkg/client/listers/sources/v1alpha1" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" + reconciler "knative.dev/pkg/reconciler" +) + +// Interface defines the strongly typed interfaces to be implemented by a +// controller reconciling v1alpha1.ApiServerSource. +type Interface interface { + // ReconcileKind implements custom logic to reconcile v1alpha1.ApiServerSource. Any changes + // to the objects .Status or .Finalizers will be propagated to the stored + // object. It is recommended that implementors do not call any update calls + // for the Kind inside of ReconcileKind, it is the responsibility of the calling + // controller to propagate those properties. The resource passed to ReconcileKind + // will always have an empty deletion timestamp. + ReconcileKind(ctx context.Context, o *v1alpha1.ApiServerSource) reconciler.Event +} + +// Finalizer defines the strongly typed interfaces to be implemented by a +// controller finalizing v1alpha1.ApiServerSource. +type Finalizer interface { + // FinalizeKind implements custom logic to finalize v1alpha1.ApiServerSource. Any changes + // to the objects .Status or .Finalizers will be ignored. Returning a nil or + // Normal type reconciler.Event will allow the finalizer to be deleted on + // the resource. The resource passed to FinalizeKind will always have a set + // deletion timestamp. + FinalizeKind(ctx context.Context, o *v1alpha1.ApiServerSource) reconciler.Event +} + +// reconcilerImpl implements controller.Reconciler for v1alpha1.ApiServerSource resources. +type reconcilerImpl struct { + // Client is used to write back status updates. + Client versioned.Interface + + // Listers index properties about resources + Lister sourcesv1alpha1.ApiServerSourceLister + + // Recorder is an event recorder for recording Event resources to the + // Kubernetes API. + Recorder record.EventRecorder + + // configStore allows for decorating a context with config maps. + // +optional + configStore reconciler.ConfigStore + + // reconciler is the implementation of the business logic of the resource. + reconciler Interface + + // finalizerName is the name of the finalizer to reconcile. + finalizerName string +} + +// Check that our Reconciler implements controller.Reconciler +var _ controller.Reconciler = (*reconcilerImpl)(nil) + +func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister sourcesv1alpha1.ApiServerSourceLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { + // Check the options function input. It should be 0 or 1. + if len(options) > 1 { + logger.Fatalf("up to one options struct is supported, found %d", len(options)) + } + + rec := &reconcilerImpl{ + Client: client, + Lister: lister, + Recorder: recorder, + reconciler: r, + finalizerName: defaultFinalizerName, + } + + for _, opts := range options { + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + } + + return rec +} + +// Reconcile implements controller.Reconciler +func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { + logger := logging.FromContext(ctx) + + // If configStore is set, attach the frozen configuration to the context. + if r.configStore != nil { + ctx = r.configStore.ToContext(ctx) + } + + // Add the recorder to context. + ctx = controller.WithEventRecorder(ctx, r.Recorder) + + // Convert the namespace/name string into a distinct namespace and name + + namespace, name, err := cache.SplitMetaNamespaceKey(key) + + if err != nil { + logger.Errorf("invalid resource key: %s", key) + return nil + } + + // Get the resource with this namespace/name. + + getter := r.Lister.ApiServerSources(namespace) + + original, err := getter.Get(name) + + if errors.IsNotFound(err) { + // The resource may no longer exist, in which case we stop processing. + logger.Debugf("resource %q no longer exists", key) + return nil + } else if err != nil { + return err + } + + // Don't modify the informers copy. + resource := original.DeepCopy() + + var reconcileEvent reconciler.Event + if resource.GetDeletionTimestamp().IsZero() { + // Append the target method to the logger. + logger = logger.With(zap.String("targetMethod", "ReconcileKind")) + + // Set and update the finalizer on resource if r.reconciler + // implements Finalizer. + if resource, err = r.setFinalizerIfFinalizer(ctx, resource); err != nil { + logger.Warnw("Failed to set finalizers", zap.Error(err)) + } + + // Reconcile this copy of the resource and then write back any status + // updates regardless of whether the reconciliation errored out. + reconcileEvent = r.reconciler.ReconcileKind(ctx, resource) + + } else if fin, ok := r.reconciler.(Finalizer); ok { + // Append the target method to the logger. + logger = logger.With(zap.String("targetMethod", "FinalizeKind")) + + // For finalizing reconcilers, if this resource being marked for deletion + // and reconciled cleanly (nil or normal event), remove the finalizer. + reconcileEvent = fin.FinalizeKind(ctx, resource) + if resource, err = r.clearFinalizer(ctx, resource, reconcileEvent); err != nil { + logger.Warnw("Failed to clear finalizers", zap.Error(err)) + } + } + + // Synchronize the status. + if equality.Semantic.DeepEqual(original.Status, resource.Status) { + // If we didn't change anything then don't call updateStatus. + // This is important because the copy we loaded from the injectionInformer's + // cache may be stale and we don't want to overwrite a prior update + // to status with this stale state. + } else if err = r.updateStatus(original, resource); err != nil { + logger.Warnw("Failed to update resource status", zap.Error(err)) + r.Recorder.Eventf(resource, v1.EventTypeWarning, "UpdateFailed", + "Failed to update status for %q: %v", resource.Name, err) + return err + } + + // Report the reconciler event, if any. + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + logger.Infow("Returned an event", zap.Any("event", reconcileEvent)) + r.Recorder.Eventf(resource, event.EventType, event.Reason, event.Format, event.Args...) + + // the event was wrapped inside an error, consider the reconciliation as failed + if _, isEvent := reconcileEvent.(*reconciler.ReconcilerEvent); !isEvent { + return reconcileEvent + } + return nil + } + + logger.Errorw("Returned an error", zap.Error(reconcileEvent)) + r.Recorder.Event(resource, v1.EventTypeWarning, "InternalError", reconcileEvent.Error()) + return reconcileEvent + } + + return nil +} + +func (r *reconcilerImpl) updateStatus(existing *v1alpha1.ApiServerSource, desired *v1alpha1.ApiServerSource) error { + existing = existing.DeepCopy() + return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { + // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. + if attempts > 0 { + + getter := r.Client.SourcesV1alpha1().ApiServerSources(desired.Namespace) + + existing, err = getter.Get(desired.Name, metav1.GetOptions{}) + if err != nil { + return err + } + } + + // If there's nothing to update, just return. + if reflect.DeepEqual(existing.Status, desired.Status) { + return nil + } + + existing.Status = desired.Status + + updater := r.Client.SourcesV1alpha1().ApiServerSources(existing.Namespace) + + _, err = updater.UpdateStatus(existing) + return err + }) +} + +// updateFinalizersFiltered will update the Finalizers of the resource. +// TODO: this method could be generic and sync all finalizers. For now it only +// updates defaultFinalizerName or its override. +func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1alpha1.ApiServerSource) (*v1alpha1.ApiServerSource, error) { + + getter := r.Lister.ApiServerSources(resource.Namespace) + + actual, err := getter.Get(resource.Name) + if err != nil { + return resource, err + } + + // Don't modify the informers copy. + existing := actual.DeepCopy() + + var finalizers []string + + // If there's nothing to update, just return. + existingFinalizers := sets.NewString(existing.Finalizers...) + desiredFinalizers := sets.NewString(resource.Finalizers...) + + if desiredFinalizers.Has(r.finalizerName) { + if existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Add the finalizer. + finalizers = append(existing.Finalizers, r.finalizerName) + } else { + if !existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Remove the finalizer. + existingFinalizers.Delete(r.finalizerName) + finalizers = existingFinalizers.List() + } + + mergePatch := map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": finalizers, + "resourceVersion": existing.ResourceVersion, + }, + } + + patch, err := json.Marshal(mergePatch) + if err != nil { + return resource, err + } + + patcher := r.Client.SourcesV1alpha1().ApiServerSources(resource.Namespace) + + resource, err = patcher.Patch(resource.Name, types.MergePatchType, patch) + if err != nil { + r.Recorder.Eventf(resource, v1.EventTypeWarning, "FinalizerUpdateFailed", + "Failed to update finalizers for %q: %v", resource.Name, err) + } else { + r.Recorder.Eventf(resource, v1.EventTypeNormal, "FinalizerUpdate", + "Updated %q finalizers", resource.GetName()) + } + return resource, err +} + +func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1alpha1.ApiServerSource) (*v1alpha1.ApiServerSource, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + // If this resource is not being deleted, mark the finalizer. + if resource.GetDeletionTimestamp().IsZero() { + finalizers.Insert(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} + +func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1alpha1.ApiServerSource, reconcileEvent reconciler.Event) (*v1alpha1.ApiServerSource, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + if resource.GetDeletionTimestamp().IsZero() { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + if event.EventType == v1.EventTypeNormal { + finalizers.Delete(r.finalizerName) + } + } + } else { + finalizers.Delete(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/controller.go b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/controller.go new file mode 100644 index 00000000000..63eec787868 --- /dev/null +++ b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/controller.go @@ -0,0 +1,54 @@ +/* +Copyright 2020 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. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package apiserversource + +import ( + context "context" + + apiserversource "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha1/apiserversource" + v1alpha1apiserversource "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource" + configmap "knative.dev/pkg/configmap" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" +) + +// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT + +// NewController creates a Reconciler for ApiServerSource and returns the result of NewImpl. +func NewController( + ctx context.Context, + cmw configmap.Watcher, +) *controller.Impl { + logger := logging.FromContext(ctx) + + apiserversourceInformer := apiserversource.Get(ctx) + + // TODO: setup additional informers here. + + r := &Reconciler{} + impl := v1alpha1apiserversource.NewImpl(ctx, r) + + logger.Info("Setting up event handlers.") + + apiserversourceInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) + + // TODO: add additional informer event handlers here. + + return impl +} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/reconciler.go b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/reconciler.go new file mode 100644 index 00000000000..d0233135bfc --- /dev/null +++ b/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource/stub/reconciler.go @@ -0,0 +1,66 @@ +/* +Copyright 2020 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. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package apiserversource + +import ( + context "context" + + v1 "k8s.io/api/core/v1" + v1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" + apiserversource "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha1/apiserversource" + reconciler "knative.dev/pkg/reconciler" +) + +// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT + +// newReconciledNormal makes a new reconciler event with event type Normal, and +// reason ApiServerSourceReconciled. +func newReconciledNormal(namespace, name string) reconciler.Event { + return reconciler.NewEvent(v1.EventTypeNormal, "ApiServerSourceReconciled", "ApiServerSource reconciled: \"%s/%s\"", namespace, name) +} + +// Reconciler implements controller.Reconciler for ApiServerSource resources. +type Reconciler struct { + // TODO: add additional requirements here. +} + +// Check that our Reconciler implements Interface +var _ apiserversource.Interface = (*Reconciler)(nil) + +// Optionally check that our Reconciler implements Finalizer +//var _ apiserversource.Finalizer = (*Reconciler)(nil) + +// ReconcileKind implements Interface.ReconcileKind. +func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.ApiServerSource) reconciler.Event { + // TODO: use this if the resource implements InitializeConditions. + // o.Status.InitializeConditions() + + // TODO: add custom reconciliation logic here. + + // TODO: use this if the object has .status.ObservedGeneration. + // o.Status.ObservedGeneration = o.Generation + return newReconciledNormal(o.Namespace, o.Name) +} + +// Optionally, use FinalizeKind to add finalizers. FinalizeKind will be called +// when the resource is deleted. +//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1alpha1.ApiServerSource) reconciler.Event { +// // TODO: add custom finalization logic here. +// return nil +//} diff --git a/pkg/client/listers/messaging/v1alpha1/channel.go b/pkg/client/listers/messaging/v1alpha1/channel.go deleted file mode 100644 index 5c8c7e7c475..00000000000 --- a/pkg/client/listers/messaging/v1alpha1/channel.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// ChannelLister helps list Channels. -type ChannelLister interface { - // List lists all Channels in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) - // Channels returns an object that can list and get Channels. - Channels(namespace string) ChannelNamespaceLister - ChannelListerExpansion -} - -// channelLister implements the ChannelLister interface. -type channelLister struct { - indexer cache.Indexer -} - -// NewChannelLister returns a new ChannelLister. -func NewChannelLister(indexer cache.Indexer) ChannelLister { - return &channelLister{indexer: indexer} -} - -// List lists all Channels in the indexer. -func (s *channelLister) List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Channel)) - }) - return ret, err -} - -// Channels returns an object that can list and get Channels. -func (s *channelLister) Channels(namespace string) ChannelNamespaceLister { - return channelNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// ChannelNamespaceLister helps list and get Channels. -type ChannelNamespaceLister interface { - // List lists all Channels in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) - // Get retrieves the Channel from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.Channel, error) - ChannelNamespaceListerExpansion -} - -// channelNamespaceLister implements the ChannelNamespaceLister -// interface. -type channelNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Channels in the indexer for a given namespace. -func (s channelNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Channel, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Channel)) - }) - return ret, err -} - -// Get retrieves the Channel from the indexer for a given namespace and name. -func (s channelNamespaceLister) Get(name string) (*v1alpha1.Channel, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("channel"), name) - } - return obj.(*v1alpha1.Channel), nil -} diff --git a/pkg/client/listers/messaging/v1alpha1/expansion_generated.go b/pkg/client/listers/messaging/v1alpha1/expansion_generated.go deleted file mode 100644 index 9df61342fe7..00000000000 --- a/pkg/client/listers/messaging/v1alpha1/expansion_generated.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -// ChannelListerExpansion allows custom methods to be added to -// ChannelLister. -type ChannelListerExpansion interface{} - -// ChannelNamespaceListerExpansion allows custom methods to be added to -// ChannelNamespaceLister. -type ChannelNamespaceListerExpansion interface{} - -// InMemoryChannelListerExpansion allows custom methods to be added to -// InMemoryChannelLister. -type InMemoryChannelListerExpansion interface{} - -// InMemoryChannelNamespaceListerExpansion allows custom methods to be added to -// InMemoryChannelNamespaceLister. -type InMemoryChannelNamespaceListerExpansion interface{} - -// SubscriptionListerExpansion allows custom methods to be added to -// SubscriptionLister. -type SubscriptionListerExpansion interface{} - -// SubscriptionNamespaceListerExpansion allows custom methods to be added to -// SubscriptionNamespaceLister. -type SubscriptionNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/messaging/v1alpha1/inmemorychannel.go b/pkg/client/listers/messaging/v1alpha1/inmemorychannel.go deleted file mode 100644 index cb1a80d61b3..00000000000 --- a/pkg/client/listers/messaging/v1alpha1/inmemorychannel.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// InMemoryChannelLister helps list InMemoryChannels. -type InMemoryChannelLister interface { - // List lists all InMemoryChannels in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.InMemoryChannel, err error) - // InMemoryChannels returns an object that can list and get InMemoryChannels. - InMemoryChannels(namespace string) InMemoryChannelNamespaceLister - InMemoryChannelListerExpansion -} - -// inMemoryChannelLister implements the InMemoryChannelLister interface. -type inMemoryChannelLister struct { - indexer cache.Indexer -} - -// NewInMemoryChannelLister returns a new InMemoryChannelLister. -func NewInMemoryChannelLister(indexer cache.Indexer) InMemoryChannelLister { - return &inMemoryChannelLister{indexer: indexer} -} - -// List lists all InMemoryChannels in the indexer. -func (s *inMemoryChannelLister) List(selector labels.Selector) (ret []*v1alpha1.InMemoryChannel, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.InMemoryChannel)) - }) - return ret, err -} - -// InMemoryChannels returns an object that can list and get InMemoryChannels. -func (s *inMemoryChannelLister) InMemoryChannels(namespace string) InMemoryChannelNamespaceLister { - return inMemoryChannelNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// InMemoryChannelNamespaceLister helps list and get InMemoryChannels. -type InMemoryChannelNamespaceLister interface { - // List lists all InMemoryChannels in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.InMemoryChannel, err error) - // Get retrieves the InMemoryChannel from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.InMemoryChannel, error) - InMemoryChannelNamespaceListerExpansion -} - -// inMemoryChannelNamespaceLister implements the InMemoryChannelNamespaceLister -// interface. -type inMemoryChannelNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all InMemoryChannels in the indexer for a given namespace. -func (s inMemoryChannelNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.InMemoryChannel, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.InMemoryChannel)) - }) - return ret, err -} - -// Get retrieves the InMemoryChannel from the indexer for a given namespace and name. -func (s inMemoryChannelNamespaceLister) Get(name string) (*v1alpha1.InMemoryChannel, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("inmemorychannel"), name) - } - return obj.(*v1alpha1.InMemoryChannel), nil -} diff --git a/pkg/client/listers/messaging/v1alpha1/subscription.go b/pkg/client/listers/messaging/v1alpha1/subscription.go deleted file mode 100644 index e9e72cc154e..00000000000 --- a/pkg/client/listers/messaging/v1alpha1/subscription.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2020 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" -) - -// SubscriptionLister helps list Subscriptions. -type SubscriptionLister interface { - // List lists all Subscriptions in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) - // Subscriptions returns an object that can list and get Subscriptions. - Subscriptions(namespace string) SubscriptionNamespaceLister - SubscriptionListerExpansion -} - -// subscriptionLister implements the SubscriptionLister interface. -type subscriptionLister struct { - indexer cache.Indexer -} - -// NewSubscriptionLister returns a new SubscriptionLister. -func NewSubscriptionLister(indexer cache.Indexer) SubscriptionLister { - return &subscriptionLister{indexer: indexer} -} - -// List lists all Subscriptions in the indexer. -func (s *subscriptionLister) List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Subscription)) - }) - return ret, err -} - -// Subscriptions returns an object that can list and get Subscriptions. -func (s *subscriptionLister) Subscriptions(namespace string) SubscriptionNamespaceLister { - return subscriptionNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// SubscriptionNamespaceLister helps list and get Subscriptions. -type SubscriptionNamespaceLister interface { - // List lists all Subscriptions in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) - // Get retrieves the Subscription from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.Subscription, error) - SubscriptionNamespaceListerExpansion -} - -// subscriptionNamespaceLister implements the SubscriptionNamespaceLister -// interface. -type subscriptionNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Subscriptions in the indexer for a given namespace. -func (s subscriptionNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Subscription, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Subscription)) - }) - return ret, err -} - -// Get retrieves the Subscription from the indexer for a given namespace and name. -func (s subscriptionNamespaceLister) Get(name string) (*v1alpha1.Subscription, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("subscription"), name) - } - return obj.(*v1alpha1.Subscription), nil -} diff --git a/pkg/reconciler/apiserversource/apiserversource_test.go b/pkg/reconciler/apiserversource/apiserversource_test.go index e5e0874dfb8..86a610726f4 100644 --- a/pkg/reconciler/apiserversource/apiserversource_test.go +++ b/pkg/reconciler/apiserversource/apiserversource_test.go @@ -47,8 +47,8 @@ import ( logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/resolver" - . "knative.dev/eventing/pkg/reconciler/testing" - rtv1beta1 "knative.dev/eventing/pkg/reconciler/testing/v1beta1" + rttestingv1alpha1 "knative.dev/eventing/pkg/reconciler/testing" + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" . "knative.dev/pkg/reconciler/testing" ) @@ -57,7 +57,7 @@ var ( Ref: &duckv1.KReference{ Name: sinkName, Kind: "Channel", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, } brokerDest = duckv1.Destination{ @@ -96,16 +96,16 @@ func TestReconcile(t *testing.T) { table := TableTest{{ Name: "not enough permissions", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -115,21 +115,21 @@ func TestReconcile(t *testing.T) { }, Key: testNS + "/" + sourceName, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceStatusObservedGeneration(generation), - WithApiServerSourceSink(sinkURI), - WithApiServerSourceNoSufficientPermissions, + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceNoSufficientPermissions, ), }}, WantCreates: []runtime.Object{ @@ -146,16 +146,16 @@ func TestReconcile(t *testing.T) { }, { Name: "valid", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -168,23 +168,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantCreates: []runtime.Object{ @@ -197,16 +197,16 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with sink URI", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -219,23 +219,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantCreates: []runtime.Object{ @@ -248,8 +248,8 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with relative uri reference", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", @@ -261,8 +261,8 @@ func TestReconcile(t *testing.T) { }, }, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -275,8 +275,8 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", @@ -288,15 +288,15 @@ func TestReconcile(t *testing.T) { }, }, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkTargetURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkTargetURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantCreates: []runtime.Object{ @@ -309,16 +309,16 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to env", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -332,23 +332,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceDeploymentUnavailable, - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -364,8 +364,8 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to service account", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", @@ -375,8 +375,8 @@ func TestReconcile(t *testing.T) { }, ServiceAccountName: "malin", }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -390,8 +390,8 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", @@ -401,15 +401,15 @@ func TestReconcile(t *testing.T) { }, ServiceAccountName: "malin", }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeploymentUnavailable, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -425,16 +425,16 @@ func TestReconcile(t *testing.T) { }, { Name: "deployment update due to container count", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), NewChannel(sinkName, testNS, WithInitChannelConditions, @@ -448,23 +448,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeploymentUnavailable, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeploymentUnavailable, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantUpdates: []clientgotesting.UpdateActionImpl{{ @@ -480,20 +480,20 @@ func TestReconcile(t *testing.T) { }, { Name: "valid with broker sink", Objects: []runtime.Object{ - NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: brokerDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), ), - rtv1beta1.NewBroker(sinkName, testNS, - rtv1beta1.WithInitBrokerConditions, - rtv1beta1.WithBrokerAddress(sinkDNS), + NewBroker(sinkName, testNS, + WithInitBrokerConditions, + WithBrokerAddress(sinkDNS), ), makeAvailableReceiveAdapter(t), }, @@ -502,23 +502,23 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ApiServerSourceReconciled", `ApiServerSource reconciled: "%s/%s"`, testNS, sourceName), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + Object: rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: brokerDest}, }), - WithApiServerSourceUID(sourceUID), - WithApiServerSourceObjectMetaGeneration(generation), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceObjectMetaGeneration(generation), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkURI), - WithApiServerSourceSufficientPermissions, - WithApiServerSourceEventTypes(source), - WithApiServerSourceStatusObservedGeneration(generation), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithApiServerSourceSufficientPermissions, + rttestingv1alpha1.WithApiServerSourceEventTypes(source), + rttestingv1alpha1.WithApiServerSourceStatusObservedGeneration(generation), ), }}, WantCreates: []runtime.Object{ @@ -558,19 +558,19 @@ func makeReceiveAdapter(t *testing.T) *appsv1.Deployment { func makeReceiveAdapterWithName(t *testing.T, sourceName string) *appsv1.Deployment { t.Helper() - src := NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + src := rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), ) args := resources.ReceiveAdapterArgs{ @@ -589,26 +589,26 @@ func makeReceiveAdapterWithName(t *testing.T, sourceName string) *appsv1.Deploym func makeAvailableReceiveAdapter(t *testing.T) *appsv1.Deployment { ra := makeReceiveAdapter(t) - WithDeploymentAvailable()(ra) + rttestingv1alpha1.WithDeploymentAvailable()(ra) return ra } func makeAvailableReceiveAdapterWithTargetURI(t *testing.T) *appsv1.Deployment { t.Helper() - src := NewApiServerSource(sourceName, testNS, - WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ + src := rttestingv1alpha1.NewApiServerSource(sourceName, testNS, + rttestingv1alpha1.WithApiServerSourceSpec(sourcesv1alpha2.ApiServerSourceSpec{ Resources: []sourcesv1alpha2.APIVersionKindSelector{{ APIVersion: "v1", Kind: "Namespace", }}, SourceSpec: duckv1.SourceSpec{Sink: sinkDest}, }), - WithApiServerSourceUID(sourceUID), + rttestingv1alpha1.WithApiServerSourceUID(sourceUID), // Status Update: - WithInitApiServerSourceConditions, - WithApiServerSourceDeployed, - WithApiServerSourceSink(sinkURI), + rttestingv1alpha1.WithInitApiServerSourceConditions, + rttestingv1alpha1.WithApiServerSourceDeployed, + rttestingv1alpha1.WithApiServerSourceSink(sinkURI), ) args := resources.ReceiveAdapterArgs{ @@ -622,7 +622,7 @@ func makeAvailableReceiveAdapterWithTargetURI(t *testing.T) *appsv1.Deployment { ra, err := resources.MakeReceiveAdapter(&args) require.NoError(t, err) - WithDeploymentAvailable()(ra) + rttestingv1alpha1.WithDeploymentAvailable()(ra) return ra } diff --git a/pkg/reconciler/channel/channel_test.go b/pkg/reconciler/channel/channel_test.go index 549a9df243e..2c3d7da0cd9 100644 --- a/pkg/reconciler/channel/channel_test.go +++ b/pkg/reconciler/channel/channel_test.go @@ -35,7 +35,7 @@ import ( "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" channelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/channel" "knative.dev/eventing/pkg/duck" - . "knative.dev/eventing/pkg/reconciler/testing" + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -60,6 +60,7 @@ var ( func init() { // Add types to scheme _ = v1beta1.AddToScheme(scheme.Scheme) + _ = eventingduckv1alpha1.AddToScheme(scheme.Scheme) } func TestReconcile(t *testing.T) { @@ -79,27 +80,27 @@ func TestReconcile(t *testing.T) { Name: "Channel is being deleted", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithChannelDeletedV1Beta1), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithChannelDeleted), }, }, { Name: "Backing Channel.Create error", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions), }, WantCreates: []runtime.Object{ createChannelCRD(testNS, channelName, false), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithInitChannelConditionsV1Beta1, - WithChannelTemplateV1Beta1(channelCRD()), - WithBackingChannelFailedV1Beta1("ChannelFailure", "inducing failure for create inmemorychannels")), + Object: NewChannel(channelName, testNS, + WithInitChannelConditions, + WithChannelTemplate(channelCRD()), + WithBackingChannelFailed("ChannelFailure", "inducing failure for create inmemorychannels")), }}, WithReactors: []clientgotesting.ReactionFunc{ InduceFailure("create", "inmemorychannels"), @@ -112,24 +113,24 @@ func TestReconcile(t *testing.T) { Name: "Successful reconciliation", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1), - NewInMemoryChannelV1Beta1(channelName, testNS, - WithInitInMemoryChannelConditionsV1Beta1, - WithInMemoryChannelDeploymentReadyV1Beta1(), - WithInMemoryChannelServiceReadyV1Beta1(), - WithInMemoryChannelEndpointsReadyV1Beta1(), - WithInMemoryChannelChannelServiceReadyV1Beta1(), - WithInMemoryChannelAddressV1Beta1(backingChannelHostname)), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions), + NewInMemoryChannel(channelName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(backingChannelHostname)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname)), + Object: NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname)), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), @@ -138,20 +139,20 @@ func TestReconcile(t *testing.T) { Name: "Already reconciled", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname)), - NewInMemoryChannelV1Beta1(channelName, testNS, - WithInitInMemoryChannelConditionsV1Beta1, - WithInMemoryChannelDeploymentReadyV1Beta1(), - WithInMemoryChannelServiceReadyV1Beta1(), - WithInMemoryChannelEndpointsReadyV1Beta1(), - WithInMemoryChannelChannelServiceReadyV1Beta1(), - WithInMemoryChannelSubscribersV1Beta1(subscribers()), - WithInMemoryChannelAddressV1Beta1(backingChannelHostname)), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname)), + NewInMemoryChannel(channelName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelSubscribers(subscribers()), + WithInMemoryChannelAddress(backingChannelHostname)), }, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), @@ -160,12 +161,12 @@ func TestReconcile(t *testing.T) { Name: "Backing channel created", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname)), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname)), }, WantCreates: []runtime.Object{ createChannel(testNS, channelName, false), @@ -174,43 +175,43 @@ func TestReconcile(t *testing.T) { Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithChannelNoAddressV1Beta1(), - WithBackingChannelUnknownV1Beta1("BackingChannelNotConfigured", "BackingChannel has not yet been reconciled.")), + Object: NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithChannelNoAddress(), + WithBackingChannelUnknown("BackingChannelNotConfigured", "BackingChannel has not yet been reconciled.")), }}, }, { Name: "Generation Bump", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname), - WithChannelGenerationV1Beta1(42)), - NewInMemoryChannelV1Beta1(channelName, testNS, - WithInitInMemoryChannelConditionsV1Beta1, - WithInMemoryChannelDeploymentReadyV1Beta1(), - WithInMemoryChannelServiceReadyV1Beta1(), - WithInMemoryChannelEndpointsReadyV1Beta1(), - WithInMemoryChannelChannelServiceReadyV1Beta1(), - WithInMemoryChannelSubscribersV1Beta1(subscribers()), - WithInMemoryChannelAddressV1Beta1(backingChannelHostname)), + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname), + WithChannelGeneration(42)), + NewInMemoryChannel(channelName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelSubscribers(subscribers()), + WithInMemoryChannelAddress(backingChannelHostname)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname), - WithChannelGenerationV1Beta1(42), + Object: NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname), + WithChannelGeneration(42), // Updates - WithChannelObservedGenerationV1Beta1(42)), + WithChannelObservedGeneration(42)), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), @@ -219,63 +220,59 @@ func TestReconcile(t *testing.T) { Name: "Updating subscribers statuses", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname)), - NewInMemoryChannelV1Beta1(channelName, testNS, - WithInitInMemoryChannelConditionsV1Beta1, + NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname)), + NewInMemoryChannel(channelName, testNS, + WithInitInMemoryChannelConditions, WithInMemoryChannelDuckAnnotationV1Beta1, - WithInMemoryChannelDeploymentReadyV1Beta1(), - WithInMemoryChannelServiceReadyV1Beta1(), - WithInMemoryChannelEndpointsReadyV1Beta1(), - WithInMemoryChannelChannelServiceReadyV1Beta1(), - WithInMemoryChannelAddressV1Beta1(backingChannelHostname), - WithInMemoryChannelSubscribersV1Beta1(subscribers()), - WithInMemoryChannelStatusSubscribersV1Beta1(subscriberStatuses())), + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(backingChannelHostname), + WithInMemoryChannelSubscribers(subscribers()), + WithInMemoryChannelStatusSubscribers(subscriberStatuses())), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelCRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRef()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname), - WithChannelSubscriberStatusesV1Beta1(subscriberStatuses())), + Object: NewChannel(channelName, testNS, + WithChannelTemplate(channelCRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRef()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname), + WithChannelSubscriberStatuses(subscriberStatuses())), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), }, }, { - Name: "Updating v1alpha1 imc subscribers statuses", + Name: "Updating v1alpha1 channelable subscribers statuses", Key: testKey, Objects: []runtime.Object{ - NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelV1Alpha1CRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRefV1Alpha1()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname)), - NewInMemoryChannel(channelName, testNS, - WithInMemoryChannelDuckAnnotationV1Alpha1, - WithInMemoryChannelDeploymentReady(), - WithInMemoryChannelServiceReady(), - WithInMemoryChannelEndpointsReady(), - WithInMemoryChannelChannelServiceReady(), - WithInMemoryChannelAddress(backingChannelHostname), - WithInMemoryChannelSubscribers(subscribersV1Alpha1()), - WithInMemoryChannelStatusSubscribers(subscriberStatuses())), + NewChannel(channelName, testNS, + WithChannelTemplate(channelableV1Alpha1CRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRefV1Alpha1()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname)), + NewChannelable(channelName, testNS, + WithChannelableReady(), + WithChannelableAddress(backingChannelHostname), + WithChannelableSubscribers(subscribersV1Alpha1()), + WithChannelableStatusSubscribers(subscriberStatuses())), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewChannelV1Beta1(channelName, testNS, - WithChannelTemplateV1Beta1(channelV1Alpha1CRD()), - WithInitChannelConditionsV1Beta1, - WithBackingChannelObjRefV1Beta1(backingChannelObjRefV1Alpha1()), - WithBackingChannelReadyV1Beta1, - WithChannelAddressV1Beta1(backingChannelHostname), - WithChannelSubscriberStatusesV1Beta1(subscriberStatuses())), + Object: NewChannel(channelName, testNS, + WithChannelTemplate(channelableV1Alpha1CRD()), + WithInitChannelConditions, + WithBackingChannelObjRef(backingChannelObjRefV1Alpha1()), + WithBackingChannelReady, + WithChannelAddress(backingChannelHostname), + WithChannelSubscriberStatuses(subscriberStatuses())), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "ChannelReconciled", "Channel reconciled: %q", testKey), @@ -287,11 +284,11 @@ func TestReconcile(t *testing.T) { ctx = channelablecombined.WithDuck(ctx) r := &Reconciler{ dynamicClientSet: fakedynamicclient.Get(ctx), - channelLister: listers.GetV1Beta1MessagingChannelLister(), + channelLister: listers.GetMessagingChannelLister(), channelableTracker: duck.NewListableTracker(ctx, channelablecombined.Get, func(types.NamespacedName) {}, 0), } return channelreconciler.NewReconciler(ctx, logger, - fakeeventingclient.Get(ctx), listers.GetV1Beta1MessagingChannelLister(), + fakeeventingclient.Get(ctx), listers.GetMessagingChannelLister(), controller.GetEventRecorder(ctx), r) }, false, @@ -306,10 +303,10 @@ func channelCRD() metav1.TypeMeta { } } -func channelV1Alpha1CRD() metav1.TypeMeta { +func channelableV1Alpha1CRD() metav1.TypeMeta { return metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "InMemoryChannel", + APIVersion: "duck.knative.dev/v1alpha1", + Kind: "Channelable", } } @@ -397,8 +394,8 @@ func backingChannelObjRef() *duckv1.KReference { func backingChannelObjRefV1Alpha1() *duckv1.KReference { return &duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "InMemoryChannel", + APIVersion: "duck.knative.dev/v1alpha1", + Kind: "Channelable", Namespace: testNS, Name: channelName, } diff --git a/pkg/reconciler/inmemorychannel/controller/inmemorychannel_test.go b/pkg/reconciler/inmemorychannel/controller/inmemorychannel_test.go index a9a1830bb6d..13b1c284691 100644 --- a/pkg/reconciler/inmemorychannel/controller/inmemorychannel_test.go +++ b/pkg/reconciler/inmemorychannel/controller/inmemorychannel_test.go @@ -38,8 +38,7 @@ import ( eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/pkg/reconciler/inmemorychannel/controller/resources" - . "knative.dev/eventing/pkg/reconciler/testing" - reconciletesting "knative.dev/eventing/pkg/reconciler/testing" + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/apis" duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" @@ -104,20 +103,20 @@ func TestAllCases(t *testing.T) { Name: "deleting", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeletedV1Beta1)}, + NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeleted)}, WantErr: false, }, { Name: "deployment does not exist", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentFailedV1Beta1("DispatcherDeploymentDoesNotExist", "Dispatcher Deployment does not exist")), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentFailed("DispatcherDeploymentDoesNotExist", "Dispatcher Deployment does not exist")), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "DispatcherDeploymentFailed", `Reconciling dispatcher Deployment failed with: deployment.apps "imc-dispatcher" not found`), @@ -129,20 +128,20 @@ func TestAllCases(t *testing.T) { makeFalseDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantErr: false, WantCreates: []runtime.Object{ - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentFailedV1Beta1("DispatcherDeploymentFalse", "The status of Dispatcher Deployment is False: Deployment Failed : Deployment Failed"), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress)), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentFailed("DispatcherDeploymentFalse", "The status of Dispatcher Deployment is False: Deployment Failed : Deployment Failed"), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress)), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "InMemoryChannelReconciled", `InMemoryChannel reconciled: "test-namespace/test-imc"`), @@ -154,20 +153,20 @@ func TestAllCases(t *testing.T) { makeUnknownDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantErr: false, WantCreates: []runtime.Object{ - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentUnknownV1Beta1("DispatcherDeploymentUnknown", "The status of Dispatcher Deployment is Unknown: Deployment Unknown : Deployment Unknown"), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress)), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentUnknown("DispatcherDeploymentUnknown", "The status of Dispatcher Deployment is Unknown: Deployment Unknown : Deployment Unknown"), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress)), }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "InMemoryChannelReconciled", `InMemoryChannel reconciled: "test-namespace/test-imc"`), @@ -177,13 +176,13 @@ func TestAllCases(t *testing.T) { Key: imcKey, Objects: []runtime.Object{ makeReadyDeployment(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServicetNotReadyV1Beta1("DispatcherServiceDoesNotExist", "Dispatcher Service does not exist")), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServicetNotReady("DispatcherServiceDoesNotExist", "Dispatcher Service does not exist")), }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "DispatcherServiceFailed", `Reconciling dispatcher Service failed: service "imc-dispatcher" not found`), @@ -194,15 +193,15 @@ func TestAllCases(t *testing.T) { Objects: []runtime.Object{ makeReadyDeployment(), makeService(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantErr: true, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsNotReadyV1Beta1("DispatcherEndpointsDoesNotExist", "Dispatcher Endpoints does not exist"), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsNotReady("DispatcherEndpointsDoesNotExist", "Dispatcher Endpoints does not exist"), ), }}, WantEvents: []string{ @@ -215,15 +214,15 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeEmptyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantErr: true, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsNotReadyV1Beta1("DispatcherEndpointsNotReady", "There are no endpoints ready for Dispatcher service"), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsNotReady("DispatcherEndpointsNotReady", "There are no endpoints ready for Dispatcher service"), ), }}, WantEvents: []string{ @@ -236,23 +235,23 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInMemoryChannelGenerationV1Beta1(imcGeneration)), + NewInMemoryChannel(imcName, testNS, + WithInMemoryChannelGeneration(imcGeneration)), }, WantErr: false, WantCreates: []runtime.Object{ - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelGenerationV1Beta1(imcGeneration), - reconciletesting.WithInMemoryChannelStatusObservedGenerationV1Beta1(imcGeneration), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelGeneration(imcGeneration), + WithInMemoryChannelStatusObservedGeneration(imcGeneration), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress), ), }}, WantEvents: []string{ @@ -265,18 +264,18 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + NewInMemoryChannel(imcName, testNS), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantErr: false, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress), ), }}, WantEvents: []string{ @@ -289,17 +288,17 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), - makeChannelServiceNotOwnedByUs(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + NewInMemoryChannel(imcName, testNS), + makeChannelServiceNotOwnedByUs(NewInMemoryChannel(imcName, testNS)), }, WantErr: true, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceNotReadyV1Beta1("ChannelServiceFailed", "Channel Service failed: inmemorychannel: test-namespace/test-imc does not own Service: \"test-imc-kn-channel\""), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceNotReady("ChannelServiceFailed", "Channel Service failed: inmemorychannel: test-namespace/test-imc does not own Service: \"test-imc-kn-channel\""), ), }}, WantEvents: []string{ @@ -312,21 +311,21 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInMemoryChannelSubscribersV1Beta1(subscribers)), - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + NewInMemoryChannel(imcName, testNS, + WithInMemoryChannelSubscribers(subscribers)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantErr: false, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelSubscribersV1Beta1(subscribers), - reconciletesting.WithInMemoryChannelStatusSubscribersV1Beta1(subscriberStatuses), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelSubscribers(subscribers), + WithInMemoryChannelStatusSubscribers(subscriberStatuses), + WithInMemoryChannelAddress(channelServiceAddress), ), }}, WantEvents: []string{ @@ -339,23 +338,23 @@ func TestAllCases(t *testing.T) { makeReadyDeployment(), makeService(), makeReadyEndpoints(), - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS), + NewInMemoryChannel(imcName, testNS), }, WantErr: true, WithReactors: []clientgotesting.ReactionFunc{ InduceFailure("create", "Services"), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceNotReadyV1Beta1("ChannelServiceFailed", "Channel Service failed: inducing failure for create services"), + Object: NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceNotReady("ChannelServiceFailed", "Channel Service failed: inducing failure for create services"), ), }}, WantCreates: []runtime.Object{ - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "InternalError", "inducing failure for create services"), @@ -368,7 +367,7 @@ func TestAllCases(t *testing.T) { r := &Reconciler{ kubeClientSet: fakekubeclient.Get(ctx), systemNamespace: testNS, - inmemorychannelLister: listers.GetV1Beta1InMemoryChannelLister(), + inmemorychannelLister: listers.GetInMemoryChannelLister(), // TODO: FIx inmemorychannelInformer: nil, deploymentLister: listers.GetDeploymentLister(), @@ -376,7 +375,7 @@ func TestAllCases(t *testing.T) { endpointsLister: listers.GetEndpointsLister(), } return inmemorychannel.NewReconciler(ctx, logger, - fakeeventingclient.Get(ctx), listers.GetV1Beta1InMemoryChannelLister(), + fakeeventingclient.Get(ctx), listers.GetInMemoryChannelLister(), controller.GetEventRecorder(ctx), r) }, false, @@ -391,26 +390,26 @@ func TestInNamespace(t *testing.T) { Name: "Works, creates new service account, role binding, dispatcher deployment and service and channel", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, reconciletesting.WithInMemoryScopeAnnotationV1Beta1(eventing.ScopeNamespace)), - makeRoleBinding(systemNS, dispatcherName+"-"+testNS, "eventing-config-reader", reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + NewInMemoryChannel(imcName, testNS, WithInMemoryScopeAnnotation(eventing.ScopeNamespace)), + makeRoleBinding(systemNS, dispatcherName+"-"+testNS, "eventing-config-reader", NewInMemoryChannel(imcName, testNS)), makeReadyEndpoints(), }, WantErr: false, WantCreates: []runtime.Object{ - makeServiceAccount(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), - makeRoleBinding(testNS, dispatcherName, dispatcherName, reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), - makeDispatcherDeployment(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeServiceAccount(NewInMemoryChannel(imcName, testNS)), + makeRoleBinding(testNS, dispatcherName, dispatcherName, NewInMemoryChannel(imcName, testNS)), + makeDispatcherDeployment(NewInMemoryChannel(imcName, testNS)), makeDispatcherService(testNS), - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInMemoryScopeAnnotationV1Beta1(eventing.ScopeNamespace), - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress), + Object: NewInMemoryChannel(imcName, testNS, + WithInMemoryScopeAnnotation(eventing.ScopeNamespace), + WithInitInMemoryChannelConditions, + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress), ), }}, WantEvents: []string{ @@ -425,26 +424,26 @@ func TestInNamespace(t *testing.T) { Name: "Works, existing service account, role binding, dispatcher deployment and service, new channel", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, reconciletesting.WithInMemoryScopeAnnotationV1Beta1(eventing.ScopeNamespace)), - makeServiceAccount(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), - makeRoleBinding(testNS, dispatcherName, dispatcherName, reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), - makeRoleBinding(systemNS, dispatcherName+"-"+testNS, "eventing-config-reader", reconciletesting.NewInMemoryChannelV1Beta1(imcName, "knative-testing")), - makeDispatcherDeployment(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + NewInMemoryChannel(imcName, testNS, WithInMemoryScopeAnnotation(eventing.ScopeNamespace)), + makeServiceAccount(NewInMemoryChannel(imcName, testNS)), + makeRoleBinding(testNS, dispatcherName, dispatcherName, NewInMemoryChannel(imcName, testNS)), + makeRoleBinding(systemNS, dispatcherName+"-"+testNS, "eventing-config-reader", NewInMemoryChannel(imcName, "knative-testing")), + makeDispatcherDeployment(NewInMemoryChannel(imcName, testNS)), makeDispatcherService(testNS), makeReadyEndpoints(), }, WantErr: false, WantCreates: []runtime.Object{ - makeChannelService(reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS)), + makeChannelService(NewInMemoryChannel(imcName, testNS)), }, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInMemoryScopeAnnotationV1Beta1(eventing.ScopeNamespace), - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress), + Object: NewInMemoryChannel(imcName, testNS, + WithInMemoryScopeAnnotation(eventing.ScopeNamespace), + WithInitInMemoryChannelConditions, + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress), ), }}, WantEvents: []string{ @@ -459,7 +458,7 @@ func TestInNamespace(t *testing.T) { kubeClientSet: fakekubeclient.Get(ctx), dispatcherImage: imageName, systemNamespace: systemNS, - inmemorychannelLister: listers.GetV1Beta1InMemoryChannelLister(), + inmemorychannelLister: listers.GetInMemoryChannelLister(), // TODO: FIx inmemorychannelInformer: nil, deploymentLister: listers.GetDeploymentLister(), @@ -469,7 +468,7 @@ func TestInNamespace(t *testing.T) { roleBindingLister: listers.GetRoleBindingLister(), } return inmemorychannel.NewReconciler(ctx, logger, - fakeeventingclient.Get(ctx), listers.GetV1Beta1InMemoryChannelLister(), + fakeeventingclient.Get(ctx), listers.GetInMemoryChannelLister(), controller.GetEventRecorder(ctx), r) }, false, diff --git a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go index 1067f4841f7..a7e7f57bd93 100644 --- a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go +++ b/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel_test.go @@ -36,8 +36,7 @@ import ( duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/pkg/channel/multichannelfanout" - . "knative.dev/eventing/pkg/reconciler/testing" - reconciletesting "knative.dev/eventing/pkg/reconciler/testing" + . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" ) const ( @@ -78,27 +77,27 @@ func TestAllCases(t *testing.T) { Name: "updated configuration, one channel", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress)), + NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelAddress(channelServiceAddress)), }, WantErr: false, }, { Name: "with subscribers", Key: imcKey, Objects: []runtime.Object{ - reconciletesting.NewInMemoryChannelV1Beta1(imcName, testNS, - reconciletesting.WithInitInMemoryChannelConditionsV1Beta1, - reconciletesting.WithInMemoryChannelDeploymentReadyV1Beta1(), - reconciletesting.WithInMemoryChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelEndpointsReadyV1Beta1(), - reconciletesting.WithInMemoryChannelChannelServiceReadyV1Beta1(), - reconciletesting.WithInMemoryChannelSubscribersV1Beta1(subscribers), - reconciletesting.WithInMemoryChannelAddressV1Beta1(channelServiceAddress)), + NewInMemoryChannel(imcName, testNS, + WithInitInMemoryChannelConditions, + WithInMemoryChannelDeploymentReady(), + WithInMemoryChannelServiceReady(), + WithInMemoryChannelEndpointsReady(), + WithInMemoryChannelChannelServiceReady(), + WithInMemoryChannelSubscribers(subscribers), + WithInMemoryChannelAddress(channelServiceAddress)), }, WantErr: false, }, {}, @@ -107,14 +106,14 @@ func TestAllCases(t *testing.T) { logger := logtesting.TestLogger(t) table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { r := &Reconciler{ - inmemorychannelLister: listers.GetV1Beta1InMemoryChannelLister(), + inmemorychannelLister: listers.GetInMemoryChannelLister(), // TODO: FIx inmemorychannelInformer: nil, dispatcher: &fakeDispatcher{}, eventDispatcherConfigStore: channel.NewEventDispatcherConfigStore(logger), } return inmemorychannel.NewReconciler(ctx, logger, - fakeeventingclient.Get(ctx), listers.GetV1Beta1InMemoryChannelLister(), + fakeeventingclient.Get(ctx), listers.GetInMemoryChannelLister(), controller.GetEventRecorder(ctx), r) }, false, logger)) } diff --git a/pkg/reconciler/pingsource/pingsource_test.go b/pkg/reconciler/pingsource/pingsource_test.go index 494bce3c60a..299c5b9f657 100644 --- a/pkg/reconciler/pingsource/pingsource_test.go +++ b/pkg/reconciler/pingsource/pingsource_test.go @@ -45,6 +45,7 @@ import ( "knative.dev/pkg/tracker" . "knative.dev/eventing/pkg/reconciler/testing" + rtv1beta1 "knative.dev/eventing/pkg/reconciler/testing/v1beta1" _ "knative.dev/pkg/client/injection/ducks/duck/v1beta1/addressable/fake" . "knative.dev/pkg/reconciler/testing" ) @@ -55,7 +56,7 @@ var ( Name: sinkName, Namespace: testNS, Kind: "Channel", - APIVersion: "messaging.knative.dev/v1alpha1", + APIVersion: "messaging.knative.dev/v1beta1", }, } sinkDestURI = duckv1.Destination{ @@ -130,7 +131,7 @@ func TestAllCases(t *testing.T) { }}, WantEvents: []string{ Eventf(corev1.EventTypeWarning, "SinkNotFound", - `Sink not found: {"ref":{"kind":"Channel","namespace":"testnamespace","name":"testsink","apiVersion":"messaging.knative.dev/v1alpha1"}}`), + `Sink not found: {"ref":{"kind":"Channel","namespace":"testnamespace","name":"testsink","apiVersion":"messaging.knative.dev/v1beta1"}}`), }, }, { Name: "valid", @@ -145,9 +146,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapter(sinkDest), }, @@ -188,9 +189,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapter(sinkDest), }, @@ -231,9 +232,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapter(sinkDest), }, @@ -280,9 +281,9 @@ func TestAllCases(t *testing.T) { WithPingSourceSink(sinkURI), WithPingSourceEventType, ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapter(sinkDest), }, @@ -323,9 +324,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapter(sinkDest), }, @@ -366,9 +367,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableMTAdapter(), }, @@ -410,9 +411,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUID), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), }, Key: testNS + "/" + sourceName, @@ -457,9 +458,9 @@ func TestAllCases(t *testing.T) { WithPingSourceUID(sourceUIDLong), WithPingSourceObjectMetaGeneration(generation), ), - NewChannel(sinkName, testNS, - WithInitChannelConditions, - WithChannelAddress(sinkDNS), + rtv1beta1.NewChannel(sinkName, testNS, + rtv1beta1.WithInitChannelConditions, + rtv1beta1.WithChannelAddress(sinkDNS), ), makeAvailableReceiveAdapterDeprecatedName(sourceNameLong, sourceUIDLong, sinkDest), }, diff --git a/pkg/reconciler/subscription/subscription.go b/pkg/reconciler/subscription/subscription.go index c68b8672bca..afeb3915491 100644 --- a/pkg/reconciler/subscription/subscription.go +++ b/pkg/reconciler/subscription/subscription.go @@ -38,7 +38,6 @@ import ( eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" "knative.dev/eventing/pkg/apis/messaging" - "knative.dev/eventing/pkg/apis/messaging/v1alpha1" "knative.dev/eventing/pkg/apis/messaging/v1beta1" subscriptionreconciler "knative.dev/eventing/pkg/client/injection/reconciler/messaging/v1beta1/subscription" listers "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" @@ -58,8 +57,7 @@ const ( ) var ( - v1alpha1ChannelGVK = v1alpha1.SchemeGroupVersion.WithKind("Channel") - v1beta1ChannelGVK = v1beta1.SchemeGroupVersion.WithKind("Channel") + v1beta1ChannelGVK = v1beta1.SchemeGroupVersion.WithKind("Channel") ) func newReconciledNormal(namespace, name string) pkgreconciler.Event { @@ -363,8 +361,7 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) // Test to see if the channel is Channel.messaging because it is going // to have a "backing" channel that is what we need to actually operate on // as well as keep track of. - if (v1alpha1ChannelGVK.Group == gvk.Group && v1alpha1ChannelGVK.Kind == gvk.Kind) || - (v1beta1ChannelGVK.Group == gvk.Group && v1beta1ChannelGVK.Kind == gvk.Kind) { + if v1beta1ChannelGVK.Group == gvk.Group && v1beta1ChannelGVK.Kind == gvk.Kind { // Track changes on Channel. // Ref: https://github.com/knative/eventing/issues/2641 // NOTE: There is a race condition with using the channelableTracker @@ -414,19 +411,7 @@ func (r *Reconciler) getChannel(ctx context.Context, sub *v1beta1.Subscription) return nil, fmt.Errorf("Failed to convert to Channelable Object: %+v", obj) } - retCh := ch.DeepCopy() - gvk = retCh.GetObjectKind().GroupVersionKind() - // IMC has been know to lie about the duck version it supports. We know that - // v1alpha1 supports v1alpha1 Subscribable duck so override it here. - // If there are other channels that have this lying behaviour, add them here... - if gvk.Kind == "InMemoryChannel" && gvk.Version == "v1alpha1" { - if retCh.Annotations == nil { - retCh.Annotations = make(map[string]string) - } - retCh.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1alpha1" - } - - return retCh, nil + return ch.DeepCopy(), nil } func isNilOrEmptyDeliveryDeadLetterSink(delivery *eventingduckv1beta1.DeliverySpec) bool { diff --git a/pkg/reconciler/subscription/subscription_test.go b/pkg/reconciler/subscription/subscription_test.go index a31b3c51fc2..73ec2b94470 100644 --- a/pkg/reconciler/subscription/subscription_test.go +++ b/pkg/reconciler/subscription/subscription_test.go @@ -35,7 +35,6 @@ import ( clientgotesting "k8s.io/client-go/testing" eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduck "knative.dev/eventing/pkg/apis/duck/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelable" "knative.dev/eventing/pkg/client/injection/ducks/duck/v1alpha1/channelablecombined" @@ -51,10 +50,8 @@ import ( logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/resolver" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/channel/fake" - _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/inmemorychannel/fake" _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/channel/fake" - rt "knative.dev/eventing/pkg/reconciler/testing" + _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1beta1/inmemorychannel/fake" . "knative.dev/eventing/pkg/reconciler/testing/v1beta1" . "knative.dev/pkg/reconciler/testing" ) @@ -113,10 +110,10 @@ var ( Kind: "InMemoryChannel", } - imcV1Alpha1GVK = metav1.GroupVersionKind{ - Group: "messaging.knative.dev", + channelableV1Alpha1GVK = metav1.GroupVersionKind{ + Group: "duck.knative.dev", Version: "v1alpha1", - Kind: "InMemoryChannel", + Kind: "Channelable", } channelV1Beta1GVK = metav1.GroupVersionKind{ @@ -125,15 +122,9 @@ var ( Kind: "Channel", } - channelV1Alpha1GVK = metav1.GroupVersionKind{ - Group: "messaging.knative.dev", - Version: "v1alpha1", - Kind: "Channel", - } - - imcV1Alpha1KRef = duckv1.KReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "InMemoryChannel", + channelableV1Alpha1KRef = duckv1.KReference{ + APIVersion: "duck.knative.dev/v1alpha1", + Kind: "Channelable", Namespace: testNS, Name: channelName, } @@ -144,28 +135,14 @@ var ( Namespace: testNS, Name: channelName, } - - imcV1Alpha1Ref = corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "InMemoryChannel", - Namespace: testNS, - Name: channelName, - } - - imcV1Beta1Ref = corev1.ObjectReference{ - APIVersion: "messaging.knative.dev/v1beta1", - Kind: "InMemoryChannel", - Namespace: testNS, - Name: channelName, - } ) func init() { // Add types to scheme _ = eventingv1beta1.AddToScheme(scheme.Scheme) _ = duckv1alpha1.AddToScheme(scheme.Scheme) + _ = eventingduckv1alpha1.AddToScheme(scheme.Scheme) _ = apiextensionsv1beta1.AddToScheme(scheme.Scheme) - _ = messagingv1alpha1.AddToScheme(scheme.Scheme) _ = messagingv1beta1.AddToScheme(scheme.Scheme) } @@ -195,8 +172,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionPhysicalSubscriptionReply(replyURI), ), // Subscriber - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), // Reply NewInMemoryChannel(replyName, testNS, @@ -256,7 +233,7 @@ func TestAllCases(t *testing.T) { WithSubscriptionChannel(imcV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS), + NewUnstructured(subscriberGVK, subscriberName, testNS), }, Key: testNS + "/" + subscriptionName, WantEvents: []string{ @@ -284,7 +261,7 @@ func TestAllCases(t *testing.T) { WithSubscriptionChannel(imcV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS), + NewUnstructured(subscriberGVK, subscriberName, testNS), }, Key: testNS + "/" + subscriptionName, WantErr: true, @@ -316,7 +293,7 @@ func TestAllCases(t *testing.T) { WithSubscriptionChannel(imcV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS), + NewUnstructured(subscriberGVK, subscriberName, testNS), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, WithInMemoryChannelAddress(channelDNS), @@ -380,8 +357,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithSubscriptionReply(imcV1Beta1GVK, replyName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS)), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS)), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, WithInMemoryChannelAddress(channelDNS), @@ -416,14 +393,14 @@ func TestAllCases(t *testing.T) { WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithSubscriptionReply(nonAddressableGVK, replyName, testNS), // reply will be a nonAddressableGVK for this test ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, WithInMemoryChannelAddress(channelDNS), ), - rt.NewUnstructured(nonAddressableGVK, replyName, testNS), + NewUnstructured(nonAddressableGVK, replyName, testNS), }, Key: testNS + "/" + subscriptionName, WantEvents: []string{ @@ -453,8 +430,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionChannel(imcV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -488,21 +465,19 @@ func TestAllCases(t *testing.T) { patchFinalizers(testNS, subscriptionName), }, }, { - // Use v1alpha1 IMC to make sure the patch uses the v1alpha1 subscribable - Name: "v1alpha1 imc, valid channel+subscriber", + // Use v1alpha1 duck shaped Channelable to make sure the patch uses the v1alpha1 subscribable + Name: "v1alpha1 channelable, valid channel+subscriber", Objects: []runtime.Object{ NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelReadySubscriber(subscriptionUID), + NewChannelable(channelName, testNS, + WithChannelableReadySubscriber(subscriptionUID), ), }, Key: testNS + "/" + subscriptionName, @@ -514,7 +489,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), // The first reconciliation will initialize the status conditions. WithInitSubscriptionConditions, @@ -539,8 +514,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithSubscriptionDeliveryRef(subscriberGVK, dlcName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -578,11 +553,11 @@ func TestAllCases(t *testing.T) { WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithSubscriptionDeliveryRef(subscriberGVK, dlcName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), - rt.NewUnstructured(subscriberGVK, dlcName, testNS, - rt.WithUnstructuredAddressable(dlcDNS), + NewUnstructured(subscriberGVK, dlcName, testNS, + WithUnstructuredAddressable(dlcDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -617,27 +592,26 @@ func TestAllCases(t *testing.T) { patchFinalizers(testNS, subscriptionName), }, }, { - Name: "v1beta1 channel+v1beta1 imc backing channel+subscriber", + // Use v1beta1 Channel, v1alpha Channelable as backing channel to make sure that backing channel gets + // patched properly using v1alpha1 + Name: "v1beta1 channel+v1alpha1 channelable backing channel+subscriber", Objects: []runtime.Object{ NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), WithSubscriptionChannel(channelV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewChannel(channelName, testNS, WithInitChannelConditions, - WithBackingChannelObjRef(&imcV1Beta1KRef), + WithBackingChannelObjRef(&channelableV1Alpha1KRef), WithBackingChannelReady, WithChannelAddress("example.com"), ), - NewInMemoryChannel(channelName, testNS, - WithInitInMemoryChannelConditions, - WithInMemoryChannelAddress(channelDNS), - WithInMemoryChannelReadySubscriber(subscriptionUID), - WithInMemoryChannelReady("example.com"), + NewChannelable(channelName, testNS, + WithChannelableReadySubscriber(subscriptionUID), ), }, Key: testNS + "/" + subscriptionName, @@ -660,35 +634,33 @@ func TestAllCases(t *testing.T) { ), }}, WantPatches: []clientgotesting.PatchActionImpl{ - patchSubscribers(testNS, channelName, []eventingduck.SubscriberSpec{ + patchSubscribersV1Alpha1(testNS, channelName, []eventingduckv1alpha1.SubscriberSpec{ {UID: subscriptionUID, SubscriberURI: subscriberURI}, }), patchFinalizers(testNS, subscriptionName), }, }, { - // Use v1beta1 Channel, v1alpha IMC as backing channel to make sure that backing channel gets + // Use v1beta1 Channel, v1alpha Channelable as backing channel to make sure that backing channel gets // patched properly using v1alpha1 - Name: "v1beta1 channel+v1alpha1 imc backing channel+subscriber", + Name: "v1beta1 channel no annotation+v1alpha1 channelable backing channel+subscriber", Objects: []runtime.Object{ NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), WithSubscriptionChannel(channelV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewChannel(channelName, testNS, WithInitChannelConditions, - WithBackingChannelObjRef(&imcV1Alpha1KRef), + WithBackingChannelObjRef(&channelableV1Alpha1KRef), WithBackingChannelReady, WithChannelAddress("example.com"), + WithNoAnnotations, ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelReadySubscriber(subscriptionUID), - rt.WithInMemoryChannelReady("example.com"), + NewChannelable(channelName, testNS, + WithChannelableReadySubscriber(subscriptionUID), ), }, Key: testNS + "/" + subscriptionName, @@ -715,28 +687,17 @@ func TestAllCases(t *testing.T) { {UID: subscriptionUID, SubscriberURI: subscriberURI}, }), patchFinalizers(testNS, subscriptionName), - }, - }, { - // Use v1alpha1 Channel with v1beta1 IMC channel. - Name: "v1alpha1 channel+v1beta1 imc backing channel+subscriber", + }}, {}, { + Name: "v1beta1 channel+v1beta1 imc backing channel+subscriber", Objects: []runtime.Object{ NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(channelV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), - rt.NewChannel(channelName, testNS, - rt.WithInitChannelConditions, - rt.WithBackingChannelObjRef(&imcV1Beta1Ref), - rt.WithBackingChannelReady, - rt.WithChannelAddress("example.com"), - ), - // We need to create a fake v1beta1 object, since we use the v1beta1 lister - // in the actual code and our test infra won't set that up correctly. - // In real world, lister would find the correct version. NewChannel(channelName, testNS, WithInitChannelConditions, WithBackingChannelObjRef(&imcV1Beta1KRef), @@ -759,7 +720,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(channelV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), // The first reconciliation will initialize the status conditions. WithInitSubscriptionConditions, @@ -775,65 +736,6 @@ func TestAllCases(t *testing.T) { }), patchFinalizers(testNS, subscriptionName), }, - }, { - // Use v1alpha1 Channel with v1alpha1 IMC channel. - Name: "v1alpha1 channel+v1alpha1 imc backing channel+subscriber", - Objects: []runtime.Object{ - NewSubscription(subscriptionName, testNS, - WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(channelV1Alpha1GVK, channelName), - WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), - ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), - ), - rt.NewChannel(channelName, testNS, - rt.WithInitChannelConditions, - rt.WithBackingChannelObjRef(&imcV1Alpha1Ref), - rt.WithBackingChannelReady, - rt.WithChannelAddress("example.com"), - ), - // We need to create a fake v1beta1 object, since we use the v1beta1 lister - // in the actual code and our test infra won't set that up correctly. - // In real world, lister would find the correct version. - NewChannel(channelName, testNS, - WithInitChannelConditions, - WithBackingChannelObjRef(&imcV1Alpha1KRef), - WithBackingChannelReady, - WithChannelAddress("example.com"), - ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelReadySubscriber(subscriptionUID), - rt.WithInMemoryChannelReady("example.com"), - ), - }, - Key: testNS + "/" + subscriptionName, - WantErr: false, - WantEvents: []string{ - Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", subscriptionName), - Eventf(corev1.EventTypeNormal, "SubscriberSync", "Subscription was synchronized to channel %q", channelName), - }, - WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: NewSubscription(subscriptionName, testNS, - WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(channelV1Alpha1GVK, channelName), - WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), - // The first reconciliation will initialize the status conditions. - WithInitSubscriptionConditions, - MarkReferencesResolved, - MarkAddedToChannel, - - WithSubscriptionPhysicalSubscriptionSubscriber(subscriberURI), - ), - }}, - WantPatches: []clientgotesting.PatchActionImpl{ - patchSubscribersV1Alpha1(testNS, channelName, []eventingduckv1alpha1.SubscriberSpec{ - {UID: subscriptionUID, SubscriberURI: subscriberURI}, - }), - patchFinalizers(testNS, subscriptionName), - }, }, { Name: "v1beta1 channel+backing v1beta1 imc channel not ready+subscriber", Objects: []runtime.Object{ @@ -842,8 +744,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionChannel(channelV1Beta1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewChannel(channelName, testNS, WithInitChannelConditions, @@ -968,8 +870,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithSubscriptionReply(imcV1Beta1GVK, replyName, testNS), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -1020,8 +922,8 @@ func TestAllCases(t *testing.T) { MarkSubscriptionReady, WithSubscriptionPhysicalSubscriptionSubscriber(subscriberURI), ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -1118,7 +1020,7 @@ func TestAllCases(t *testing.T) { WithInMemoryChannelAddress(channelDNS), WithInMemoryChannelReadySubscriber(subscriptionUID), ), - rt.NewService(serviceName, testNS), + NewService(serviceName, testNS), }, Key: testNS + "/" + subscriptionName, WantErr: false, @@ -1167,7 +1069,7 @@ func TestAllCases(t *testing.T) { WithInMemoryChannelReadySubscriber("a-"+subscriptionUID), WithInMemoryChannelReadySubscriber("b-"+subscriptionUID), ), - rt.NewService(serviceName, testNS), + NewService(serviceName, testNS), }, Key: testNS + "/" + "a-" + subscriptionName, WantErr: false, @@ -1203,8 +1105,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionDeliveryRef(subscriberGVK, dlcName, testNS), WithSubscriptionDeadLetterSinkURI(dlcURI), ), - rt.NewUnstructured(subscriberGVK, dlcName, testNS, - rt.WithUnstructuredAddressable(dlcDNS), + NewUnstructured(subscriberGVK, dlcName, testNS, + WithUnstructuredAddressable(dlcDNS), ), // an already rec'ed subscription NewSubscription("b-"+subscriptionName, testNS, @@ -1224,7 +1126,7 @@ func TestAllCases(t *testing.T) { WithInMemoryChannelReadySubscriber("a-"+subscriptionUID), WithInMemoryChannelReadySubscriber("b-"+subscriptionUID), ), - rt.NewService(serviceName, testNS), + NewService(serviceName, testNS), }, Key: testNS + "/" + "a-" + subscriptionName, WantErr: false, @@ -1253,30 +1155,28 @@ func TestAllCases(t *testing.T) { patchFinalizers(testNS, "a-"+subscriptionName), }, }, { - Name: "v1alpha1 imc+two subscribers for a channel", + Name: "v1alpha1 channelable+two subscribers for a channel", Objects: []runtime.Object{ NewSubscription("a-"+subscriptionName, testNS, WithSubscriptionUID("a-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), ), // an already rec'ed subscription NewSubscription("b-"+subscriptionName, testNS, WithSubscriptionUID("b-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), WithInitSubscriptionConditions, MarkSubscriptionReady, WithSubscriptionPhysicalSubscriptionSubscriber(serviceURIWithPath), ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelSubscribers([]eventingduckv1alpha1.SubscriberSpec{{UID: "b-" + subscriptionUID}}), - rt.WithInMemoryChannelReadySubscriber("a-"+subscriptionUID), - rt.WithInMemoryChannelReadySubscriber("b-"+subscriptionUID), + NewChannelable(channelName, testNS, + WithChannelableSubscribers([]eventingduckv1alpha1.SubscriberSpec{{UID: "b-" + subscriptionUID}}), + WithChannelableReadySubscriber("a-"+subscriptionUID), + WithChannelableReadySubscriber("b-"+subscriptionUID), ), - rt.NewService(serviceName, testNS), + NewService(serviceName, testNS), }, Key: testNS + "/" + "a-" + subscriptionName, WantErr: false, @@ -1287,7 +1187,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSubscription("a-"+subscriptionName, testNS, WithSubscriptionUID("a-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), // The first reconciliation will initialize the status conditions. WithInitSubscriptionConditions, @@ -1304,30 +1204,28 @@ func TestAllCases(t *testing.T) { patchFinalizers(testNS, "a-"+subscriptionName), }, }, { - Name: "v1alpha1 imc+two subscribers for a channel - updated", + Name: "v1alpha1 channelable+two subscribers for a channel - updated", Objects: []runtime.Object{ NewSubscription("a-"+subscriptionName, testNS, WithSubscriptionUID("a-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), ), // an already rec'ed subscription NewSubscription("b-"+subscriptionName, testNS, WithSubscriptionUID("b-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), WithInitSubscriptionConditions, MarkSubscriptionReady, WithSubscriptionPhysicalSubscriptionSubscriber(serviceURIWithPath), ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelSubscribers([]eventingduckv1alpha1.SubscriberSpec{{UID: "b-" + subscriptionUID}, {UID: "a-" + subscriptionUID}}), - rt.WithInMemoryChannelReadySubscriber("a-"+subscriptionUID), - rt.WithInMemoryChannelReadySubscriber("b-"+subscriptionUID), + NewChannelable(channelName, testNS, + WithChannelableSubscribers([]eventingduckv1alpha1.SubscriberSpec{{UID: "b-" + subscriptionUID}, {UID: "a-" + subscriptionUID}}), + WithChannelableReadySubscriber("a-"+subscriptionUID), + WithChannelableReadySubscriber("b-"+subscriptionUID), ), - rt.NewService(serviceName, testNS), + NewService(serviceName, testNS), }, Key: testNS + "/" + "a-" + subscriptionName, WantErr: false, @@ -1338,7 +1236,7 @@ func TestAllCases(t *testing.T) { WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ Object: NewSubscription("a-"+subscriptionName, testNS, WithSubscriptionUID("a-"+subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(serviceGVK, serviceName, testNS), // The first reconciliation will initialize the status conditions. WithInitSubscriptionConditions, @@ -1367,8 +1265,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionPhysicalSubscriptionSubscriber(serviceURI), WithSubscriptionDeleted, ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -1389,11 +1287,11 @@ func TestAllCases(t *testing.T) { patchRemoveFinalizers(testNS, subscriptionName), }, }, { - Name: "v1alpha1 imc+deleted - channel patch succeeded", + Name: "v1alpha1 channelable+deleted - channel patch succeeded", Objects: []runtime.Object{ NewSubscription(subscriptionName, testNS, WithSubscriptionUID(subscriptionUID), - WithSubscriptionChannel(imcV1Alpha1GVK, channelName), + WithSubscriptionChannel(channelableV1Alpha1GVK, channelName), WithSubscriptionSubscriberRef(subscriberGVK, subscriberName, testNS), WithInitSubscriptionConditions, MarkSubscriptionReady, @@ -1401,13 +1299,11 @@ func TestAllCases(t *testing.T) { WithSubscriptionPhysicalSubscriptionSubscriber(serviceURI), WithSubscriptionDeleted, ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), - rt.NewInMemoryChannel(channelName, testNS, - rt.WithInitInMemoryChannelConditions, - rt.WithInMemoryChannelAddress(channelDNS), - rt.WithInMemoryChannelSubscribers([]eventingduckv1alpha1.SubscriberSpec{ + NewChannelable(channelName, testNS, + WithChannelableSubscribers([]eventingduckv1alpha1.SubscriberSpec{ {UID: subscriptionUID, SubscriberURI: subscriberURI}, }), ), @@ -1435,8 +1331,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionPhysicalSubscriptionSubscriber(serviceURI), WithSubscriptionDeleted, ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), NewInMemoryChannel(channelName, testNS, WithInitInMemoryChannelConditions, @@ -1484,8 +1380,8 @@ func TestAllCases(t *testing.T) { WithSubscriptionPhysicalSubscriptionSubscriber(serviceURI), WithSubscriptionDeleted, ), - rt.NewUnstructured(subscriberGVK, subscriberName, testNS, - rt.WithUnstructuredAddressable(subscriberDNS), + NewUnstructured(subscriberGVK, subscriberName, testNS, + WithUnstructuredAddressable(subscriberDNS), ), }, Key: testNS + "/" + subscriptionName, diff --git a/pkg/reconciler/testing/channel.go b/pkg/reconciler/testing/channel.go deleted file mode 100644 index 54f84006fa5..00000000000 --- a/pkg/reconciler/testing/channel.go +++ /dev/null @@ -1,261 +0,0 @@ -/* -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 testing - -import ( - "context" - "time" - - "k8s.io/apimachinery/pkg/types" - - v1 "k8s.io/api/core/v1" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" -) - -// ChannelOption enables further configuration of a Channel. -type ChannelOptionV1Beta1 func(*v1beta1.Channel) - -// NewChannel creates a Channel with ChannelOptions -func NewChannelV1Beta1(name, namespace string, o ...ChannelOptionV1Beta1) *v1beta1.Channel { - c := &v1beta1.Channel{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1beta1", - Kind: "Channel", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - for _, opt := range o { - opt(c) - } - c.SetDefaults(context.Background()) - return c -} - -// WithInitChannelConditions initializes the Channel's conditions. -func WithInitChannelConditionsV1Beta1(c *v1beta1.Channel) { - c.Status.InitializeConditions() -} - -func WithChannelGenerationV1Beta1(gen int64) ChannelOptionV1Beta1 { - return func(s *v1beta1.Channel) { - s.Generation = gen - } -} -func WithChannelObservedGenerationV1Beta1(gen int64) ChannelOptionV1Beta1 { - return func(s *v1beta1.Channel) { - s.Status.ObservedGeneration = gen - } -} - -func WithChannelDeletedV1Beta1(c *v1beta1.Channel) { - t := metav1.NewTime(time.Unix(1e9, 0)) - c.ObjectMeta.SetDeletionTimestamp(&t) -} - -func WithChannelTemplateV1Beta1(typeMeta metav1.TypeMeta) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Spec.ChannelTemplate = &messagingv1beta1.ChannelTemplateSpec{ - TypeMeta: typeMeta, - } - } -} - -func WithBackingChannelFailedV1Beta1(reason, msg string) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.MarkBackingChannelFailed(reason, msg) - } -} - -func WithBackingChannelUnknownV1Beta1(reason, msg string) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.MarkBackingChannelUnknown(reason, msg) - } -} - -func WithBackingChannelReadyV1Beta1(c *v1beta1.Channel) { - c.Status.MarkBackingChannelReady() -} - -func WithBackingChannelObjRefV1Beta1(objRef *duckv1.KReference) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.Channel = objRef - } -} - -func WithChannelNoAddressV1Beta1() ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.SetAddress(nil) - } -} - -func WithChannelAddressV1Beta1(hostname string) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.SetAddress(&duckv1.Addressable{URL: apis.HTTP(hostname)}) - } -} - -func WithChannelReadySubscriberV1Beta1(uid string) ChannelOptionV1Beta1 { - return WithChannelReadySubscriberAndGenerationV1Beta1(uid, 0) -} - -func WithChannelReadySubscriberAndGenerationV1Beta1(uid string, observedGeneration int64) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.Subscribers = append(c.Status.Subscribers, eventingduckv1beta1.SubscriberStatus{ - UID: types.UID(uid), - ObservedGeneration: observedGeneration, - Ready: v1.ConditionTrue, - }) - } -} - -func WithChannelSubscriberStatusesV1Beta1(subscriberStatuses []eventingduckv1beta1.SubscriberStatus) ChannelOptionV1Beta1 { - return func(c *v1beta1.Channel) { - c.Status.Subscribers = subscriberStatuses - } -} - -// ChannelOption enables further configuration of a Channel. -type ChannelOption func(*v1alpha1.Channel) - -// NewChannel creates a Channel with ChannelOptions -func NewChannel(name, namespace string, o ...ChannelOption) *v1alpha1.Channel { - c := &v1alpha1.Channel{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "messaging.knative.dev/v1alpha1", - Kind: "Channel", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - for _, opt := range o { - opt(c) - } - c.SetDefaults(context.Background()) - return c -} - -// WithInitChannelConditions initializes the Channel's conditions. -func WithInitChannelConditions(c *v1alpha1.Channel) { - c.Status.InitializeConditions() -} - -func WithChannelGeneration(gen int64) ChannelOption { - return func(s *v1alpha1.Channel) { - s.Generation = gen - } -} -func WithChannelObservedGeneration(gen int64) ChannelOption { - return func(s *v1alpha1.Channel) { - s.Status.ObservedGeneration = gen - } -} - -func WithChannelDeleted(c *v1alpha1.Channel) { - t := metav1.NewTime(time.Unix(1e9, 0)) - c.ObjectMeta.SetDeletionTimestamp(&t) -} - -func WithChannelTemplate(typeMeta metav1.TypeMeta) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Spec.ChannelTemplate = &messagingv1beta1.ChannelTemplateSpec{ - TypeMeta: typeMeta, - } - } -} - -func WithBackingChannelFailed(reason, msg string) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.MarkBackingChannelFailed(reason, msg) - } -} - -func WithBackingChannelUnknown(reason, msg string) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.MarkBackingChannelUnknown(reason, msg) - } -} - -func WithBackingChannelReady(c *v1alpha1.Channel) { - c.Status.MarkBackingChannelReady() -} - -func WithBackingChannelObjRef(objRef *v1.ObjectReference) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.Channel = objRef - } -} - -func WithChannelNoAddress() ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.SetAddress(nil) - } -} - -func WithChannelAddress(hostname string) ChannelOption { - return func(c *v1alpha1.Channel) { - address := &duckv1alpha1.Addressable{ - Addressable: duckv1beta1.Addressable{ - URL: &apis.URL{ - Scheme: "http", - Host: hostname, - }, - }, - } - c.Status.SetAddress(address) - } -} - -func WithChannelReadySubscriber(uid string) ChannelOption { - return WithChannelReadySubscriberAndGeneration(uid, 0) -} - -func WithChannelReadySubscriberAndGeneration(uid string, observedGeneration int64) ChannelOption { - return func(c *v1alpha1.Channel) { - if c.Status.GetSubscribableTypeStatus() == nil { // Both the SubscribableStatus fields are nil - c.Status.SetSubscribableTypeStatus(eventingduckv1alpha1.SubscribableStatus{}) - } - c.Status.SubscribableTypeStatus.AddSubscriberToSubscribableStatus(eventingduckv1beta1.SubscriberStatus{ - UID: types.UID(uid), - ObservedGeneration: observedGeneration, - Ready: v1.ConditionTrue, - }) - } -} - -func WithChannelSubscriberStatuses(subscriberStatuses []eventingduckv1beta1.SubscriberStatus) ChannelOption { - return func(c *v1alpha1.Channel) { - c.Status.SetSubscribableTypeStatus(eventingduckv1alpha1.SubscribableStatus{ - Subscribers: subscriberStatuses, - }) - } -} diff --git a/pkg/reconciler/testing/inmemorychannel.go b/pkg/reconciler/testing/inmemorychannel.go deleted file mode 100644 index eb0fee0583e..00000000000 --- a/pkg/reconciler/testing/inmemorychannel.go +++ /dev/null @@ -1,355 +0,0 @@ -/* -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 testing - -import ( - "context" - "time" - - "k8s.io/apimachinery/pkg/types" - - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - "knative.dev/eventing/pkg/apis/eventing" - "knative.dev/eventing/pkg/apis/messaging" - "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - "knative.dev/eventing/pkg/apis/messaging/v1beta1" - "knative.dev/pkg/apis" -) - -// InMemoryChannelOptionV1Beta1 enables further configuration of a v1beta1.InMemoryChannel. -type InMemoryChannelOptionV1Beta1 func(*v1beta1.InMemoryChannel) - -// NewInMemoryChannelV1Beta1 creates a v1beta1.InMemoryChannel with InMemoryChannelOptionV1Beta1 . -func NewInMemoryChannelV1Beta1(name, namespace string, imcopt ...InMemoryChannelOptionV1Beta1) *v1beta1.InMemoryChannel { - imc := &v1beta1.InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - Spec: v1beta1.InMemoryChannelSpec{}, - } - for _, opt := range imcopt { - opt(imc) - } - imc.SetDefaults(context.Background()) - return imc -} - -func WithInitInMemoryChannelConditionsV1Beta1(imc *v1beta1.InMemoryChannel) { - imc.Status.InitializeConditions() -} - -func WithInMemoryChannelDuckAnnotationV1Beta1(imc *v1beta1.InMemoryChannel) { - annotations := map[string]string{ - messaging.SubscribableDuckVersionAnnotation: "v1beta1", - } - imc.ObjectMeta.SetAnnotations(annotations) - -} - -func WithInMemoryChannelDuckAnnotationV1Alpha1(imc *v1alpha1.InMemoryChannel) { - annotations := map[string]string{ - messaging.SubscribableDuckVersionAnnotation: "v1alpha1", - } - imc.ObjectMeta.SetAnnotations(annotations) - -} - -func WithInMemoryChannelGenerationV1Beta1(gen int64) InMemoryChannelOptionV1Beta1 { - return func(s *v1beta1.InMemoryChannel) { - s.Generation = gen - } -} - -func WithInMemoryChannelStatusObservedGenerationV1Beta1(gen int64) InMemoryChannelOptionV1Beta1 { - return func(s *v1beta1.InMemoryChannel) { - s.Status.ObservedGeneration = gen - } -} - -func WithInMemoryChannelDeletedV1Beta1(imc *v1beta1.InMemoryChannel) { - deleteTime := metav1.NewTime(time.Unix(1e9, 0)) - imc.ObjectMeta.SetDeletionTimestamp(&deleteTime) -} - -func WithInMemoryChannelSubscribersV1Beta1(subscribers []duckv1beta1.SubscriberSpec) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Spec.Subscribers = subscribers - } -} - -func WithInMemoryChannelDeploymentFailedV1Beta1(reason, message string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkDispatcherFailed(reason, message) - } -} - -func WithInMemoryChannelDeploymentUnknownV1Beta1(reason, message string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkDispatcherUnknown(reason, message) - } -} - -func WithInMemoryChannelDeploymentReadyV1Beta1() InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.PropagateDispatcherStatus(&appsv1.DeploymentStatus{Conditions: []appsv1.DeploymentCondition{{Type: appsv1.DeploymentAvailable, Status: corev1.ConditionTrue}}}) - } -} - -func WithInMemoryChannelServicetNotReadyV1Beta1(reason, message string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkServiceFailed(reason, message) - } -} - -func WithInMemoryChannelServiceReadyV1Beta1() InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkServiceTrue() - } -} - -func WithInMemoryChannelChannelServiceNotReadyV1Beta1(reason, message string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkChannelServiceFailed(reason, message) - } -} - -func WithInMemoryChannelChannelServiceReadyV1Beta1() InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkChannelServiceTrue() - } -} - -func WithInMemoryChannelEndpointsNotReadyV1Beta1(reason, message string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkEndpointsFailed(reason, message) - } -} - -func WithInMemoryChannelEndpointsReadyV1Beta1() InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.MarkEndpointsTrue() - } -} - -func WithInMemoryChannelAddressV1Beta1(a string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.SetAddress(&apis.URL{ - Scheme: "http", - Host: a, - }) - } -} - -func WithInMemoryChannelReadyV1Beta1(host string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.SetAddress(&apis.URL{ - Scheme: "http", - Host: host, - }) - imc.Status.MarkChannelServiceTrue() - imc.Status.MarkEndpointsTrue() - imc.Status.MarkServiceTrue() - } -} - -func WithInMemoryChannelReadySubscriberV1Beta1(uid string) InMemoryChannelOptionV1Beta1 { - return WithInMemoryChannelReadySubscriberAndGenerationV1Beta1(uid, 0) -} - -func WithInMemoryChannelReadySubscriberAndGenerationV1Beta1(uid string, observedGeneration int64) InMemoryChannelOptionV1Beta1 { - return func(c *v1beta1.InMemoryChannel) { - c.Status.Subscribers = append(c.Status.Subscribers, duckv1beta1.SubscriberStatus{ - UID: types.UID(uid), - ObservedGeneration: observedGeneration, - Ready: corev1.ConditionTrue, - }) - } -} - -func WithInMemoryChannelStatusSubscribersV1Beta1(subscriberStatuses []duckv1beta1.SubscriberStatus) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - imc.Status.Subscribers = subscriberStatuses - } -} - -func WithInMemoryScopeAnnotationV1Beta1(value string) InMemoryChannelOptionV1Beta1 { - return func(imc *v1beta1.InMemoryChannel) { - if imc.Annotations == nil { - imc.Annotations = make(map[string]string) - } - imc.Annotations[eventing.ScopeAnnotationKey] = value - } -} - -// InMemoryChannelOption enables further configuration of a InMemoryChannel. -type InMemoryChannelOption func(*v1alpha1.InMemoryChannel) - -// NewInMemoryChannel creates an InMemoryChannel with InMemoryChannelOptions. -func NewInMemoryChannel(name, namespace string, imcopt ...InMemoryChannelOption) *v1alpha1.InMemoryChannel { - imc := &v1alpha1.InMemoryChannel{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - Spec: v1alpha1.InMemoryChannelSpec{}, - } - for _, opt := range imcopt { - opt(imc) - } - imc.SetDefaults(context.Background()) - return imc -} - -func WithInitInMemoryChannelConditions(imc *v1alpha1.InMemoryChannel) { - imc.Status.InitializeConditions() -} - -func WithInMemoryChannelGeneration(gen int64) InMemoryChannelOption { - return func(s *v1alpha1.InMemoryChannel) { - s.Generation = gen - } -} - -func WithInMemoryChannelStatusObservedGeneration(gen int64) InMemoryChannelOption { - return func(s *v1alpha1.InMemoryChannel) { - s.Status.ObservedGeneration = gen - } -} - -func WithInMemoryChannelDeleted(imc *v1alpha1.InMemoryChannel) { - deleteTime := metav1.NewTime(time.Unix(1e9, 0)) - imc.ObjectMeta.SetDeletionTimestamp(&deleteTime) -} - -func WithInMemoryChannelSubscribers(subscribers []duckv1alpha1.SubscriberSpec) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Spec.Subscribable = &duckv1alpha1.Subscribable{Subscribers: subscribers} - } -} - -func WithInMemoryChannelDeploymentFailed(reason, message string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkDispatcherFailed(reason, message) - } -} - -func WithInMemoryChannelDeploymentUnknown(reason, message string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkDispatcherUnknown(reason, message) - } -} - -func WithInMemoryChannelDeploymentReady() InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.PropagateDispatcherStatus(&appsv1.DeploymentStatus{Conditions: []appsv1.DeploymentCondition{{Type: appsv1.DeploymentAvailable, Status: corev1.ConditionTrue}}}) - } -} - -func WithInMemoryChannelServicetNotReady(reason, message string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkServiceFailed(reason, message) - } -} - -func WithInMemoryChannelServiceReady() InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkServiceTrue() - } -} - -func WithInMemoryChannelChannelServiceNotReady(reason, message string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkChannelServiceFailed(reason, message) - } -} - -func WithInMemoryChannelChannelServiceReady() InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkChannelServiceTrue() - } -} - -func WithInMemoryChannelEndpointsNotReady(reason, message string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkEndpointsFailed(reason, message) - } -} - -func WithInMemoryChannelEndpointsReady() InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.MarkEndpointsTrue() - } -} - -func WithInMemoryChannelAddress(a string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.SetAddress(&apis.URL{ - Scheme: "http", - Host: a, - }) - } -} - -func WithInMemoryChannelReady(host string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.SetAddress(&apis.URL{ - Scheme: "http", - Host: host, - }) - imc.Status.MarkChannelServiceTrue() - imc.Status.MarkEndpointsTrue() - imc.Status.MarkServiceTrue() - } -} - -func WithInMemoryChannelReadySubscriber(uid string) InMemoryChannelOption { - return WithInMemoryChannelReadySubscriberAndGeneration(uid, 0) -} - -func WithInMemoryChannelReadySubscriberAndGeneration(uid string, observedGeneration int64) InMemoryChannelOption { - return func(c *v1alpha1.InMemoryChannel) { - if c.Status.GetSubscribableTypeStatus() == nil { // Both the SubscribableStatus fields are nil - c.Status.SetSubscribableTypeStatus(duckv1alpha1.SubscribableStatus{}) - } - c.Status.SubscribableTypeStatus.AddSubscriberToSubscribableStatus(duckv1beta1.SubscriberStatus{ - UID: types.UID(uid), - ObservedGeneration: observedGeneration, - Ready: corev1.ConditionTrue, - }) - } -} - -func WithInMemoryChannelStatusSubscribers(subscriberStatuses []duckv1beta1.SubscriberStatus) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - imc.Status.SetSubscribableTypeStatus(duckv1alpha1.SubscribableStatus{ - Subscribers: subscriberStatuses}) - } -} - -func WithInMemoryScopeAnnotation(value string) InMemoryChannelOption { - return func(imc *v1alpha1.InMemoryChannel) { - if imc.Annotations == nil { - imc.Annotations = make(map[string]string) - } - imc.Annotations[eventing.ScopeAnnotationKey] = value - } -} diff --git a/pkg/reconciler/testing/listers.go b/pkg/reconciler/testing/listers.go index 0c1dc11463b..dea33a99159 100644 --- a/pkg/reconciler/testing/listers.go +++ b/pkg/reconciler/testing/listers.go @@ -34,7 +34,6 @@ import ( configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2" @@ -42,7 +41,6 @@ import ( configslisters "knative.dev/eventing/pkg/client/listers/configs/v1alpha1" eventingv1beta1listers "knative.dev/eventing/pkg/client/listers/eventing/v1beta1" flowslisters "knative.dev/eventing/pkg/client/listers/flows/v1beta1" - messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" messaginglistersv1beta1 "knative.dev/eventing/pkg/client/listers/messaging/v1beta1" sourcelisters "knative.dev/eventing/pkg/client/listers/sources/v1alpha1" sourcev1alpha2listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2" @@ -124,10 +122,6 @@ func (l *Listers) GetV1Beta1SubscriptionLister() messaginglistersv1beta1.Subscri return messaginglistersv1beta1.NewSubscriptionLister(l.indexerFor(&messagingv1beta1.Subscription{})) } -func (l *Listers) GetSubscriptionLister() messaginglisters.SubscriptionLister { - return messaginglisters.NewSubscriptionLister(l.indexerFor(&messagingv1alpha1.Subscription{})) -} - func (l *Listers) GetFlowsSequenceLister() flowslisters.SequenceLister { return flowslisters.NewSequenceLister(l.indexerFor(&flowsv1beta1.Sequence{})) } @@ -144,18 +138,10 @@ func (l *Listers) GetV1Beta1EventTypeLister() eventingv1beta1listers.EventTypeLi return eventingv1beta1listers.NewEventTypeLister(l.indexerFor(&eventingv1beta1.EventType{})) } -func (l *Listers) GetInMemoryChannelLister() messaginglisters.InMemoryChannelLister { - return messaginglisters.NewInMemoryChannelLister(l.indexerFor(&messagingv1alpha1.InMemoryChannel{})) -} - func (l *Listers) GetV1Beta1InMemoryChannelLister() messaginglistersv1beta1.InMemoryChannelLister { return messaginglistersv1beta1.NewInMemoryChannelLister(l.indexerFor(&messagingv1beta1.InMemoryChannel{})) } -func (l *Listers) GetMessagingChannelLister() messaginglisters.ChannelLister { - return messaginglisters.NewChannelLister(l.indexerFor(&messagingv1alpha1.Channel{})) -} - func (l *Listers) GetV1Beta1MessagingChannelLister() messaginglistersv1beta1.ChannelLister { return messaginglistersv1beta1.NewChannelLister(l.indexerFor(&messagingv1beta1.Channel{})) } diff --git a/pkg/reconciler/testing/subscription.go b/pkg/reconciler/testing/subscription.go deleted file mode 100644 index 77fd8d60810..00000000000 --- a/pkg/reconciler/testing/subscription.go +++ /dev/null @@ -1,233 +0,0 @@ -/* -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 testing - -import ( - "context" - "errors" - "time" - - "k8s.io/apimachinery/pkg/types" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" - "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -// SubscriptionOption enables further configuration of a Subscription. -type SubscriptionOption func(*v1alpha1.Subscription) - -// NewSubscription creates a Subscription with SubscriptionOptions -func NewSubscription(name, namespace string, so ...SubscriptionOption) *v1alpha1.Subscription { - s := &v1alpha1.Subscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - for _, opt := range so { - opt(s) - } - s.SetDefaults(context.Background()) - return s -} - -// NewSubscriptionWithoutNamespace creates a Subscription with SubscriptionOptions but without a specific namespace -func NewSubscriptionWithoutNamespace(name string, so ...SubscriptionOption) *v1alpha1.Subscription { - s := &v1alpha1.Subscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - for _, opt := range so { - opt(s) - } - s.SetDefaults(context.Background()) - return s -} - -func WithSubscriptionUID(uid types.UID) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.UID = uid - } -} - -func WithSubscriptionGeneration(gen int64) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Generation = gen - } -} - -func WithSubscriptionStatusObservedGeneration(gen int64) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Status.ObservedGeneration = gen - } -} - -func WithSubscriptionGenerateName(generateName string) SubscriptionOption { - return func(c *v1alpha1.Subscription) { - c.ObjectMeta.GenerateName = generateName - } -} - -// WithInitSubscriptionConditions initializes the Subscriptions's conditions. -func WithInitSubscriptionConditions(s *v1alpha1.Subscription) { - s.Status.InitializeConditions() -} - -func WithSubscriptionReady(s *v1alpha1.Subscription) { - s.Status = *eventingv1beta1.TestHelper.ReadySubscriptionStatusV1Alpha1() -} - -// TODO: this can be a runtime object -func WithSubscriptionDeleted(s *v1alpha1.Subscription) { - t := metav1.NewTime(time.Unix(1e9, 0)) - s.ObjectMeta.SetDeletionTimestamp(&t) -} - -func WithSubscriptionOwnerReferences(ownerReferences []metav1.OwnerReference) SubscriptionOption { - return func(c *v1alpha1.Subscription) { - c.ObjectMeta.OwnerReferences = ownerReferences - } -} - -func WithSubscriptionLabels(labels map[string]string) SubscriptionOption { - return func(c *v1alpha1.Subscription) { - c.ObjectMeta.Labels = labels - } -} - -func WithSubscriptionChannel(gvk metav1.GroupVersionKind, name string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Spec.Channel = corev1.ObjectReference{ - APIVersion: apiVersion(gvk), - Kind: gvk.Kind, - Name: name, - } - } -} - -func WithSubscriptionSubscriberRef(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Spec.Subscriber = &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: apiVersion(gvk), - Kind: gvk.Kind, - Name: name, - Namespace: namespace, - }, - } - } -} - -func WithSubscriptionDeliveryRef(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Spec.Delivery = &duckv1beta1.DeliverySpec{ - DeadLetterSink: &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: apiVersion(gvk), - Kind: gvk.Kind, - Name: name, - Namespace: namespace, - }, - }, - } - } -} - -func WithSubscriptionPhysicalSubscriptionSubscriber(uri *apis.URL) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - if uri == nil { - panic(errors.New("nil URI")) - } - s.Status.PhysicalSubscription.SubscriberURI = uri - } -} - -func WithSubscriptionPhysicalSubscriptionReply(uri *apis.URL) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - if uri == nil { - panic(errors.New("nil URI")) - } - s.Status.PhysicalSubscription.ReplyURI = uri - } -} - -func WithSubscriptionDeadLetterSinkURI(uri *apis.URL) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - if uri == nil { - panic(errors.New("nil URI")) - } - s.Status.PhysicalSubscription.DeadLetterSinkURI = uri - } -} - -func WithSubscriptionFinalizers(finalizers ...string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Finalizers = finalizers - } -} - -func MarkSubscriptionReady(s *v1alpha1.Subscription) { - s.Status.MarkChannelReady() - s.Status.MarkReferencesResolved() - s.Status.MarkAddedToChannel() -} - -func MarkAddedToChannel(s *v1alpha1.Subscription) { - s.Status.MarkAddedToChannel() -} - -func MarkNotAddedToChannel(reason, msg string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Status.MarkNotAddedToChannel(reason, msg) - } -} - -func MarkReferencesResolved(s *v1alpha1.Subscription) { - s.Status.MarkReferencesResolved() -} - -func WithSubscriptionReferencesNotResolved(reason, msg string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Status.MarkReferencesNotResolved(reason, msg) - } -} - -func WithSubscriptionReferencesResolvedUnknown(reason, msg string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Status.MarkReferencesResolvedUnknown(reason, msg) - } -} - -func WithSubscriptionReply(gvk metav1.GroupVersionKind, name, namespace string) SubscriptionOption { - return func(s *v1alpha1.Subscription) { - s.Spec.Reply = &duckv1.Destination{ - Ref: &duckv1.KReference{ - APIVersion: apiVersion(gvk), - Kind: gvk.Kind, - Name: name, - Namespace: namespace, - }, - } - } -} diff --git a/pkg/reconciler/testing/v1beta1/channel.go b/pkg/reconciler/testing/v1beta1/channel.go index 9ed34344020..8a40744f536 100644 --- a/pkg/reconciler/testing/v1beta1/channel.go +++ b/pkg/reconciler/testing/v1beta1/channel.go @@ -60,6 +60,10 @@ func WithInitChannelConditions(c *v1beta1.Channel) { c.Status.InitializeConditions() } +func WithNoAnnotations(c *v1beta1.Channel) { + c.ObjectMeta.Annotations = nil +} + func WithChannelGeneration(gen int64) ChannelOption { return func(s *v1beta1.Channel) { s.Generation = gen diff --git a/pkg/reconciler/testing/v1beta1/channelable.go b/pkg/reconciler/testing/v1beta1/channelable.go new file mode 100644 index 00000000000..d8e24f72b5e --- /dev/null +++ b/pkg/reconciler/testing/v1beta1/channelable.go @@ -0,0 +1,113 @@ +/* +Copyright 2020 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 testing + +import ( + "time" + + "k8s.io/apimachinery/pkg/types" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/pkg/apis/duck/v1alpha1" + duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" + "knative.dev/eventing/pkg/apis/messaging" + "knative.dev/pkg/apis" + pkgduckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" + pkgduckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" +) + +// Channelable allows us to have a fake channel for testing that implements a v1alpha1.Channelable type. + +// ChannelableOption enables further configuration of a v1alpha1.Channelable. +type ChannelableOption func(*v1alpha1.Channelable) + +// NewChannelable creates an Channelable with ChannelableOptions. +func NewChannelable(name, namespace string, imcopt ...ChannelableOption) *v1alpha1.Channelable { + c := &v1alpha1.Channelable{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + Annotations: map[string]string{messaging.SubscribableDuckVersionAnnotation: "v1alpha1"}, + }, + Spec: v1alpha1.ChannelableSpec{}, + } + for _, opt := range imcopt { + opt(c) + } + return c +} + +func WithChannelableGeneration(gen int64) ChannelableOption { + return func(s *v1alpha1.Channelable) { + s.Generation = gen + } +} + +func WithChannelableStatusObservedGeneration(gen int64) ChannelableOption { + return func(s *v1alpha1.Channelable) { + s.Status.ObservedGeneration = gen + } +} + +func WithChannelableDeleted(imc *v1alpha1.Channelable) { + deleteTime := metav1.NewTime(time.Unix(1e9, 0)) + imc.ObjectMeta.SetDeletionTimestamp(&deleteTime) +} + +func WithChannelableSubscribers(subscribers []v1alpha1.SubscriberSpec) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Spec.Subscribable = &v1alpha1.Subscribable{Subscribers: subscribers} + } +} + +func WithChannelableReadySubscriber(uid string) ChannelableOption { + return WithChannelableReadySubscriberAndGeneration(uid, 0) +} + +func WithChannelableReadySubscriberAndGeneration(uid string, observedGeneration int64) ChannelableOption { + return func(c *v1alpha1.Channelable) { + if c.Status.GetSubscribableTypeStatus() == nil { // Both the SubscribableStatus fields are nil + c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{}) + } + c.Status.SubscribableTypeStatus.AddSubscriberToSubscribableStatus(duckv1beta1.SubscriberStatus{ + UID: types.UID(uid), + ObservedGeneration: observedGeneration, + Ready: corev1.ConditionTrue, + }) + } +} + +func WithChannelableStatusSubscribers(subscriberStatuses []duckv1beta1.SubscriberStatus) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.SetSubscribableTypeStatus(v1alpha1.SubscribableStatus{ + Subscribers: subscriberStatuses}) + } +} + +func WithChannelableReady() ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.Conditions = []apis.Condition{apis.Condition{Type: apis.ConditionReady, Status: corev1.ConditionTrue}} + } +} + +func WithChannelableAddress(a string) ChannelableOption { + return func(c *v1alpha1.Channelable) { + c.Status.Address = &pkgduckv1alpha1.Addressable{ + Addressable: pkgduckv1beta1.Addressable{ + URL: apis.HTTP(a), + }, + } + } +} diff --git a/pkg/reconciler/testing/v1beta1/inmemorychannel.go b/pkg/reconciler/testing/v1beta1/inmemorychannel.go index a7a9e796b5c..9507e77b424 100644 --- a/pkg/reconciler/testing/v1beta1/inmemorychannel.go +++ b/pkg/reconciler/testing/v1beta1/inmemorychannel.go @@ -174,6 +174,14 @@ func WithInMemoryChannelStatusSubscribers(subscriberStatuses []duckv1beta1.Subsc } } +func WithInMemoryChannelDuckAnnotationV1Beta1(imc *v1beta1.InMemoryChannel) { + annotations := map[string]string{ + messaging.SubscribableDuckVersionAnnotation: "v1beta1", + } + imc.ObjectMeta.SetAnnotations(annotations) + +} + func WithInMemoryScopeAnnotation(value string) InMemoryChannelOption { return func(imc *v1beta1.InMemoryChannel) { if imc.Annotations == nil { diff --git a/pkg/reconciler/testing/v1beta1/listers.go b/pkg/reconciler/testing/v1beta1/listers.go index e31dec5eae5..a36927e107b 100644 --- a/pkg/reconciler/testing/v1beta1/listers.go +++ b/pkg/reconciler/testing/v1beta1/listers.go @@ -32,6 +32,7 @@ import ( rbacv1listers "k8s.io/client-go/listers/rbac/v1" "k8s.io/client-go/tools/cache" configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1" + eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" @@ -64,6 +65,7 @@ var clientSetSchemes = []func(*runtime.Scheme) error{ fakeapiextensionsclientset.AddToScheme, subscriberAddToScheme, sourceAddToScheme, + eventingduckv1alpha1.AddToScheme, } type Listers struct { diff --git a/pkg/reconciler/testing/v1beta1/service.go b/pkg/reconciler/testing/v1beta1/service.go new file mode 100644 index 00000000000..1eb8817d1dc --- /dev/null +++ b/pkg/reconciler/testing/v1beta1/service.go @@ -0,0 +1,62 @@ +/* +Copyright 2020 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 testing + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// ServiceOption enables further configuration of a Service. +type ServiceOption func(*corev1.Service) + +// NewService creates a Service with ServiceOptions +func NewService(name, namespace string, so ...ServiceOption) *corev1.Service { + s := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: corev1.ServiceSpec{}, + } + for _, opt := range so { + opt(s) + } + return s +} + +func WithServiceOwnerReferences(ownerReferences []metav1.OwnerReference) ServiceOption { + return func(s *corev1.Service) { + s.OwnerReferences = ownerReferences + } +} + +func WithServiceLabels(labels map[string]string) ServiceOption { + return func(s *corev1.Service) { + s.ObjectMeta.Labels = labels + s.Spec.Selector = labels + } +} + +func WithServicePorts(ports []corev1.ServicePort) ServiceOption { + return func(s *corev1.Service) { + s.Spec.Ports = ports + } +} + +func WithServiceAnnotations(annotations map[string]string) ServiceOption { + return func(s *corev1.Service) { + s.ObjectMeta.Annotations = annotations + } +} diff --git a/pkg/reconciler/testing/v1beta1/subscription.go b/pkg/reconciler/testing/v1beta1/subscription.go index 1d5c4a55c4e..0866df4920f 100644 --- a/pkg/reconciler/testing/v1beta1/subscription.go +++ b/pkg/reconciler/testing/v1beta1/subscription.go @@ -231,11 +231,3 @@ func WithSubscriptionReply(gvk metav1.GroupVersionKind, name, namespace string) } } } - -func apiVersion(gvk metav1.GroupVersionKind) string { - groupVersion := gvk.Version - if gvk.Group != "" { - groupVersion = gvk.Group + "/" + gvk.Version - } - return groupVersion -} diff --git a/pkg/reconciler/testing/v1beta1/unstructured.go b/pkg/reconciler/testing/v1beta1/unstructured.go new file mode 100644 index 00000000000..60b3f6d48d5 --- /dev/null +++ b/pkg/reconciler/testing/v1beta1/unstructured.go @@ -0,0 +1,68 @@ +/* +Copyright 2020 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 testing + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// UnstructuredOption enables further configuration of a Unstructured. +type UnstructuredOption func(*unstructured.Unstructured) + +// NewUnstructured creates a unstructured.Unstructured with UnstructuredOption +func NewUnstructured(gvk metav1.GroupVersionKind, name, namespace string, uo ...UnstructuredOption) *unstructured.Unstructured { + u := &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": apiVersion(gvk), + "kind": gvk.Kind, + "metadata": map[string]interface{}{ + "namespace": namespace, + "name": name, + }, + "spec": map[string]interface{}{}, + "status": map[string]interface{}{}, + }, + } + for _, opt := range uo { + opt(u) + } + return u +} + +func WithUnstructuredAddressable(hostname string) UnstructuredOption { + return func(u *unstructured.Unstructured) { + status, ok := u.Object["status"].(map[string]interface{}) + if ok { + status["address"] = map[string]interface{}{ + "hostname": hostname, + "url": fmt.Sprintf("http://%s", hostname), + } + } + } +} + +func apiVersion(gvk metav1.GroupVersionKind) string { + groupVersion := gvk.Version + if gvk.Group != "" { + groupVersion = gvk.Group + "/" + gvk.Version + } + return groupVersion +} diff --git a/test/conformance/helpers/channel.go b/test/conformance/helpers/channel.go index a574ef4dd53..0750fae6c3b 100644 --- a/test/conformance/helpers/channel.go +++ b/test/conformance/helpers/channel.go @@ -26,7 +26,6 @@ import ( eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1" eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) @@ -35,13 +34,7 @@ const ( ) var ( - channelv1alpha1GVK = (&messagingv1alpha1.Channel{}).GetGroupVersionKind() - channelv1beta1GVK = (&messagingv1beta1.Channel{}).GetGroupVersionKind() - - channelv1alpha1 = metav1.TypeMeta{ - Kind: channelv1alpha1GVK.Kind, - APIVersion: channelv1alpha1GVK.GroupVersion().String(), - } + channelv1beta1GVK = (&messagingv1beta1.Channel{}).GetGroupVersionKind() channelv1beta1 = metav1.TypeMeta{ Kind: channelv1beta1GVK.Kind, diff --git a/test/conformance/helpers/channel_spec_test_helper.go b/test/conformance/helpers/channel_spec_test_helper.go index 191714cb872..0e3c4928be7 100644 --- a/test/conformance/helpers/channel_spec_test_helper.go +++ b/test/conformance/helpers/channel_spec_test_helper.go @@ -43,7 +43,7 @@ func ChannelSpecTestHelperWithChannelTestRunner( defer lib.TearDown(client) t.Run("Channel spec allows subscribers", func(t *testing.T) { - if channel == channelv1alpha1 || channel == channelv1beta1 { + if channel == channelv1beta1 { t.Skip("Not running spec.subscribers array test for generic Channel") } channelSpecAllowsSubscribersArray(st, client, channel) diff --git a/test/conformance/helpers/channel_status_subscriber_test_helper.go b/test/conformance/helpers/channel_status_subscriber_test_helper.go index 1474211e9ad..0e982c8c6f5 100644 --- a/test/conformance/helpers/channel_status_subscriber_test_helper.go +++ b/test/conformance/helpers/channel_status_subscriber_test_helper.go @@ -20,7 +20,7 @@ import ( "testing" duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" - eventingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" + eventingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/eventing/test/lib" "knative.dev/eventing/test/lib/resources" @@ -118,7 +118,7 @@ func channelHasRequiredSubscriberStatus(st *testing.T, client *lib.Client, chann } } -func findSubscriberStatus(statusArr []duckv1beta1.SubscriberStatus, subscription *eventingv1alpha1.Subscription) *duckv1beta1.SubscriberStatus { +func findSubscriberStatus(statusArr []duckv1beta1.SubscriberStatus, subscription *eventingv1beta1.Subscription) *duckv1beta1.SubscriberStatus { for _, v := range statusArr { if v.UID == subscription.UID { return &v diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 80445d4e28a..adb66e808ff 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -35,6 +35,6 @@ initialize $@ --skip-istio-addon install_mt_broker || fail_test "Could not install MT Channel Based Broker" echo "Running tests with Multi Tenant Channel Based Broker" -go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1alpha1:InMemoryChannel,messaging.knative.dev/v1alpha1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel || fail_test +go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel || fail_test success diff --git a/test/e2e/channel_single_event_test.go b/test/e2e/channel_single_event_test.go index ccf990f5db9..dc7f795fdc1 100644 --- a/test/e2e/channel_single_event_test.go +++ b/test/e2e/channel_single_event_test.go @@ -33,26 +33,6 @@ EventSource ---> Channel ---> Subscription ---> Service(Logger) */ -func TestSingleBinaryEventForChannel(t *testing.T) { - helpers.SingleEventForChannelTestHelper( - t, - cloudevents.EncodingBinary, - helpers.SubscriptionV1alpha1, - "", - channelTestRunner, - ) -} - -func TestSingleStructuredEventForChannel(t *testing.T) { - helpers.SingleEventForChannelTestHelper( - t, - cloudevents.EncodingStructured, - helpers.SubscriptionV1alpha1, - "", - channelTestRunner, - ) -} - func TestSingleBinaryEventForChannelV1Beta1(t *testing.T) { helpers.SingleEventForChannelTestHelper( t, @@ -63,16 +43,6 @@ func TestSingleBinaryEventForChannelV1Beta1(t *testing.T) { ) } -func TestSingleBinaryEventForChannelV1Beta1SubscribeToV1Alpha1(t *testing.T) { - helpers.SingleEventForChannelTestHelper( - t, - cloudevents.EncodingBinary, - helpers.SubscriptionV1beta1, - "messaging.knative.dev/v1alpha1", - channelTestRunner, - ) -} - func TestSingleStructuredEventForChannelV1Beta1(t *testing.T) { helpers.SingleEventForChannelTestHelper( t, diff --git a/test/e2e/helpers/channel_defaulter_test_helper.go b/test/e2e/helpers/channel_defaulter_test_helper.go index 8473514868a..b11aedf0e66 100644 --- a/test/e2e/helpers/channel_defaulter_test_helper.go +++ b/test/e2e/helpers/channel_defaulter_test_helper.go @@ -28,7 +28,7 @@ import ( eventingduck "knative.dev/eventing/pkg/apis/duck/v1alpha1" "knative.dev/eventing/pkg/apis/messaging/config" - eventingtesting "knative.dev/eventing/pkg/reconciler/testing" + eventingtesting "knative.dev/eventing/pkg/reconciler/testing/v1beta1" "knative.dev/eventing/test/lib" "knative.dev/eventing/test/lib/cloudevents" "knative.dev/eventing/test/lib/duck" diff --git a/test/e2e/helpers/channel_single_event_helper.go b/test/e2e/helpers/channel_single_event_helper.go index 6a2e790bf75..8f929066101 100644 --- a/test/e2e/helpers/channel_single_event_helper.go +++ b/test/e2e/helpers/channel_single_event_helper.go @@ -32,8 +32,7 @@ import ( type SubscriptionVersion string const ( - SubscriptionV1alpha1 SubscriptionVersion = "v1alpha1" - SubscriptionV1beta1 SubscriptionVersion = "v1beta1" + SubscriptionV1beta1 SubscriptionVersion = "v1beta1" ) // SingleEventForChannelTestHelper is the helper function for channel_single_event_test @@ -76,20 +75,15 @@ func SingleEventForChannelTestHelper(t *testing.T, encoding cloudevents.Encoding } // create subscription to subscribe the channel, and forward the received events to the logger service switch subscriptionVersion { - case SubscriptionV1alpha1: + case SubscriptionV1beta1: client.CreateSubscriptionOrFail( subscriptionName, channelName, &channel, resources.WithSubscriberForSubscription(eventRecorder), ) - case SubscriptionV1beta1: - client.CreateSubscriptionOrFailV1Beta1( - subscriptionName, - channelName, - &channel, - resources.WithSubscriberForSubscriptionV1Beta1(eventRecorder), - ) + default: + t.Fatalf("Invalid subscription version") } // wait for all test resources to be ready, so that we can start sending events diff --git a/test/lib/creation.go b/test/lib/creation.go index 66d4db3913f..9705f4b1e41 100644 --- a/test/lib/creation.go +++ b/test/lib/creation.go @@ -30,7 +30,7 @@ import ( "knative.dev/eventing/pkg/apis/eventing/v1beta1" flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" "knative.dev/eventing/pkg/utils" "knative.dev/eventing/test/lib/duck" @@ -67,9 +67,9 @@ func (c *Client) CreateChannelsOrFail(names []string, channelTypeMeta *metav1.Ty } // CreateChannelWithDefaultOrFail will create a default Channel Resource in Eventing or fail the test if there is an error. -func (c *Client) CreateChannelWithDefaultOrFail(channel *messagingv1alpha1.Channel) { +func (c *Client) CreateChannelWithDefaultOrFail(channel *messagingv1beta1.Channel) { c.T.Logf("Creating default channel %+v", channel) - channels := c.Eventing.MessagingV1alpha1().Channels(c.Namespace) + channels := c.Eventing.MessagingV1beta1().Channels(c.Namespace) _, err := channels.Create(channel) if err != nil { c.T.Fatalf("Failed to create channel %q: %v", channel.Name, err) @@ -79,29 +79,10 @@ func (c *Client) CreateChannelWithDefaultOrFail(channel *messagingv1alpha1.Chann // CreateSubscriptionOrFail will create a Subscription or fail the test if there is an error. func (c *Client) CreateSubscriptionOrFail( - name, channelName string, - channelTypeMeta *metav1.TypeMeta, - options ...resources.SubscriptionOption, -) *messagingv1alpha1.Subscription { - namespace := c.Namespace - subscription := resources.Subscription(name, channelName, channelTypeMeta, options...) - subscriptions := c.Eventing.MessagingV1alpha1().Subscriptions(namespace) - c.T.Logf("Creating subscription %s for channel %+v-%s", name, channelTypeMeta, channelName) - // update subscription with the new reference - subscription, err := subscriptions.Create(subscription) - if err != nil { - c.T.Fatalf("Failed to create subscription %q: %v", name, err) - } - c.Tracker.AddObj(subscription) - return subscription -} - -// CreateSubscriptionOrFailV1Beta1 will create a Subscription or fail the test if there is an error. -func (c *Client) CreateSubscriptionOrFailV1Beta1( name, channelName string, channelTypeMeta *metav1.TypeMeta, options ...resources.SubscriptionOptionV1Beta1, -) { +) *messagingv1beta1.Subscription { namespace := c.Namespace subscription := resources.SubscriptionV1Beta1(name, channelName, channelTypeMeta, options...) subscriptions := c.Eventing.MessagingV1beta1().Subscriptions(namespace) @@ -112,6 +93,7 @@ func (c *Client) CreateSubscriptionOrFailV1Beta1( c.T.Fatalf("Failed to create subscription %q: %v", name, err) } c.Tracker.AddObj(subscription) + return subscription } // CreateSubscriptionsOrFail will create a list of Subscriptions with the same configuration except the name. @@ -119,7 +101,7 @@ func (c *Client) CreateSubscriptionsOrFail( names []string, channelName string, channelTypeMeta *metav1.TypeMeta, - options ...resources.SubscriptionOption, + options ...resources.SubscriptionOptionV1Beta1, ) { c.T.Logf("Creating subscriptions %v for channel %+v-%s", names, channelTypeMeta, channelName) for _, name := range names { diff --git a/test/lib/resources/eventing.go b/test/lib/resources/eventing.go index 58902782890..85ced726fc7 100644 --- a/test/lib/resources/eventing.go +++ b/test/lib/resources/eventing.go @@ -29,7 +29,6 @@ import ( eventingduckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" ) @@ -39,9 +38,6 @@ type BrokerV1Beta1Option func(*eventingv1beta1.Broker) // TriggerOptionV1Beta1 enables further configuration of a v1beta1 Trigger. type TriggerOptionV1Beta1 func(*eventingv1beta1.Trigger) -// SubscriptionOption enables further configuration of a Subscription. -type SubscriptionOption func(*messagingv1alpha1.Subscription) - // SubscriptionOptionV1Beta1 enables further configuration of a Subscription. type SubscriptionOptionV1Beta1 func(*messagingv1beta1.Subscription) @@ -71,20 +67,9 @@ func KnativeRefForBroker(name, namespace string) *duckv1.KReference { } } -// WithSubscriberForSubscription returns an option that adds a Subscriber for the given Subscription. -func WithSubscriberForSubscription(name string) SubscriptionOption { - return func(s *messagingv1alpha1.Subscription) { - if name != "" { - s.Spec.Subscriber = &duckv1.Destination{ - Ref: KnativeRefForService(name, ""), - } - } - } -} - -// WithSubscriberForSubscriptionV1Beta1 returns an option that adds a Subscriber for the given +// WithSubscriberForSubscription returns an option that adds a Subscriber for the given // v1beta1 Subscription. -func WithSubscriberForSubscriptionV1Beta1(name string) SubscriptionOptionV1Beta1 { +func WithSubscriberForSubscription(name string) SubscriptionOptionV1Beta1 { return func(s *messagingv1beta1.Subscription) { if name != "" { s.Spec.Subscriber = &duckv1.Destination{ @@ -95,8 +80,8 @@ func WithSubscriberForSubscriptionV1Beta1(name string) SubscriptionOptionV1Beta1 } // WithReplyForSubscription returns an options that adds a ReplyStrategy for the given Subscription. -func WithReplyForSubscription(name string, typemeta *metav1.TypeMeta) SubscriptionOption { - return func(s *messagingv1alpha1.Subscription) { +func WithReplyForSubscription(name string, typemeta *metav1.TypeMeta) SubscriptionOptionV1Beta1 { + return func(s *messagingv1beta1.Subscription) { if name != "" { s.Spec.Reply = &duckv1.Destination{ Ref: &duckv1.KReference{ @@ -110,8 +95,8 @@ func WithReplyForSubscription(name string, typemeta *metav1.TypeMeta) Subscripti } // WithDeadLetterSinkForSubscription returns an options that adds a DeadLetterSink for the given Subscription. -func WithDeadLetterSinkForSubscription(name string) SubscriptionOption { - return func(s *messagingv1alpha1.Subscription) { +func WithDeadLetterSinkForSubscription(name string) SubscriptionOptionV1Beta1 { + return func(s *messagingv1beta1.Subscription) { if name != "" { delivery := s.Spec.Delivery if delivery == nil { @@ -127,26 +112,6 @@ func WithDeadLetterSinkForSubscription(name string) SubscriptionOption { } } -// Subscription returns a Subscription. -func Subscription( - name, channelName string, - channelTypeMeta *metav1.TypeMeta, - options ...SubscriptionOption, -) *messagingv1alpha1.Subscription { - subscription := &messagingv1alpha1.Subscription{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - Spec: messagingv1alpha1.SubscriptionSpec{ - Channel: *channelRef(channelName, channelTypeMeta), - }, - } - for _, option := range options { - option(subscription) - } - return subscription -} - // SubscriptionV1Beta1 returns a v1beta1 Subscription. func SubscriptionV1Beta1( name, channelName string, diff --git a/test/upgrade/smoke_test.go b/test/upgrade/smoke_test.go index da67fb6d9de..59a49cc4df6 100644 --- a/test/upgrade/smoke_test.go +++ b/test/upgrade/smoke_test.go @@ -26,7 +26,7 @@ func runSmokeTest(t *testing.T) { helpers.SingleEventForChannelTestHelper( t, cloudevents.EncodingBinary, - helpers.SubscriptionV1alpha1, + helpers.SubscriptionV1beta1, "", channelTestRunner, ) diff --git a/vendor/k8s.io/code-generator/generate-groups.sh b/vendor/k8s.io/code-generator/generate-groups.sh old mode 100644 new mode 100755 diff --git a/vendor/knative.dev/pkg/hack/generate-knative.sh b/vendor/knative.dev/pkg/hack/generate-knative.sh old mode 100644 new mode 100755