@@ -3,8 +3,8 @@ package repository
33import (
44 "encoding/json"
55 "errors"
6+ util2 "github.com/devtron-labs/devtron/internal/util"
67 "github.com/devtron-labs/devtron/pkg/sql"
7- "github.com/devtron-labs/devtron/util"
88 "path"
99 "time"
1010
@@ -31,6 +31,15 @@ type ClusterEntity struct {
3131 K8sVersion string
3232 ErrorInConnecting string
3333 Description string
34+ PrometheusEndpoint string
35+ CdArgoSetup bool
36+ PUserName string
37+ PPassword string
38+ PTlsClientCert string
39+ PTlsClientKey string
40+ AgentInstallationStage int
41+ IsVirtualCluster bool
42+ InsecureSkipTlsVerify bool
3443 sql.AuditLog
3544}
3645
@@ -43,20 +52,16 @@ func NewClusterRepositoryFileBased(logger *zap.SugaredLogger) *ClusterFileBasedR
4352 }
4453 migrator := db .Migrator ()
4554 clusterEntity := & ClusterEntity {}
46- //TODO KB: Need to handle table upgrade migration
47- hasTable := migrator .HasTable (clusterEntity )
48- if ! hasTable {
49- err = migrator .CreateTable (clusterEntity )
50- if err != nil {
51- logger .Fatal ("error occurred while creating cluster table" , "error" , err )
52- }
55+ err = migrator .AutoMigrate (clusterEntity )
56+ if err != nil {
57+ logger .Fatal ("error occurred while migrating cluster table" , "error" , err )
5358 }
5459 logger .Debugw ("cluster repository file based initialized" )
5560 return & ClusterFileBasedRepository {logger , db }
5661}
5762
5863func createOrCheckClusterDbPath (logger * zap.SugaredLogger ) (error , string ) {
59- err , devtronDirPath := util .CheckOrCreateDevtronDir ()
64+ err , devtronDirPath := util2 .CheckOrCreateDevtronDir ()
6065 if err != nil {
6166 logger .Errorw ("error occurred while creating devtron dir " , "err" , err )
6267 return err , ""
@@ -72,6 +77,9 @@ func (impl *ClusterFileBasedRepository) FindAllActiveExceptVirtual() ([]Cluster,
7277 Where ("is_virtual_cluster=? OR is_virtual_cluster IS NULL" , false ).
7378 Find (& clusterEntities )
7479 err := result .Error
80+ if errors .Is (err , gorm .ErrRecordNotFound ) {
81+ err = pg .ErrNoRows
82+ }
7583 if err != nil {
7684 impl .logger .Errorw ("error occurred while finding all cluster data" , "err" , err )
7785 return nil , err
@@ -93,7 +101,7 @@ func (impl *ClusterFileBasedRepository) SetDescription(id int, description strin
93101 clusterEntity .Description = description
94102 clusterEntity .UpdatedBy = userId
95103 clusterEntity .UpdatedOn = time .Now ()
96- result := impl .dbConnection .Model (& ClusterEntity {} ).Updates (clusterEntity )
104+ result := impl .dbConnection .Model (clusterEntity ).Updates (clusterEntity )
97105 err = result .Error
98106 if err != nil {
99107 impl .logger .Errorw ("error occurred while updating cluster description" , "clusterId" , id , "err" , err )
@@ -277,6 +285,9 @@ func (impl *ClusterFileBasedRepository) FindById(id int) (*Cluster, error) {
277285 Find (clusterEntity ).
278286 Limit (1 )
279287 err := result .Error
288+ if errors .Is (err , gorm .ErrRecordNotFound ) {
289+ err = pg .ErrNoRows
290+ }
280291 if err != nil {
281292 impl .logger .Errorw ("error occurred while finding cluster data " , "id" , id , "err" , err )
282293 return nil , err
@@ -295,22 +306,19 @@ func (impl *ClusterFileBasedRepository) FindByIds(id []int) ([]Cluster, error) {
295306
296307 var clusterEntities []ClusterEntity
297308 result := impl .dbConnection .
298- Where ("id in(?) " , pg . In ( id ) ).
309+ Where ("id in ? " , id ).
299310 Where ("active = ?" , true ).
300311 Find (& clusterEntities )
301312 err := result .Error
313+ if errors .Is (err , gorm .ErrRecordNotFound ) {
314+ err = pg .ErrNoRows
315+ }
302316 if err != nil {
303317 impl .logger .Errorw ("error occurred while finding all cluster data" , "err" , err )
304318 return nil , err
305319 }
306320 clusters := impl .ConvertEntitiesToModel (clusterEntities )
307321 return clusters , nil
308- //var cluster []Cluster
309- //result := impl.dbConnection.
310- // Find(&cluster).
311- // Where("id in(?)", pg.In(id)).
312- // Where("active =?", true)
313- //return cluster, result.Error
314322}
315323
316324func (impl * ClusterFileBasedRepository ) Update (model * Cluster ) error {
0 commit comments