Skip to content

Commit

Permalink
Simplify DefaultFunc to just Default (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladRassokhin authored and alexsomesan committed Mar 29, 2019
1 parent f116747 commit 2c87cda
Showing 1 changed file with 10 additions and 13 deletions.
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

0 comments on commit 2c87cda

Please sign in to comment.