-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (38 loc) · 1.15 KB
/
main.go
File metadata and controls
45 lines (38 loc) · 1.15 KB
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
package main
import (
"strconv"
"github.com/Azure/eno/pkg/function"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type Inputs struct {
Config *corev1.ConfigMap `eno_key:"example-input"`
}
func synthesize(inputs Inputs) ([]client.Object, error) {
replicas, _ := strconv.ParseInt(inputs.Config.Data["replicas"], 10, 32)
deploy := &appsv1.Deployment{}
deploy.Name = "example-nginx-deployment"
deploy.Namespace = "default"
deploy.Spec.Replicas = ptr.To(int32(replicas))
deploy.Spec.Selector = &metav1.LabelSelector{MatchLabels: map[string]string{"app": "nginx-example"}}
deploy.Spec.Template = corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "nginx-example"},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "nginx",
Image: "nginx:latest",
Ports: []corev1.ContainerPort{{ContainerPort: 80}},
}},
},
}
return []client.Object{deploy}, nil
}
func main() {
function.Main(synthesize, function.WithScheme(scheme.Scheme))
}