Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify DefaultFunc to just Default #379

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions kubernetes/schema_pod_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
Type: schema.TypeString,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, "ClusterFirst"),
Default: defaultIfNotComputed(isComputed, "ClusterFirst"),
Description: "Set DNS policy for containers within the pod. One of 'ClusterFirst' or 'Default'. Defaults to 'ClusterFirst'.",
Deprecated: deprecatedMessage,
},
"host_ipc": {
Type: schema.TypeBool,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, false),
Default: defaultIfNotComputed(isComputed, false),
Description: "Use the host's ipc namespace. Optional: Default to false.",
Deprecated: deprecatedMessage,
},
"host_network": {
Type: schema.TypeBool,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, false),
Default: defaultIfNotComputed(isComputed, false),
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.",
Deprecated: deprecatedMessage,
},
Expand All @@ -68,7 +68,7 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
Type: schema.TypeBool,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, false),
Default: defaultIfNotComputed(isComputed, false),
Description: "Use the host's pid namespace.",
Deprecated: deprecatedMessage,
},
Expand Down Expand Up @@ -114,7 +114,7 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
Type: schema.TypeString,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, "Always"),
Default: defaultIfNotComputed(isComputed, "Always"),
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.",
Deprecated: deprecatedMessage,
},
Expand Down Expand Up @@ -180,7 +180,7 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
Type: schema.TypeInt,
Optional: true,
Computed: isComputed,
DefaultFunc: defaultIfNotComputed(isComputed, 30),
Default: defaultIfNotComputed(isComputed, 30),
ValidateFunc: validateTerminationGracePeriodSeconds,
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.",
Deprecated: deprecatedMessage,
Expand Down Expand Up @@ -213,14 +213,11 @@ func podSpecFields(isUpdatable, isDeprecated, isComputed bool) map[string]*schem
return s
}

func defaultIfNotComputed(isComputed bool, defaultValue interface{}) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
if isComputed {
return nil, nil
}

return defaultValue, nil
func defaultIfNotComputed(isComputed bool, defaultValue interface{}) interface{} {
if isComputed {
return nil
}
return defaultValue
}

func volumeSchema() *schema.Resource {
Expand Down