Create a new feature#
A feature is made of
- a helm chart
- (a) validation check(s)
- a description of the Concourse pipeline (for validation and deployment) in envs-ng/concourse_provisioning.cue
There is a dedicated git repo in Gitlab for each helm chart and the validation check(s).
Deploying the feature consists in
- propagating the feature git repo from Gitlab to client Giteas with gitea_provision
- propagating the feature Concourse pipeline in client Concourses with concourse_provisioning_infra
Feature files hierarchy#
The repo containing the deployed chart must have the following structure:
ci
ci/check.cue
helm
helm/templates
helm/values.yaml
helm/Chart.yaml
ci/check.cue#
The file ci/check.cue contains the schema that validates the value file provided by the client. It is used in the caascad-cicd-libs scripts to validate like this :
cue vet <client value file> ci/check.cue
helm chart#
This is the chart that deploys the feature. The helm/values.yaml contains the default values that may be overwritten in the client values file.
The helm template will be validated by the check job (Concourse pipeline). The validation is based on helm template.
Propagate the git repo with gitea_provision#
This will propagate the feature git repo from Gitlab to client Giteas.
Step 1 : tag the gitlab repo#
For the tests, put a temporary tag with your trigram and an identifier like YYYYMMDD_HHMM. Example : NCA_20211225_1200.
When going to Production, you will merge the MR and then put a semver tag (example: v1.0.0).
Step 2 : edit envs-ng/gitea_provision.cue#
Edit envs-ng/gitea_provision.cue.
Add your application in provision_repositories :
{name: <feature_name>, organisation: "internal", owner: "caascad", git_corp_path: "caascad/applications/caascad-<feature_name>", git_corp_tag: "v1.0.0", force_replace: true}
name: name of the featureorganisation:internalbecause the feature will always be provisionned in theinternalorganisation.owner:caascadbecause this is the used user in Gitea.git_corp_path: this is the source repo pathgit_corp_tag: this is the source repo tag to propagate in Gitea destinationsforce_replace: alwaystruein order to force the propagation even if the destination diverged from the source.
Step 3 : deploy with Trackbone#
trackbone apply -c gitea_provision -z <cloud zone>
Step 4 : control the propagation#
Log on https://git.<ocb zone>.caascad.com.
Login and password can be found in Vault (in secrets/concourse-infra/global/gitea-caascad).
Check the repo internal/<feature name>.
Propagate the Concourse pipeline#
Step 1 : Add/modify the pipeline definition#
Note
The generic pipeline resources are defined https://git.corp.caascad.com/caascad/terraform/lib/-/blob/master/configurations/concourse_provisioning/files/client-feature.yaml.
Edit envs-ng/concourse_provisioning.cue.
Add or modify the pipeline templates. There are 2 big sections containing pipeline definition templates. They depend on where the feature will be deployed, on cloud zone or on client zone.
If it's a feature for client zone, add your pipeline like this :
if zone.type == "client" {
...
pipelines: "<feature_name>-client-\(zone.name)": #ConcoursePipeline & {
parent_zone_name: _target_zone
team_name: "deploy"
pipeline_name: "<feature_name>-client-" + zone.name
pipeline_config_file: "client-feature.yaml"
feature_name: "<feature_name>"
gitea_repo_configurations: "caascad-\(zone.name)/configurations.git"
post_install_triggers: [] // optional triggers (see below)
post_uninstall_triggers: [] // optional triggers (see below)
}
If it's a feature for cloud zone, add your pipeline like this :
if zone.type == "cloud" {
...
pipelines: "<feature_name>-\(zone.name)": #ConcoursePipeline & {
parent_zone_name: zone.name
team_name: "deploy"
pipeline_name: "<feature_name>-" + zone.name
pipeline_config_file: "client-feature.yaml"
feature_name: "<feature_name>"
gitea_repo_configurations: "caascad-global/configurations.git"
post_install_triggers: [] // optional triggers (see below)
post_uninstall_triggers: [] // optional triggers (see below)
}
}
Note
Replace <feature_name> by the name of the feature. It must be the same as in step Deploy gitea provision.
Step 2 : Propagate the Concourse pipeline on client Concourses#
trackbone apply -c concourse_provisioning_infra -z <cloud zone|client zone>
Using triggers in your pipelines#
Principle#
Here are additional triggers for pipelines :
post_install_triggers: run the triggers after a deploymentpost_uninstall_triggers: run the triggers after a removal
They can be used for example to restart a component after a chart uninstallation.
Triggers are defined in https://git.corp.caascad.com/caascad/cicd/caascad-cicd-libs/-/blob/master/helm/triggers.sh.
Example :
if zone.type == "cloud" {
pipelines: "grafana-dashboards-\(zone.name)": #ConcoursePipeline & {
parent_zone_name: zone.name
team_name: "deploy"
pipeline_name: "grafana-dashboards-" + zone.name
pipeline_config_file: "client-feature.yaml"
feature_name: "grafana-dashboards"
gitea_repo_configurations: "caascad-global/configurations.git"
post_uninstall_triggers: [
"restart-client-grafana",
"<name_of_your_trigger>",
]
}
}
Define a new trigger#
Step 1 : create a new branch#
Create a branch of the repository https://git.corp.caascad.com/caascad/cicd/caascad-cicd-libs.
Step 2 : Write the new function(s)#
In helm/triggers.sh, add a new function :
function <name_of_the_function> {
echo "<What the function will do>.........."
if <CMD>; then
echo "[OK]"
else
echo "[FAILED]"
fi
}
Step 3 : Reference the function in the main switch/case#
In triggers.sh, there is a switch/case in the functions below. Add your new function there :
post_helm_chart_install_triggersfor post deployment triggerspost_helm_chart_uninstall_triggersfor post removal triggers
Example :
function post_helm_chart_uninstall_triggers {
local postUninstallTriggers=$1
echo "List of triggers configured for this uninstall: ${postUninstallTriggers}"
case "${postUninstallTriggers}" in
*"restart-client-grafana"*)
restart_client_grafana;;
*"<name_of_your_trigger"*)
<name_of_the_function>
*)
true;;
esac
}
Step 4 : Commit, push and tag#
For the tests, put a temporary tag with your trigram and an identifier like YYYYMMDD_HHMM. Example : VJO_20211225_1200.
When going to Production, you will merge the MR and then put a semver tag (example: v1.0.0).
Step 5 : Reference the new trigger in concourse_provisioning#
As described above, add your new trigger in post_install_triggers or post_uninstall_triggers in the pipeline definition in envs-ng/concourse_provisioning.cue.
Step 6 : Test your work#
Edit envs-ng/gitea_provision.cue.
Find this line :
{name: "cicd", organisation: "internal", owner: "caascad", git_corp_path: "caascad/cicd/caascad-cicd-libs", git_corp_tag: "v1.2.1", force_replace: true},
Replace the git_corp_tag tag with your new tag.
Then redeploy :
trackbone apply -c gitea_provision -z <cloud zone>
trackbone apply -c concourse_provisioning_infra -z <cloud zone|client zone>
Step 7 : Go to Production#
Checklist :
- Merge the MR for
triggers.sh - Add a new semver tag on https://git.corp.caascad.com/caascad/cicd/caascad-cicd-libs
- Reference the new tag in gitea_provision
- Follow the usual workflow (gitea_provision and concourse_provisioning)