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

JENKINS-46253 Add support for subPath to all volume types #1031

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hameno
Copy link

@hameno hameno commented Sep 15, 2021

Includes work from Miguel Campos (#1024)

refs JENKINS-46253

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Includes work from Miguel Campos (jenkinsci#1024)

refs JENKINS-46253
@mcamposv
Copy link
Contributor

Dear Hameno,
I'm no expert however before I placed my pull request I was told that we should not modify the existing API methods in a class.
if you check my initial commit I changed the
sprylab@a309ac1#diff-76b7e7535ea9463d5389851a958cc07955f2fcfbe99bb393079fdc6f70b0e46f

I created a new constructor but I maintained the old one that calls the new one:
public ConfigMapVolume(String mountPath, String configMapName, Boolean optional) {
this(mountPath, configMapName, optional, (String) null);
}

If I'm not seeing wrong you changed the constructor but did not maintain the old one for compatibility purpose that might be a reason for the pull request to be rejected.
could you please amend your code to maintain compatibility?

Thanks.

Copy link
Member

@Vlatombe Vlatombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert any hunk unrelated to the change you want to accomplish.

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.nio.file.Paths;
import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use wildcard imports in production code. Please revert.

import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.combine;
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.isNullOrEmpty;
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.substituteEnv;
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above.

Comment on lines +5 to +6
import java.util.List;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

Comment on lines +31 to +32
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid this kind of change that is just making reviews and blaming more complex.

Comment on lines +157 to +158
// We need to normalize the subPath, or we can end up in really hard to debug issues Just in case.
final String subPath = substituteEnv(Paths.get(volumeSubPath).normalize().toString().replace("\\", "/"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that normalization really needed? What happens if the agent is on Windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Viatombe,
I'm answering this because this piece of code is also in my original PR wich was intended only for ConfigMap volumes.
I think the answer applies on both.
To be honest I do not know what will happen in a windows container.
But what I can see is that that normalization is there since 4 years ago. in commit: 43afca4c3209dc6b1d8b768b157ab53cc12da052 made by Alex Johnson ajohnson@bombora.com
The only modification I did was to surround it with an if to control whether the new parameter is empty or not.
So I guess that piece of code is as secure or insecure as it was before and is out of the intention of this PR to modify/evaluate that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, I didn't see that the same code was applied to mountPath.

Comment on lines +41 to +42
@DataBoundConstructor
public ConfigMapVolume(String mountPath, String configMapName, Boolean optional, String subPath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, you could add a setter for subPath annotated with @DataBoundSetter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, viatombe,
I'm going to need a bit more explanation on why this is not the correct way of doing things. or how you preffer me to do it
I do not know why is wrong the go from 3 parameters in the constructor to 4.
I do not know the difference between @DataBoundConstructor and @DataboundSetter.
however @DataBoundSetter was not used anywhere in the previous code.
and I'm just adding a new parameter to the constructor. keeping the old one for compatibility issues.
I do not know where is the issue. please explain.
I'm very happy to learn the right way of doing things.

Copy link
Member

@Vlatombe Vlatombe Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can read the explanation here -- Constructor vs. setters.
In that case ideally only mountPath and configMapName should be left in the constructor since they are mandatory, and optional and subPath should be set using setters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vincent,
the link was quite useful and I understand the difference.
I've done the modifications on my original code/PR
All the other issues are not in my original code/PR.
Please consider merging PR while @hameno fixes the issues on his side.

@Vlatombe Vlatombe added the enhancement Improvements label Oct 4, 2021
@jgournet
Copy link

@hameno : would you be able to progress this further after the comments ? This is a great feature that is direly missing

@hameno
Copy link
Author

hameno commented Nov 17, 2021

@hameno : would you be able to progress this further after the comments ? This is a great feature that is direly missing

Unfortunately I won't have capacity until next year. I found a workaround which works for us so this currently doesn't have priority

@jgournet
Copy link

May I ask what workaround you're using ? (right now, I'm just mounting the whole volume and hardcoding paths ... that will work, but if there's better, I wouldn't mind ;) )

@hameno
Copy link
Author

hameno commented Nov 17, 2021

(On mobile right now, so not exactly sure how it's called)
I'm using the agent yaml template to adjust the Pod spec

@EricDales
Copy link

Hello, any chance this pull request will be finalized ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants