Rework diff generation and usage
Currently we omit new zones in the diff. The goal is to include them and also to be able to differentiate between a change in an existing zone and a new zone.
This is a first step towards zone bootstrap automation.
Related to https://md.corp.caascad.com/eeZipEavTtmJMqULvy9Zzg#
Given a change in config1 and config2 in zone1 the diff currently looks like this:
{
"zone1": [ "config1", "config2" ]
}
The proposal is to change it to something like:
{
"<ZONE_NAME>": {
"<CONFIG_NAME>": "<CHANGE_TYPE>"
}
}
CHANGE_TYPE is create | update | delete
When a config is removed another is updated:
{
"zone1": {
"config1": "update"
"config2": "delete"
}
}
When a new zone appears it could look like this:
{
"zone2": {
"configa": "create"
"configb": "create"
"configc": "create"
}
}
Now after the diff generation we should be able to determine if a new zone needs to be bootstrapped:
If all configs change type is "create", then we are bootstrapping a zone:
- create a branch (but no MR)
- generate the bootstrap pipeline using this branch
- the different jobs in the pipeline will be running
trackbone apply -z zone -c config -t bootstrap=true
If no new zone:
- create MR like it is done currently
Since the diff can now contain configurations to create, update or delete we should have a dedicated command to apply a diff.
- Maybe we can rename the
diffcommand tomake-difforgenerate-diff - Add a
plan-diff <DIFF_PATH>command - Add a
apply-diff <DIFF_PATH>command - the
--diff-fileoption ofplan,applyanddestroycommands is removed
The plan-diff command set action to plan for configurations with create or update change type, for delete we can just comment the fact that the configuration will be deleted.
The apply-diff command will properly set action to realize on the different configs. create, update -> apply, delete -> destroy