-
Notifications
You must be signed in to change notification settings - Fork 216
/
manifest.go
96 lines (86 loc) · 2.18 KB
/
manifest.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
package simulator
import (
"strconv"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/rancher/fleet/pkg/basic"
"github.com/rancher/fleet/pkg/config"
"github.com/rancher/wrangler/pkg/yaml"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)
const (
DefaultName = "fleet-agent"
)
func Manifest(namespace, systemNamespace, image string, simulators int, tokenConfig []runtime.Object) ([]runtime.Object, error) {
if image == "" {
image = config.DefaultAgentSimulatorImage
}
data, err := yaml.Export(tokenConfig...)
if err != nil {
return nil, err
}
cm := basic.ConfigMap(namespace, DefaultName, "config", string(data))
deployment := basic.Deployment(namespace, DefaultName, image, "", "")
deployment.Spec.Template.Spec.Containers[0].Env = []v1.EnvVar{
{
Name: "NAMESPACE",
Value: systemNamespace,
},
}
deployment.Spec.Template.Spec.Containers[0].VolumeMounts = []v1.VolumeMount{
{
Name: "db",
MountPath: "/var/lib/rancher/k3s/server/db",
SubPath: "db",
},
{
Name: "config",
ReadOnly: true,
MountPath: "/var/lib/rancher/k3s/server/manifests/manifest.yaml",
SubPath: "config",
},
}
deployment.Spec.Template.Spec.Containers[0].Args = []string{
"fleetagent", "--simulators", strconv.Itoa(simulators),
}
deployment.Spec.Template.Spec.Volumes = []v1.Volume{
{
Name: "db",
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: "simulator-db",
},
},
},
{
Name: "config",
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: DefaultName,
},
},
},
},
}
return []runtime.Object{
cm,
deployment,
&v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "simulator-db",
},
Spec: v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce,
},
Resources: v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceStorage: *resource.NewScaledQuantity(100, resource.Mega),
},
},
},
},
}, nil
}