forked from knative/eventing
/
cronjobsource.go
114 lines (92 loc) · 3.31 KB
/
cronjobsource.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
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 (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"knative.dev/eventing/pkg/apis/legacysources/v1alpha1"
)
// CronJobSourceOption enables further configuration of a CronJob.
type CronJobSourceOption func(*v1alpha1.CronJobSource)
// NewCronJobSource creates a CronJobSource with CronJobOptions.
func NewCronJobSource(name, namespace string, o ...CronJobSourceOption) *v1alpha1.CronJobSource {
c := &v1alpha1.CronJobSource{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
for _, opt := range o {
opt(c)
}
// c.SetDefaults(context.Background()) // TODO: We should add defaults and validation.
return c
}
func WithCronJobSourceUID(uid string) CronJobSourceOption {
return func(c *v1alpha1.CronJobSource) {
c.UID = types.UID(uid)
}
}
// WithInitCronJobSourceConditions initializes the CronJobSource's conditions.
func WithInitCronJobSourceConditions(s *v1alpha1.CronJobSource) {
s.Status.InitializeConditions()
s.MarkDeprecated(&s.Status.Status, "CronJobSourceDeprecated", "cronjobsources.sources.eventing.knative.dev are deprecated and will be removed in the future. Use a CronJob and SinkBinding.sources.knative.dev instead.")
}
func WithValidCronJobSourceSchedule(s *v1alpha1.CronJobSource) {
s.Status.MarkSchedule()
}
func WithInvalidCronJobSourceSchedule(s *v1alpha1.CronJobSource) {
s.Status.MarkInvalidSchedule("Invalid", "")
}
func WithCronJobSourceSinkNotFound(s *v1alpha1.CronJobSource) {
s.Status.MarkNoSink("NotFound", "")
}
func WithCronJobSourceSink(uri string) CronJobSourceOption {
return func(s *v1alpha1.CronJobSource) {
s.Status.MarkSink(uri)
}
}
func WithCronJobSourceDeployed(s *v1alpha1.CronJobSource) {
s.Status.PropagateDeploymentAvailability(NewDeployment("any", "any", WithDeploymentAvailable()))
}
func WithCronJobSourceEventType(s *v1alpha1.CronJobSource) {
s.Status.MarkEventType()
}
func WithValidCronJobSourceResources(s *v1alpha1.CronJobSource) {
s.Status.MarkResourcesCorrect()
}
func WithCronJobSourceDeleted(c *v1alpha1.CronJobSource) {
t := metav1.NewTime(time.Unix(1e9, 0))
c.ObjectMeta.SetDeletionTimestamp(&t)
}
func WithCronJobSourceSpec(spec v1alpha1.CronJobSourceSpec) CronJobSourceOption {
return func(c *v1alpha1.CronJobSource) {
c.Spec = spec
}
}
func WithCronJobApiVersion(apiVersion string) CronJobSourceOption {
return func(c *v1alpha1.CronJobSource) {
c.APIVersion = apiVersion
}
}
func WithCronJobSourceStatusObservedGeneration(generation int64) CronJobSourceOption {
return func(c *v1alpha1.CronJobSource) {
c.Status.ObservedGeneration = generation
}
}
func WithCronJobSourceObjectMetaGeneration(generation int64) CronJobSourceOption {
return func(c *v1alpha1.CronJobSource) {
c.ObjectMeta.Generation = generation
}
}