diff --git a/internal/kubernetes/core/v1/pod/volume/fields.go b/internal/kubernetes/core/v1/pod/volume/fields.go index 5149a222..3e00bd67 100644 --- a/internal/kubernetes/core/v1/pod/volume/fields.go +++ b/internal/kubernetes/core/v1/pod/volume/fields.go @@ -3,6 +3,7 @@ package volume import ( "github.com/hashicorp/terraform/helper/schema" "github.com/previousnext/terraform-provider-k8s/internal/kubernetes/core/v1/pod/volume/nfs" + "github.com/previousnext/terraform-provider-k8s/internal/kubernetes/core/v1/pod/volume/hostpath" ) const ( @@ -16,6 +17,9 @@ const ( FieldEmptyDir = "empty_dir" // FieldNFS is a field identifier. FieldNFS = "nfs" + // FieldHostPath is a field identifier. + FieldHostPath = "host_path" + ) // Fields returns the fields for this package. @@ -42,7 +46,8 @@ func Fields() *schema.Schema { Type: schema.TypeString, Optional: true, }, - FieldNFS: nfs.Fields(), + FieldNFS: nfs.Fields(), + FieldHostPath: hostpath.Fields(), }, }, } diff --git a/internal/kubernetes/core/v1/pod/volume/hostpath/expand.go b/internal/kubernetes/core/v1/pod/volume/hostpath/expand.go new file mode 100644 index 00000000..2d2a8708 --- /dev/null +++ b/internal/kubernetes/core/v1/pod/volume/hostpath/expand.go @@ -0,0 +1,26 @@ +package hostpath + +import ( + corev1 "k8s.io/api/core/v1" +) + +// Expand will return a structured object. +func Expand(in []interface{}) *corev1.HostPathVolumeSource { + if len(in) == 0 { + return nil + } + + source := &corev1.HostPathVolumeSource{} + + raw := in[0].(map[string]interface{}) + + if val, ok := raw[FieldPath]; ok { + source.Path = val.(string) + } + + if val, ok := raw[FieldType]; ok { + source.Type = val.(*corev1.HostPathType) + } + + return source +} diff --git a/internal/kubernetes/core/v1/pod/volume/hostpath/fields.go b/internal/kubernetes/core/v1/pod/volume/hostpath/fields.go new file mode 100644 index 00000000..fcbb8be4 --- /dev/null +++ b/internal/kubernetes/core/v1/pod/volume/hostpath/fields.go @@ -0,0 +1,32 @@ +package hostpath + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +const ( + // FieldPath is a field identifier. + FieldPath = "path" + // FieldType is a field identifier. + FieldType = "type" +) + +// Fields returns the fields for this package. +func Fields() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + FieldPath: &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + FieldType: &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + }, + }, + } +} diff --git a/internal/kubernetes/core/v1/pod/volume/hostpath/flatten.go b/internal/kubernetes/core/v1/pod/volume/hostpath/flatten.go new file mode 100644 index 00000000..24b6d335 --- /dev/null +++ b/internal/kubernetes/core/v1/pod/volume/hostpath/flatten.go @@ -0,0 +1,23 @@ +package hostpath + +import ( + corev1 "k8s.io/api/core/v1" +) + +// Flatten structured object into unstructured. +func Flatten(in *corev1.HostPathVolumeSource) []interface{} { + out := make([]interface{}, 1) + + row := map[string]interface{}{} + + if in.Path != "" { + row[FieldPath] = in.Path + } + if *in.Type != corev1.HostPathUnset { + row[FieldType] = in.Type + } + + out[0] = row + + return out +}