Skip to content

Commit e12adaf

Browse files
committed
add kustomize options type to include load-restrictor
1 parent 7bbb07c commit e12adaf

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

kustomize/data_source_kustomization_build.go

+34-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7-
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
87

98
"sigs.k8s.io/kustomize/api/filesys"
109
)
@@ -18,14 +17,17 @@ func dataSourceKustomization() *schema.Resource {
1817
Type: schema.TypeString,
1918
Required: true,
2019
},
21-
"load_restrictor": &schema.Schema{
22-
Type: schema.TypeString,
20+
"kustomize_options": &schema.Schema{
21+
Type: schema.TypeMap,
2322
Optional: true,
24-
Default: "",
25-
ValidateFunc: validation.StringInSlice(
26-
[]string{"none", ""},
27-
false,
28-
),
23+
Elem: &schema.Resource{
24+
Schema: map[string]*schema.Schema{
25+
"load_restrictor": {
26+
Type: schema.TypeString,
27+
Optional: true,
28+
},
29+
},
30+
},
2931
},
3032
"ids": &schema.Schema{
3133
Type: schema.TypeSet,
@@ -52,17 +54,39 @@ func dataSourceKustomization() *schema.Resource {
5254
}
5355
}
5456

57+
type kustomizeOptions struct {
58+
loadRestrictor string
59+
}
60+
61+
func getKustomizeOptions(d *schema.ResourceData) (k kustomizeOptions) {
62+
// initialize kustomizeOptions with defaults
63+
k = kustomizeOptions{
64+
loadRestrictor: "",
65+
}
66+
67+
kOpts := d.Get("kustomize_options").(map[string]interface{})
68+
69+
if kOpts["load_restrictor"] != nil {
70+
if kOpts["load_restrictor"].(string) == "none" {
71+
k.loadRestrictor = "none"
72+
}
73+
}
74+
75+
return k
76+
}
77+
5578
func kustomizationBuild(d *schema.ResourceData, m interface{}) error {
5679
path := d.Get("path").(string)
57-
load_restrictor := d.Get("load_restrictor").(string)
80+
81+
kOpts := getKustomizeOptions(d)
5882

5983
fSys := filesys.MakeFsOnDisk()
6084

6185
// mutex as tmp workaround for upstream bug
6286
// https://github.com/kubernetes-sigs/kustomize/issues/3659
6387
mu := m.(*Config).Mutex
6488
mu.Lock()
65-
rm, err := runKustomizeBuild(fSys, path, load_restrictor)
89+
rm, err := runKustomizeBuild(fSys, path, kOpts.loadRestrictor)
6690
mu.Unlock()
6791
if err != nil {
6892
return fmt.Errorf("kustomizationBuild: %s", err)

kustomize/data_source_kustomization_overlay.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,17 @@ func dataSourceKustomizationOverlay() *schema.Resource {
387387
Computed: true,
388388
Elem: &schema.Schema{Type: schema.TypeString},
389389
},
390-
"load_restrictor": &schema.Schema{
391-
Type: schema.TypeString,
390+
"kustomize_options": &schema.Schema{
391+
Type: schema.TypeMap,
392392
Optional: true,
393-
Default: "",
394-
ValidateFunc: validation.StringInSlice(
395-
[]string{"none", ""},
396-
false,
397-
),
393+
Elem: &schema.Resource{
394+
Schema: map[string]*schema.Schema{
395+
"load_restrictor": {
396+
Type: schema.TypeString,
397+
Optional: true,
398+
},
399+
},
400+
},
398401
},
399402
},
400403
}
@@ -675,7 +678,7 @@ func refuseExistingKustomization(fSys filesys.FileSystem) error {
675678
func kustomizationOverlay(d *schema.ResourceData, m interface{}) error {
676679
k := getKustomization(d)
677680

678-
load_restrictor := d.Get("load_restrictor").(string)
681+
kOpts := getKustomizeOptions(d)
679682

680683
var b bytes.Buffer
681684
ye := yaml.NewEncoder(io.Writer(&b))
@@ -702,7 +705,7 @@ func kustomizationOverlay(d *schema.ResourceData, m interface{}) error {
702705
// https://github.com/kubernetes-sigs/kustomize/issues/3659
703706
mu := m.(*Config).Mutex
704707
mu.Lock()
705-
rm, err := runKustomizeBuild(fSys, ".", load_restrictor)
708+
rm, err := runKustomizeBuild(fSys, ".", kOpts.loadRestrictor)
706709
mu.Unlock()
707710
if err != nil {
708711
return fmt.Errorf("buildKustomizeOverlay: %s", err)

0 commit comments

Comments
 (0)