@@ -71,7 +71,7 @@ func Test_GracePeriodFromWriteTimeout(t *testing.T) {
71
71
}
72
72
}
73
73
74
- func Test_newDeployment (t * testing.T ) {
74
+ func Test_newDeployment_withHTTPProbe (t * testing.T ) {
75
75
function := & faasv1.Function {
76
76
ObjectMeta : metav1.ObjectMeta {
77
77
Name : "kubesec" ,
@@ -80,29 +80,26 @@ func Test_newDeployment(t *testing.T) {
80
80
Name : "kubesec" ,
81
81
Image : "docker.io/kubesec/kubesec" ,
82
82
Annotations : & map [string ]string {
83
- "com.openfaas.serviceaccount" : "kubesec" ,
84
- "com.openfaas.health.http.initialDelay" : "2m" ,
85
- "com.openfaas.health.http.path" : "/healthz" ,
83
+ "com.openfaas.serviceaccount" : "kubesec" ,
86
84
},
87
85
ReadOnlyRootFilesystem : true ,
88
86
},
89
87
}
90
-
91
- factory := NewFunctionFactory (fake .NewSimpleClientset (),
92
- k8s.DeploymentConfig {
93
- HTTPProbe : false ,
94
- SetNonRootUser : true ,
95
- LivenessProbe : & k8s.ProbeConfig {
96
- PeriodSeconds : 1 ,
97
- TimeoutSeconds : 3 ,
98
- InitialDelaySeconds : 0 ,
99
- },
100
- ReadinessProbe : & k8s.ProbeConfig {
101
- PeriodSeconds : 1 ,
102
- TimeoutSeconds : 3 ,
103
- InitialDelaySeconds : 0 ,
104
- },
105
- })
88
+ k8sConfig := k8s.DeploymentConfig {
89
+ HTTPProbe : true ,
90
+ SetNonRootUser : true ,
91
+ LivenessProbe : & k8s.ProbeConfig {
92
+ PeriodSeconds : 1 ,
93
+ TimeoutSeconds : 3 ,
94
+ InitialDelaySeconds : 0 ,
95
+ },
96
+ ReadinessProbe : & k8s.ProbeConfig {
97
+ PeriodSeconds : 1 ,
98
+ TimeoutSeconds : 3 ,
99
+ InitialDelaySeconds : 0 ,
100
+ },
101
+ }
102
+ factory := NewFunctionFactory (fake .NewSimpleClientset (), k8sConfig )
106
103
107
104
secrets := map [string ]* corev1.Secret {}
108
105
@@ -113,12 +110,16 @@ func Test_newDeployment(t *testing.T) {
113
110
t .Fail ()
114
111
}
115
112
116
- if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet .Path != "/healthz" {
117
- t .Errorf ("Readiness probe should have HTTPGet handler set to %s" , "/healthz" )
113
+ if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet == nil {
114
+ t .Fatalf ("ReadinessProbe's HTTPGet should not be nil" )
115
+ }
116
+
117
+ if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet .Path != "/_/health" {
118
+ t .Errorf ("Readiness probe should have HTTPGet handler set to %s" , "/_/health" )
118
119
t .Fail ()
119
120
}
120
121
121
- if deployment .Spec .Template .Spec .Containers [0 ].LivenessProbe .InitialDelaySeconds != 120 {
122
+ if deployment .Spec .Template .Spec .Containers [0 ].LivenessProbe .InitialDelaySeconds != k8sConfig . ReadinessProbe . InitialDelaySeconds {
122
123
t .Errorf ("Liveness probe should have initial delay seconds set to %s" , "2m" )
123
124
t .Fail ()
124
125
}
@@ -134,6 +135,51 @@ func Test_newDeployment(t *testing.T) {
134
135
}
135
136
}
136
137
138
+ func Test_newDeployment_withExecProbe (t * testing.T ) {
139
+ function := & faasv1.Function {
140
+ ObjectMeta : metav1.ObjectMeta {
141
+ Name : "kubesec" ,
142
+ },
143
+ Spec : faasv1.FunctionSpec {
144
+ Name : "kubesec" ,
145
+ Image : "docker.io/kubesec/kubesec" ,
146
+ Annotations : & map [string ]string {
147
+ "com.openfaas.serviceaccount" : "kubesec" ,
148
+ },
149
+ ReadOnlyRootFilesystem : true ,
150
+ },
151
+ }
152
+ k8sConfig := k8s.DeploymentConfig {
153
+ HTTPProbe : false ,
154
+ SetNonRootUser : true ,
155
+ LivenessProbe : & k8s.ProbeConfig {
156
+ PeriodSeconds : 1 ,
157
+ TimeoutSeconds : 3 ,
158
+ InitialDelaySeconds : 0 ,
159
+ },
160
+ ReadinessProbe : & k8s.ProbeConfig {
161
+ PeriodSeconds : 1 ,
162
+ TimeoutSeconds : 3 ,
163
+ InitialDelaySeconds : 0 ,
164
+ },
165
+ }
166
+
167
+ factory := NewFunctionFactory (fake .NewSimpleClientset (), k8sConfig )
168
+
169
+ secrets := map [string ]* corev1.Secret {}
170
+
171
+ deployment := newDeployment (function , nil , secrets , factory )
172
+
173
+ if deployment .Spec .Template .Spec .ServiceAccountName != "kubesec" {
174
+ t .Errorf ("ServiceAccountName should be %s" , "kubesec" )
175
+ t .Fail ()
176
+ }
177
+
178
+ if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet != nil {
179
+ t .Fatalf ("ReadinessProbe's HTTPGet should be nil due to exec probe" )
180
+ }
181
+ }
182
+
137
183
func Test_newDeployment_PrometheusScrape_NotOverridden (t * testing.T ) {
138
184
function := & faasv1.Function {
139
185
ObjectMeta : metav1.ObjectMeta {
0 commit comments