-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from previousnext/8--hostpath
Added host_path volume type.
- Loading branch information
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
internal/kubernetes/core/v1/pod/volume/hostpath/flatten.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |