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

Add support for volume mounts #4673

Merged
merged 4 commits into from
Dec 1, 2023
Merged

Add support for volume mounts #4673

merged 4 commits into from
Dec 1, 2023

Conversation

c0d1ngm0nk3y
Copy link
Member

@c0d1ngm0nk3y c0d1ngm0nk3y commented Nov 14, 2023

containerMountPath did not work and was partly commented out. For now, it only accepts mountPath with the name volume. If provided, the mountPath will be used as containerMountPath.

Changes

  • Tests
  • Documentation

@c0d1ngm0nk3y c0d1ngm0nk3y requested a review from a team as a code owner November 14, 2023 09:00
@c0d1ngm0nk3y
Copy link
Member Author

@anilkeshav27 As discussed, this is a prerequisite to make detectExecuteScan scan images as well.

@anilkeshav27
Copy link
Member

@c0d1ngm0nk3y , i have also forwarded this request to jenkins as a service to make sure that there is no restriction from their side if the pod template changes . i dont know their public github usernames so have forwarded the PR to them to also get a nod from their side

Copy link

@patrick-lerch patrick-lerch left a comment

Choose a reason for hiding this comment

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

Some comments

pkg/config/stepmeta.go Show resolved Hide resolved
@NonCPS
def containerMountPathFromVolumeBind(dockerVolumeBind) {
if (dockerVolumeBind) {
return dockerVolumeBind[0].split(":")[1]
Copy link

@patrick-lerch patrick-lerch Nov 20, 2023

Choose a reason for hiding this comment

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

Are you sure all customers will use : as separator?
Docker also provides the option to specify mounts via source and target properties. For those use cases your function is not going to work.
Not sure if this is supported by Piper.

Choose a reason for hiding this comment

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

Also why only the first volume get's translated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also why only the first volume get's translated?

It is containerMountPath. The user cannot influence WHAT is mounted, only to what path.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure all customers will use : as separator? Docker also provides the option to specify mounts via source and target properties. For those use cases your function is not going to work. Not sure if this is supported by Piper.

Do you mean this? This ist actually a mount command and not bind. So I do not think it is supported.

Choose a reason for hiding this comment

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

As part of the JaaS setup within SAP, we do not permit the use of hostPath volumes. This practice aligns with security best practices, especially in a shared cluster environment. The proposed change would have an impact on our internal customers

Copy link
Member

@anilkeshav27 anilkeshav27 Nov 21, 2023

Choose a reason for hiding this comment

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

@basava12345 , @c0d1ngm0nk3y , the code only talks about the volume mounts in the main app container running in the pod and this functionality is unchanged, if i understand correctly the change can allow any path to be mounted in the side care container ?.

Since the environment is shared does that allow me to bring a path from any other project into my running pod with the side car container or is it a named volume that already exists which i want to mount at a specefic path in my container ?

if its an already existing volume who creates it ?

maybe i missing something here and so want to be sure,

Copy link
Member Author

Choose a reason for hiding this comment

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

@basava12345 , @c0d1ngm0nk3y , the code only talks about the volume mounts in the main app container running in the pod and this functionality is unchanged,

if i understand correctly the change can allow any path to be mounted in the side care container ?.

Yes, the path in the container can be anything, but that is only the path within the container. WHAT to mount is hardcoded (here: "volume").

Since the environment is shared does that allow me to bring a path from any other project into my running pod with the side car container

I don't se how...

or is it a named volume that already exists which i want to mount at a specefic path in my container ?

Yes. In case of Kubernetes, it is a emptyDir, I do not know what the other orchestrators are doing tbh.

if its an already existing volume who creates it ?

Hopefully, the orchestrator specific code. Or docker when starting it with the correct arguments.

maybe i missing something here and so want to be sure,

I am not 100% sure that we are talking about the same thing, similar to this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, I now got your point. On Kubernetes, it is clear that an empty dir is mounted. But we will check what happens for ADO and GHA.

Copy link
Member

Choose a reason for hiding this comment

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

i think it will confusing for users with the current paramter. if someone called dockerExecute with dockerVolumeBind then there is a implicit understanding in code that the target path is taken into account and an emptyDir is mounted into the target path . and this changes the understanding of a traditional volume bind hostPath:targetPath which is not allowed in shared k8s cluster environment but can work outside a shared k8s cluster

we have a clean parameter in dockerExecuteOnKubernetes, couldn't we reuse that as a new param for dockerExecute ? so the behavior remains the same ?

/**
 * The path to which a volume should be mounted to. This volume will be available at the same
 * mount path in each container of the provided containerMap. The volume is of type emptyDir
 * and has the name 'volume'. With the additionalPodProperties parameter one can for example
 * use this volume in an initContainer.
 */
'containerMountPath',
 /**

Copy link
Member Author

Choose a reason for hiding this comment

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

To summarise the meeting we had:

We will stick to volumeBind, but make sure that the Name is volume. With that, we would still be flexible to enhance in the future, but for the user there won't be surprises what ist actually mounted. We should document this restriction though.

WorkingDir string `json:"workingDir"`
Conditions []Condition `json:"conditions,omitempty"`
Options []Option `json:"options,omitempty"`
VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"`
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should not go for "VolumeMounts []VolumeMounts", but for "MountPath string". That is what we do for kubernetes anyway (ignoring the name and take the first one). So the docker arguments would be in synch. The user could configure the mountPath of an empty and shared volume. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, maybe it DOES make sense to keep the API generic to be able to easily extend the capabilities later.

@@ -385,7 +385,7 @@ func (container *Container) commonConfiguration(keyPrefix string, config *map[st
}
putStringIfNotEmpty(*config, keyPrefix+"Workspace", container.WorkingDir)
putSliceIfNotEmpty(*config, keyPrefix+"Options", OptionsAsStringSlice(container.Options))
//putSliceIfNotEmpty(*config, keyPrefix+"VolumeBind", volumeMountsAsStringSlice(container.VolumeMounts))
putSliceIfNotEmpty(*config, keyPrefix+"VolumeBind", volumeMountsAsStringSlice(container.VolumeMounts))
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't we put it into the dockerOptions? Ecspecially if we limit it to one empty volume.

Copy link
Member

@anilkeshav27 anilkeshav27 left a comment

Choose a reason for hiding this comment

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

lgtm

@anilkeshav27
Copy link
Member

/it-go

@anilkeshav27
Copy link
Member

will merge in the morning , to be sure if anything breaks, we can rework if needed

@pbusko
Copy link
Member

pbusko commented Nov 30, 2023

/it-go

@loewenstein
Copy link

@anilkeshav27 Anything missing?

Copy link

sonarqubecloud bot commented Dec 1, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@anilkeshav27
Copy link
Member

/it-go

1 similar comment
@anilkeshav27
Copy link
Member

/it-go

@anilkeshav27 anilkeshav27 merged commit 6efb21b into master Dec 1, 2023
11 checks passed
@anilkeshav27 anilkeshav27 deleted the k8s-volumes branch December 1, 2023 12:33
@vtintillier
Copy link
Member

This change broke our pipeline, can you please have a look at #4705 ? Thanks.

maxatsap pushed a commit to maxatsap/jenkins-library that referenced this pull request Jul 23, 2024
* Add support for volume mounts

* Adatpt unit test to include VolumeMounts

Co-authored-by: Ralf Pannemans <[email protected]>

* Only accept volumeMounts with the name volume

---------

Co-authored-by: Johannes Dillmann <[email protected]>
Co-authored-by: Philipp Stehle <[email protected]>
Co-authored-by: Anil Keshav <[email protected]>
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.

9 participants