@@ -24,6 +24,7 @@ import (
24
24
util3 "github.com/devtron-labs/common-lib/utils/k8s"
25
25
"io"
26
26
"io/ioutil"
27
+ errors2 "k8s.io/apimachinery/pkg/api/errors"
27
28
"net/http"
28
29
"net/url"
29
30
"strconv"
@@ -354,11 +355,24 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
354
355
} else {
355
356
secretData := impl .CreateSecretDataForHelmChart (request , isPrivateChart )
356
357
secret , err := impl .K8sUtil .GetSecret (impl .aCDAuthConfig .ACDConfigMapNamespace , previousName , client )
357
- if err != nil {
358
+ statusError , ok := err .(* errors2.StatusError )
359
+ if err != nil && (ok && statusError != nil && statusError .Status ().Code != http .StatusNotFound ) {
358
360
impl .logger .Errorw ("error in fetching secret" , "err" , err )
359
361
continue
360
362
}
361
- secret .StringData = secretData
363
+
364
+ if ok && statusError != nil && statusError .Status ().Code == http .StatusNotFound {
365
+ secretLabel := make (map [string ]string )
366
+ secretLabel [LABEL ] = REPOSITORY
367
+ _ , err = impl .K8sUtil .CreateSecret (impl .aCDAuthConfig .ACDConfigMapNamespace , nil , chartRepo .Name , "" , client , secretLabel , secretData )
368
+ if err != nil {
369
+ impl .logger .Errorw ("Error in creating secret for chart repo" , "Chart Name" , chartRepo .Name , "err" , err )
370
+ continue
371
+ }
372
+ updateSuccess = true
373
+ break
374
+ }
375
+
362
376
if previousName != request .Name {
363
377
err = impl .DeleteChartSecret (previousName )
364
378
if err != nil {
@@ -372,6 +386,7 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
372
386
impl .logger .Errorw ("Error in creating secret for chart repo" , "Chart Name" , chartRepo .Name , "err" , err )
373
387
}
374
388
} else {
389
+ secret .StringData = secretData
375
390
_ , err = impl .K8sUtil .UpdateSecret (impl .aCDAuthConfig .ACDConfigMapNamespace , secret , client )
376
391
if err != nil {
377
392
impl .logger .Errorw ("Error in creating secret for chart repo" , "Chart Name" , chartRepo .Name , "err" , err )
0 commit comments