@@ -2,6 +2,7 @@ package utils
2
2
3
3
import (
4
4
"errors"
5
+ "strconv"
5
6
6
7
"github.com/securesign/operator/api/v1alpha1"
7
8
"github.com/securesign/operator/internal/controller/common/utils"
@@ -12,12 +13,34 @@ import (
12
13
"k8s.io/apimachinery/pkg/util/intstr"
13
14
)
14
15
15
- func CreateDeployment (instance * v1alpha1.CTlog , deploymentName string , sa string , labels map [string ]string ) (* appsv1.Deployment , error ) {
16
+ func CreateDeployment (instance * v1alpha1.CTlog , deploymentName string , sa string , labels map [string ]string , serverPort , metricsPort int32 ) (* appsv1.Deployment , error ) {
16
17
if instance .Status .ServerConfigRef == nil {
17
18
return nil , errors .New ("server config name not specified" )
18
19
}
19
20
replicas := int32 (1 )
20
21
// Define a new Deployment object
22
+
23
+ containerPorts := []corev1.ContainerPort {
24
+ {
25
+ ContainerPort : serverPort ,
26
+ Protocol : corev1 .ProtocolTCP ,
27
+ },
28
+ }
29
+
30
+ appArgs := []string {
31
+ "--http_endpoint=0.0.0.0:" + strconv .Itoa (int (serverPort )),
32
+ "--log_config=/ctfe-keys/config" ,
33
+ "--alsologtostderr" ,
34
+ }
35
+
36
+ if instance .Spec .Monitoring .Enabled {
37
+ appArgs = append (appArgs , "--metrics_endpoint=0.0.0.0:" + strconv .Itoa (int (metricsPort )))
38
+ containerPorts = append (containerPorts , corev1.ContainerPort {
39
+ ContainerPort : metricsPort ,
40
+ Protocol : corev1 .ProtocolTCP ,
41
+ })
42
+ }
43
+
21
44
dep := & appsv1.Deployment {
22
45
ObjectMeta : metav1.ObjectMeta {
23
46
Name : deploymentName ,
@@ -39,17 +62,12 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
39
62
{
40
63
Name : "ctlog" ,
41
64
Image : constants .CTLogImage ,
42
- Args : []string {
43
- "--http_endpoint=0.0.0.0:6962" ,
44
- "--metrics_endpoint=0.0.0.0:6963" ,
45
- "--log_config=/ctfe-keys/config" ,
46
- "--alsologtostderr" ,
47
- },
65
+ Args : appArgs ,
48
66
LivenessProbe : & corev1.Probe {
49
67
ProbeHandler : corev1.ProbeHandler {
50
68
HTTPGet : & corev1.HTTPGetAction {
51
69
Path : "/healthz" ,
52
- Port : intstr .FromInt32 (6962 ),
70
+ Port : intstr .FromInt32 (serverPort ),
53
71
},
54
72
},
55
73
InitialDelaySeconds : 10 ,
@@ -62,7 +80,7 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
62
80
ProbeHandler : corev1.ProbeHandler {
63
81
HTTPGet : & corev1.HTTPGetAction {
64
82
Path : "/healthz" ,
65
- Port : intstr .FromInt32 (6962 ),
83
+ Port : intstr .FromInt32 (serverPort ),
66
84
},
67
85
},
68
86
InitialDelaySeconds : 10 ,
@@ -78,16 +96,7 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
78
96
ReadOnly : true ,
79
97
},
80
98
},
81
- Ports : []corev1.ContainerPort {
82
- {
83
- ContainerPort : 6962 ,
84
- Protocol : corev1 .ProtocolTCP ,
85
- },
86
- {
87
- ContainerPort : 6963 ,
88
- Protocol : corev1 .ProtocolTCP ,
89
- },
90
- },
99
+ Ports : containerPorts ,
91
100
},
92
101
},
93
102
Volumes : []corev1.Volume {
0 commit comments