-
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
Cannot specify integer/bool/base64 types in templates #3946
Comments
Even if you find a way to make the parameter typed, doing the actual replacement is more complicated. The template with the replaceable token has to be valid JSON, so you couldn't do this:
We'd have to find a way to:
I can't think of a clean way to do that off the top of my head |
@liggitt and I discussed this and he had a proposal of a format like:
(ok we didn't discus the exact formatting so he may disagree there). then we'd do normal parameter generation but then cast/convert the generated/overridden value into the appropriate type and specify it in the json in the correct format (eg stripping quotes for non-stirngs). this would also enable parameterizing secrets with a format like: "mySecret": ${SOME_PARAM}{BASE64} though it would still not make it possible to supply a binary value or disk file as a secret parameter since you still have to first provide it in the Parameter definition and that only takes strings right now. |
the whole syntax would have to be in a string to be valid JSON and parameterize the value. also, my preference would be to include it in the parameter syntax, e.g.
the pipe syntax would only be allowed if the parameter was the entire value (you couldn't do Possible transformations:
For the conversion cases, we'd have to define what happens in error cases, either the template processing fails, or a default value (probably empty, so |
Hey @bparees @liggitt , Like it says on the 1.0.5 release notes:
|
validating the input and describing the format of the output are different. What if you wanted to validate a numeric input (like "1"), but you wanted to set it in an envvar definition (which expects a string, so "1"). |
And is there an issue to validate the input? This should be also needed, as this could allow to fail soon before doing the template processing. |
@liggitt @bparees alternative proposal (just brainstorming)... {
"name": "INITIAL_REPLICAS_COUNT",
"description": "The number of initial replicas",
"path": ".deploymentConfig[name=foo]....",
"value": 2,
}, This will allow us to substitute basically any type (bool, array, etc..). |
That feels harder to me as a user and more work to maintain if I rename I take it your point is we could just do direct assignment then? "value" Ben Parees | OpenShift
|
Is failing at processing so bad? Processing is fast. Whether we should do more validation as part of process is a valid Ben Parees | OpenShift
|
@bparees yes, the value is interface{} Making the integer and boolean accepting string values with parameters seems to be much harder to implement (the JSON parser will have to be more relaxed on it). |
Validation is orthogonal. I might want to validate something as an integer, even if it is going to be plugged in as a string.
Which parser, parsing when we process the template? |
@liggitt yes, like if you parse |
any field that contains a parameter substitution already has to be a string, in order to contain the param name syntax... I think we have to let that be transformed from a string to a non-string |
It is a problem since the template today consists of (among other things) a list of API Structs, so the assumption is that the json in the template can be directly deserialized into an api object. (which is what we do, and then we iterate the objects/fields and do the substitution). So @mfojtik makes a valid point that we can't just put String values into non-String fields in the template json, because it won't deserialize anymore (without some help) |
I thought this meant the objects could be arbitrary JSON:
I thought the template process visited all the structs using reflection, and could swap a string value out with an int value, then reserialize. I didn't think templates items got converted to actual API structs during processing. |
could be. i'm guilty of assuming/speculating w/o checking the code. |
If we're adding types, how about a
|
this is about how parameters are rendered into the template, not input... you can already do
|
You can, at least under bash and if your file has no commas, but is that what we want to tell users? Anyway, point taken, this might be too much overloading of the "types" concept. |
This is done through the new boolean field "disableSSLCheck" inside GitBuildSource object. The use case is to allow the user to specify a git repository with a self-signed SSL certificate. Currently sti build fails at git (ls-remote|clone) stage. So, one can write a template like this ... "source": { "contextDir": "${CONTEXT_DIR}", "git": { "disableSSLCheck": true, "ref": "${SOURCE_REPOSITORY_REF}", "uri": "${SOURCE_REPOSITORY_URL}" }, "type": "Git" ... In the future, with openshift#3946 implemented, one might use a boolean parameter in the template and have it rendered into a checkbox in the UI.
Any update on this? I just gained a few new grey hairs because of this 😀 As a temporary hack I'm doing the following:
Nasty but works |
At this point we're looking to address this as part of moving templates upstream to kubernetes, you can see the proposal here: https://github.com/kubernetes/kubernetes/blob/master/docs/proposals/templates.md it includes support for handling this sort of scenario. |
Similar to what we just merged for archivist, the role to deploy the app will no longer destroy the running app and trigger a build. Instead we maintain the OpenShift objects, update them if necessary, and check if a start-build is required on each run. Several parameters in the template which user integers now fail to process citing a "int32" error on OpenShift 3.7. Suspect related to: openshift/origin#3946. These parameters were never customized so to work around they have been removed and just hard coded. We can update the template and re-run ansible to adjust in future, which would be required even to reprocess the template.
Similar to what we just merged for archivist, the role to deploy the app will no longer destroy the running app and trigger a build. Instead we maintain the OpenShift objects, update them if necessary, and check if a start-build is required on each run. Several parameters in the template which user integers now fail to process citing a "int32" error on OpenShift 3.7. Suspect related to: openshift/origin#3946. These parameters were never customized so to work around they have been removed and just hard coded. We can update the template and re-run ansible to adjust in future, which would be required even to reprocess the template.
As referenced here: #11068 There is a workaround using |
In my case I had to remove the spaces as well: |
It is not currently possible to specify integer types in template parameters.
For example, we want to be able to specify a parameter:
where N_MIAMI will actually be fed to a replication controller to specify the number of replicas.
As written, this fails during oc process with:
error: unable to load "agree21-template.yaml": json: cannot unmarshal number into Go value of type string
We can fix this with:
which now successfully processes. However, the output now contains:
"replicas": "1"
which fails on creation with:
json: cannot unmarshall string into Go value of type int
A possible fix would be to be able to specify the expected parameter type (string, int or float should cover it) in the parameter definition.
The text was updated successfully, but these errors were encountered: