@@ -24,6 +24,7 @@ import (
2424 util3 "github.com/devtron-labs/common-lib/utils/k8s"
2525 "io"
2626 "io/ioutil"
27+ errors2 "k8s.io/apimachinery/pkg/api/errors"
2728 "net/http"
2829 "net/url"
2930 "strconv"
@@ -354,11 +355,24 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
354355 } else {
355356 secretData := impl .CreateSecretDataForHelmChart (request , isPrivateChart )
356357 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 ) {
358360 impl .logger .Errorw ("error in fetching secret" , "err" , err )
359361 continue
360362 }
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+
362376 if previousName != request .Name {
363377 err = impl .DeleteChartSecret (previousName )
364378 if err != nil {
@@ -372,6 +386,7 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
372386 impl .logger .Errorw ("Error in creating secret for chart repo" , "Chart Name" , chartRepo .Name , "err" , err )
373387 }
374388 } else {
389+ secret .StringData = secretData
375390 _ , err = impl .K8sUtil .UpdateSecret (impl .aCDAuthConfig .ACDConfigMapNamespace , secret , client )
376391 if err != nil {
377392 impl .logger .Errorw ("Error in creating secret for chart repo" , "Chart Name" , chartRepo .Name , "err" , err )
0 commit comments