Skip to content

Commit 116728c

Browse files
bug fixes
1 parent a99045d commit 116728c

File tree

5 files changed

+44
-32
lines changed

5 files changed

+44
-32
lines changed

api/bean/AppView.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ type Environment struct {
205205
DeploymentAppDeleteRequest bool `json:"deploymentAppDeleteRequest"`
206206
Description string `json:"description" validate:"max=40"`
207207
IsVirtualEnvironment bool `json:"isVirtualEnvironment"`
208+
ClusterId int `json:"clusterId"`
208209
}
209210

210211
type InstanceDetail struct {

internal/sql/repository/AppListingRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ func (impl AppListingRepositoryImpl) FetchOtherEnvironment(appId int) ([]*bean.E
654654
func (impl AppListingRepositoryImpl) FetchMinDetailOtherEnvironment(appId int) ([]*bean.Environment, error) {
655655
impl.Logger.Debug("reached at FetchMinDetailOtherEnvironment:")
656656
var otherEnvironments []*bean.Environment
657-
query := `SELECT p.environment_id,env.environment_name,env.description,env.is_virtual_environment, env.default as prod, p.deployment_app_delete_request,
657+
query := `SELECT p.environment_id,env.environment_name,env.description,env.is_virtual_environment, env.cluster_id, env.default as prod, p.deployment_app_delete_request,
658658
env_app_m.app_metrics,env_app_m.infra_metrics from
659659
(SELECT pl.id,pl.app_id,pl.environment_id,pl.deleted, pl.deployment_app_delete_request from pipeline pl
660660
LEFT JOIN pipeline_config_override pco on pco.pipeline_id = pl.id where pl.app_id = ? and pl.deleted = FALSE

pkg/variables/ScopedVariableService.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ type ScopedVariableService interface {
2929
type ScopedVariableServiceImpl struct {
3030
logger *zap.SugaredLogger
3131
scopedVariableRepository repository2.ScopedVariableRepository
32-
appRepository app.AppRepository
33-
environmentRepository repository.EnvironmentRepository
34-
devtronResourceService devtronResource.DevtronResourceService
35-
clusterRepository repository.ClusterRepository
3632
VariableNameConfig *VariableConfig
3733
VariableCache *cache.VariableCacheObj
34+
35+
//Enterprise only
36+
appRepository app.AppRepository
37+
environmentRepository repository.EnvironmentRepository
38+
devtronResourceService devtronResource.DevtronResourceService
39+
clusterRepository repository.ClusterRepository
3840
}
3941

4042
func NewScopedVariableServiceImpl(logger *zap.SugaredLogger, scopedVariableRepository repository2.ScopedVariableRepository, appRepository app.AppRepository, environmentRepository repository.EnvironmentRepository, devtronResourceService devtronResource.DevtronResourceService, clusterRepository repository.ClusterRepository) (*ScopedVariableServiceImpl, error) {
4143
scopedVariableService := &ScopedVariableServiceImpl{
4244
logger: logger,
4345
scopedVariableRepository: scopedVariableRepository,
44-
appRepository: appRepository,
45-
environmentRepository: environmentRepository,
46-
devtronResourceService: devtronResourceService,
47-
clusterRepository: clusterRepository,
4846
VariableCache: &cache.VariableCacheObj{CacheLock: &sync.Mutex{}},
47+
48+
//Enterprise only
49+
appRepository: appRepository,
50+
environmentRepository: environmentRepository,
51+
devtronResourceService: devtronResourceService,
52+
clusterRepository: clusterRepository,
4953
}
5054
cfg, err := GetVariableNameConfig()
5155
if err != nil {
@@ -133,7 +137,6 @@ func (impl *ScopedVariableServiceImpl) CreateVariables(payload models.Payload) e
133137
}
134138

135139
}
136-
137140
err = impl.scopedVariableRepository.CommitTx(tx)
138141
if err != nil {
139142
impl.logger.Errorw("error in committing transaction of variable creation", "err", err)
@@ -194,7 +197,10 @@ func (impl *ScopedVariableServiceImpl) createVariableScopes(payload models.Paylo
194197
variableId := variableNameToId[variable.Definition.VarName]
195198
for _, value := range variable.AttributeValues {
196199
var varValue string
197-
varValue = utils.StringifyValue(value.VariableValue.Value)
200+
varValue, err = utils.StringifyValue(value.VariableValue.Value)
201+
if err != nil {
202+
return nil, err
203+
}
198204
if value.AttributeType == models.Global {
199205
scope := &repository2.VariableScope{
200206
VariableDefinitionId: variableId,
@@ -210,8 +216,7 @@ func (impl *ScopedVariableServiceImpl) createVariableScopes(payload models.Paylo
210216
compositeString = fmt.Sprintf("%v-%s-%s", variableId, value.AttributeParams[models.ApplicationName], value.AttributeParams[models.EnvName])
211217
}
212218
for identifierType, IdentifierName := range value.AttributeParams {
213-
var identifierValue int
214-
identifierValue, err = helper.GetIdentifierValue(identifierType, appNameToIdMap, IdentifierName, envNameToIdMap, clusterNameToIdMap)
219+
identifierValue, err := helper.GetIdentifierValue(identifierType, appNameToIdMap, IdentifierName, envNameToIdMap, clusterNameToIdMap)
215220
if err != nil {
216221
impl.logger.Errorw("error in getting identifierValue", "err", err)
217222
return nil, err
@@ -336,9 +341,6 @@ func (impl *ScopedVariableServiceImpl) selectScopeForCompoundQualifier(scopes []
336341
}
337342
}
338343

339-
// app=1 env=1 cluster=1
340-
// app=1 env=1 Xcluster=2X
341-
342344
// Now in the map only those will exist with all child matched or partial matches.
343345
// Because only one will entry exist with all matched we'll return that scope.
344346
var selectedParentScope *repository2.VariableScope

pkg/variables/repository/ScopedVariableRepository.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (impl *ScopedVariableRepositoryImpl) GetAllVariableMetadata() ([]*VariableD
7878
variableDefinition := make([]*VariableDefinition, 0)
7979
err := impl.
8080
dbConnection.Model(&variableDefinition).
81-
Column("id", "name", "data_type", "var_type").
81+
Column("id", "name", "data_type", "var_type", "description").
8282
Where("active = ?", true).
8383
Select()
8484
if err == pg.ErrNoRows {
@@ -121,22 +121,28 @@ func (impl *ScopedVariableRepositoryImpl) GetAllVariableScopeAndDefinition() ([]
121121
return variableDefinition, err
122122

123123
}
124+
125+
func (impl *ScopedVariableRepositoryImpl) addScopeWhereClause(query *orm.Query, scope models.Scope, searchableKeyNameIdMap map[bean.DevtronResourceSearchableKeyName]int) *orm.Query {
126+
return query.Where(
127+
"(((identifier_key = ? AND identifier_value_int = ?) OR (identifier_key = ? AND identifier_value_int = ?)) AND qualifier_id = ?) "+
128+
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
129+
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
130+
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
131+
"OR (qualifier_id = ?)",
132+
searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_APP_ID], scope.AppId, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_ENV_ID], scope.EnvId, APP_AND_ENV_QUALIFIER,
133+
APP_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_APP_ID], scope.AppId,
134+
ENV_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_ENV_ID], scope.EnvId,
135+
CLUSTER_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_CLUSTER_ID], scope.ClusterId,
136+
GLOBAL_QUALIFIER,
137+
)
138+
}
124139
func (impl *ScopedVariableRepositoryImpl) GetScopedVariableData(scope models.Scope, searchableKeyNameIdMap map[bean.DevtronResourceSearchableKeyName]int, varIds []int) ([]*VariableScope, error) {
125140
var variableScopes []*VariableScope
126141
query := impl.dbConnection.Model(&variableScopes).
127-
Where("active = ?", true).
128-
Where(
129-
"(((identifier_key = ? AND identifier_value_int = ?) OR (identifier_key = ? AND identifier_value_int = ?)) AND qualifier_id = ?) "+
130-
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
131-
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
132-
"OR (qualifier_id = ? AND identifier_key = ? AND identifier_value_int = ?) "+
133-
"OR (qualifier_id = ?)",
134-
searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_APP_ID], scope.AppId, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_ENV_ID], scope.EnvId, APP_AND_ENV_QUALIFIER,
135-
APP_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_APP_ID], scope.AppId,
136-
ENV_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_ENV_ID], scope.EnvId,
137-
CLUSTER_QUALIFIER, searchableKeyNameIdMap[bean.DEVTRON_RESOURCE_SEARCHABLE_KEY_CLUSTER_ID], scope.ClusterId,
138-
GLOBAL_QUALIFIER,
139-
)
142+
Where("active = ?", true)
143+
144+
//Enterprise only
145+
query = impl.addScopeWhereClause(query, scope, searchableKeyNameIdMap)
140146

141147
if len(varIds) > 0 {
142148
query = query.Where("variable_definition_id IN (?)", pg.In(varIds))

pkg/variables/utils/type-utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package utils
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"github.com/ghodss/yaml"
67
"strconv"
78
"strings"
89
)
910

10-
func StringifyValue(data interface{}) string {
11+
func StringifyValue(data interface{}) (string, error) {
1112
var value string
1213
switch data.(type) {
1314
case json.Number:
@@ -18,8 +19,10 @@ func StringifyValue(data interface{}) string {
1819
value = "\"" + value + "\""
1920
case bool:
2021
value = strconv.FormatBool(data.(bool))
22+
default:
23+
return "", fmt.Errorf("complex values are not allowed. %v neeeds to be stringified", data)
2124
}
22-
return value
25+
return value, nil
2326
}
2427
func DestringifyValue(Data string) (interface{}, error) {
2528
var value interface{}

0 commit comments

Comments
 (0)