@@ -9,40 +9,44 @@ import (
99 "github.com/drycc/workflow-cli/internal/loader"
1010)
1111
12- func getHealthcheckString (ptype , probeType string , healthcheck * api.Healthcheck ) string {
12+ func getContainerProbeString (ptype , probeType string , containerProbe * api.ContainerProbe ) string {
1313 params := fmt .Sprintf (
1414 "delay=%ds timeout=%ds period=%ds #success=%d #failure=%d" ,
15- healthcheck .InitialDelaySeconds ,
16- healthcheck .TimeoutSeconds ,
17- healthcheck .PeriodSeconds ,
18- healthcheck .SuccessThreshold ,
19- healthcheck .FailureThreshold ,
15+ containerProbe .InitialDelaySeconds ,
16+ containerProbe .TimeoutSeconds ,
17+ containerProbe .PeriodSeconds ,
18+ containerProbe .SuccessThreshold ,
19+ containerProbe .FailureThreshold ,
2020 )
2121
22- if healthcheck .Exec != nil {
23- return fmt .Sprintf ("%s %s exec %v %s" , probeType , ptype , healthcheck .Exec .Command , params )
24- } else if healthcheck .TCPSocket != nil {
25- return fmt .Sprintf ("%s %s tcp-socket port=%v %s" , probeType , ptype , healthcheck .TCPSocket .Port , params )
26- } else if healthcheck .HTTPGet != nil {
22+ if containerProbe .Exec != nil {
23+ return fmt .Sprintf ("%s %s exec %v %s" , probeType , ptype , containerProbe .Exec .Command , params )
24+ } else if containerProbe .TCPSocket != nil {
25+ return fmt .Sprintf ("%s %s tcp-socket port=%v %s" , probeType , ptype , containerProbe .TCPSocket .Port , params )
26+ } else if containerProbe .HTTPGet != nil {
2727 return fmt .Sprintf (
2828 "%s %s http-get headers=%v path=%s port=%d %s" ,
2929 probeType ,
3030 ptype ,
31- healthcheck .HTTPGet .HTTPHeaders ,
32- healthcheck .HTTPGet .Path ,
33- healthcheck .HTTPGet .Port ,
31+ containerProbe .HTTPGet .HTTPHeaders ,
32+ containerProbe .HTTPGet .Path ,
33+ containerProbe .HTTPGet .Port ,
3434 params ,
3535 )
3636 }
3737 return ""
3838}
3939
40- func getHealthchecksStrings (ptype string , healthchecks * api.Healthchecks ) []string {
41- var probes []string
42- for key := range * healthchecks {
43- probes = append (probes , getHealthcheckString (ptype , key , (* healthchecks )[key ]))
40+ func getHealthchecksStrings (ptype string , healthcheck * api.Healthcheck ) []string {
41+ var containerProbes []string
42+ if healthcheck .StartupProbe != nil {
43+ containerProbes = append (containerProbes , getContainerProbeString (ptype , "startupProbe" , * healthcheck .StartupProbe ))
44+ } else if healthcheck .LivenessProbe != nil {
45+ containerProbes = append (containerProbes , getContainerProbeString (ptype , "livenessProbe" , * healthcheck .LivenessProbe ))
46+ } else if healthcheck .ReadinessProbe != nil {
47+ containerProbes = append (containerProbes , getContainerProbeString (ptype , "readinessProbe" , * healthcheck .ReadinessProbe ))
4448 }
45- return probes
49+ return containerProbes
4650}
4751
4852// HealthchecksList lists an app's healthchecks.
@@ -105,7 +109,7 @@ func (d *DryccCmd) HealthchecksList(appID, ptype string, version int) error {
105109}
106110
107111// HealthchecksSet sets an app's healthchecks.
108- func (d * DryccCmd ) HealthchecksSet (appID , healthcheckType , ptype string , probe * api.Healthcheck ) error {
112+ func (d * DryccCmd ) HealthchecksSet (appID , healthcheckType , ptype string , probe * api.ContainerProbe ) error {
109113 appID , s , err := loader .LoadAppSettings (d .ConfigFile , appID )
110114 if err != nil {
111115 return err
@@ -114,11 +118,19 @@ func (d *DryccCmd) HealthchecksSet(appID, healthcheckType, ptype string, probe *
114118 d .Printf ("Applying %s healthcheck... " , healthcheckType )
115119
116120 quit := progress (d .WOut )
117-
118- healthcheckMap := make (api.Healthchecks )
119- healthcheckMap [healthcheckType ] = probe
120- configObj := api.Config {Healthcheck : make (map [string ]* api.Healthchecks )}
121- configObj .Healthcheck [ptype ] = & healthcheckMap
121+ var healthcheck api.Healthcheck
122+ switch healthcheckType {
123+ case "livenessProbe" :
124+ healthcheck .LivenessProbe = & probe
125+ case "readinessProbe" :
126+ healthcheck .ReadinessProbe = & probe
127+ case "startupProbe" :
128+ healthcheck .StartupProbe = & probe
129+ default :
130+ return fmt .Errorf ("unknown healthcheck type: %s" , healthcheckType )
131+ }
132+ configObj := api.Config {Healthcheck : make (map [string ]* api.Healthcheck )}
133+ configObj .Healthcheck [ptype ] = & healthcheck
122134
123135 _ , err = config .Set (s .Client , appID , configObj , true )
124136
@@ -135,7 +147,7 @@ func (d *DryccCmd) HealthchecksSet(appID, healthcheckType, ptype string, probe *
135147}
136148
137149// HealthchecksUnset removes an app's healthchecks.
138- func (d * DryccCmd ) HealthchecksUnset (appID , ptype string , healthchecks []string ) error {
150+ func (d * DryccCmd ) HealthchecksUnset (appID , ptype string , containerProbeTypes []string ) error {
139151 appID , s , err := loader .LoadAppSettings (d .ConfigFile , appID )
140152 if err != nil {
141153 return err
@@ -147,16 +159,23 @@ func (d *DryccCmd) HealthchecksUnset(appID, ptype string, healthchecks []string)
147159
148160 configObj := api.Config {}
149161
150- healthchecksMap := make (map [string ]* api.Healthchecks )
151- healthcheckMap := make (api.Healthchecks )
152-
153- for _ , healthcheck := range healthchecks {
154- healthcheckMap [healthcheck ] = nil
162+ healthcheckMap := make (map [string ]* api.Healthcheck )
163+ var nullContainerProbe * api.ContainerProbe = nil
164+ for _ , containerProbeType := range containerProbeTypes {
165+ healthcheck := & api.Healthcheck {}
166+ switch containerProbeType {
167+ case "livenessProbe" :
168+ healthcheck .LivenessProbe = & nullContainerProbe
169+ case "readinessProbe" :
170+ healthcheck .ReadinessProbe = & nullContainerProbe
171+ case "startupProbe" :
172+ healthcheck .StartupProbe = & nullContainerProbe
173+ default :
174+ return fmt .Errorf ("unknown container probe type: %s" , containerProbeType )
175+ }
176+ healthcheckMap [containerProbeType ] = healthcheck
155177 }
156- healthchecksMap [ptype ] = & healthcheckMap
157-
158- configObj .Healthcheck = healthchecksMap
159-
178+ configObj .Healthcheck = healthcheckMap
160179 _ , err = config .Set (s .Client , appID , configObj , true )
161180
162181 quit <- true
0 commit comments