1
1
package generator
2
2
3
3
import (
4
+ "fmt"
4
5
"katenary/generator/labels"
5
6
"katenary/generator/labels/labelStructs"
6
7
"katenary/utils"
@@ -141,7 +142,7 @@ func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string
141
142
// cumulate the path to the WorkingDir
142
143
path = filepath .Join (service .WorkingDir , path )
143
144
path = filepath .Clean (path )
144
- cm .AppenddDir (path )
145
+ cm .AppendDir (path )
145
146
return cm
146
147
}
147
148
@@ -160,17 +161,17 @@ func (c *ConfigMap) AddBinaryData(key string, value []byte) {
160
161
161
162
// AddFile adds files from given path to the configmap. It is not recursive, to add all files in a directory,
162
163
// you need to call this function for each subdirectory.
163
- func (c * ConfigMap ) AppenddDir (path string ) {
164
+ func (c * ConfigMap ) AppendDir (path string ) error {
164
165
// read all files in the path and add them to the configmap
165
166
stat , err := os .Stat (path )
166
167
if err != nil {
167
- log . Fatalf ("Path %s does not exist\n " , path )
168
+ return fmt . Errorf ("Path %s does not exist, %w \n " , path , err )
168
169
}
169
170
// recursively read all files in the path and add them to the configmap
170
171
if stat .IsDir () {
171
172
files , err := os .ReadDir (path )
172
173
if err != nil {
173
- log . Fatal ( err )
174
+ return err
174
175
}
175
176
for _ , file := range files {
176
177
if file .IsDir () {
@@ -180,7 +181,7 @@ func (c *ConfigMap) AppenddDir(path string) {
180
181
path := filepath .Join (path , file .Name ())
181
182
content , err := os .ReadFile (path )
182
183
if err != nil {
183
- log . Fatal ( err )
184
+ return err
184
185
}
185
186
// remove the path from the file
186
187
filename := filepath .Base (path )
@@ -195,7 +196,7 @@ func (c *ConfigMap) AppenddDir(path string) {
195
196
// add the file to the configmap
196
197
content , err := os .ReadFile (path )
197
198
if err != nil {
198
- log . Fatal ( err )
199
+ return err
199
200
}
200
201
filename := filepath .Base (path )
201
202
if utf8 .Valid (content ) {
@@ -204,20 +205,21 @@ func (c *ConfigMap) AppenddDir(path string) {
204
205
c .AddBinaryData (filename , content )
205
206
}
206
207
}
208
+ return nil
207
209
}
208
210
209
- func (c * ConfigMap ) AppendFile (path string ) {
211
+ func (c * ConfigMap ) AppendFile (path string ) error {
210
212
// read all files in the path and add them to the configmap
211
213
stat , err := os .Stat (path )
212
214
if err != nil {
213
- log . Fatalf ("Path %s does not exist \n " , path )
215
+ return fmt . Errorf ("Path %s doesn not exists, %w " , path , err )
214
216
}
215
217
// recursively read all files in the path and add them to the configmap
216
218
if ! stat .IsDir () {
217
219
// add the file to the configmap
218
220
content , err := os .ReadFile (path )
219
221
if err != nil {
220
- log . Fatal ( err )
222
+ return err
221
223
}
222
224
if utf8 .Valid (content ) {
223
225
c .AddData (filepath .Base (path ), string (content ))
@@ -226,6 +228,7 @@ func (c *ConfigMap) AppendFile(path string) {
226
228
}
227
229
228
230
}
231
+ return nil
229
232
}
230
233
231
234
// Filename returns the filename of the configmap. If the configmap is used for files, the filename contains the path.
0 commit comments