Skip to content

Commit 846c2d9

Browse files
authored
fix: cluster update issue (#6465)
* fix for cluster update * modifying comment
1 parent b90e419 commit 846c2d9

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

Diff for: pkg/cluster/ClusterServiceExtended.go

+4-31
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"time"
3030

3131
cluster3 "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
32-
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
3332
"github.com/devtron-labs/devtron/client/grafana"
3433
"github.com/devtron-labs/devtron/internal/constants"
3534
"github.com/devtron-labs/devtron/internal/util"
@@ -236,37 +235,11 @@ func (impl *ClusterServiceImplExtended) Update(ctx context.Context, bean *bean.C
236235

237236
}
238237

239-
// if git-ops configured, then only update cluster in ACD, otherwise ignore
238+
// if git-ops configured and ArgoCD module is installed, then only update cluster in ACD, otherwise ignore
240239
if gitOpsConfigurationStatus.IsGitOpsConfiguredAndArgoCdInstalled() {
241-
configMap := bean.Config
242-
serverUrl := bean.ServerUrl
243-
bearerToken := ""
244-
if configMap[commonBean.BearerToken] != "" {
245-
bearerToken = configMap[commonBean.BearerToken]
246-
}
247-
248-
tlsConfig := v1alpha1.TLSClientConfig{
249-
Insecure: bean.InsecureSkipTLSVerify,
250-
}
251-
if !bean.InsecureSkipTLSVerify {
252-
tlsConfig.KeyData = []byte(configMap[commonBean.TlsKey])
253-
tlsConfig.CertData = []byte(configMap[commonBean.CertData])
254-
tlsConfig.CAData = []byte(configMap[commonBean.CertificateAuthorityData])
255-
}
256-
257-
cdClusterConfig := v1alpha1.ClusterConfig{
258-
BearerToken: bearerToken,
259-
TLSClientConfig: tlsConfig,
260-
}
261-
262-
cl := &v1alpha1.Cluster{
263-
Name: bean.ClusterName,
264-
Server: serverUrl,
265-
Config: cdClusterConfig,
266-
}
267-
268-
_, err = impl.argoCDClientWrapper.UpdateCluster(ctx, &cluster3.ClusterUpdateRequest{Cluster: cl})
269240

241+
cl := impl.ConvertClusterBeanObjectToCluster(bean)
242+
_, err = impl.argoCDClientWrapper.CreateCluster(ctx, &cluster3.ClusterCreateRequest{Upsert: true, Cluster: cl})
270243
if err != nil {
271244
impl.logger.Errorw("service err, Update", "error", err, "payload", cl)
272245
userMsg := "failed to update on cluster via ACD"
@@ -349,7 +322,7 @@ func (impl *ClusterServiceImplExtended) Save(ctx context.Context, bean *bean.Clu
349322
return nil, err
350323
}
351324

352-
// if git-ops configured, then only add cluster in ACD, otherwise ignore
325+
// if git-ops configured and ArgoCD module is installed, then only add cluster in ACD, otherwise ignore
353326
if gitOpsConfigurationStatus.IsGitOpsConfiguredAndArgoCdInstalled() {
354327
//create it into argo cd as well
355328
cl := impl.ConvertClusterBeanObjectToCluster(bean)

Diff for: pkg/cluster/repository/ClusterRepository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (impl ClusterRepositoryImpl) FindByClusterURL(clusterURL string) (*Cluster,
212212
err := impl.dbConnection.
213213
Model(cluster).
214214
Where("server_url =?", clusterURL).
215-
Where("active =?", true).
215+
Where("active =?", true).Order("id DESC").Limit(1).
216216
Select()
217217
return cluster, err
218218
}

0 commit comments

Comments
 (0)