-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
TemplateConfig implementation with Kubernetes #41
Conversation
@mfojtik why are we back to having replicationControllers and not DeploymentConfig objects in this spec? |
@bparees deploymentConfig is not yet merged, so I can't use them atm. I made a TODO in this PR to replace replicationController once it will be there. Also the k8s Config{} right now does not define deploymentConfig. |
@bparees actually I'm taking the last comment back ;-) The replicationController should stay here, the deploymentConfig and buildConfig will be added to the list once they will become available. |
@@ -100,7 +101,8 @@ func startAllInOne() { | |||
|
|||
// initialize OpenShift API | |||
storage := map[string]apiserver.RESTStorage{ | |||
"services": service.NewRESTStorage(service.MakeMemoryRegistry()), | |||
"services": service.NewRESTStorage(service.MakeMemoryRegistry()), | |||
"templateConfigs": template.NewRegistryStorage(), |
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.
@VojtechVitek maybe rename this to NewRESTStorage ?
c403459
to
8853d77
Compare
} | ||
|
||
// ProcessParameters searches the ReplicationControllers and Pods defined in the | ||
// TemplateConfig and substitutes the references to parameters with the parameter |
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.
Are we assuming services won't have substitutable content?
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.
It's a fair point. I can imagine service having randomized port number.
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.
well, if you think about this more, we can also do substitutions in properties like 'name' or 'description', maybe even in 'label'. I can think of scenario when you have development and production template and you want to change the environment (even the name of services) based on the parameter value.
@smarterclayton does it make sense?
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.
Make sense to me. One templateConfig should be able to create several (dev
, prod
, qa
etc.) resources that differ just in one label.
@mfojtik how would we propagate such different value to parameter generator? I mean, I have a template config file with ${environment}
parameter that defaults to prod
and I want to change it to dev
during the POST /templateConfigs
. Does it make sense?
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.
@VojtechVitek I think you'd have to specify the value when defining the parameter at the top of the file (ie in the parameters section). I suppose we could also enable the /templateConfigs endpoint to accept arguments that overrode/explicitly set parameter values.
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.
@bparees we can do that by using the custom parameters we already support. I just need to figure out how to pass a map of parameters to the Create method ;-)
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.
@VojtechVitek there are two options. First is what @bparees described and the second is that you will have 2 different templates (one for prod and one for dev)
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.
It would be pretty easy for a client submitting a template to change the values. Worth discussion.
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.
@smarterclayton you mean the actual client implementation would swap out values (based on some flags passed to the client invocation) in the json before invoking the rest endpoint? Sounds reasonable...
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.
Yeah - cause at least a Go client will have a TemplateConfig object, so for them they can just say "read template config from disk, override parameter X".
This is a good pattern in general in Kubernetes - making the API objects composable so that your client code on both the server or in a CLI can do the same thing the same way.
How to build/run:
How to test (in different terminal window):
|
ca6c1d3
to
a52edc8
Compare
@@ -100,7 +101,8 @@ func startAllInOne() { | |||
|
|||
// initialize OpenShift API | |||
storage := map[string]apiserver.RESTStorage{ | |||
"services": service.NewRESTStorage(service.MakeMemoryRegistry()), | |||
"services": service.NewRESTStorage(service.MakeMemoryRegistry()), | |||
"templateConfigs": template.NewRESTStorage(), |
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.
Change the name here to be NewStorage() - the other ones will be removed.
default: | ||
err = append(err, NewFieldInvalid("kind", fmt.Sprintf("%T", item))) | ||
} | ||
errs = append(errs, err.Prefix(fmt.Sprintf("items[%d]", i))...) |
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.
err.PrefixIndex(i).Prefix("items")
d587206
to
cf08db6
Compare
@smarterclayton I think we are ready for the final round :-) |
Can you guys open a follow up pull to do the following:
|
@smarterclayton sure thing... the object creation integration test will require Config PR. |
95f20ca
to
0671283
Compare
Let me know when this is ready for final review. |
shouldPass := func(template *api.Template) { | ||
errs := ValidateTemplate(template) | ||
if len(errs) != 0 { | ||
_, _, line, _ := goruntime.Caller(1) |
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.
This is probably not the right way to do this, I understand why you added it though. Generally you would write this as a table test instead. In your follow up can you refactor this to make a table 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.
Sure, I'll do the refactoring in the follow up.
0671283
to
e7c775d
Compare
LGTM |
Adds TemplateProcessor implementation using the default ExpressionValueGenerator, which is capable of transforming Template api objects into Config api objects. Authors: Michal Fojtik <mfojtik@redhat.com> Vojtech Vitek <vvitek@redhat.com>
e7c775d
to
1ba20a8
Compare
LGTM [merge] |
Evaluated for origin up to 1ba20a8 |
Origin Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_openshift3/74/) (Image: devenv-fedora_140) |
Fix UI e2e test failure
return if error is a stop by user event
Initial implementation of TemplateConfig REST endpoint.
See the project.json example.
To test this PR:
This will return
Config{}
which is essentially the same as atemplateConfig{}
but without parameters.FYI: This is a wip, all commits will be squashed in the end. @VojtechVitek is working on validation atm. so I don't want to force push ;-)