Skip to content
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

Implement namespace management. #26

Merged
merged 6 commits into from
Mar 23, 2018
Merged

Implement namespace management. #26

merged 6 commits into from
Mar 23, 2018

Conversation

paddycarver
Copy link
Contributor

Allow Terraform to manage Nomad namespaces. At the moment, we have an
unadvertised parameter for setting a quota on the namespace, as well.
This will be tested and then advertised in a future commit, after quota
management with Terraform (#25) is merged.

Allow Terraform to manage Nomad namespaces. At the moment, we have an
unadvertised parameter for setting a quota on the namespace, as well.
This will be tested and then advertised in a future commit, after quota
management with Terraform is merged.
@paddycarver paddycarver requested a review from a team February 12, 2018 16:38
Copy link

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @paddycarver

I've taken a look through and left some comments in-line - they're mostly minor nits; the one issue which needs to be resolved before merging would be sorting the missing documentation entry

Thanks!

log.Printf("[DEBUG] Creating namespace %q", namespace.Name)
_, err := client.Namespaces().Register(&namespace, nil)
if err != nil {
return fmt.Errorf("error inserting namespace %q: %s", namespace.Name, err.Error())

Choose a reason for hiding this comment

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

minor given the comment above, should this be upserting?

return resourceNamespaceRead(d, meta)
}

func resourceNamespaceUpdate(d *schema.ResourceData, meta interface{}) error {

Choose a reason for hiding this comment

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

minor: given these methods are the same - we can combine them for now?

Quota: d.Get("quota").(string),
}

// upsert our namespace

Choose a reason for hiding this comment

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

minor: I think we can remove this, since it's covered by the print statement below?

client := meta.(*api.Client)
name := d.Id()

// delete the namespace

Choose a reason for hiding this comment

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

minor: I think we can remove this, since it's covered by the print statement below?

if err != nil {
// As of Nomad 0.4.1, the API client returns an error for 404
// rather than a nil result, so we must check this way.
if strings.Contains(err.Error(), "404") {

Choose a reason for hiding this comment

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

I'm assuming that means the status code also isn't a 404?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably is, unfortunately the client library doesn't expose that to me :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Please link to hashicorp/nomad#1849 in this comment so we can follow up later more easily.

}
if resp == nil {
// just to be sure
return false, nil

Choose a reason for hiding this comment

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

this probably wants a log statement here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks!

The following arguments are supported:

- `name` `(string: <required>)` - A unique name for the namespace.
- `description` `(string: "")` - A description of the namespace.

Choose a reason for hiding this comment

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

I might be wrong, but isn't the convention:

* `name` - (Required) A unique name for the namespace. Changing this forces a new resource to be created.
* `description` - (Optional) Description for this namespace.
* `quota` - (Optional) Quota for this namespace.

(note: quota is missing above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in general, yes, but when I got to the provider, it already had the above format, so I was trying to keep it consistent within the provider :/ Happy to do a sweep to update, though I have to admit I do think the version I copied is a bit more informative, providing information on defaults and types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, also, quota is intentionally missing until #25 gets merged, because I have no way to test it until then. I just included the code here because I was already in the code, but I don't want to document it until I can actually test it.

Remove unnecessary log lines, combine update/create methods.
@paddycarver paddycarver dismissed tombuildsstuff’s stale review February 20, 2018 08:36

Made suggested changes, left feedback on documentation feedback.

if err != nil {
// As of Nomad 0.4.1, the API client returns an error for 404
// rather than a nil result, so we must check this way.
if strings.Contains(err.Error(), "404") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please link to hashicorp/nomad#1849 in this comment so we can follow up later more easily.

@paddycarver paddycarver merged commit ad744e1 into master Mar 23, 2018
@cgbaker cgbaker deleted the paddy_namespaces branch March 1, 2019 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants