@@ -10,117 +10,46 @@ import (
1010 "k8s.io/client-go/kubernetes/fake"
1111)
1212
13- func Test_GracePeriodFromWriteTimeout (t * testing.T ) {
14-
15- scenarios := []struct {
16- name string
17- wantSeconds int64
18- envs map [string ]string
19- }{
20- {"grace period is the default" , 32 , map [string ]string {}},
21- {"grace period is set from write_timeout" , 62 , map [string ]string {"write_timeout" : "60s" }},
22- }
23-
24- for _ , s := range scenarios {
25- t .Run (s .name , func (t * testing.T ) {
26-
27- want := int64 (s .wantSeconds )
28- function := & faasv1.Function {
29- ObjectMeta : metav1.ObjectMeta {
30- Name : "alpine" ,
31- },
32- Spec : faasv1.FunctionSpec {
33- Name : "alpine" ,
34- Image : "ghcr.io/openfaas/alpine:latest" ,
35- Annotations : & map [string ]string {},
36- ReadOnlyRootFilesystem : true ,
37- Environment : & s .envs },
38- }
39-
40- factory := NewFunctionFactory (fake .NewSimpleClientset (),
41- k8s.DeploymentConfig {
42- HTTPProbe : false ,
43- SetNonRootUser : true ,
44- LivenessProbe : & k8s.ProbeConfig {
45- PeriodSeconds : 1 ,
46- TimeoutSeconds : 3 ,
47- InitialDelaySeconds : 0 ,
48- },
49- ReadinessProbe : & k8s.ProbeConfig {
50- PeriodSeconds : 1 ,
51- TimeoutSeconds : 3 ,
52- InitialDelaySeconds : 0 ,
53- },
54- })
55-
56- secrets := map [string ]* corev1.Secret {}
57-
58- deployment := newDeployment (function , nil , secrets , factory )
59- got := deployment .Spec .Template .Spec .TerminationGracePeriodSeconds
60- if got == nil {
61- t .Errorf ("TerminationGracePeriodSeconds not set, but want %d" , want )
62- t .Fail ()
63- return
64- }
65-
66- if want != * got {
67- t .Errorf ("TerminationGracePeriodSeconds want %d, but got %d" , want , got )
68- t .Fail ()
69- }
70- })
71- }
72- }
73-
74- func Test_newDeployment_withHTTPProbe (t * testing.T ) {
13+ func Test_newDeployment (t * testing.T ) {
7514 function := & faasv1.Function {
7615 ObjectMeta : metav1.ObjectMeta {
7716 Name : "kubesec" ,
7817 },
7918 Spec : faasv1.FunctionSpec {
80- Name : "kubesec" ,
81- Image : "docker.io/kubesec/kubesec" ,
82- Annotations : & map [string ]string {
83- "com.openfaas.serviceaccount" : "kubesec" ,
84- },
19+ Name : "kubesec" ,
20+ Image : "docker.io/kubesec/kubesec" ,
21+ Annotations : & map [string ]string {},
8522 ReadOnlyRootFilesystem : true ,
8623 },
8724 }
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 )
25+
26+ factory := NewFunctionFactory (fake .NewSimpleClientset (),
27+ k8s.DeploymentConfig {
28+ HTTPProbe : true ,
29+ SetNonRootUser : true ,
30+ LivenessProbe : & k8s.ProbeConfig {
31+ PeriodSeconds : 1 ,
32+ TimeoutSeconds : 3 ,
33+ InitialDelaySeconds : 0 ,
34+ },
35+ ReadinessProbe : & k8s.ProbeConfig {
36+ PeriodSeconds : 1 ,
37+ TimeoutSeconds : 3 ,
38+ InitialDelaySeconds : 0 ,
39+ },
40+ })
10341
10442 secrets := map [string ]* corev1.Secret {}
10543
10644 deployment := newDeployment (function , nil , secrets , factory )
10745
108- if deployment .Spec .Template .Spec .ServiceAccountName != "kubesec" {
109- t .Errorf ("ServiceAccountName should be %s" , "kubesec" )
110- t .Fail ()
111- }
112-
113- if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet == nil {
114- t .Fatalf ("ReadinessProbe's HTTPGet should not be nil" )
115- }
116-
11746 if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet .Path != "/_/health" {
11847 t .Errorf ("Readiness probe should have HTTPGet handler set to %s" , "/_/health" )
11948 t .Fail ()
12049 }
12150
122- if deployment .Spec .Template .Spec .Containers [0 ].LivenessProbe .InitialDelaySeconds != k8sConfig . ReadinessProbe . InitialDelaySeconds {
123- t .Errorf ("Liveness probe should have initial delay seconds set to %s" , "2m " )
51+ if deployment .Spec .Template .Spec .Containers [0 ].LivenessProbe .InitialDelaySeconds != 0 {
52+ t .Errorf ("Liveness probe should have initial delay seconds set to %s" , "0 " )
12453 t .Fail ()
12554 }
12655
@@ -141,11 +70,9 @@ func Test_newDeployment_withExecProbe(t *testing.T) {
14170 Name : "kubesec" ,
14271 },
14372 Spec : faasv1.FunctionSpec {
144- Name : "kubesec" ,
145- Image : "docker.io/kubesec/kubesec" ,
146- Annotations : & map [string ]string {
147- "com.openfaas.serviceaccount" : "kubesec" ,
148- },
73+ Name : "kubesec" ,
74+ Image : "docker.io/kubesec/kubesec" ,
75+ Annotations : & map [string ]string {},
14976 ReadOnlyRootFilesystem : true ,
15077 },
15178 }
@@ -170,11 +97,6 @@ func Test_newDeployment_withExecProbe(t *testing.T) {
17097
17198 deployment := newDeployment (function , nil , secrets , factory )
17299
173- if deployment .Spec .Template .Spec .ServiceAccountName != "kubesec" {
174- t .Errorf ("ServiceAccountName should be %s" , "kubesec" )
175- t .Fail ()
176- }
177-
178100 if deployment .Spec .Template .Spec .Containers [0 ].ReadinessProbe .HTTPGet != nil {
179101 t .Fatalf ("ReadinessProbe's HTTPGet should be nil due to exec probe" )
180102 }
0 commit comments