Skip to content

Commit

Permalink
fix: use gateway namespace for secrets if namespace is not mentioned …
Browse files Browse the repository at this point in the history
…in event source (#569)
  • Loading branch information
VaibhavPage authored Mar 30, 2020
1 parent b1a3e2b commit 739f169
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 10 deletions.
6 changes: 5 additions & 1 deletion gateways/server/azure-events-hub/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ func main() {
panic(err)
}
clientset := kubernetes.NewForConfigOrDie(restConfig)

namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
server.StartGateway(&azure_events_hub.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
5 changes: 5 additions & 0 deletions gateways/server/azure-events-hub/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type EventListener struct {
Logger *logrus.Logger
// k8sClient is kubernetes client
K8sClient kubernetes.Interface
Namespace string
}

func (listener *EventListener) StartEventSource(eventSource *gateways.EventSource, eventStream gateways.Eventing_StartEventSourceServer) error {
Expand Down Expand Up @@ -67,6 +68,10 @@ func (listener *EventListener) listenEvents(eventSource *gateways.EventSource, c
return errors.Wrapf(err, "failed to parsed the event source %s", eventSource.Name)
}

if hubEventSource.Namespace == "" {
hubEventSource.Namespace = listener.Namespace
}

logger.Infoln("retrieving the shared access key name...")
sharedAccessKeyName, err := common.GetSecrets(listener.K8sClient, hubEventSource.Namespace, hubEventSource.SharedAccessKeyName)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions gateways/server/emitter/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ func main() {
if err != nil {
panic(err)
}
namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
server.StartGateway(&emitter.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
7 changes: 6 additions & 1 deletion gateways/server/emitter/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type EventListener struct {
// K8sClient is the kubernetes client
K8sClient kubernetes.Interface
// Logger to log stuff
Logger *logrus.Logger
Logger *logrus.Logger
Namespace string
}

// StartEventSource starts an event source
Expand Down Expand Up @@ -69,6 +70,10 @@ func (listener *EventListener) listenEvents(eventSource *gateways.EventSource, c
return errors.Wrapf(err, "failed to parse the event source %s", eventSource.Name)
}

if emitterEventSource.Namespace == "" {
emitterEventSource.Namespace = listener.Namespace
}

var options []func(client *emitter.Client)
options = append(options, emitter.WithBrokers(emitterEventSource.Broker), emitter.WithAutoReconnect(true))

Expand Down
5 changes: 5 additions & 0 deletions gateways/server/hdfs/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ func main() {
if err != nil {
panic(err)
}
namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
server.StartGateway(&hdfs.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
5 changes: 5 additions & 0 deletions gateways/server/hdfs/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type EventListener struct {
Logger *logrus.Logger
// k8sClient is kubernetes client
K8sClient kubernetes.Interface
Namespace string
}

// WatchableHDFS wraps hdfs.Client for naivewatcher
Expand Down Expand Up @@ -77,6 +78,10 @@ func (listener *EventListener) listenEvents(eventSource *gateways.EventSource, c
return errors.Wrapf(err, "failed to parse event source %s", eventSource.Name)
}

if hdfsEventSource.Namespace == "" {
hdfsEventSource.Namespace = listener.Namespace
}

logger.Infoln("setting up HDFS configuration...")
hdfsConfig, err := createHDFSConfig(listener.K8sClient, hdfsEventSource.Namespace, hdfsEventSource)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions gateways/server/redis/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ func main() {
if err != nil {
panic(err)
}
namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
server.StartGateway(&redis.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
5 changes: 5 additions & 0 deletions gateways/server/redis/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type EventListener struct {
Logger *logrus.Logger
// K8sClient is the kubernetes client
K8sClient kubernetes.Interface
Namespace string
}

// StartEventSource starts an event source
Expand Down Expand Up @@ -68,6 +69,10 @@ func (listener *EventListener) listenEvents(eventSource *gateways.EventSource, c
return errors.Wrapf(err, "failed to parse the event source %s", eventSource.Name)
}

if redisEventSource.Namespace == "" {
redisEventSource.Namespace = listener.Namespace
}

logger.Infoln("retrieving password if it has been configured...")
password, err := listener.getPassword(redisEventSource)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions gateways/server/slack/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ func main() {
if err != nil {
panic(err)
}
namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
server.StartGateway(&slack.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
4 changes: 4 additions & 0 deletions gateways/server/slack/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ func (listener *EventListener) StartEventSource(eventSource *gateways.EventSourc
return err
}

if slackEventSource.Namespace == "" {
slackEventSource.Namespace = listener.Namespace
}

logger.Infoln("retrieving the slack token...")
token, err := store.GetSecrets(listener.K8sClient, slackEventSource.Namespace, slackEventSource.Token.Name, slackEventSource.Token.Key)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion gateways/server/slack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type EventListener struct {
// K8sClient is kubernetes client
K8sClient kubernetes.Interface
// Logger logs stuff
Logger *logrus.Logger
Logger *logrus.Logger
Namespace string
}

// Router contains information about a REST endpoint
Expand Down
5 changes: 5 additions & 0 deletions gateways/server/stripe/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ func main() {
if err != nil {
panic(err)
}
namespace, ok := os.LookupEnv(common.EnvVarNamespace)
if !ok {
panic("namespace is not provided")
}
clientset := kubernetes.NewForConfigOrDie(restConfig)
server.StartGateway(&stripe.EventListener{
Logger: common.NewArgoEventsLogger(),
K8sClient: clientset,
Namespace: namespace,
})
}
4 changes: 4 additions & 0 deletions gateways/server/stripe/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (listener *EventListener) StartEventSource(eventSource *gateways.EventSourc
return err
}

if stripeEventSource.Namespace == "" {
stripeEventSource.Namespace = listener.Namespace
}

route := webhook.NewRoute(stripeEventSource.Webhook, listener.Logger, eventSource)

return webhook.ManageRoute(&Router{
Expand Down
3 changes: 2 additions & 1 deletion gateways/server/stripe/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type EventListener struct {
// K8sClient is kubernetes client
K8sClient kubernetes.Interface
// Logger logs stuff
Logger *logrus.Logger
Logger *logrus.Logger
Namespace string
}

// Router contains information about a REST endpoint
Expand Down
18 changes: 12 additions & 6 deletions pkg/apis/eventsources/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ type GithubEventSource struct {
// +optional
GithubUploadURL string `json:"githubUploadURL,omitempty" protobuf:"bytes,12,opt,name=githubUploadURL"`
// Namespace refers to Kubernetes namespace which is used to retrieve webhook secret and api token from.
Namespace string `json:"namespace" protobuf:"bytes,13,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,13.opt,name=namespace"`
// DeleteHookOnFinish determines whether to delete the GitHub hook for the repository once the event source is stopped.
// +optional
DeleteHookOnFinish bool `json:"deleteHookOnFinish,omitempty" protobuf:"bytes,14,opt,name=deleteHookOnFinish"`
Expand All @@ -349,7 +350,8 @@ type GitlabEventSource struct {
// GitlabBaseURL is the base URL for API requests to a custom endpoint
GitlabBaseURL string `json:"gitlabBaseURL" protobuf:"bytes,6,name=gitlabBaseURL"`
// Namespace refers to Kubernetes namespace which is used to retrieve access token from.
Namespace string `json:"namespace" protobuf:"bytes,7,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,7,opt,name=namespace"`
// DeleteHookOnFinish determines whether to delete the GitLab hook for the project once the event source is stopped.
// +optional
DeleteHookOnFinish bool `json:"deleteHookOnFinish,omitempty" protobuf:"bytes,8,opt,name=deleteHookOnFinish"`
Expand Down Expand Up @@ -391,7 +393,8 @@ type HDFSEventSource struct {
// It must be set if either ccache or keytab is used.
KrbServicePrincipalName string `json:"krbServicePrincipalName,omitempty"`
// Namespace refers to Kubernetes namespace which is used to retrieve cache secret and ket tab secret from.
Namespace string `json:"namespace" protobuf:"bytes,1,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"`
}

// SlackEventSource refers to event-source for Slack related events
Expand All @@ -403,7 +406,8 @@ type SlackEventSource struct {
// Webhook holds configuration for a REST endpoint
Webhook *webhook.Context `json:"webhook" protobuf:"bytes,3,name=webhook"`
// Namespace refers to Kubernetes namespace which is used to retrieve token and signing secret from.
Namespace string `json:"namespace" protobuf:"bytes,4,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,4.opt,name=namespace"`
}

// StorageGridEventSource refers to event-source for StorageGrid related events
Expand Down Expand Up @@ -439,7 +443,8 @@ type AzureEventsHubEventSource struct {
// Event Hub path/name
HubName string `json:"hubName" protobuf:"bytes,4,name=hubName"`
// Namespace refers to Kubernetes namespace which is used to retrieve the shared access key and name from.
Namespace string `json:"namespace" protobuf:"bytes,5,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,5,opt,name=namespace"`
}

// StripeEventSource describes the event source for stripe webhook notifications
Expand Down Expand Up @@ -473,7 +478,8 @@ type EmitterEventSource struct {
// ChannelName refers to the channel name
ChannelName string `json:"channelName" protobuf:"bytes,3,name=channelName"`
// Namespace to use to retrieve the channel key and optional username/password
Namespace string `json:"namespace" protobuf:"bytes,4,name=namespace"`
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,4,opt,name=namespace"`
// Username to use to connect to broker
// +optional
Username *corev1.SecretKeySelector `json:"username,omitempty" protobuf:"bytes,5,opt,name=username"`
Expand Down

0 comments on commit 739f169

Please sign in to comment.