From d085241e6b410559af72a4e629b31590f082dd98 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Tue, 10 Sep 2024 10:26:29 +0200 Subject: [PATCH] Implemented the code to create the volumeMounts and volumes for a secret. #89 Signed-off-by: cmoulliard --- .../konflux/build-remote-ssh-cfg.yaml | 2 +- .../dev/snowdrop/factory/TektonResource.java | 30 +++++++++++++++++++ src/main/java/dev/snowdrop/model/Volume.java | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/configurations/konflux/build-remote-ssh-cfg.yaml b/configurations/konflux/build-remote-ssh-cfg.yaml index 7a2aa6d..fad7dcd 100644 --- a/configurations/konflux/build-remote-ssh-cfg.yaml +++ b/configurations/konflux/build-remote-ssh-cfg.yaml @@ -69,7 +69,7 @@ job: volumes: - name: ssh mountPath: /ssh - accessMode: ReadOnly + # readOnly: true ==> The default value is true secret: "multi-platform-ssh-$(context.taskRun.name)" script: | diff --git a/src/main/java/dev/snowdrop/factory/TektonResource.java b/src/main/java/dev/snowdrop/factory/TektonResource.java index 5c5428c..a4d428c 100644 --- a/src/main/java/dev/snowdrop/factory/TektonResource.java +++ b/src/main/java/dev/snowdrop/factory/TektonResource.java @@ -92,8 +92,10 @@ public static PipelineTask createTaskWithEmbeddedScript(Action action, String ru .withArgs(args) .withImage(action.getImage() != null ? action.getImage() : action.IMAGES.get(STEP_SCRIPT_IMAGE)) .withScript(embeddedScript) + .withVolumeMounts(populateTaskVolumeMounts(action)) // Volum(s) to be mounted from Volume(s) declared at the task level: secret, configMap, etc .endStep() .withResults(results) + .withVolumes(populateTaskVolumes(action)) // Volumes used by the steps .build()) .build(); // @formatter:on @@ -126,6 +128,34 @@ public static PipelineTask createTaskUsingRef(Action action, String runAfter, Bu return pipelineTask; } + public static List populateTaskVolumeMounts(Action action) { + List taskVolumes = action.getVolumes(); + List volumeMounts = new ArrayList<>(); + taskVolumes.forEach(v -> { + volumeMounts.add(new VolumeMountBuilder() + .withName(v.getName()) + .withMountPath(v.getMountPath()) + .withReadOnly(v.getReadOnly()) + .build()); + }); + return volumeMounts; + } + + public static List populateTaskVolumes(Action action) { + List taskVolumes = action.getVolumes(); + List volumes = new ArrayList<>(); + taskVolumes.forEach(v -> { + volumes.add(new VolumeBuilder() + .withName(v.getName()) + // TODO: Improve the code to support to mount different types: ConfigMap, etc + .withSecret(new SecretVolumeSourceBuilder() + .withSecretName(v.getSecret()) + .build()) + .build()); + }); + return volumes; + } + public static List populateTaskWorkspaces(Action action, Map jobWorkspacesMap, List taskWorkspaces) { // List of workspaces to be generated by this method List wksPipelineTask = new ArrayList<>(); diff --git a/src/main/java/dev/snowdrop/model/Volume.java b/src/main/java/dev/snowdrop/model/Volume.java index c3c3a67..e30425a 100644 --- a/src/main/java/dev/snowdrop/model/Volume.java +++ b/src/main/java/dev/snowdrop/model/Volume.java @@ -11,6 +11,7 @@ public class Volume { private String accessMode; private String secret; private String mountPath; + private Boolean readOnly = true; public static String STORAGE = "storage"; }