Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit c6c6a29

Browse files
committed
cronjobsource replaced with pingsource, dependencies and tests updated
1 parent e024707 commit c6c6a29

16 files changed

+1501
-321
lines changed

cloudbuild.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ steps:
1111
- ${_KANIKO_EXTRA_ARGS}
1212
waitFor: ['-']
1313

14+
timeout: 1800s
15+
1416
substitutions:
1517
_KANIKO_IMAGE_TAG: "latest"
1618
_KANIKO_NO_PUSH: "false"

go.mod

+18-25
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,35 @@ module github.com/triggermesh/tm
33
go 1.13
44

55
require (
6-
contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect
7-
contrib.go.opencensus.io/exporter/stackdriver v0.12.9 // indirect
86
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
9-
github.com/dsnet/compress v0.0.1 // indirect
10-
github.com/frankban/quicktest v1.7.2 // indirect
117
github.com/ghodss/yaml v1.0.0
12-
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
8+
github.com/json-iterator/go v1.1.10 // indirect
139
github.com/knative/build v0.7.0
1410
github.com/knative/pkg v0.0.0-20190624141606-d82505e6c5b4
1511
github.com/mholt/archiver v2.1.0+incompatible
16-
github.com/nwaples/rardecode v1.0.0 // indirect
1712
github.com/olekukonko/tablewriter v0.0.4
18-
github.com/openzipkin/zipkin-go v0.2.2 // indirect
1913
github.com/pierrec/lz4 v2.4.0+incompatible // indirect
20-
github.com/robfig/cron v1.2.0 // indirect
21-
github.com/sirupsen/logrus v1.4.2
14+
github.com/sirupsen/logrus v1.6.0
2215
github.com/spf13/afero v1.2.2
23-
github.com/spf13/cobra v0.0.5
24-
github.com/stretchr/testify v1.4.0
25-
github.com/tektoncd/pipeline v0.11.2
16+
github.com/spf13/cobra v1.0.0
17+
github.com/stretchr/testify v1.5.1
18+
github.com/tektoncd/pipeline v0.14.0
2619
github.com/tektoncd/triggers v0.1.0
2720
github.com/tidwall/gjson v1.3.2 // indirect
28-
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
29-
google.golang.org/genproto v0.0.0-20191028173616-919d9bdd9fe6 // indirect
21+
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0
22+
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
23+
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
3024
gopkg.in/src-d/go-git.v4 v4.13.1
31-
gopkg.in/yaml.v2 v2.2.5
32-
k8s.io/api v0.17.2
33-
k8s.io/apimachinery v0.17.2
34-
k8s.io/client-go v0.17.0
35-
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d // indirect
36-
knative.dev/eventing v0.12.0
37-
knative.dev/eventing-contrib v0.11.2
38-
knative.dev/pkg v0.0.0-20200207155214-fef852970f43
39-
knative.dev/serving v0.12.0
40-
sigs.k8s.io/controller-runtime v0.4.0 // indirect
25+
gopkg.in/yaml.v2 v2.3.0
26+
k8s.io/api v0.18.5
27+
k8s.io/apimachinery v0.18.5
28+
k8s.io/client-go v12.0.0+incompatible
29+
k8s.io/klog/v2 v2.3.0 // indirect
30+
k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19 // indirect
31+
knative.dev/eventing v0.15.0
32+
knative.dev/eventing-contrib v0.15.0
33+
knative.dev/pkg v0.0.0-20200708171447-5358179e7499
34+
knative.dev/serving v0.15.0
4135
)
4236

4337
replace (
@@ -61,5 +55,4 @@ replace (
6155
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20191016115707-22244e5b01eb
6256
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113728-f445c7b35c1c
6357
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112728-ceb381866e80
64-
knative.dev/pkg => knative.dev/pkg v0.0.0-20200122022923-4e81bc3c320f
6558
)

go.sum

+1,157-29
Large diffs are not rendered by default.

pkg/client/client.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
printerwrapper "github.com/triggermesh/tm/pkg/printer"
3333
githubSource "knative.dev/eventing-contrib/github/pkg/client/clientset/versioned"
3434
eventingApi "knative.dev/eventing/pkg/client/clientset/versioned"
35-
legacyEventingApi "knative.dev/eventing/pkg/legacyclient/clientset/versioned"
3635
servingApi "knative.dev/serving/pkg/client/clientset/versioned"
3736

3837
"k8s.io/client-go/kubernetes"
@@ -52,11 +51,6 @@ const (
5251
var (
5352
// Namespace to work in passed with "-n" argument or defined in kube configs
5453
Namespace string
55-
// Registry to store docker images for user services
56-
// Default value for tm cloud is knative.registry.svc.cluster.local
57-
// RegistryHost string
58-
// RegistrySecret string
59-
// RegistrySkipTLS bool
6054
// Output format for k8s objects in "tm get" result. Can be either "yaml" (default) or "json"
6155
Output string
6256
// Debug enables verbose output for CLI commands
@@ -67,6 +61,7 @@ var (
6761
Wait bool
6862
)
6963

64+
// Registry to store docker images for user services
7065
type Registry struct {
7166
Host string
7267
Secret string
@@ -78,7 +73,6 @@ type ConfigSet struct {
7873
Core *kubernetes.Clientset
7974
Build *buildApi.Clientset
8075
Serving *servingApi.Clientset
81-
LegacyEventing *legacyEventingApi.Clientset
8276
Eventing *eventingApi.Clientset
8377
GithubSource *githubSource.Clientset
8478
TektonPipelines *tektonResource.Clientset
@@ -185,9 +179,6 @@ func NewClient(cfgFile string, output ...io.Writer) (ConfigSet, error) {
185179
if c.Eventing, err = eventingApi.NewForConfig(config); err != nil {
186180
return c, err
187181
}
188-
if c.LegacyEventing, err = legacyEventingApi.NewForConfig(config); err != nil {
189-
return c, err
190-
}
191182
if c.Build, err = buildApi.NewForConfig(config); err != nil {
192183
return c, err
193184
}

pkg/file/serverless.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,27 @@ type TriggermeshProvider struct {
3838

3939
// Function describes function definition in serverless format
4040
type Function struct {
41-
Handler string `yaml:"handler,omitempty"`
42-
Source string `yaml:"source,omitempty"`
43-
Revision string `yaml:"revision,omitempty"`
44-
Runtime string `yaml:"runtime,omitempty"`
45-
Concurrency int `yaml:"concurrency,omitempty"`
46-
Buildargs []string `yaml:"buildargs,omitempty"`
47-
Description string `yaml:"description,omitempty"`
48-
Labels []string `yaml:"labels,omitempty"`
49-
Environment map[string]string `yaml:"environment,omitempty"`
50-
EnvSecrets []string `yaml:"env-secrets,omitempty"`
51-
Annotations map[string]string `yaml:"annotations,omitempty"`
52-
Events []map[string]interface{} `yaml:"events,omitempty"`
41+
Handler string `yaml:"handler,omitempty"`
42+
Source string `yaml:"source,omitempty"`
43+
Revision string `yaml:"revision,omitempty"`
44+
Runtime string `yaml:"runtime,omitempty"`
45+
Concurrency int `yaml:"concurrency,omitempty"`
46+
Buildargs []string `yaml:"buildargs,omitempty"`
47+
Description string `yaml:"description,omitempty"`
48+
Labels []string `yaml:"labels,omitempty"`
49+
Environment map[string]string `yaml:"environment,omitempty"`
50+
EnvSecrets []string `yaml:"env-secrets,omitempty"`
51+
Annotations map[string]string `yaml:"annotations,omitempty"`
52+
Schedule []Schedule `yaml:"schedule,omitempty"`
5353
}
5454

55-
// Schedule represents simple structure of event schedule
56-
// with cronjob-style rate string and data to use in event.
57-
// Deprecated.
55+
// Schedule struct contains a data in JSON format and a cron
56+
// that defines how often events should be sent to a function.
57+
// Description string may be used to explain events purpose.
5858
type Schedule struct {
59-
Rate string
60-
Data string
59+
Cron string
60+
JSONData string
61+
Description string
6162
}
6263

6364
// Aos returns filesystem object with standard set of os methods implemented by afero package

pkg/log/log.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ func NewLogger() *StandardLogger {
2020
var baseLogger = logrus.New()
2121
var standardLogger = &StandardLogger{baseLogger}
2222

23-
standardLogger.Formatter = &logrus.TextFormatter{}
23+
standardLogger.Formatter = &logrus.TextFormatter{
24+
FullTimestamp: true,
25+
TimestampFormat: "15:04:05",
26+
}
2427

2528
return standardLogger
2629
}

pkg/push/push.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
legacysourcesv1alpha1 "knative.dev/eventing/pkg/apis/legacysources/v1alpha1"
33-
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
32+
sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
33+
duckv1 "knative.dev/pkg/apis/duck/v1"
3434
)
3535

3636
// Push tries to read git configuration in current directory and if it succeeds
@@ -137,8 +137,8 @@ func Push(clientset *client.ConfigSet, token string) error {
137137
return nil
138138
}
139139

140-
func getContainerSource(project, owner, token string) *legacysourcesv1alpha1.ContainerSource {
141-
return &legacysourcesv1alpha1.ContainerSource{
140+
func getContainerSource(project, owner, token string) *sourcesv1alpha2.ContainerSource {
141+
return &sourcesv1alpha2.ContainerSource{
142142
TypeMeta: metav1.TypeMeta{
143143
Kind: "ContainerSource",
144144
APIVersion: "sources.eventing.knative.dev/v1alpha1",
@@ -147,15 +147,17 @@ func getContainerSource(project, owner, token string) *legacysourcesv1alpha1.Con
147147
Name: project,
148148
Namespace: client.Namespace,
149149
},
150-
Spec: legacysourcesv1alpha1.ContainerSourceSpec{
151-
Sink: &duckv1beta1.Destination{
152-
Ref: &corev1.ObjectReference{
153-
Kind: "Service",
154-
APIVersion: "serving.knative.dev/v1beta1",
155-
Name: project + "-transceiver",
150+
Spec: sourcesv1alpha2.ContainerSourceSpec{
151+
SourceSpec: duckv1.SourceSpec{
152+
Sink: duckv1.Destination{
153+
Ref: &duckv1.KReference{
154+
Kind: "Service",
155+
APIVersion: "serving.knative.dev/v1beta1",
156+
Name: project + "-transceiver",
157+
},
156158
},
157159
},
158-
Template: &corev1.PodTemplateSpec{
160+
Template: corev1.PodTemplateSpec{
159161
Spec: corev1.PodSpec{
160162
Containers: []corev1.Container{
161163
{
@@ -269,14 +271,14 @@ func createOrUpdateConfigmap(clientset *client.ConfigSet, cm *corev1.ConfigMap)
269271
return nil
270272
}
271273

272-
func createOrUpdateContainersource(clientset *client.ConfigSet, cs *legacysourcesv1alpha1.ContainerSource) error {
273-
if _, err := clientset.LegacyEventing.SourcesV1alpha1().ContainerSources(cs.Namespace).Create(cs); k8sErrors.IsAlreadyExists(err) {
274-
csObj, err := clientset.LegacyEventing.SourcesV1alpha1().ContainerSources(cs.Namespace).Get(cs.Name, metav1.GetOptions{})
274+
func createOrUpdateContainersource(clientset *client.ConfigSet, cs *sourcesv1alpha2.ContainerSource) error {
275+
if _, err := clientset.Eventing.SourcesV1alpha2().ContainerSources(cs.Namespace).Create(cs); k8sErrors.IsAlreadyExists(err) {
276+
csObj, err := clientset.Eventing.SourcesV1alpha2().ContainerSources(cs.Namespace).Get(cs.Name, metav1.GetOptions{})
275277
if err != nil {
276278
return err
277279
}
278280
cs.ObjectMeta.ResourceVersion = csObj.GetResourceVersion()
279-
if _, err := clientset.LegacyEventing.SourcesV1alpha1().ContainerSources(cs.Namespace).Update(cs); err != nil {
281+
if _, err := clientset.Eventing.SourcesV1alpha2().ContainerSources(cs.Namespace).Update(cs); err != nil {
280282
return err
281283
}
282284
} else if err != nil {

pkg/resources/service/create.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ import (
2222
"time"
2323

2424
"github.com/ghodss/yaml"
25-
"github.com/triggermesh/tm/pkg/client"
2625
corev1 "k8s.io/api/core/v1"
2726
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
2929
"knative.dev/pkg/apis"
3030
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
31+
32+
"github.com/triggermesh/tm/pkg/client"
3133
)
3234

35+
const defaultBuildTimeout = 10
36+
3337
// Deploy receives Service structure and generate knative/service object to deploy it in knative cluster
3438
func (s *Service) Deploy(clientset *client.ConfigSet) (string, error) {
3539
var err error
@@ -119,12 +123,20 @@ func (s *Service) Deploy(clientset *client.ConfigSet) (string, error) {
119123
return "", fmt.Errorf("Creating service: %s", err)
120124
}
121125

122-
// TODO Add cronjob yaml into --dry output
123-
// if len(s.Cronjob.Schedule) != 0 {
124-
// if err := s.CreateCronjobSource(clientset); err != nil {
125-
// return "", fmt.Errorf("Creating cronjob source: %s", err)
126-
// }
127-
// }
126+
// before creating PingSources remove old ones
127+
// to make sure that we're in sync with manifest
128+
if err := s.removePingSources(service.UID, clientset); err != nil {
129+
clientset.Log.Warnf("Failed to remove schedule: %v\n", err)
130+
}
131+
132+
for _, sched := range s.Schedule {
133+
ps := s.pingSource(sched.Cron, sched.JSONData, service.UID)
134+
clientset.Log.Infof("Creating %q schedule\n", ps.Spec.Schedule)
135+
err := s.createPingSource(ps, clientset)
136+
if err != nil {
137+
clientset.Log.Errorf("Failed to create schedule: %v\n", err)
138+
}
139+
}
128140

129141
if !client.Wait {
130142
return fmt.Sprintf("Deployment started. Run \"tm -n %s describe service %s\" to see details", s.Namespace, s.Name), nil
@@ -210,7 +222,7 @@ func (s *Service) wait(clientset *client.ConfigSet) (string, error) {
210222

211223
duration, err := time.ParseDuration(s.BuildTimeout)
212224
if err != nil {
213-
duration = 10 * time.Minute
225+
duration = defaultBuildTimeout * time.Minute
214226
}
215227

216228
ticker := time.NewTicker(duration)
@@ -265,7 +277,7 @@ func (s *Service) wait(clientset *client.ConfigSet) (string, error) {
265277
}
266278
}
267279
case <-ticker.C:
268-
return "", fmt.Errorf("watch service timeout")
280+
return "", fmt.Errorf("Service %q didn't become ready in time", s.Name)
269281
}
270282
}
271283
}

0 commit comments

Comments
 (0)