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

42 update templates #43

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ dist/
.ash_history
/docker-compose.override.yml
_temp/

./momentum-core/momentum-core
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configMapGenerator:
disableNameSuffixHash: true
secretGenerator:
- files:
- secrets.yaml
- values.yaml=secrets.yaml
name: base-secrets
options:
disableNameSuffixHash: true
Expand Down
4 changes: 2 additions & 2 deletions momentum-core/_templates/applications/_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: 10m
interval: '{{ .ReconcileInterval }}'
chart:
spec:
chart: '{{ .ApplicationChartName }}'
version: '{{ .ChartVersion }}'
sourceRef:
kind: HelmRepository
name: '{{ .ApplicationName }}-charts'
Expand Down
4 changes: 3 additions & 1 deletion momentum-core/_templates/deployments/deploymentName.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: '{{ .DeploymentNameWithoutEnding }}'
namespace: flux-system
spec:
targetNamespace: '{{ .DeploymentNameWithoutEnding }}'
interval: 5m0s
path: ./_deploy/{{ .DeploymentName }}/
path: {{ .PathFromMomentumRoot }}
prune: true
sourceRef:
kind: GitRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configMapGenerator:
disableNameSuffixHash: true
secretGenerator:
- files:
- secrets.yaml
- values.yaml=secrets.yaml
name: deploy-secrets
options:
disableNameSuffixHash: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: {{ .ApplicationName }}
name: {{ .ApplicationName }}
spec:
interval: '{{ .ReconcileInterval }}'
chart:
spec:
version: '{{ .ChartVersion }}'
19 changes: 7 additions & 12 deletions momentum-core/_templates/stages/_base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../_base/release.yaml
- ../../_base/
configMapGenerator:
- files:
- ../../_base/values.yaml
name: base-values
options:
disableNameSuffixHash: true
- files:
- values.yaml
name: '{{ .StageName }}-values'
options:
disableNameSuffixHash: true
secretGenerator:
- files:
- ../../_base/secrets.yaml
name: base-secrets
options:
disableNameSuffixHash: true
- files:
- secrets.yaml
- values.yaml=secrets.yaml
name: '{{ .StageName }}-secrets'
options:
disableNameSuffixHash: true
patches:
- path: release.yaml
labels:
- includeSelectors: true
pairs:
gitops.natron.io/application: '{{ .ApplicationName }}'
gitops.natron.io/stage: '{{ .StageName }}'
5 changes: 5 additions & 0 deletions momentum-core/_templates/stages/_base/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: '{{ .ApplicationName }}'
spec:
interval: '{{ .ReconcileInterval }}'
chart:
spec:
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