Skip to content

Commit

Permalink
Merge pull request #9 from previousnext/8--hostpath
Browse files Browse the repository at this point in the history
Added host_path volume type.
  • Loading branch information
nickschuch authored Apr 3, 2019
2 parents 85b6cb6 + 2231378 commit 9ee9b16
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/kubernetes/core/v1/pod/volume/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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.
Expand All @@ -42,7 +46,8 @@ func Fields() *schema.Schema {
Type: schema.TypeString,
Optional: true,
},
FieldNFS: nfs.Fields(),
FieldNFS: nfs.Fields(),
FieldHostPath: hostpath.Fields(),
},
},
}
Expand Down
26 changes: 26 additions & 0 deletions internal/kubernetes/core/v1/pod/volume/hostpath/expand.go
Original file line number Diff line number Diff line change
@@ -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
}
32 changes: 32 additions & 0 deletions internal/kubernetes/core/v1/pod/volume/hostpath/fields.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
}
}
23 changes: 23 additions & 0 deletions internal/kubernetes/core/v1/pod/volume/hostpath/flatten.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9ee9b16

Please sign in to comment.