-
Notifications
You must be signed in to change notification settings - Fork 167
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
Conversation
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. |
5f19132
to
ea958ef
Compare
9110902
to
5e2bd3b
Compare
@moolitayer @zeari Please review |
Currently the feature is not merged on k8s side and that PR wasn't updated for a while. |
|
||
```ruby | ||
client.process_template template | ||
``` |
There was a problem hiding this comment.
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?
Yes, @zakiva this should be move to the openshift client. |
moved to openshift client, closing. |
5e2bd3b
to
bb8d9c9
Compare
@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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thank you
There was a problem hiding this 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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks.
bb8d9c9
to
409f4f6
Compare
rest_client[ns_prefix + 'processedtemplates'] | ||
.post(template.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(@headers)) | ||
end | ||
JSON.parse(response) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
LGTM 👍 |
Since last comments regarding kubeclinet vs openshift_client from 24 days ago some things changed:
@abonas @jonmoter @jimmidyson @nyxcharon @Fryguy @zeari @yaacov @cben @grosser 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. |
LGTM 👍 |
There was a problem hiding this 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/\"}]}" |
There was a problem hiding this comment.
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.
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? |
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