Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config diff #4619

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1fc038b
story(configDiffView) : open api spec
adi6859 Feb 1, 2024
8eda368
story(configDiffView) : open api spec updated
adi6859 Feb 1, 2024
2d00c6a
story(configDiffView) : open api spec updated for error state
adi6859 Feb 1, 2024
00d1e6c
story(configDiffView) : WIP
adi6859 Feb 1, 2024
4e3582b
story(configDiffView) : WIP "some code changed"
adi6859 Feb 1, 2024
8c9a4cc
story(configDiffView) : support for names added
adi6859 Feb 2, 2024
55a2c0c
story(configDiffView) : iota removed
adi6859 Feb 2, 2024
bcdfa26
story(configDiffView) : pg no rows handled
adi6859 Feb 2, 2024
197db9b
story(configDiffView) : spelling check
adi6859 Feb 2, 2024
7469461
story(configDiffView) : code review comment resolved
adi6859 Feb 5, 2024
c7a145a
story(configDiffView) : env id added
adi6859 Feb 5, 2024
4eaa138
story(configDiffView) : intersection added
adi6859 Feb 5, 2024
256e505
story(configDiffView) : comments removed
adi6859 Feb 5, 2024
47f798f
story(configDiffView) : code review comment resolved
adi6859 Feb 6, 2024
de50f02
story(configDiffView) : comment removed
adi6859 Feb 6, 2024
f2947e3
story(configDiffView) : CMCSNames DTO moved
adi6859 Feb 6, 2024
a3b3271
story(configDiffView) : main merge
adi6859 Feb 7, 2024
44862e9
story(configDiffView) : null case handled
adi6859 Feb 7, 2024
7733ea0
story(configDiffView) : logger added
adi6859 Feb 7, 2024
06e39fc
story(configDiffView) : main merge
adi6859 Feb 8, 2024
e4e39c6
story(configDiffView) : code refactored
adi6859 Feb 8, 2024
dce967a
story(configDiffView) : code refactored v2
adi6859 Feb 8, 2024
4174161
story(configDiffView) : spec updated
adi6859 Feb 8, 2024
186efa7
story(configDiffView) : main merge
adi6859 Feb 13, 2024
736047a
story(configDiffView) : code refactored
adi6859 Feb 14, 2024
16d07d3
story(configDiffView) : config names
adi6859 Feb 14, 2024
3a55c5b
Merge branch 'main' into config-diff
prakash100198 Feb 19, 2024
a4e9c4f
Merge branch 'main' into config-diff
prakash100198 Feb 20, 2024
706afc6
merged with main
vikramdevtron Jun 25, 2024
014e59d
Merge branch 'main' into config-diff
prakash100198 Jul 3, 2024
6196f31
main sync
prakash100198 Jul 3, 2024
e076783
overridden and global flag introduced in config diff autocomplete api
prakash100198 Jul 3, 2024
a1eba0f
Merge branch 'main' into config-diff
prakash100198 Jul 9, 2024
ffa3ba1
ent sync
prakash100198 Jul 9, 2024
4749c45
Merge branch 'main' into config-diff
prakash100198 Jul 16, 2024
0e319d2
Merge branch 'main' into config-diff
prakash100198 Jul 17, 2024
2c5c7c6
using a single key instead of global and overridden key in config/aut…
prakash100198 Jul 17, 2024
8696b08
ConfigState made string instead of int
prakash100198 Jul 17, 2024
a11549f
Merge branch 'main' into config-diff
prakash100198 Jul 23, 2024
f9d9c65
not sending inheriting in case base config
prakash100198 Jul 23, 2024
359022a
Merge branch 'main' into config-diff
prakash100198 Jul 30, 2024
5628d6c
code review comment incorporation
prakash100198 Jul 30, 2024
41784ca
Merge branch 'main' into config-diff
prakash100198 Jul 31, 2024
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
Prev Previous commit
Next Next commit
story(configDiffView) : code refactored
  • Loading branch information
adi6859 committed Feb 14, 2024
commit 736047a36dbc1176a8135fc56cc852e825d6adb5
29 changes: 24 additions & 5 deletions internal/sql/repository/chartConfig/ConfigMapRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ConfigMapRepository interface {
GetByAppIdAppLevel(appId int) (*ConfigMapAppModel, error)
GetByAppIdAndEnvIdEnvLevel(appId int, envId int) (*ConfigMapEnvModel, error)
GetEnvLevelByAppId(appId int) ([]*ConfigMapEnvModel, error)
GetConfigNamesForAppAndEnvLevel(appId int, envId int) ([]bean.CMCSNames, error)
GetConfigNamesForAppAndEnvLevel(appId int, envId int) ([]bean.ConfigNameAndType, error)
}

type ConfigMapRepositoryImpl struct {
Expand All @@ -65,9 +65,13 @@ type ConfigMapAppModel struct {
SecretData string `sql:"secret_data"`
sql.AuditLog
}
type cMCSNames struct {
CMName string `json:"cm_name"`
CSName string `json:"cs_name"`
}

func (impl ConfigMapRepositoryImpl) GetConfigNamesForAppAndEnvLevel(appId int, envId int) ([]bean.CMCSNames, error) {
var cMCSNames []bean.CMCSNames
func (impl ConfigMapRepositoryImpl) GetConfigNamesForAppAndEnvLevel(appId int, envId int) ([]bean.ConfigNameAndType, error) {
var cMCSNames []cMCSNames
tableName := ConfigMapEnvLevel
if envId == -1 {
tableName = ConfigMapAppLevel
Expand All @@ -85,10 +89,25 @@ func (impl ConfigMapRepositoryImpl) GetConfigNamesForAppAndEnvLevel(appId int, e
if err := query.Select(&cMCSNames); err != nil {
if err != pg.ErrNoRows {
impl.Logger.Errorw("error occurred while fetching CM/CS names", "appId", appId, "err", err)
return nil, err
}
}
var configNameAndType []bean.ConfigNameAndType
for _, name := range cMCSNames {
if name.CMName != "" {
configNameAndType = append(configNameAndType, bean.ConfigNameAndType{
Name: name.CMName,
Type: bean.CM,
})
}
if name.CSName != "" {
configNameAndType = append(configNameAndType, bean.ConfigNameAndType{
Name: name.CSName,
Type: bean.CS,
})
}
return cMCSNames, err
}
return cMCSNames, nil
return configNameAndType, nil
}

func (impl ConfigMapRepositoryImpl) CreateAppLevel(model *ConfigMapAppModel) (*ConfigMapAppModel, error) {
Expand Down
23 changes: 10 additions & 13 deletions pkg/config/DeploymentConfigurationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewDeploymentConfigurationServiceImpl(logger *zap.SugaredLogger,
func (impl *DeploymentConfigurationServiceImpl) ConfigAutoComplete(appId int, envId int) (*ConfigDataResponse, error) {
cMCSNamesAppLevel, cMCSNamesEnvLevel, err := impl.configMapService.FetchCmCsNamesAppAndEnvLevel(appId, envId)
if err != nil {
impl.logger.Errorw("error in fetching CM and CS names at app or env level", "appId", appId, "envId", envId)
impl.logger.Errorw("error in fetching CM and CS names at app or env level", "appId", appId, "envId", envId, "err", err)
return nil, err
}
combinedProperties := make([]*ConfigProperty, 0)
Expand All @@ -38,33 +38,30 @@ func (impl *DeploymentConfigurationServiceImpl) ConfigAutoComplete(appId int, en
combinedProperties = append(combinedProperties,
getUniqueConfigPropertyList(cMCSNamesEnvLevel, combinedProperties)...)
combinedProperties = append(combinedProperties,
getConfigProperty("", DeploymentTemplate, PublishedConfigState))
getConfigProperty("", bean.DeploymentTemplate, PublishedConfigState))
return &ConfigDataResponse{ResourceConfig: combinedProperties}, nil
}

func getUniqueConfigPropertyList(cMCSNames []bean.CMCSNames, combinedProperties []*ConfigProperty) []*ConfigProperty {
func getUniqueConfigPropertyList(cMCSNames []bean.ConfigNameAndType, combinedProperties []*ConfigProperty) []*ConfigProperty {
properties := make([]*ConfigProperty, 0)
if len(cMCSNames) == 0 {
return properties
}
combinedNames := make(map[string]bool)
for _, config := range combinedProperties {
combinedNames[config.Name] = true
combinedNames[config.getKey()] = true
}
for _, name := range cMCSNames {
// Fill in CM property if the CMName is not empty
if name.CMName != "" && !combinedNames[name.CMName] {
properties = append(properties, getConfigProperty(name.CMName, CM, PublishedConfigState))
}
// Fill in CS property if the CSName is not empty
if name.CSName != "" && !combinedNames[name.CSName] {
properties = append(properties, getConfigProperty(name.CSName, CS, PublishedConfigState))
for _, config := range cMCSNames {
// Fill in CM and CS property
property := getConfigProperty(config.Name, config.Type, PublishedConfigState)
if !combinedNames[property.getKey()] {
properties = append(properties, property)
}
}
return properties
}

func getConfigProperty(name string, configType ResourceType, State ConfigState) *ConfigProperty {
func getConfigProperty(name string, configType bean.ResourceType, State ConfigState) *ConfigProperty {
return &ConfigProperty{
Name: name,
Type: configType,
Expand Down
20 changes: 9 additions & 11 deletions pkg/config/bean.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package config

import "github.com/devtron-labs/devtron/pkg/pipeline/bean"

type ConfigState int

const (
PublishedConfigState ConfigState = 3
)

type ResourceType string

const (
CM ResourceType = "ConfigMap"
CS ResourceType = "Secret"
DeploymentTemplate ResourceType = "Deployment Template"
)

type ConfigProperty struct {
Name string `json:"name"`
ConfigState ConfigState `json:"configState"`
Type ResourceType `json:"type"`
Name string `json:"name"`
ConfigState ConfigState `json:"configState"`
Type bean.ResourceType `json:"type"`
}
type ConfigDataResponse struct {
ResourceConfig []*ConfigProperty `json:"resourceConfig"`
}

func (config ConfigProperty) getKey() string {
return string(config.Type) + config.Name
}
6 changes: 3 additions & 3 deletions pkg/pipeline/ConfigMapService.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type ConfigMapService interface {
ConfigSecretEnvironmentGet(appId int) ([]bean.JobEnvOverrideResponse, error)
ConfigSecretEnvironmentClone(appId int, cloneAppId int, userId int32) ([]chartConfig.ConfigMapEnvModel, error)

FetchCmCsNamesAppAndEnvLevel(appId int, envId int) ([]bean.CMCSNames, []bean.CMCSNames, error)
FetchCmCsNamesAppAndEnvLevel(appId int, envId int) ([]bean.ConfigNameAndType, []bean.ConfigNameAndType, error)
}

type ConfigMapServiceImpl struct {
Expand Down Expand Up @@ -1994,8 +1994,8 @@ func (impl ConfigMapServiceImpl) ConfigSecretEnvironmentClone(appId int, cloneAp

return jobEnvOverrideResponse, nil
}
func (impl ConfigMapServiceImpl) FetchCmCsNamesAppAndEnvLevel(appId int, envId int) ([]bean.CMCSNames, []bean.CMCSNames, error) {
var cMCSNamesEnvLevel []bean.CMCSNames
func (impl ConfigMapServiceImpl) FetchCmCsNamesAppAndEnvLevel(appId int, envId int) ([]bean.ConfigNameAndType, []bean.ConfigNameAndType, error) {
var cMCSNamesEnvLevel []bean.ConfigNameAndType

cMCSNamesAppLevel, err := impl.configMapRepository.GetConfigNamesForAppAndEnvLevel(appId, -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 should be used as constant to be clear what it denotes

Copy link
Contributor

@prakash100198 prakash100198 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-07-30 at 6 09 54 PM

in ide it shows envId

if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions pkg/pipeline/bean/ConfigMapBean.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ type CreateJobEnvOverridePayload struct {
type SecretsList struct {
ConfigData []*ConfigData `json:"secrets"`
}
type CMCSNames struct {
CMName string `json:"cm_name"`
CSName string `json:"cs_name"`

type ConfigNameAndType struct {
Name string
Type ResourceType
}

type ResourceType string

const (
CM ResourceType = "ConfigMap"
CS ResourceType = "Secret"
DeploymentTemplate ResourceType = "Deployment Template"
)
6 changes: 3 additions & 3 deletions specs/configDiffView.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ components:
$ref: '#/components/schemas/ResourceTypeEnum'

ConfigStateEnum:
type: integer
enum: [ 3 ]
description: State of config (3 represents published state)
type: integer
enum: [ 1, 2, 3 ]
description: State of config (1 represents draft state , 2 represents approval pending state,3 represents published state)

ResourceTypeEnum:
type: string
Expand Down
Loading