Skip to content

Commit 3558c31

Browse files
aviralsrivastava01nishantAviral Srivastavavikramdevtronmanish-agrawal-ai
authored
Deployment template (#778)
* deployment template WIP * json schema * json schema * sql name change * json files * json schema code * validate json * json schema validation * jsonSchemaValidation * DeploymentTemplateValidate * deploymentTemplate * updates json schema * schema json * deploymenttemplate * changed schema * docs update * deployment template valaidation * resolve code conflicts * no change * chart group auth issue fixred * deployment template * validator * deployment template * Deployment template (#790) * deployment template WIP * json schema * json schema * sql name change * json files * json schema code * validate json * json schema validation * jsonSchemaValidation * DeploymentTemplateValidate * deploymentTemplate * updates json schema * schema json * deploymenttemplate * changed schema * docs update * deployment template valaidation * resolve code conflicts * no change * deployment template * validator * deployment template Co-authored-by: nishant <[email protected]> Co-authored-by: Aviral Srivastava <[email protected]> * deployment-template * deployment template bug fix * deployment template validator log * bug fix * Deployment template (#792) * deployment template WIP * json schema * json schema * sql name change * json files * json schema code * validate json * json schema validation * jsonSchemaValidation * DeploymentTemplateValidate * deploymentTemplate * updates json schema * schema json * deploymenttemplate * changed schema * docs update * deployment template valaidation * resolve code conflicts * no change * deployment template * validator * deployment template * deployment-template * deployment template bug fix * deployment template validator log * bug fix Co-authored-by: nishant <[email protected]> Co-authored-by: Aviral Srivastava <[email protected]> * wip * wip * checking file * prometheus endpoint validating only if provided * Delete 466 * rewrite cross manager access issue * review points * deployment template update * file read * file exist * json schema * file check exist * final code * deployment template bug resolved * review changes * review change * review changes * changes * code review changes * review changes * docs update * docs table update * wire changes * format checker initialise * Create ValidatorHelper.go * json schema * schema changes * error message * env-template validation * deployment-template * doc changes * doc changes * doc changes Co-authored-by: nishant <[email protected]> Co-authored-by: Aviral Srivastava <[email protected]> Co-authored-by: Vikram Singh <[email protected]> Co-authored-by: Manish Agrawal <[email protected]> Co-authored-by: Manish Agrawal <[email protected]>
1 parent 8485208 commit 3558c31

File tree

46 files changed

+9520
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+9520
-43
lines changed

Wire.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build wireinject
1+
//go:build wireinject
2+
// +build wireinject
23

34
/*
45
* Copyright (c) 2020 Devtron Labs
@@ -20,7 +21,16 @@
2021
package main
2122

2223
import (
24+
"github.com/devtron-labs/devtron/api/connector"
25+
"github.com/devtron-labs/devtron/api/restHandler"
26+
"github.com/devtron-labs/devtron/api/router"
2327
"github.com/devtron-labs/devtron/api/router/pubsub"
28+
"github.com/devtron-labs/devtron/api/sse"
29+
"github.com/devtron-labs/devtron/client/argocdServer"
30+
"github.com/devtron-labs/devtron/client/argocdServer/application"
31+
cluster2 "github.com/devtron-labs/devtron/client/argocdServer/cluster"
32+
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
33+
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
2434
"github.com/devtron-labs/devtron/client/dashboard"
2535
eClient "github.com/devtron-labs/devtron/client/events"
2636
"github.com/devtron-labs/devtron/client/gitSensor"
@@ -30,20 +40,27 @@ import (
3040
pubsub2 "github.com/devtron-labs/devtron/client/pubsub"
3141
"github.com/devtron-labs/devtron/client/telemetry"
3242
"github.com/devtron-labs/devtron/internal/casbin"
43+
"github.com/devtron-labs/devtron/internal/sql/models"
3344
"github.com/devtron-labs/devtron/internal/sql/repository"
3445
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
3546
appstore2 "github.com/devtron-labs/devtron/internal/sql/repository/appstore"
3647
"github.com/devtron-labs/devtron/internal/sql/repository/appstore/chartGroup"
48+
"github.com/devtron-labs/devtron/internal/sql/repository/bulkUpdate"
49+
"github.com/devtron-labs/devtron/internal/sql/repository/chartConfig"
50+
"github.com/devtron-labs/devtron/internal/sql/repository/cluster"
3751
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
52+
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
3853
security2 "github.com/devtron-labs/devtron/internal/sql/repository/security"
3954
teamRepo "github.com/devtron-labs/devtron/internal/sql/repository/team"
4055
"github.com/devtron-labs/devtron/internal/util"
4156
"github.com/devtron-labs/devtron/internal/util/ArgoUtil"
57+
"github.com/devtron-labs/devtron/pkg/app"
4258
"github.com/devtron-labs/devtron/pkg/appClone"
4359
"github.com/devtron-labs/devtron/pkg/appClone/batch"
4460
"github.com/devtron-labs/devtron/pkg/appWorkflow"
4561
"github.com/devtron-labs/devtron/pkg/appstore"
4662
"github.com/devtron-labs/devtron/pkg/attributes"
63+
clusterAccounts2 "github.com/devtron-labs/devtron/pkg/cluster"
4764
"github.com/devtron-labs/devtron/pkg/commonService"
4865
"github.com/devtron-labs/devtron/pkg/deploymentGroup"
4966
"github.com/devtron-labs/devtron/pkg/dex"
@@ -52,32 +69,15 @@ import (
5269
"github.com/devtron-labs/devtron/pkg/gitops"
5370
jira2 "github.com/devtron-labs/devtron/pkg/jira"
5471
"github.com/devtron-labs/devtron/pkg/notifier"
72+
"github.com/devtron-labs/devtron/pkg/pipeline"
5573
"github.com/devtron-labs/devtron/pkg/projectManagementService/jira"
5674
"github.com/devtron-labs/devtron/pkg/security"
5775
"github.com/devtron-labs/devtron/pkg/sso"
5876
"github.com/devtron-labs/devtron/pkg/team"
5977
"github.com/devtron-labs/devtron/pkg/terminal"
60-
"github.com/devtron-labs/devtron/util/rbac"
61-
62-
"github.com/devtron-labs/devtron/api/connector"
63-
"github.com/devtron-labs/devtron/api/restHandler"
64-
"github.com/devtron-labs/devtron/api/router"
65-
"github.com/devtron-labs/devtron/api/sse"
66-
"github.com/devtron-labs/devtron/client/argocdServer"
67-
"github.com/devtron-labs/devtron/client/argocdServer/application"
68-
cluster2 "github.com/devtron-labs/devtron/client/argocdServer/cluster"
69-
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
70-
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
71-
"github.com/devtron-labs/devtron/internal/sql/models"
72-
"github.com/devtron-labs/devtron/internal/sql/repository/bulkUpdate"
73-
"github.com/devtron-labs/devtron/internal/sql/repository/chartConfig"
74-
"github.com/devtron-labs/devtron/internal/sql/repository/cluster"
75-
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
76-
"github.com/devtron-labs/devtron/pkg/app"
77-
clusterAccounts2 "github.com/devtron-labs/devtron/pkg/cluster"
78-
79-
"github.com/devtron-labs/devtron/pkg/pipeline"
8078
user2 "github.com/devtron-labs/devtron/pkg/user"
79+
util2 "github.com/devtron-labs/devtron/util"
80+
"github.com/devtron-labs/devtron/util/rbac"
8181
"github.com/devtron-labs/devtron/util/session"
8282
"github.com/google/wire"
8383
)
@@ -107,7 +107,6 @@ func InitializeApp() (*App, error) {
107107
casbin.Create,
108108
rbac.NewEnforcerImpl,
109109
wire.Bind(new(rbac.Enforcer), new(*rbac.EnforcerImpl)),
110-
111110
dex.GetConfig,
112111
argocdServer.GetConfig,
113112
session2.NewSessionServiceClient,
@@ -702,6 +701,7 @@ func InitializeApp() (*App, error) {
702701
wire.Bind(new(app.AppLabelService), new(*app.AppLabelServiceImpl)),
703702
pipelineConfig.NewAppLabelRepositoryImpl,
704703
wire.Bind(new(pipelineConfig.AppLabelRepository), new(*pipelineConfig.AppLabelRepositoryImpl)),
704+
util2.NewGoJsonSchemaCustomFormatChecker,
705705
)
706706
return &App{}, nil
707707
}

api/restHandler/PipelineConfigRestHandler.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ func (handler PipelineConfigRestHandlerImpl) ConfigureDeploymentTemplateForApp(w
605605
writeJsonResp(w, err, nil, http.StatusBadRequest)
606606
return
607607
}
608+
chartRefId := templateRequest.ChartRefId
609+
validate, error := handler.chartService.DeploymentTemplateValidate(templateRequest.ValuesOverride, chartRefId)
610+
if !validate {
611+
writeJsonResp(w, error, nil, http.StatusBadRequest)
612+
613+
return
614+
}
608615
handler.Logger.Infow("request payload, ConfigureDeploymentTemplateForApp", "payload", templateRequest)
609616
err = handler.validator.Struct(templateRequest)
610617
if err != nil {
@@ -861,6 +868,13 @@ func (handler PipelineConfigRestHandlerImpl) EnvConfigOverrideUpdate(w http.Resp
861868
}
862869
var envConfigProperties pipeline.EnvironmentProperties
863870
err = decoder.Decode(&envConfigProperties)
871+
chartRefId := envConfigProperties.ChartRefId
872+
validate, error := handler.chartService.DeploymentTemplateValidate(envConfigProperties.EnvOverrideValues, chartRefId)
873+
if !validate {
874+
handler.Logger.Errorw("validation err, UpdateAppOverride", "err", error, "payload", envConfigProperties)
875+
writeJsonResp(w, error, nil, http.StatusBadRequest)
876+
return
877+
}
864878
envConfigProperties.UserId = userId
865879
if err != nil {
866880
handler.Logger.Errorw("request err, EnvConfigOverrideUpdate", "err", err, "payload", envConfigProperties)
@@ -1008,6 +1022,7 @@ func (handler PipelineConfigRestHandlerImpl) GetDeploymentTemplate(w http.Respon
10081022
writeJsonResp(w, err, nil, http.StatusInternalServerError)
10091023
return
10101024
}
1025+
10111026
if pg.ErrNoRows == err {
10121027
appOverride, err := handler.chartService.GetAppOverrideForDefaultTemplate(chartRefId)
10131028
if err != nil {
@@ -1029,6 +1044,7 @@ func (handler PipelineConfigRestHandlerImpl) GetDeploymentTemplate(w http.Respon
10291044
writeJsonResp(w, err, nil, http.StatusInternalServerError)
10301045
return
10311046
}
1047+
10321048
if pg.ErrNoRows == err {
10331049
template.ChartRefId = chartRefId
10341050
template.Id = 0
@@ -1266,6 +1282,7 @@ func (handler PipelineConfigRestHandlerImpl) UpdateAppOverride(w http.ResponseWr
12661282
writeJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
12671283
return
12681284
}
1285+
12691286
var templateRequest pipeline.TemplateRequest
12701287
err = decoder.Decode(&templateRequest)
12711288
templateRequest.UserId = userId
@@ -1274,13 +1291,15 @@ func (handler PipelineConfigRestHandlerImpl) UpdateAppOverride(w http.ResponseWr
12741291
writeJsonResp(w, err, nil, http.StatusBadRequest)
12751292
return
12761293
}
1294+
12771295
err = handler.validator.Struct(templateRequest)
12781296
if err != nil {
12791297
handler.Logger.Errorw("validation err, UpdateAppOverride", "err", err, "payload", templateRequest)
12801298
writeJsonResp(w, err, nil, http.StatusBadRequest)
12811299
return
12821300
}
12831301
handler.Logger.Infow("request payload, UpdateAppOverride", "payload", templateRequest)
1302+
12841303
token := r.Header.Get("token")
12851304
app, err := handler.pipelineBuilder.GetApp(templateRequest.AppId)
12861305
if err != nil {
@@ -1293,14 +1312,21 @@ func (handler PipelineConfigRestHandlerImpl) UpdateAppOverride(w http.ResponseWr
12931312
writeJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
12941313
return
12951314
}
1296-
1315+
chartRefId := templateRequest.ChartRefId
1316+
validate, error := handler.chartService.DeploymentTemplateValidate(templateRequest.ValuesOverride, chartRefId)
1317+
if !validate {
1318+
handler.Logger.Errorw("validation err, UpdateAppOverride", "err", error, "payload", templateRequest)
1319+
writeJsonResp(w, error, nil, http.StatusBadRequest)
1320+
return
1321+
}
12971322
createResp, err := handler.chartService.UpdateAppOverride(&templateRequest)
12981323
if err != nil {
12991324
handler.Logger.Errorw("service err, UpdateAppOverride", "err", err, "payload", templateRequest)
13001325
writeJsonResp(w, err, nil, http.StatusInternalServerError)
13011326
return
13021327
}
13031328
writeJsonResp(w, err, createResp, http.StatusOK)
1329+
13041330
}
13051331
func (handler PipelineConfigRestHandlerImpl) FetchArtifactForRollback(w http.ResponseWriter, r *http.Request) {
13061332
vars := mux.Vars(r)

api/router/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package router
1919

2020
import (
2121
"encoding/json"
22+
"net/http"
2223
"github.com/devtron-labs/devtron/api/restHandler"
2324
"github.com/devtron-labs/devtron/api/router/pubsub"
2425
pubsub2 "github.com/devtron-labs/devtron/client/pubsub"
@@ -27,7 +28,6 @@ import (
2728
"github.com/gorilla/mux"
2829
"github.com/prometheus/client_golang/prometheus/promhttp"
2930
"go.uber.org/zap"
30-
"net/http"
3131
)
3232

3333
type MuxRouter struct {

docs/user-guide/creating-application/deployment-template.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This defines ports on which application services will be exposed to other servic
3434
```yaml
3535
ContainerPort:
3636
- envoyPort: 8799
37-
idleTimeout:
37+
idleTimeout:
3838
name: app
3939
port: 8080
4040
servicePort: 80
@@ -75,7 +75,7 @@ LivenessProbe:
7575
scheme: ""
7676
tcp: true
7777
```
78-
78+
7979
| Key | Description |
8080
| :--- | :--- |
8181
| `Path` | It define the path where the liveness needs to be checked. |
@@ -90,7 +90,7 @@ LivenessProbe:
9090

9191

9292
### MaxUnavailable
93-
93+
9494
```yaml
9595
MaxUnavailable: 0
9696
```
@@ -240,11 +240,11 @@ These define minimum and maximum RAM and CPU available to the application.
240240
```yaml
241241
resources:
242242
limits:
243-
cpu: '1'
244-
memory: 200Mi
243+
cpu: "1"
244+
memory: "200Mi"
245245
requests:
246-
cpu: '0.10'
247-
memory: 100Mi
246+
cpu: "0.10"
247+
memory: "100Mi"
248248
```
249249

250250
Resources are required to set CPU and memory usage.
@@ -502,11 +502,11 @@ envoyproxy:
502502
configMapName: ""
503503
resources:
504504
limits:
505-
cpu: 50m
506-
memory: 50Mi
505+
cpu: "50m"
506+
memory: "50Mi"
507507
requests:
508-
cpu: 50m
509-
memory: 50Mi
508+
cpu: "50m"
509+
memory: "50Mi"
510510
```
511511

512512
Envoy is attached as a sidecar to the application container to collect metrics like 4XX, 5XX, Throughput and latency. You can now configure the envoy settings such as idleTimeout, resources etc.
@@ -575,3 +575,25 @@ If you want to see application metrics like different HTTP status codes metrics,
575575

576576
Once all the Deployment template configurations are done, click on `Save` to save your deployment configuration. Now you are ready to create [Workflow](workflow/) to do CI/CD.
577577

578+
### Helm Chart Json Schema Table
579+
580+
Helm Chart json schema is used to validate the deployment template values.
581+
582+
| Chart Version | Link |
583+
| :--- | :--- |
584+
| `reference-chart_3-12-0` | [Json Schema](../../../scripts/devtron-reference-helm-charts/reference-chart_3-12-0/schema.json) |
585+
| `reference-chart_3-11-0` | [Json Schema](../../../scripts/devtron-reference-helm-charts/reference-chart_3-11-0/schema.json) |
586+
| `reference-chart_3-10-0` | [Json Schema](../../../scripts/devtron-reference-helm-charts/reference-chart_3-10-0/schema.json) |
587+
| `reference-chart_3-9-0` | [Json Schema](../../../scripts/devtron-reference-helm-charts/reference-chart_3-9-0/schema.json) |
588+
589+
590+
### Other Validations in Json Schema
591+
592+
The values of CPU and Memory in limits must be greater than or equal to in requests respectively. Similarly, In case of envoyproxy, the values of limits are greater than or equal to requests as mentioned below.
593+
```
594+
resources.limits.cpu >= resources.requests.cpu
595+
resources.limits.memory >= resources.requests.memory
596+
envoyproxy.resources.limits.cpu >= envoyproxy.resources.requests.cpu
597+
envoyproxy.resources.limits.memory >= envoyproxy.resources.requests.memory
598+
```
599+

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e // indirect
2525
github.com/emicklei/go-restful v2.11.0+incompatible // indirect
2626
github.com/evanphx/json-patch v4.5.0+incompatible
27+
github.com/xeipuuv/gojsonschema v1.2.0
2728
github.com/ghodss/yaml v1.0.0
2829
github.com/go-openapi/jsonreference v0.19.3 // indirect
2930
github.com/go-openapi/spec v0.19.4 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ github.com/xanzy/go-gitlab v0.16.1 h1:kRHZ/wDsMkJHJvzfielqBTTrsbCtoxeEFrwiwtvVbZ
530530
github.com/xanzy/go-gitlab v0.16.1/go.mod h1:LSfUQ9OPDnwRqulJk2HcWaAiFfCzaknyeGvjQI67MbE=
531531
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
532532
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
533+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
534+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
535+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
536+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
537+
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
538+
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
533539
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
534540
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
535541
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=

0 commit comments

Comments
 (0)