Skip to content

Commit

Permalink
Implemented the code to create the volumeMounts and volumes for a sec…
Browse files Browse the repository at this point in the history
…ret. #89

Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Sep 10, 2024
1 parent 78ed2a5 commit d085241
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configurations/konflux/build-remote-ssh-cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/dev/snowdrop/factory/TektonResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,6 +128,34 @@ public static PipelineTask createTaskUsingRef(Action action, String runAfter, Bu
return pipelineTask;
}

public static List<VolumeMount> populateTaskVolumeMounts(Action action) {
List<Volume> taskVolumes = action.getVolumes();
List<VolumeMount> 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<io.fabric8.kubernetes.api.model.Volume> populateTaskVolumes(Action action) {
List<Volume> taskVolumes = action.getVolumes();
List<io.fabric8.kubernetes.api.model.Volume> 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<WorkspacePipelineTaskBinding> populateTaskWorkspaces(Action action, Map<String, Workspace> jobWorkspacesMap, List<WorkspaceDeclaration> taskWorkspaces) {
// List of workspaces to be generated by this method
List<WorkspacePipelineTaskBinding> wksPipelineTask = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/snowdrop/model/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit d085241

Please sign in to comment.