Skip to content

Commit 7d2dbec

Browse files
authored
Merge pull request #101 from ContainerSolutions/feature/no-load-restrictor
add option to set load_restrictor to none
2 parents bcf3393 + 38fbd51 commit 7d2dbec

3 files changed

+45
-4
lines changed

kustomize/data_source_kustomization.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sigs.k8s.io/kustomize/api/krusty"
1515
"sigs.k8s.io/kustomize/api/resid"
1616
"sigs.k8s.io/kustomize/api/resmap"
17+
"sigs.k8s.io/kustomize/api/types"
1718
)
1819

1920
func getIDFromResources(rm resmap.ResMap) (s string, err error) {
@@ -79,8 +80,9 @@ func idSetHash(v interface{}) int {
7980
return prefixHash(p, h)
8081
}
8182

82-
func runKustomizeBuild(fSys filesys.FileSystem, path string) (rm resmap.ResMap, err error) {
83-
opts := krusty.MakeDefaultOptions()
83+
func runKustomizeBuild(fSys filesys.FileSystem, path string, kOpts *schema.ResourceData) (rm resmap.ResMap, err error) {
84+
85+
opts := getKustomizeOptions(kOpts)
8486

8587
k := krusty.MakeKustomizer(fSys, opts)
8688

@@ -111,3 +113,18 @@ func setGeneratedAttributes(d *schema.ResourceData, rm resmap.ResMap) error {
111113

112114
return nil
113115
}
116+
117+
func getKustomizeOptions(d *schema.ResourceData) (opts *krusty.Options) {
118+
119+
opts = krusty.MakeDefaultOptions()
120+
121+
kOpts := d.Get("kustomize_options").(map[string]interface{})
122+
123+
if kOpts["load_restrictor"] != nil {
124+
if kOpts["load_restrictor"].(string) == "none" {
125+
opts.LoadRestrictions = types.LoadRestrictionsNone
126+
}
127+
}
128+
129+
return opts
130+
}

kustomize/data_source_kustomization_build.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ func dataSourceKustomization() *schema.Resource {
1717
Type: schema.TypeString,
1818
Required: true,
1919
},
20+
"kustomize_options": &schema.Schema{
21+
Type: schema.TypeMap,
22+
Optional: true,
23+
Elem: &schema.Resource{
24+
Schema: map[string]*schema.Schema{
25+
"load_restrictor": {
26+
Type: schema.TypeString,
27+
Optional: true,
28+
},
29+
},
30+
},
31+
},
2032
"ids": &schema.Schema{
2133
Type: schema.TypeSet,
2234
Computed: true,
@@ -51,7 +63,7 @@ func kustomizationBuild(d *schema.ResourceData, m interface{}) error {
5163
// https://github.com/kubernetes-sigs/kustomize/issues/3659
5264
mu := m.(*Config).Mutex
5365
mu.Lock()
54-
rm, err := runKustomizeBuild(fSys, path)
66+
rm, err := runKustomizeBuild(fSys, path, d)
5567
mu.Unlock()
5668
if err != nil {
5769
return fmt.Errorf("kustomizationBuild: %s", err)

kustomize/data_source_kustomization_overlay.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ func dataSourceKustomizationOverlay() *schema.Resource {
387387
Computed: true,
388388
Elem: &schema.Schema{Type: schema.TypeString},
389389
},
390+
"kustomize_options": &schema.Schema{
391+
Type: schema.TypeMap,
392+
Optional: true,
393+
Elem: &schema.Resource{
394+
Schema: map[string]*schema.Schema{
395+
"load_restrictor": {
396+
Type: schema.TypeString,
397+
Optional: true,
398+
},
399+
},
400+
},
401+
},
390402
},
391403
}
392404
}
@@ -691,7 +703,7 @@ func kustomizationOverlay(d *schema.ResourceData, m interface{}) error {
691703
// https://github.com/kubernetes-sigs/kustomize/issues/3659
692704
mu := m.(*Config).Mutex
693705
mu.Lock()
694-
rm, err := runKustomizeBuild(fSys, ".")
706+
rm, err := runKustomizeBuild(fSys, ".", d)
695707
mu.Unlock()
696708
if err != nil {
697709
return fmt.Errorf("buildKustomizeOverlay: %s", err)

0 commit comments

Comments
 (0)