forked from knative/eventing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobrunner.go
117 lines (105 loc) · 2.92 KB
/
jobrunner.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
115
116
117
/*
Copyright 2020 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 resources
import (
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/system"
)
var (
jobRunnerLabels = map[string]string{
"sources.knative.dev/source": "ping-source",
"sources.knative.dev/role": "jobrunner",
}
)
type JobRunnerArgs struct {
ServiceAccountName string
JobRunnerName string
JobRunnerNamespace string
Image string
}
// MakeJobRunner generates the jobrunner deployment for pingsource
func MakeJobRunner(args JobRunnerArgs) *v1.Deployment {
replicas := int32(1)
return &v1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployments",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: args.JobRunnerNamespace,
Name: args.JobRunnerName,
},
Spec: v1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: jobRunnerLabels,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: jobRunnerLabels,
},
Spec: corev1.PodSpec{
ServiceAccountName: args.ServiceAccountName,
Containers: []corev1.Container{
{
Name: "dispatcher",
Image: args.Image,
Env: makeEnv(),
// Set low resource requests and limits.
// This should be configurable.
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("125m"),
corev1.ResourceMemory: resource.MustParse("64Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1000m"),
corev1.ResourceMemory: resource.MustParse("2048Mi"),
},
},
Ports: []corev1.ContainerPort{{
Name: "metrics",
ContainerPort: 9090,
}},
},
},
},
},
},
}
}
func makeEnv() []corev1.EnvVar {
return []corev1.EnvVar{{
Name: system.NamespaceEnvKey,
Value: system.Namespace(),
}, {
Name: "METRICS_DOMAIN",
Value: "knative.dev/pingsource-jobrunner",
}, {
Name: "CONFIG_OBSERVABILITY_NAME",
Value: "config-observability",
}, {
Name: "CONFIG_LOGGING_NAME",
Value: "config-logging",
}, {
Name: "NAMESPACE",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.namespace",
},
},
}}
}