Skip to content

Commit

Permalink
feat: update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Haeberli committed Jul 20, 2023
1 parent fa45023 commit 8730566
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 64 deletions.
2 changes: 1 addition & 1 deletion momentum-core/_templates/applications/_base/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec:
interval: '{{ .ReconcileInterval }}'
chart:
spec:
version: '{{ .HelmChartVersion }}'
version: '{{ .ChartVersion }}'
sourceRef:
kind: HelmRepository
name: '{{ .ApplicationName }}-charts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ spec:
interval: '{{ .ReconcileInterval }}'
chart:
spec:
version: '{{ .HelmChartVersion }}'
version: '{{ .ChartVersion }}'
4 changes: 2 additions & 2 deletions momentum-core/_templates/stages/_base/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ kind: HelmRelease
metadata:
name: '{{ .ApplicationName }}'
spec:
interval: '{{ .StageReconcileInterval }}'
interval: '{{ .ReconcileInterval }}'
chart:
spec:
version: '{{ .HelmChartVersion }}'
version: '{{ .ChartVersion }}'
spec:
valuesFrom:
- kind: ConfigMap
Expand Down
18 changes: 18 additions & 0 deletions momentum-core/docs/docs.go

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

18 changes: 18 additions & 0 deletions momentum-core/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,15 @@
"models.ApplicationCreateRequest": {
"type": "object",
"properties": {
"chartVersion": {
"type": "string"
},
"name": {
"type": "string"
},
"reconcileInterval": {
"type": "string"
},
"repositoryName": {
"type": "string"
}
Expand Down Expand Up @@ -689,12 +695,18 @@
"applicationName": {
"type": "string"
},
"chartVersion": {
"type": "string"
},
"name": {
"type": "string"
},
"parentStageId": {
"type": "string"
},
"reconcileInterval": {
"type": "string"
},
"repositoryName": {
"type": "string"
}
Expand Down Expand Up @@ -742,6 +754,9 @@
"models.StageCreateRequest": {
"type": "object",
"properties": {
"chartVersion": {
"type": "string"
},
"name": {
"type": "string"
},
Expand All @@ -751,6 +766,9 @@
"parentStageId": {
"type": "string"
},
"reconcileInterval": {
"type": "string"
},
"repositoryName": {
"type": "string"
}
Expand Down
12 changes: 12 additions & 0 deletions momentum-core/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ definitions:
type: object
models.ApplicationCreateRequest:
properties:
chartVersion:
type: string
name:
type: string
reconcileInterval:
type: string
repositoryName:
type: string
type: object
Expand All @@ -45,10 +49,14 @@ definitions:
properties:
applicationName:
type: string
chartVersion:
type: string
name:
type: string
parentStageId:
type: string
reconcileInterval:
type: string
repositoryName:
type: string
type: object
Expand Down Expand Up @@ -79,12 +87,16 @@ definitions:
type: object
models.StageCreateRequest:
properties:
chartVersion:
type: string
name:
type: string
parentApplicationId:
type: string
parentStageId:
type: string
reconcileInterval:
type: string
repositoryName:
type: string
type: object
Expand Down
6 changes: 4 additions & 2 deletions momentum-core/models/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
)

type ApplicationCreateRequest struct {
Name string `json:"name"`
RepositoryName string `json:"repositoryName"`
Name string `json:"name"`
ReconcileInterval string `json:"reconcileInterval"`
ChartVersion string `json:"chartVersion"`
RepositoryName string `json:"repositoryName"`
}

type Application struct {
Expand Down
13 changes: 8 additions & 5 deletions momentum-core/models/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import (
"momentum-core/clients"
"momentum-core/tree"
"momentum-core/utils"
"strings"

"github.com/gin-gonic/gin"
)

type DeploymentCreateRequest struct {
Name string `json:"name"`
ParentStageId string `json:"parentStageId"`
RepositoryName string `json:"repositoryName"`
ApplicationName string `json:"applicationName"`
Name string `json:"name"`
ReconcileInterval string `json:"reconcileInterval"`
ChartVersion string `json:"chartVersion"`
ParentStageId string `json:"parentStageId"`
RepositoryName string `json:"repositoryName"`
ApplicationName string `json:"applicationName"`
}

type Deployment struct {
Expand Down Expand Up @@ -41,7 +44,7 @@ func ToDeploymentFromNode(n *tree.Node, repositoryId string) (*Deployment, error
deployment := new(Deployment)

deployment.Id = n.Id
deployment.Name = n.Path
deployment.Name = strings.Split(n.Path, "::")[0]
deployment.Path = n.FullPath()
deployment.RepositoryId = repositoryId
deployment.ParentStageId = n.Parent.Id
Expand Down
2 changes: 2 additions & 0 deletions momentum-core/models/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

type StageCreateRequest struct {
Name string `json:"name"`
ReconcileInterval string `json:"reconcileInterval"`
ChartVersion string `json:"chartVersion"`
RepositoryName string `json:"repositoryName"`
ParentApplicationId string `json:"parentApplicationId"`
ParentStageId string `json:"parentStageId"`
Expand Down
Binary file removed momentum-core/momentum-core
Binary file not shown.
4 changes: 1 addition & 3 deletions momentum-core/services/application-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ func (as *ApplicationService) AddApplication(request *models.ApplicationCreateRe
}
}

appChartName := request.Name + "-chart"

appMountPath := utils.BuildPath(repo.MomentumRoot().FullPath(), request.Name)
appBasePath := utils.BuildPath(appMountPath, "_base")

Expand All @@ -88,7 +86,7 @@ func (as *ApplicationService) AddApplication(request *models.ApplicationCreateRe
appBaseKustomizationPath := utils.BuildPath(appBasePath, KUSTOMIZATION_FILE_NAME)
appBaseReleasePath := utils.BuildPath(appBasePath, "release.yaml")

template := as.templateService.NewApplicationTemplate(appRepositoryPath, appNamespacePath, appBaseKustomizationPath, appBaseReleasePath, request.Name, appChartName)
template := as.templateService.NewApplicationTemplate(appRepositoryPath, appNamespacePath, appBaseKustomizationPath, appBaseReleasePath, request.Name, request.ReconcileInterval, request.ChartVersion)
err = as.templateService.ApplyApplicationTemplate(template)
if err != nil {
config.LOGGER.LogWarning("failed applying application template", err, traceId)
Expand Down
16 changes: 15 additions & 1 deletion momentum-core/services/deployment-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"momentum-core/config"
"momentum-core/models"
"momentum-core/utils"
"strings"
)

type DeploymentService struct {
Expand Down Expand Up @@ -92,8 +93,21 @@ func (ds *DeploymentService) AddDeployment(request *models.DeploymentCreateReque

releaseYamlPath := utils.BuildPath(deploymentFolderDestinationPath, "release.yaml")
deploymentKustomizationYamlPath := utils.BuildPath(deploymentFolderDestinationPath, KUSTOMIZATION_FILE_NAME)
pathFromMomentumRoot := strings.Split(deploymentFolderDestinationPath, config.MOMENTUM_ROOT)[1]
pathFromMomentumRoot = utils.BuildPath(config.MOMENTUM_ROOT, pathFromMomentumRoot)

template := ds.templateService.NewDeploymentTemplate(
deploymentKustomizationYamlPath,
deploymentFileDestinationPath,
releaseYamlPath,
deploymentYamlDestinationName,
pathFromMomentumRoot,
request.ReconcileInterval,
request.ChartVersion,
request.ApplicationName,
request.RepositoryName,
)

template := ds.templateService.NewDeploymentTemplate(deploymentKustomizationYamlPath, deploymentFileDestinationPath, releaseYamlPath, deploymentYamlDestinationName, request.ApplicationName, request.RepositoryName)
err = ds.templateService.ApplyDeploymentTemplate(template)
if err != nil {
config.LOGGER.LogWarning("failed applying deployment template", err, traceId)
Expand Down
2 changes: 1 addition & 1 deletion momentum-core/services/stage-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *StageService) AddStage(request *models.StageCreateRequest, traceId stri
stageBaseKustomizationPath := utils.BuildPath(stageBasePath, KUSTOMIZATION_FILE_NAME)
stageBaseReleasePath := utils.BuildPath(stageBasePath, "release.yaml")

template := s.templateService.NewStageTemplate(stageBaseKustomizationPath, stageBaseReleasePath, request.Name, parentAppNode.Path)
template := s.templateService.NewStageTemplate(stageBaseKustomizationPath, stageBaseReleasePath, request.Name, parentAppNode.Path, request.ReconcileInterval, request.ChartVersion)
err = s.templateService.ApplyStageTemplate(template)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 8730566

Please sign in to comment.