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

Add support for processing templates #183

Merged
merged 1 commit into from
Sep 23, 2016

Conversation

zakiva
Copy link
Contributor

@zakiva zakiva commented Aug 16, 2016

This PR adds support for processing templates.
A template allows the user to generate a list of objects with certain labels and parameters. This list can be then used in order to create these objects. So, we would like to support processing the template and return the list of objects to create (as part of the processed template).
Template is currently an Openshift entity, and will be added to k8s here.
cc @abonas @simon3z @zeari

@zakiva zakiva changed the title Add support for processing templates [WIP] Add support for processing templates Aug 16, 2016
@abonas
Copy link
Member

abonas commented Aug 16, 2016

are you going to add tests? what is this feature about/link to k8s documentation?

@zakiva
Copy link
Contributor Author

zakiva commented Aug 16, 2016

are you going to add tests? what is this feature about/link to k8s documentation?

yes, I marked it with WIP since tests and updating the Readme are still missing. I'll also update the description above.

@zakiva zakiva force-pushed the add_process_template branch from 5f19132 to ea958ef Compare August 17, 2016 12:44
@zakiva zakiva force-pushed the add_process_template branch 4 times, most recently from 9110902 to 5e2bd3b Compare August 28, 2016 12:32
@zakiva zakiva changed the title [WIP] Add support for processing templates Add support for processing templates Aug 28, 2016
@zakiva
Copy link
Contributor Author

zakiva commented Aug 28, 2016

@moolitayer @zeari Please review

@abonas
Copy link
Member

abonas commented Aug 28, 2016

Currently the feature is not merged on k8s side and that PR wasn't updated for a while.
So either this support should be added to openshift ruby client, or be blocked from merging here until it's merged in k8s - to be on the safe side for users who are using k8s and not openshift.
cc @simon3z


```ruby
client.process_template template
```
Copy link
Member

Choose a reason for hiding this comment

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

any example/rules how a template should look like? any mandatory fields?

@simon3z
Copy link
Collaborator

simon3z commented Aug 29, 2016

Currently the feature is not merged on k8s side and that PR wasn't updated for a while.
So either this support should be added to openshift ruby client, or be blocked from merging here until it's merged in k8s - to be on the safe side for users who are using k8s and not openshift.

Yes, @zakiva this should be move to the openshift client.

@zakiva
Copy link
Contributor Author

zakiva commented Aug 29, 2016

moved to openshift client, closing.

@zakiva
Copy link
Contributor Author

zakiva commented Sep 18, 2016

@simon3z @zeari @moolitayer reopened, please take another look.

@headers['Content-Type'] = 'application/json'
response = handle_exception do
rest_client[ns_prefix + 'processedtemplates']
.post(template.to_h.to_json, @headers)
Copy link

Choose a reason for hiding this comment

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

Question: I dont understand how this is different from create_template. They are both using post on the received template hash. Can you please explain how this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both indeed use Post on a template, but while create_template actually creates a template, process_template does not. It is only used to substitute the template parameters and generate their values (if required), in order to get a list of objects to create from the template. Note that we need here a separated method because although both requests are using Post they are still different:

POST /oapi/v1/namespaces/{namespace}/templates for creating a template.

POST /oapi/v1/namespaces/{namespace}/processedtemplates for processing a template.

Copy link

Choose a reason for hiding this comment

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

👍 Thank you

Copy link
Collaborator

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

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

Looks good pending minor comment.

.post(template.to_h.to_json, @headers)
end
result = JSON.parse(response)
result
Copy link
Collaborator

Choose a reason for hiding this comment

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

style: replace the above two lines with

JSON.parse(response)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks.

@@ -405,6 +405,17 @@ def proxy_url(kind, name, port, namespace = '')
end
end

def process_template(template)
ns_prefix = build_namespace_prefix(template[:metadata][:namespace])
@headers['Content-Type'] = 'application/json'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually we do not want to update @headers except for this request.
Please follow #190 to clean this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks.

@zakiva zakiva force-pushed the add_process_template branch from bb8d9c9 to 409f4f6 Compare September 19, 2016 08:00
rest_client[ns_prefix + 'processedtemplates']
.post(template.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(@headers))
end
JSON.parse(response)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@zakiva @moolitayer I thought this was taken care of by the rest client.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No and I don't see rest_client has support for that. Our exception handler parses exceptions but other then that we parse the response manually on all calls but get_pod_log. I recently thought about wrapping some of the rest_client logic since it is repetitive. Maybe that belongs there too. Not in this PR though

@moolitayer
Copy link
Collaborator

LGTM 👍

@moolitayer
Copy link
Collaborator

moolitayer commented Sep 21, 2016

Since last comments regarding kubeclinet vs openshift_client from 24 days ago some things changed:

  • we are looking into replacing openshift_client with a kubeclient with discovery on the openshift endpoint - see openshift_client here
  • The only real functional difference between the two would be the new process_template method as clients were kept functionally similar up until this point (which is great for us)
  • Given those facts and that the issue in question is targeted to reach kubernetes at some point our cleanest direction for these two clients would be to add process_templates in kubeclient

@abonas @jonmoter @jimmidyson @nyxcharon @Fryguy @zeari @yaacov @cben @grosser

Any comment on this? We'd like to merge this ASAP

@simon3z
Copy link
Collaborator

simon3z commented Sep 21, 2016

Any comment on this? We'd like to merge this ASAP

LGTM 👍, I haven't reviewed the code closely, maybe there are nits to fix, but I agree with the direction.

@zeari
Copy link

zeari commented Sep 22, 2016

LGTM 👍

Copy link

@enoodle enoodle left a comment

Choose a reason for hiding this comment

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

👍 LGTM.
I would have made the test a bit more simple but its not very important as it can be easily changed if someone ever finds it as a problem.

req_body = "{\"metadata\":{\"name\":\"my-template\",\"namespace\":\"default\"},"\
"\"kind\":\"Template\",\"apiVersion\":\"v1\",\"objects\":[{\"metadata\":"\
"{\"name\":\"${NAME_PREFIX}my-service\"},\"kind\":\"Service\",\"apiVersion\":\"v1\"}],"\
"\"parameters\":[{\"name\":\"NAME_PREFIX\",\"value\":\"test/\"}]}"
Copy link

@enoodle enoodle Sep 22, 2016

Choose a reason for hiding this comment

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

Is this the best way to create the request body?
Do we really need a request body here? I see that in other tests we just mocked without this and it seems to be enough.

@salilgupta1
Copy link
Contributor

Might be nice to clarify in the README that process_template is not something that is supported by k8s right now.

@simon3z
Copy link
Collaborator

simon3z commented Mar 1, 2017

Might be nice to clarify in the README that process_template is not something that is supported by k8s right now.

Right @salilgupta1, can you or @zakiva send a PR to update the README file?

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.

7 participants