This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
forked from knative/eventing
/
main.go
86 lines (67 loc) · 2.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
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 main
import (
"flag"
"log"
"github.com/kelseyhightower/envconfig"
"github.com/knative/eventing/pkg/adapter/cronjobevents"
"github.com/knative/eventing/pkg/tracing"
"github.com/knative/pkg/signals"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/net/context"
)
type envConfig struct {
// Environment variable container schedule.
Schedule string `envconfig:"SCHEDULE" required:"true"`
// Environment variable containing data.
Data string `envconfig:"DATA" required:"true"`
// Sink for messages.
Sink string `envconfig:"SINK_URI" required:"true"`
// Environment variable containing the name of the cron job.
Name string `envconfig:"NAME" required:"true"`
// Environment variable containing the namespace of the cron job.
Namespace string `envconfig:"NAMESPACE" required:"true"`
}
func main() {
flag.Parse()
ctx := context.Background()
logCfg := zap.NewProductionConfig()
logCfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logger, err := logCfg.Build()
if err != nil {
log.Fatalf("Unable to create logger: %v", err)
}
var env envConfig
if err := envconfig.Process("", &env); err != nil {
log.Fatal("Failed to process env var", zap.Error(err))
}
if err = tracing.SetupStaticZipkinPublishing("apiserversource", tracing.OnePercentSampling); err != nil {
// If tracing doesn't work, we will log an error, but allow the importer to continue to
// start.
logger.Error("Error setting up Zipkin publishing", zap.Error(err))
}
adapter := &cronjobevents.Adapter{
Schedule: env.Schedule,
Data: env.Data,
SinkURI: env.Sink,
Name: env.Name,
Namespace: env.Namespace,
}
logger.Info("Starting Receive Adapter", zap.Any("adapter", adapter))
stopCh := signals.SetupSignalHandler()
if err := adapter.Start(ctx, stopCh); err != nil {
logger.Fatal("Failed to start adapter", zap.Error(err))
}
}