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

feat: Config diff phase 2 oss #5488

Merged
merged 68 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 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
7968e75
get config data in resthandler
prakash100198 Jul 10, 2024
c85395f
new api for showing all config data in config/data :- Service func ->…
prakash100198 Jul 11, 2024
48b59a4
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Jul 11, 2024
4749c45
Merge branch 'main' into config-diff
prakash100198 Jul 16, 2024
0e319d2
Merge branch 'main' into config-diff
prakash100198 Jul 17, 2024
6bba387
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Jul 17, 2024
6a9eaa7
Merge branch 'config-diff' into config-diff-phase-2-oss
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
f293b8c
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Jul 30, 2024
08e247c
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Jul 31, 2024
7f29f20
ent sync
prakash100198 Jul 31, 2024
41784ca
Merge branch 'main' into config-diff
prakash100198 Jul 31, 2024
b70d2bd
Merge branch 'config-diff' into config-diff-phase-2-oss
prakash100198 Jul 31, 2024
9fbd056
code review comment incorp -1
prakash100198 Jul 31, 2024
6f23f30
code review comment incorp -2
prakash100198 Jul 31, 2024
cf5ce0b
code review comment incorp -3
prakash100198 Jul 31, 2024
dacfd8b
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Aug 6, 2024
7fd7eee
small fix in plugin
prakash100198 Aug 6, 2024
779e913
migration number changes (#5692)
prakash100198 Aug 15, 2024
3c54313
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Aug 16, 2024
728de28
main sync
prakash100198 Aug 16, 2024
2fa3c2e
minor fix
prakash100198 Aug 19, 2024
4f04d6b
refrain from checkin autoscalingCheckBeforeTrigger for virt clus (#5696)
prakash100198 Aug 20, 2024
2e58e77
fix: Decode secret fix on add update oss (#5695)
prakash100198 Aug 20, 2024
bf23515
saving pco concurrency case handled (#5688)
prakash100198 Aug 20, 2024
694831c
fix: script for pipelineStageStepVariable, making input value and def…
prakash100198 Aug 21, 2024
144a6d2
Merge branch 'main' into config-diff-phase-2-oss
prakash100198 Aug 21, 2024
4167246
Merge remote-tracking branch 'origin/develop' into config-diff-phase-…
prakash100198 Aug 21, 2024
3843077
scipt number change
prakash100198 Aug 21, 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
8 changes: 8 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import (
"github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig"
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
"github.com/devtron-labs/devtron/pkg/commonService"
"github.com/devtron-labs/devtron/pkg/configDiff"
delete2 "github.com/devtron-labs/devtron/pkg/delete"
deployment2 "github.com/devtron-labs/devtron/pkg/deployment"
"github.com/devtron-labs/devtron/pkg/deployment/common"
Expand Down Expand Up @@ -711,6 +712,13 @@ func InitializeApp() (*App, error) {
scopedVariable.NewScopedVariableRestHandlerImpl,
wire.Bind(new(scopedVariable.ScopedVariableRestHandler), new(*scopedVariable.ScopedVariableRestHandlerImpl)),

router.NewDeploymentConfigurationRouter,
wire.Bind(new(router.DeploymentConfigurationRouter), new(*router.DeploymentConfigurationRouterImpl)),
restHandler.NewDeploymentConfigurationRestHandlerImpl,
wire.Bind(new(restHandler.DeploymentConfigurationRestHandler), new(*restHandler.DeploymentConfigurationRestHandlerImpl)),
configDiff.NewDeploymentConfigurationServiceImpl,
wire.Bind(new(configDiff.DeploymentConfigurationService), new(*configDiff.DeploymentConfigurationServiceImpl)),

router.NewTelemetryRouterImpl,
wire.Bind(new(router.TelemetryRouter), new(*router.TelemetryRouterImpl)),
restHandler.NewTelemetryRestHandlerImpl,
Expand Down
135 changes: 135 additions & 0 deletions api/restHandler/DeploymentConfigurationRestHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package restHandler

import (
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/configDiff"
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/schema"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
"net/http"
)

type DeploymentConfigurationRestHandler interface {
ConfigAutoComplete(w http.ResponseWriter, r *http.Request)
GetConfigData(w http.ResponseWriter, r *http.Request)
}
type DeploymentConfigurationRestHandlerImpl struct {
logger *zap.SugaredLogger
userAuthService user.UserService
validator *validator.Validate
enforcerUtil rbac.EnforcerUtil
deploymentConfigurationService configDiff.DeploymentConfigurationService
enforcer casbin.Enforcer
}

func NewDeploymentConfigurationRestHandlerImpl(logger *zap.SugaredLogger,
userAuthService user.UserService,
enforcerUtil rbac.EnforcerUtil,
deploymentConfigurationService configDiff.DeploymentConfigurationService,
enforcer casbin.Enforcer,
) *DeploymentConfigurationRestHandlerImpl {
return &DeploymentConfigurationRestHandlerImpl{
logger: logger,
userAuthService: userAuthService,
enforcerUtil: enforcerUtil,
deploymentConfigurationService: deploymentConfigurationService,
enforcer: enforcer,
}
}

func (handler *DeploymentConfigurationRestHandlerImpl) ConfigAutoComplete(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
envId, err := common.ExtractIntQueryParam(w, r, "envId", 0)
if err != nil {
return
}

//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//RBAC END

res, err := handler.deploymentConfigurationService.ConfigAutoComplete(appId, envId)
if err != nil {
handler.logger.Errorw("service err, ConfigAutoComplete ", "appId", appId, "envId", envId, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
configDataQueryParams, err := getConfigDataQueryParams(r)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACName(configDataQueryParams.AppName)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//RBAC END

res, err := handler.deploymentConfigurationService.GetAllConfigData(r.Context(), configDataQueryParams)
if err != nil {
handler.logger.Errorw("service err, GetAllConfigData ", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
res.IsAppAdmin = handler.enforceForAppAndEnv(configDataQueryParams.AppName, configDataQueryParams.EnvName, token, casbin.ActionUpdate)

common.WriteJsonResp(w, nil, res, http.StatusOK)
}

func (handler *DeploymentConfigurationRestHandlerImpl) enforceForAppAndEnv(appName, envName string, token string, action string) bool {
object := handler.enforcerUtil.GetAppRBACNameByAppName(appName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, action, object); !ok {
return false
}

object = handler.enforcerUtil.GetEnvRBACNameByAppAndEnvName(appName, envName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, action, object); !ok {
return false
}
return true
}
func getConfigDataQueryParams(r *http.Request) (*bean.ConfigDataQueryParams, error) {
v := r.URL.Query()
var decoder = schema.NewDecoder()
decoder.IgnoreUnknownKeys(true)
queryParams := bean.ConfigDataQueryParams{}
err := decoder.Decode(&queryParams, v)
if err != nil {
return nil, err
}

return &queryParams, nil
}
31 changes: 31 additions & 0 deletions api/router/DeploymentConfigRouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package router

import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/gorilla/mux"
)

type DeploymentConfigurationRouter interface {
initDeploymentConfigurationRouter(configRouter *mux.Router)
}

type DeploymentConfigurationRouterImpl struct {
deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler
}

func NewDeploymentConfigurationRouter(deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler) *DeploymentConfigurationRouterImpl {
router := &DeploymentConfigurationRouterImpl{
deploymentGroupRestHandler: deploymentGroupRestHandler,
}
return router
}

func (router DeploymentConfigurationRouterImpl) initDeploymentConfigurationRouter(configRouter *mux.Router) {
configRouter.Path("/autocomplete").
HandlerFunc(router.deploymentGroupRestHandler.ConfigAutoComplete).
Methods("GET")
configRouter.Path("/data").
HandlerFunc(router.deploymentGroupRestHandler.GetConfigData).
Methods("GET")

}
8 changes: 6 additions & 2 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type MuxRouter struct {
rbacRoleRouter user.RbacRoleRouter
scopedVariableRouter ScopedVariableRouter
ciTriggerCron cron.CiTriggerCron
deploymentConfigurationRouter DeploymentConfigurationRouter
infraConfigRouter infraConfig.InfraConfigRouter
argoApplicationRouter argoApplication.ArgoApplicationRouter
fluxApplicationRouter fluxApplication2.FluxApplicationRouter
Expand Down Expand Up @@ -146,6 +147,7 @@ func NewMuxRouter(logger *zap.SugaredLogger,
scopedVariableRouter ScopedVariableRouter,
ciTriggerCron cron.CiTriggerCron,
proxyRouter proxy.ProxyRouter,
deploymentConfigurationRouter DeploymentConfigurationRouter,
infraConfigRouter infraConfig.InfraConfigRouter,
argoApplicationRouter argoApplication.ArgoApplicationRouter,
devtronResourceRouter devtronResource.DevtronResourceRouter,
Expand Down Expand Up @@ -210,6 +212,7 @@ func NewMuxRouter(logger *zap.SugaredLogger,
rbacRoleRouter: rbacRoleRouter,
scopedVariableRouter: scopedVariableRouter,
ciTriggerCron: ciTriggerCron,
deploymentConfigurationRouter: deploymentConfigurationRouter,
infraConfigRouter: infraConfigRouter,
argoApplicationRouter: argoApplicationRouter,
devtronResourceRouter: devtronResourceRouter,
Expand Down Expand Up @@ -293,8 +296,9 @@ func (r MuxRouter) Init() {
chartRefRouter := r.Router.PathPrefix("/orchestrator/chartref").Subrouter()
r.ChartRefRouter.initChartRefRouter(chartRefRouter)

configMapRouter := r.Router.PathPrefix("/orchestrator/config").Subrouter()
r.ConfigMapRouter.initConfigMapRouter(configMapRouter)
configRouter := r.Router.PathPrefix("/orchestrator/config").Subrouter()
r.ConfigMapRouter.initConfigMapRouter(configRouter)
r.deploymentConfigurationRouter.initDeploymentConfigurationRouter(configRouter)

appStoreRouter := r.Router.PathPrefix("/orchestrator/app-store").Subrouter()
r.AppStoreRouter.Init(appStoreRouter)
Expand Down
6 changes: 3 additions & 3 deletions cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/sql/repository/app/AppRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type AppRepository interface {
UpdateWithTxn(app *App, tx *pg.Tx) error
SetDescription(id int, description string, userId int32) error
FindActiveByName(appName string) (pipelineGroup *App, err error)
FindAppIdByName(appName string) (int, error)

FindJobByDisplayName(appName string) (pipelineGroup *App, err error)
FindActiveListByName(appName string) ([]*App, error)
FindById(id int) (pipelineGroup *App, err error)
Expand Down Expand Up @@ -137,6 +139,19 @@ func (repo AppRepositoryImpl) FindActiveByName(appName string) (*App, error) {
// there is only single active app will be present in db with a same name.
return pipelineGroup, err
}
func (repo AppRepositoryImpl) FindAppIdByName(appName string) (int, error) {
app := &App{}
err := repo.dbConnection.
Model(app).
Column("app.id").
Where("app_name = ?", appName).
Where("active = ?", true).
Order("id DESC").Limit(1).
Select()
// there is only single active app will be present in db with a same name.
return app.Id, err
}

func (repo AppRepositoryImpl) FindJobByDisplayName(appName string) (*App, error) {
pipelineGroup := &App{}
err := repo.dbConnection.
Expand Down
56 changes: 56 additions & 0 deletions internal/sql/repository/chartConfig/ConfigMapRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package chartConfig

import (
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
Expand All @@ -38,6 +39,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.ConfigNameAndType, error)
}

type ConfigMapRepositoryImpl struct {
Expand All @@ -49,6 +51,11 @@ func NewConfigMapRepositoryImpl(Logger *zap.SugaredLogger, dbConnection *pg.DB)
return &ConfigMapRepositoryImpl{dbConnection: dbConnection, Logger: Logger}
}

const (
ConfigMapAppLevel string = "config_map_app_level"
ConfigMapEnvLevel string = "config_map_env_level"
)

type ConfigMapAppModel struct {
TableName struct{} `sql:"config_map_app_level" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Expand All @@ -57,6 +64,55 @@ type ConfigMapAppModel struct {
SecretData string `sql:"secret_data"`
sql.AuditLog
}
type cMCSNames struct {
Id int `json:"id"`
CMName string `json:"cm_name"`
CSName string `json:"cs_name"`
}

func (impl ConfigMapRepositoryImpl) GetConfigNamesForAppAndEnvLevel(appId int, envId int) ([]bean.ConfigNameAndType, error) {
var cMCSNames []cMCSNames
tableName := ConfigMapEnvLevel
if envId == -1 {
tableName = ConfigMapAppLevel
}
//below query iterates over the cm, cs stored as json element, and fetches cmName and csName, id for a particular appId or envId if provided
query := impl.dbConnection.
Model().
Table(tableName).
Column("id").
ColumnExpr("json_array_elements(CASE WHEN (config_map_data::json->'maps')::TEXT != 'null' THEN (config_map_data::json->'maps') ELSE '[]' END )->>'name' AS cm_name").
ColumnExpr("json_array_elements(CASE WHEN (secret_data::json->'secrets')::TEXT != 'null' THEN (secret_data::json->'secrets') ELSE '[]' END )->>'name' AS cs_name").
Where("app_id = ?", appId)

if envId > 0 {
query = query.Where("environment_id=?", envId)
}
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 configNames []bean.ConfigNameAndType
for _, name := range cMCSNames {
if name.CMName != "" {
configNames = append(configNames, bean.ConfigNameAndType{
Id: name.Id,
Name: name.CMName,
Type: bean.CM,
})
}
if name.CSName != "" {
configNames = append(configNames, bean.ConfigNameAndType{
Id: name.Id,
Name: name.CSName,
Type: bean.CS,
})
}
}
return configNames, nil
}

func (impl ConfigMapRepositoryImpl) CreateAppLevel(model *ConfigMapAppModel) (*ConfigMapAppModel, error) {
err := impl.dbConnection.Insert(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type PipelineConfigOverrideMetadata struct {

type PipelineOverrideRepository interface {
Save(*PipelineOverride) error
Update(pipelineOverride *PipelineOverride) error
UpdateStatusByRequestIdentifier(requestId string, newStatus models.ChartStatus) (int, error)
GetLatestConfigByRequestIdentifier(requestIdentifier string) (pipelineOverride *PipelineOverride, err error)
GetLatestConfigByEnvironmentConfigOverrideId(envConfigOverrideId int) (pipelineOverride *PipelineOverride, err error)
Expand Down Expand Up @@ -85,6 +86,10 @@ func (impl PipelineOverrideRepositoryImpl) Save(pipelineOverride *PipelineOverri
return impl.dbConnection.Insert(pipelineOverride)
}

func (impl PipelineOverrideRepositoryImpl) Update(pipelineOverride *PipelineOverride) error {
return impl.dbConnection.Update(pipelineOverride)
}

func (impl PipelineOverrideRepositoryImpl) UpdatePipelineMergedValues(ctx context.Context, tx *pg.Tx, id int, pipelineMergedValues string, userId int32) error {
_, span := otel.Tracer("orchestrator").Start(ctx, "PipelineOverrideRepositoryImpl.UpdatePipelineMergedValues")
defer span.End()
Expand Down
Loading
Loading