-
Notifications
You must be signed in to change notification settings - Fork 240
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
Check casc version to match changes in YamlSource #409
Check casc version to match changes in YamlSource #409
Conversation
Check for casc version 1.41 or to match the api changes to YamlSource
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 can easily be reduced to two lines.
Though I do not appreciate it calling a restricted method.
pkg/configuration/user/casc/casc.go
Outdated
def source = new io.jenkins.plugins.casc.yaml.YamlSource(stream, io.jenkins.plugins.casc.yaml.YamlSource.READ_FROM_INPUTSTREAM) | ||
def plugin = jenkins.model.Jenkins.instance.getPluginManager().whichPlugin(io.jenkins.plugins.casc.ConfigurationAsCode) | ||
def version = plugin.getVersionNumber() | ||
|
||
def source | ||
|
||
switch (version) { | ||
case { it.isNewerThanOrEqualTo(new VersionNumber("1.41")) }: | ||
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream) | ||
break | ||
default: | ||
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream, io.jenkins.plugins.casc.yaml.YamlSource.READ_FROM_INPUTSTREAM) | ||
break | ||
} | ||
|
||
io.jenkins.plugins.casc.ConfigurationAsCode.get().configureWith(source) |
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.
Here is a clearer version that is backwards compatible.
def source = new io.jenkins.plugins.casc.yaml.YamlSource(stream, io.jenkins.plugins.casc.yaml.YamlSource.READ_FROM_INPUTSTREAM) | |
def plugin = jenkins.model.Jenkins.instance.getPluginManager().whichPlugin(io.jenkins.plugins.casc.ConfigurationAsCode) | |
def version = plugin.getVersionNumber() | |
def source | |
switch (version) { | |
case { it.isNewerThanOrEqualTo(new VersionNumber("1.41")) }: | |
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream) | |
break | |
default: | |
source = new io.jenkins.plugins.casc.yaml.YamlSource(stream, io.jenkins.plugins.casc.yaml.YamlSource.READ_FROM_INPUTSTREAM) | |
break | |
} | |
io.jenkins.plugins.casc.ConfigurationAsCode.get().configureWith(source) | |
def source = io.jenkins.plugins.casc.yaml.YamlSource.of(stream) | |
io.jenkins.plugins.casc.ConfigurationAsCode.get().configureWith(source) |
However this method is marked restricted for a reason. https://github.com/jenkinsci/configuration-as-code-plugin/blob/1c32633d879379b83bb4c0475bf9876c8f88c051/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java#L606-L611
If you need an official way to call with stdin we currently offer the ApplyConfigurationCommand
That will takes stdin
.
If you need a better entrypoint you could have asked for it when creating this.
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.
As the one who made the so called breaking change.
I do not think so.
You were calling the wrong API in the first place.
This was the very reason why we offer the YamlSource.of()
method, so that the internal method could change.
The constructor for YamlSource class was changed and we removed the YamlReader functional interface because it caused leaking readers that were holding file handles open when using Path input source.
JCasC still supports InputStream conversion:
https://github.com/jenkinsci/configuration-as-code-plugin/blob/1c32633d879379b83bb4c0475bf9876c8f88c051/plugin/src/main/java/io/jenkins/plugins/casc/yaml/YamlUtils.java#L83-L96
See this PR: jenkinsci/configuration-as-code-plugin#1398
And see specifially this comment: jenkinsci/configuration-as-code-plugin#1398 (comment)
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.
@jetersen Thanks for the detailed explanation! And sorry for not reaching out before creating the PR, my apologies for rushing it, I should have done my due diligence.
The two lines are certainly nicer than what I ended up with😰 I do understand your concern with calling configureWith
. I am not familiar enough with the operator and jcasc code base to suggest an alternative to the original implementation, so this issue is better handled by someone else than me.
I am very green when it comes to contributing to any project, so I am unsure what a good follow up would be, my suggest is to close this PR and open an issue regarding how the configurations is applied, does that sound like the right next step to 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.
I think the next should be applying my suggestions. Than the maintainers can merge this PR.
Credit where credit is due. I am very thankful that you found this issue.
Than we can consider our next step in another issue or PR.
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.
👍 I applied you suggestion, and thanks again for your feedback. I am just excited to start using anchors in my configuration😀
pkg/configuration/user/casc/casc.go
Outdated
String[] configContent = ['''%s'''] | ||
import hudson.util.VersionNumber | ||
|
||
String[] configContent = ['''%s'''] |
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.
String[] configContent = ['''%s'''] | |
import hudson.util.VersionNumber | |
String[] configContent = ['''%s'''] | |
String[] configContent = ['''%s'''] |
@madsjakobsen Thanks for poking us over on gitter. Much appreciated Going forward I would like to more involved in this project. Especially on any changes to jcasc. |
Much cleaner solution provided by @jetersen which is also backwards compatible
@jetersen Regarding code-owners first we have to separate code to introduce it. |
@madsjakobsen Thanks for the PR 🎉 |
@tomaszsek Any chance we can get an emergency point release with this fix? There are a number of plugins that need updating that depend on 1.41 of JCasC. |
Users are still waiting for a patch. Perhaps we could get a |
Hi, What is the deal with the |
Casc version 1.41 introduced changed to YamlSource which breaks the current implementation in the operator. The commit checks the version of casc and loads the yaml accordingly.
Changes
Check casc plugin version, to accommodate for api changes in version casc v1.41 in YamlSource
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Reviewer Notes
If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS.