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

TemplateConfig implementation with Kubernetes #41

Merged
merged 1 commit into from
Sep 9, 2014

Conversation

mfojtik
Copy link
Contributor

@mfojtik mfojtik commented Sep 2, 2014

Initial implementation of TemplateConfig REST endpoint.

See the project.json example.

To test this PR:

$ curl -d @pkg/template/examples/project.json \
  http://localhost:8080/api/v1beta1/templateConfigs

This will return Config{} which is essentially the same as a templateConfig{} 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 ;-)

@bparees
Copy link
Contributor

bparees commented Sep 2, 2014

@mfojtik why are we back to having replicationControllers and not DeploymentConfig objects in this spec?

@mfojtik
Copy link
Contributor Author

mfojtik commented Sep 2, 2014

@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.

@mfojtik
Copy link
Contributor Author

mfojtik commented Sep 2, 2014

@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(),
Copy link
Contributor Author

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 ?

}

// ProcessParameters searches the ReplicationControllers and Pods defined in the
// TemplateConfig and substitutes the references to parameters with the parameter
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 ;-)

Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Contributor

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...

Copy link
Contributor

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.

@VojtechVitek
Copy link
Contributor

How to build/run:

cd $GOPATH/src/github.com/openshift/origin
./hack/build-go.sh
./output/go/bin/openshift start

How to test (in different terminal window):

cd $GOPATH/src/github.com/openshift/origin
curl -d @examples/guestbook/template.json http://localhost:8080/osapi/v1beta1/templateConfigs

@VojtechVitek VojtechVitek force-pushed the templateConfig branch 2 times, most recently from ca6c1d3 to a52edc8 Compare September 2, 2014 22:07
@smarterclayton smarterclayton changed the title [WIP][POC] TemplateConfig implementation with Kubernetes [WIP] TemplateConfig implementation with Kubernetes Sep 3, 2014
@mfojtik mfojtik changed the title [WIP] TemplateConfig implementation with Kubernetes TemplateConfig implementation with Kubernetes Sep 3, 2014
@smarterclayton smarterclayton self-assigned this Sep 3, 2014
@@ -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(),
Copy link
Contributor

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))...)
Copy link
Contributor

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")

@mfojtik mfojtik force-pushed the templateConfig branch 2 times, most recently from d587206 to cf08db6 Compare September 9, 2014 10:48
@mfojtik
Copy link
Contributor Author

mfojtik commented Sep 9, 2014

@smarterclayton I think we are ready for the final round :-)

@smarterclayton
Copy link
Contributor

Can you guys open a follow up pull to do the following:

  • example readme that describes how to use this
  • openshift cli support (not kubecfg) for turning a template into a config and then creating the config (the config part should be near identical to the pull you did for Kube)
  • an integration test that mutates a template into config by POSTing to /templateConfigs and then uses the client config code to create the objects, then test that the objects were correctly created

@mfojtik
Copy link
Contributor Author

mfojtik commented Sep 9, 2014

@smarterclayton sure thing... the object creation integration test will require Config PR.

@VojtechVitek VojtechVitek force-pushed the templateConfig branch 4 times, most recently from 95f20ca to 0671283 Compare September 9, 2014 15:33
@smarterclayton
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor

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.

@mfojtik
Copy link
Contributor Author

mfojtik commented Sep 9, 2014

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>
@smarterclayton
Copy link
Contributor

LGTM [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin up to 1ba20a8

@openshift-bot
Copy link
Contributor

Origin Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_openshift3/74/) (Image: devenv-fedora_140)

openshift-bot pushed a commit that referenced this pull request Sep 9, 2014
@openshift-bot openshift-bot merged commit af59397 into openshift:master Sep 9, 2014
spadgett pushed a commit to spadgett/origin that referenced this pull request Apr 11, 2016
danwinship pushed a commit to danwinship/origin that referenced this pull request Jun 24, 2016
return if error is a stop by user event
ncdc pushed a commit to ncdc/origin that referenced this pull request Mar 22, 2017
jpeeler pushed a commit to jpeeler/origin that referenced this pull request Feb 1, 2018
@mfojtik mfojtik deleted the templateConfig branch September 5, 2018 21:08
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.

6 participants