Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
add channel
Browse files Browse the repository at this point in the history
  • Loading branch information
grac3gao committed May 26, 2020
1 parent 4efdd80 commit 2b159a6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
55 changes: 29 additions & 26 deletions pkg/reconciler/messaging/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan
genName := resources.GenerateSubscriptionName(s.UID)

ps := resources.MakePullSubscription(&resources.PullSubscriptionArgs{
Owner: channel,
Name: genName,
Project: channel.Spec.Project,
Topic: channel.Status.TopicID,
ServiceAccount: channel.Spec.GoogleServiceAccount,
Secret: channel.Spec.Secret,
Labels: resources.GetPullSubscriptionLabels(controllerAgentName, channel.Name, genName, string(channel.UID)),
Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, clusterName),
Subscriber: s,
Owner: channel,
Name: genName,
Project: channel.Spec.Project,
Topic: channel.Status.TopicID,
ServiceAccount: channel.Spec.GoogleServiceAccount,
ServiceAccountName: channel.Spec.ServiceAccountName,
Secret: channel.Spec.Secret,
Labels: resources.GetPullSubscriptionLabels(controllerAgentName, channel.Name, genName, string(channel.UID)),
Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, clusterName),
Subscriber: s,
})
ps, err := r.RunClientSet.InternalV1alpha1().PullSubscriptions(channel.Namespace).Create(ps)
if apierrs.IsAlreadyExists(err) {
Expand All @@ -194,15 +195,16 @@ func (r *Reconciler) syncSubscribers(ctx context.Context, channel *v1alpha1.Chan
genName := resources.GenerateSubscriptionName(s.UID)

ps := resources.MakePullSubscription(&resources.PullSubscriptionArgs{
Owner: channel,
Name: genName,
Project: channel.Spec.Project,
Topic: channel.Status.TopicID,
ServiceAccount: channel.Spec.GoogleServiceAccount,
Secret: channel.Spec.Secret,
Labels: resources.GetPullSubscriptionLabels(controllerAgentName, channel.Name, genName, string(channel.UID)),
Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, clusterName),
Subscriber: s,
Owner: channel,
Name: genName,
Project: channel.Spec.Project,
Topic: channel.Status.TopicID,
ServiceAccount: channel.Spec.GoogleServiceAccount,
ServiceAccountName: channel.Spec.ServiceAccountName,
Secret: channel.Spec.Secret,
Labels: resources.GetPullSubscriptionLabels(controllerAgentName, channel.Name, genName, string(channel.UID)),
Annotations: resources.GetPullSubscriptionAnnotations(channel.Name, clusterName),
Subscriber: s,
})

existingPs, found := pullsubs[genName]
Expand Down Expand Up @@ -309,14 +311,15 @@ func (r *Reconciler) reconcileTopic(ctx context.Context, channel *v1alpha1.Chann
}
clusterName := channel.GetAnnotations()[duckv1alpha1.ClusterNameAnnotation]
t := resources.MakeTopic(&resources.TopicArgs{
Owner: channel,
Name: resources.GeneratePublisherName(channel),
Project: channel.Spec.Project,
ServiceAccount: channel.Spec.GoogleServiceAccount,
Secret: channel.Spec.Secret,
Topic: resources.GenerateTopicID(channel.UID),
Labels: resources.GetLabels(controllerAgentName, channel.Name, string(channel.UID)),
Annotations: resources.GetTopicAnnotations(clusterName),
Owner: channel,
Name: resources.GeneratePublisherName(channel),
Project: channel.Spec.Project,
ServiceAccount: channel.Spec.GoogleServiceAccount,
ServiceAccountName: channel.Spec.ServiceAccountName,
Secret: channel.Spec.Secret,
Topic: resources.GenerateTopicID(channel.UID),
Labels: resources.GetLabels(controllerAgentName, channel.Name, string(channel.UID)),
Annotations: resources.GetTopicAnnotations(clusterName),
})

topic, err = r.RunClientSet.InternalV1alpha1().Topics(channel.Namespace).Create(t)
Expand Down
20 changes: 11 additions & 9 deletions pkg/reconciler/messaging/channel/resources/pullsubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import (
// PullSubscriptionArgs are the arguments needed to create a Channel Subscriber.
// Every field is required.
type PullSubscriptionArgs struct {
Owner kmeta.OwnerRefable
Name string
Project string
Topic string
ServiceAccount string
Secret *corev1.SecretKeySelector
Labels map[string]string
Annotations map[string]string
Subscriber duckv1alpha1.SubscriberSpec
Owner kmeta.OwnerRefable
Name string
Project string
Topic string
ServiceAccount string
ServiceAccountName string
Secret *corev1.SecretKeySelector
Labels map[string]string
Annotations map[string]string
Subscriber duckv1alpha1.SubscriberSpec
}

// MakePullSubscription generates (but does not insert into K8s) the
Expand All @@ -50,6 +51,7 @@ func MakePullSubscription(args *PullSubscriptionArgs) *v1alpha1.PullSubscription
SourceSpec: duckv1.SourceSpec{},
IdentitySpec: gcpduckv1alpha1.IdentitySpec{
GoogleServiceAccount: args.ServiceAccount,
ServiceAccountName: args.ServiceAccountName,
},
Secret: args.Secret,
Project: args.Project,
Expand Down
18 changes: 10 additions & 8 deletions pkg/reconciler/messaging/channel/resources/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ import (
// TopicArgs are the arguments needed to create a Channel Topic.
// Every field is required.
type TopicArgs struct {
Owner kmeta.OwnerRefable
Name string
Project string
Topic string
ServiceAccount string
Secret *corev1.SecretKeySelector
Labels map[string]string
Annotations map[string]string
Owner kmeta.OwnerRefable
Name string
Project string
Topic string
ServiceAccount string

This comment has been minimized.

Copy link
@nachocano

nachocano May 26, 2020

Member

I think this one is the old one that we never used and can be removed? Same in other places
If you want in a follow up so that we get this in asap

This comment has been minimized.

Copy link
@nachocano

nachocano May 26, 2020

Member

my bad, that is the GSA... confusing name.. discard the comment

ServiceAccountName string
Secret *corev1.SecretKeySelector
Labels map[string]string
Annotations map[string]string
}

// MakeInvoker generates (but does not insert into K8s) the Topic for Channels.
Expand All @@ -52,6 +53,7 @@ func MakeTopic(args *TopicArgs) *v1alpha1.Topic {
Spec: v1alpha1.TopicSpec{
IdentitySpec: duckv1alpha1.IdentitySpec{
GoogleServiceAccount: args.ServiceAccount,
ServiceAccountName: args.ServiceAccountName,
},
Secret: args.Secret,
Project: args.Project,
Expand Down

0 comments on commit 2b159a6

Please sign in to comment.