diff --git a/go.mod b/go.mod index d2a2b66c09..bda344e9d0 100644 --- a/go.mod +++ b/go.mod @@ -291,8 +291,8 @@ require ( replace ( github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13 - github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250317062447-742cf1539ee2 - github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250317062447-742cf1539ee2 + github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250324113450-bdbee9063174 + github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250324113450-bdbee9063174 github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 k8s.io/api => k8s.io/api v0.29.7 diff --git a/go.sum b/go.sum index 89f0f7ee7b..eec8ac89fd 100644 --- a/go.sum +++ b/go.sum @@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU= github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA= -github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250317062447-742cf1539ee2 h1:7jQYKn1eLMIn7QgV13bNhueU+CbbRaSBxkWp+Dp/GTo= -github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250317062447-742cf1539ee2/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250317062447-742cf1539ee2 h1:blntkjXNtvA1AccbAcM6TKV+WcbXNyIstSnhDtAfuI8= -github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250317062447-742cf1539ee2/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA= +github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250324113450-bdbee9063174 h1:Tf3xomEdbSkgrxW9mUpuQ6W2f8ZX3rX1fwlY/evEWGU= +github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250324113450-bdbee9063174/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250324113450-bdbee9063174 h1:0ro/HoPor0pamglXYqe9Z4MlQsO3pyW94C/byzzsxig= +github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250324113450-bdbee9063174/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs= diff --git a/pkg/cluster/ClusterServiceExtended.go b/pkg/cluster/ClusterServiceExtended.go index cbd673cd60..d1efda3b3a 100644 --- a/pkg/cluster/ClusterServiceExtended.go +++ b/pkg/cluster/ClusterServiceExtended.go @@ -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" @@ -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" @@ -351,7 +324,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) diff --git a/pkg/cluster/repository/ClusterRepository.go b/pkg/cluster/repository/ClusterRepository.go index 27a78a040d..1680a44ff2 100644 --- a/pkg/cluster/repository/ClusterRepository.go +++ b/pkg/cluster/repository/ClusterRepository.go @@ -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 } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0ad6211390..60e1467aef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -342,7 +342,7 @@ github.com/davecgh/go-spew/spew # github.com/deckarep/golang-set v1.8.0 ## explicit; go 1.17 github.com/deckarep/golang-set -# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250317062447-742cf1539ee2 +# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250324113450-bdbee9063174 ## explicit; go 1.21 github.com/devtron-labs/authenticator/apiToken github.com/devtron-labs/authenticator/client @@ -350,7 +350,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250317062447-742cf1539ee2 +# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250324113450-bdbee9063174 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage @@ -2226,8 +2226,8 @@ xorm.io/xorm/log xorm.io/xorm/names xorm.io/xorm/schemas xorm.io/xorm/tags -# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250317062447-742cf1539ee2 -# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250317062447-742cf1539ee2 +# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250324113450-bdbee9063174 +# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250324113450-bdbee9063174 # github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 # github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 # k8s.io/api => k8s.io/api v0.29.7