Skip to content

Commit 1b556b5

Browse files
committed
feat: add support for container sleep lifecycle hook
1 parent 0acfdf9 commit 1b556b5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

kubernetes/schema_container.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ func lifecycleHandlerFields() map[string]*schema.Schema {
9898
},
9999
},
100100
},
101+
"sleep": {
102+
Type: schema.TypeList,
103+
Optional: true,
104+
MaxItems: 1,
105+
Description: "Sleep represents a duration that the container should sleep",
106+
Elem: &schema.Resource{
107+
Schema: map[string]*schema.Schema{
108+
"seconds": {
109+
Type: schema.TypeInt,
110+
Required: true,
111+
ValidateFunc: validation.IntAtLeast(0),
112+
Description: "Number of seconds to sleep.",
113+
},
114+
},
115+
},
116+
},
101117
}
102118
}
103119

kubernetes/structures_container.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,19 @@ func flattenLifecycleHandler(in *v1.LifecycleHandler) []interface{} {
8080
if in.TCPSocket != nil {
8181
att["tcp_socket"] = flattenTCPSocket(in.TCPSocket)
8282
}
83+
if in.Sleep != nil {
84+
att["sleep"] = flattenSleep(in.Sleep)
85+
}
8386

8487
return []interface{}{att}
8588
}
8689

90+
func flattenSleep(in *v1.SleepAction) []interface{} {
91+
att := make(map[string]interface{})
92+
att["seconds"] = in.Seconds
93+
return []interface{}{att}
94+
}
95+
8796
func flattenHTTPHeader(in []v1.HTTPHeader) []interface{} {
8897
att := make([]interface{}, len(in))
8998
for i, v := range in {
@@ -686,6 +695,18 @@ func expandSecurityCapabilities(l []interface{}) *v1.Capabilities {
686695
return &obj
687696
}
688697

698+
func expandSleep(l []interface{}) *v1.SleepAction {
699+
if len(l) == 0 || l[0] == nil {
700+
return &v1.SleepAction{}
701+
}
702+
in := l[0].(map[string]interface{})
703+
obj := v1.SleepAction{}
704+
if v, ok := in["seconds"].(int); ok && v >= 0 {
705+
obj.Seconds = int64(v)
706+
}
707+
return &obj
708+
}
709+
689710
func expandTCPSocket(l []interface{}) *v1.TCPSocketAction {
690711
if len(l) == 0 || l[0] == nil {
691712
return &v1.TCPSocketAction{}
@@ -791,6 +812,9 @@ func expandLifecycleHandlers(l []interface{}) *v1.LifecycleHandler {
791812
if v, ok := in["tcp_socket"].([]interface{}); ok && len(v) > 0 {
792813
obj.TCPSocket = expandTCPSocket(v)
793814
}
815+
if v, ok := in["sleep"].([]interface{}); ok && len(v) > 0 {
816+
obj.Sleep = expandSleep(v)
817+
}
794818
return &obj
795819
}
796820

0 commit comments

Comments
 (0)