Skip to content

add option to set load_restrictor to none #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 6, 2021

Conversation

darren-reddick
Copy link

Hey!
Hope you are good.

This PR is to add support for --load_restrictor=none as requested in issue #70 .

I have tested the functionality locally but can look at pushing an update to the acceptance tests to specifically test this if needed.

Cheers,
Darren

@cewood
Copy link

cewood commented Mar 26, 2021

What a great looking PR, 12/10 would merge 😉

@@ -17,6 +18,15 @@ func dataSourceKustomization() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"load_restrictor": &schema.Schema{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the schema, even if for now we only implement the loadrestrictions, I think we should still wrap it in a hash map. Because I'm sure somebody will eventually have a requirement for another one of the supported options.

And I think it would be cleaner to not add all of them to the schema at the top level? What do you think about that @darren-reddick?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact there was already a question about making the plugins configurable, which I suppose could also go into that hash map. I'm not saying you need to implement that as well. Just saying, wrap the load_restrictions into a hash map, and maybe it will be extended in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Makes sense - just re-reading the issue and see that you hinted at this. I'll update this.

@pst
Copy link
Member

pst commented Mar 26, 2021

Thanks for the contribution Darren. Only small change I think would be good is the schema change. Happy to discuss.

@darren-reddick darren-reddick force-pushed the feature/no-load-restrictor branch from e12adaf to f5c279d Compare April 1, 2021 09:45
@darren-reddick
Copy link
Author

darren-reddick commented Apr 1, 2021

Hi,
Have just pushed an update. I thought it would be better to have a type to hold the kustomize options as would be easier to add options in the future. Does this make sense?

func kustomizationBuild(d *schema.ResourceData, m interface{}) error {
path := d.Get("path").(string)

kOpts := getKustomizeOptions(d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to pass the entire kOpts into runKustomizeBuild and handle the defaults and overwrites in there just once, instead of handling it once for kustomization_build and once for kustomization_overlay?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. I'm not sure I follow this here. Do you mean to remove the code for setting the default and checking the load_restictor from getKustomizeOptions down into runKustomizeBuild?

Copy link
Member

@pst pst Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, you changed runKustomizeBuild to accept an additional parameter load_restrictor string and passed that string in right from the schema. But now, we're wrapping the load_restrictor in a hash map. So you added getKustomizeOptions to get the string form the hash map and be able to pass it into the runKustomizeBuild method. But inside that method is where it current gets the default config, and if load_restrictor was not none, it overwrites that value.

I was wondering, if it wasn't cleaner to pass the hash map into runKustomizeBuild, the same way it comes from Terraform, and then handle conversion, defaults and overwriting all just in one place. You wouldn't have to call getKustomizeOptions from two places. Plus getKustomizeOptions could also handle the defaults and overwriting, that's now implemented in runKustomizeBuild.

Basically I'm asking if we should not replace:

opts := krusty.MakeDefaultOptions()

// If the load_restrictor option is set to none then the krusty.Options
// should be updated to reflect this.
if load_restrictor == "none" {
    opts.LoadRestrictions = types.LoadRestrictionsNone
}

with

opts := getKustomizeOptions(kOpts)

and change runKustomizeBuild to accept kOpts *schema.ResourceData

runKustomizeBuild(fSys filesys.FileSystem, path string, kOpts *schema.ResourceData)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm fine merging without that change too. Since all these methods are private, I can probably change this at any time in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Passing the schema thru was what i thought you meant originally but then had doubts. That totally makes sense so I will update.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Have updated this and its much cleaner now. Having the new kustomizeOptions type didnt make any sense also so have removed that.

@@ -17,6 +17,18 @@ func dataSourceKustomization() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"kustomize_options": &schema.Schema{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this is what I meant. 💯

loadRestrictor string
}

func getKustomizeOptions(d *schema.ResourceData) (k kustomizeOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is probably better located in the same file as runKustomizeBuild.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@pst
Copy link
Member

pst commented Apr 6, 2021

Thanks Darren, this looks great.

I'll get it merged to run the tests. I should probably run the tests on PRs not just on commits. To get them run on contributions like this.

@pst pst merged commit 7d2dbec into kbst:master Apr 6, 2021
willthames added a commit to willthames/terraform-provider-kustomization that referenced this pull request Aug 31, 2021
PR kbst#101 added the ability to set load restrictor to `"none"`

This adds documentation for that change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants