Skip to content

Commit e49b177

Browse files
committed
feat: mount file type variable in ci-runner through cm
1 parent 3074d15 commit e49b177

7 files changed

Lines changed: 38 additions & 25 deletions

File tree

ci-runner/executor/StageExecutor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (impl *StageExecutorImpl) RunCiCdStep(stepType helper.StepType, ciCdRequest
294294
stepIndexFileMountMap := make(map[int]map[string]*fileContentDto)
295295
for _, inVar := range step.InputVars {
296296
if inVar.Format == commonBean.FormatTypeFile {
297-
fileContent := newFileContentDto(inVar.FileContent, inVar.Value)
297+
fileContent := newFileContentDto(inVar.FileReferencePath, inVar.Value)
298298
if fileMap, ok := stepIndexFileMountMap[inVar.VariableStepIndexInPlugin]; ok {
299299
fileMap[inVar.Name] = fileContent
300300
stepIndexFileMountMap[inVar.VariableStepIndexInPlugin] = fileMap
@@ -320,8 +320,8 @@ func (impl *StageExecutorImpl) RunCiCdStep(stepType helper.StepType, ciCdRequest
320320
if fileMap, ok := stepIndexFileMountMap[step.Index]; ok {
321321
for _, inVar := range step.InputVars {
322322
if fileContent, ok := fileMap[inVar.Name]; ok {
323-
inVar.Value = fileContent.filePath
324-
inVar.FileContent = fileContent.content
323+
inVar.Value = fileContent.mountPath
324+
inVar.FileReferencePath = fileContent.referencePath
325325
}
326326
}
327327
}

ci-runner/executor/scriptExecutor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ type executionConf struct {
178178
}
179179

180180
type fileContentDto struct {
181-
content string
182-
filePath string
181+
referencePath string
182+
mountPath string
183183
}
184184

185-
func newFileContentDto(content, filePath string) *fileContentDto {
185+
func newFileContentDto(fileReferencePath, fileMountPath string) *fileContentDto {
186186
return &fileContentDto{
187-
content: content,
188-
filePath: filePath,
187+
referencePath: fileReferencePath,
188+
mountPath: fileMountPath,
189189
}
190190
}
191191

ci-runner/vendor/github.com/devtron-labs/common-lib/workflow/bean.go

Lines changed: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common-lib/utils/k8s/commonBean/bean.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
)
2525

2626
const (
27+
ConfigMapKind = "ConfigMap"
2728
SecretKind = "Secret"
2829
ServiceKind = "Service"
2930
ServiceAccountKind = "ServiceAccount"
@@ -300,8 +301,8 @@ type PodMetadata struct {
300301
EphemeralContainers []*EphemeralContainerData `json:"ephemeralContainers"`
301302
}
302303

303-
// use value field as generic type
304304
// InfoItem contains arbitrary, human readable information about an application
305+
// use value field as generic type
305306
type InfoItem struct {
306307
// Name is a human readable title for this piece of information.
307308
Name string `json:"name,omitempty"`

common-lib/workflow/bean.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package workflow
22

33
import (
4-
"encoding/base64"
54
"encoding/json"
65
"fmt"
76
"os"
@@ -168,8 +167,8 @@ type VariableObject struct {
168167
ReferenceVariableName string `json:"referenceVariableName"`
169168
ReferenceVariableStepIndex int `json:"referenceVariableStepIndex"`
170169
VariableStepIndexInPlugin int `json:"variableStepIndexInPlugin"`
171-
FileContent string `json:"fileContent"` // FileContent is the base64 encoded content of the file
172-
TypedValue interface{} `json:"-"` // TypedValue is the formatted value of the variable after type conversion
170+
FileReferencePath string `json:"fileReferencePath"` // FileContent is the base64 encoded content of the file
171+
TypedValue interface{} `json:"-"` // TypedValue is the formatted value of the variable after type conversion
173172
}
174173

175174
// TypeCheck converts the VariableObject.Value to the VariableObject.Format type
@@ -188,19 +187,25 @@ func (v *VariableObject) TypeCheck() error {
188187
return nil
189188
}
190189

191-
// SetFileContent decodes the base64 encoded file content and writes it to the file at filePath
190+
// SetFileContent sets the content of the file referenced by the VariableObject.FileReferencePath field.
192191
func (v *VariableObject) SetFileContent(filePath string) error {
193192
if v.Format != FormatTypeFile {
194193
return nil
195194
}
195+
if len(v.FileReferencePath) == 0 {
196+
// for plugins we may receive the filePath as "",
197+
// even thought VariableObject.Value is there;
198+
// for this case don't mount the file.
199+
return nil
200+
}
196201
file, fileErr := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
197202
if fileErr != nil {
198203
return fileErr
199204
}
200205
defer file.Close()
201-
fileBytes, fileErr := base64.StdEncoding.DecodeString(v.FileContent)
202-
if fileErr != nil {
203-
return fileErr
206+
fileBytes, err := os.ReadFile(v.FileReferencePath)
207+
if err != nil {
208+
return err
204209
}
205210
_, wErr := file.Write(fileBytes)
206211
if wErr != nil {

kubelink/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kubewatch/vendor/github.com/devtron-labs/common-lib/utils/k8s/commonBean/bean.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)