Skip to content

Commit 49e616c

Browse files
committed
Use dynamic default func to keep defaults when item is not computed in other usecases
1 parent 61d3085 commit 49e616c

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

kubernetes/schema_pod_spec.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,35 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
4040
},
4141
},
4242
"dns_policy": {
43-
Type: schema.TypeString,
44-
Optional: true,
45-
Computed: isComputed,
46-
//Default: "ClusterFirst"
43+
Type: schema.TypeString,
44+
Optional: true,
45+
Computed: isComputed,
46+
DefaultFunc: defaultIfNotComputed(isComputed, "ClusterFirst"),
4747
Description: "Set DNS policy for containers within the pod. One of 'ClusterFirst' or 'Default'. Defaults to 'ClusterFirst'.",
4848
Deprecated: deprecatedMessage,
4949
},
5050
"host_ipc": {
51-
Type: schema.TypeBool,
52-
Optional: true,
53-
Computed: isComputed,
54-
//Default: false,
51+
Type: schema.TypeBool,
52+
Optional: true,
53+
Computed: isComputed,
54+
DefaultFunc: defaultIfNotComputed(isComputed, false),
5555
Description: "Use the host's ipc namespace. Optional: Default to false.",
5656
Deprecated: deprecatedMessage,
5757
},
5858
"host_network": {
59-
Type: schema.TypeBool,
60-
Optional: true,
61-
Computed: isComputed,
62-
//Default: false,
59+
Type: schema.TypeBool,
60+
Optional: true,
61+
Computed: isComputed,
62+
DefaultFunc: defaultIfNotComputed(isComputed, false),
6363
Description: "Host networking requested for this pod. Use the host's network namespace. If this option is set, the ports that will be used must be specified.",
6464
Deprecated: deprecatedMessage,
6565
},
6666

6767
"host_pid": {
68-
Type: schema.TypeBool,
69-
Optional: true,
70-
Computed: isComputed,
71-
//Default: false,
68+
Type: schema.TypeBool,
69+
Optional: true,
70+
Computed: isComputed,
71+
DefaultFunc: defaultIfNotComputed(isComputed, false),
7272
Description: "Use the host's pid namespace.",
7373
Deprecated: deprecatedMessage,
7474
},
@@ -111,10 +111,10 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
111111
Deprecated: deprecatedMessage,
112112
},
113113
"restart_policy": {
114-
Type: schema.TypeString,
115-
Optional: true,
116-
Computed: isComputed,
117-
//Default: "Always",
114+
Type: schema.TypeString,
115+
Optional: true,
116+
Computed: isComputed,
117+
DefaultFunc: defaultIfNotComputed(isComputed, "Always"),
118118
Description: "Restart policy for all containers within the pod. One of Always, OnFailure, Never. More info: http://kubernetes.io/docs/user-guide/pod-states#restartpolicy.",
119119
Deprecated: deprecatedMessage,
120120
},
@@ -177,10 +177,10 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
177177
Deprecated: deprecatedMessage,
178178
},
179179
"termination_grace_period_seconds": {
180-
Type: schema.TypeInt,
181-
Optional: true,
182-
Computed: isComputed,
183-
//Default: 30,
180+
Type: schema.TypeInt,
181+
Optional: true,
182+
Computed: isComputed,
183+
DefaultFunc: defaultIfNotComputed(isComputed, 30),
184184
ValidateFunc: validateTerminationGracePeriodSeconds,
185185
Description: "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process.",
186186
Deprecated: deprecatedMessage,
@@ -213,6 +213,16 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
213213
return s
214214
}
215215

216+
func defaultIfNotComputed(isComputed bool, defaultValue interface{}) schema.SchemaDefaultFunc {
217+
return func() (interface{}, error) {
218+
if isComputed {
219+
return nil, nil
220+
}
221+
222+
return defaultValue, nil
223+
}
224+
}
225+
216226
func volumeSchema() *schema.Resource {
217227
v := commonVolumeSources()
218228

0 commit comments

Comments
 (0)