-
Notifications
You must be signed in to change notification settings - Fork 2
/
eks.go
111 lines (109 loc) · 2.92 KB
/
eks.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
package spec
import (
"github.com/samber/lo"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func EKS(nodeName, jobName string) *batchv1.Job {
//https://raw.githubusercontent.com/aquasecurity/kube-bench/v0.6.9/job-eks.yaml
return &batchv1.Job{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
Annotations: map[string]string{
"autoscaling.cast.ai/disposable": "true",
},
Labels: map[string]string{
"app": "kube-bench",
"app.kubernetes.io/managed-by": "castai",
},
},
Spec: batchv1.JobSpec{
BackoffLimit: lo.ToPtr(int32(0)),
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
HostPID: true,
NodeName: nodeName,
RestartPolicy: "Never",
AutomountServiceAccountToken: lo.ToPtr(true),
Containers: []corev1.Container{
{
Name: "kube-bench",
Image: "<placeholder>",
SecurityContext: &corev1.SecurityContext{
ReadOnlyRootFilesystem: lo.ToPtr(false),
AllowPrivilegeEscalation: lo.ToPtr(false),
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(requestCPU),
corev1.ResourceMemory: resource.MustParse(requestMem),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(limitCPU),
corev1.ResourceMemory: resource.MustParse(limitMem),
},
},
Command: []string{
"/usr/local/bin/kvisor-linter",
},
Args: []string{
"kube-bench",
"--config-dir", "/etc/kubebench-rules/",
"run",
"--targets", "node",
"--benchmark", "eks-1.3.0",
"--json",
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "var-lib-kubelet",
MountPath: "/var/lib/kubelet",
ReadOnly: true,
},
{
Name: "etc-systemd",
MountPath: "/etc/systemd",
ReadOnly: true,
},
{
Name: "etc-kubernetes",
MountPath: "/etc/kubernetes",
ReadOnly: true,
},
},
},
},
Volumes: []corev1.Volume{
{
Name: "var-lib-kubelet",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/var/lib/kubelet",
},
},
},
{
Name: "etc-systemd",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/etc/systemd",
},
},
},
{
Name: "etc-kubernetes",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/etc/kubernetes",
},
},
},
},
},
},
},
}
}