Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 4 additions & 31 deletions pkg/cluster/ClusterServiceExtended.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"time"

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

}

// if git-ops configured, then only update cluster in ACD, otherwise ignore
// if git-ops configured and ArgoCD module is installed, then only update cluster in ACD, otherwise ignore
if gitOpsConfigurationStatus.IsGitOpsConfiguredAndArgoCdInstalled() {
configMap := bean.Config
serverUrl := bean.ServerUrl
bearerToken := ""
if configMap[commonBean.BearerToken] != "" {
bearerToken = configMap[commonBean.BearerToken]
}

tlsConfig := v1alpha1.TLSClientConfig{
Insecure: bean.InsecureSkipTLSVerify,
}
if !bean.InsecureSkipTLSVerify {
tlsConfig.KeyData = []byte(configMap[commonBean.TlsKey])
tlsConfig.CertData = []byte(configMap[commonBean.CertData])
tlsConfig.CAData = []byte(configMap[commonBean.CertificateAuthorityData])
}

cdClusterConfig := v1alpha1.ClusterConfig{
BearerToken: bearerToken,
TLSClientConfig: tlsConfig,
}

cl := &v1alpha1.Cluster{
Name: bean.ClusterName,
Server: serverUrl,
Config: cdClusterConfig,
}

_, err = impl.argoCDClientWrapper.UpdateCluster(ctx, &cluster3.ClusterUpdateRequest{Cluster: cl})

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

// if git-ops configured, then only add cluster in ACD, otherwise ignore
// if git-ops configured and ArgoCD module is installed, then only add cluster in ACD, otherwise ignore
if gitOpsConfigurationStatus.IsGitOpsConfiguredAndArgoCdInstalled() {
//create it into argo cd as well
cl := impl.ConvertClusterBeanObjectToCluster(bean)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/repository/ClusterRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (impl ClusterRepositoryImpl) FindByClusterURL(clusterURL string) (*Cluster,
err := impl.dbConnection.
Model(cluster).
Where("server_url =?", clusterURL).
Where("active =?", true).
Where("active =?", true).Order("id DESC").Limit(1).
Select()
return cluster, err
}