-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgenerate_resources_overcommit_class_controller_controller.go
More file actions
103 lines (97 loc) · 2.76 KB
/
generate_resources_overcommit_class_controller_controller.go
File metadata and controls
103 lines (97 loc) · 2.76 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
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
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
// SPDX-FileContributor: enriqueavi@inditex.com
//
// SPDX-License-Identifier: Apache-2.0
package resources
import (
"os"
overcommit "github.com/InditexTech/k8s-overcommit-operator/api/v1alphav1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func GenerateOvercommitClassControllerDeployment(overcommitObject overcommit.Overcommit) *appsv1.Deployment {
replicas := int32(1)
labels := overcommitObject.Spec.Labels
if labels == nil {
labels = make(map[string]string)
}
labels["app"] = "overcommit-controller"
// Ensure annotations are properly handled
annotations := overcommitObject.Spec.Annotations
if annotations == nil {
annotations = make(map[string]string)
}
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "k8s-overcommit-overcommitclass-controller",
Namespace: os.Getenv("POD_NAMESPACE"),
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "overcommit-controller",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: os.Getenv("SERVICE_ACCOUNT_NAME"),
Containers: []corev1.Container{
{
Name: "overcommit-controller",
Image: os.Getenv("IMAGE_REGISTRY") + "/" + os.Getenv("IMAGE_REPOSITORY") + ":" + os.Getenv("APP_VERSION"),
Args: []string{
"--metrics-bind-address=:8080",
"-metrics-secure=false",
},
Env: []corev1.EnvVar{
{
Name: "ENABLE_OVERCOMMIT_CLASS_CONTROLLER",
Value: "true",
},
{
Name: "IMAGE_REGISTRY",
Value: os.Getenv("IMAGE_REGISTRY"),
},
{
Name: "IMAGE_REPOSITORY",
Value: os.Getenv("IMAGE_REPOSITORY"),
},
{
Name: "APP_VERSION",
Value: os.Getenv("APP_VERSION"),
},
{
Name: "POD_NAMESPACE",
Value: os.Getenv("POD_NAMESPACE"),
},
{
Name: "SERVICE_ACCOUNT_NAME",
Value: os.Getenv("SERVICE_ACCOUNT_NAME"),
},
{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
},
Ports: []corev1.ContainerPort{
{ContainerPort: 8080, Name: "metrics", Protocol: corev1.ProtocolTCP},
},
},
},
NodeSelector: overcommitObject.Spec.NodeSelector,
Tolerations: overcommitObject.Spec.Tolerations,
},
},
},
}
}