Skip to content

Commit

Permalink
use systemvar replacement for pipeline files
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Nov 27, 2024
1 parent 9009bc8 commit 270bf1e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tooling/templatize/pkg/ev2/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestProcessPipelineForEV2(t *testing.T) {
configProvider := config.NewConfigProvider("../../testdata/config.yaml")
vars, err := configProvider.GetVariables("public", "int", "", NewEv2ConfigReplacements())
vars, err := configProvider.GetVariables("public", "int", "", NewEv2SystemVariableReplacements())
if err != nil {
t.Errorf("failed to get variables: %v", err)
}
Expand Down
22 changes: 15 additions & 7 deletions tooling/templatize/pkg/ev2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ import (
// This package contains helper functions to extract EV2 conformant data from a config.yaml file.
//

func NewEv2ConfigReplacements() *config.ConfigReplacements {
func NewEv2ServiceConfigReplacements() *config.ConfigReplacements {
return config.NewConfigReplacements(
"$location()",
"$(regionName)",
"$(regionShortName)",
"",
)
}

func NewEv2SystemVariableReplacements() *config.ConfigReplacements {
return config.NewConfigReplacements(
"$location()",
"$config(regionShortName)",
"$stamp()",
)
}
Expand All @@ -23,7 +31,7 @@ func NewEv2ConfigReplacements() *config.ConfigReplacements {
// The variable values are formatted to contain EV2 $location(), $stamp() and $(serviceConfigVar) variables.
// This function is useful to get the variables to fill the `Settings` section of an EV2 `ServiceConfig.json“
func GetNonRegionalServiceConfigVariables(configProvider config.ConfigProvider, cloud, deployEnv string) (config.Variables, error) {
return configProvider.GetVariables(cloud, deployEnv, "", NewEv2ConfigReplacements())
return configProvider.GetVariables(cloud, deployEnv, "", NewEv2ServiceConfigReplacements())
}

// GetRegionalServiceConfigVariableOverrides returns the regional overrides of a config.yaml file.
Expand All @@ -36,7 +44,7 @@ func GetRegionalServiceConfigVariableOverrides(configProvider config.ConfigProvi
}
overrides := make(map[string]config.Variables)
for _, region := range regions {
regionOverrides, err := configProvider.GetRegionOverrides(cloud, deployEnv, region, NewEv2ConfigReplacements())
regionOverrides, err := configProvider.GetRegionOverrides(cloud, deployEnv, region, NewEv2ServiceConfigReplacements())
if err != nil {
return nil, err
}
Expand All @@ -49,7 +57,7 @@ func GetRegionalServiceConfigVariableOverrides(configProvider config.ConfigProvi
// It uses the provided configProvider to fetch the variables, flattens them into a __VAR__ = $config(var) formatted map.
// This function is useful to get the find/replace pairs for an EV2 `ScopeBinding.json`
func ScopeBindingVariables(configProvider config.ConfigProvider, cloud, deployEnv string) (map[string]string, error) {
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2ConfigReplacements())
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2SystemVariableReplacements())
if err != nil {
return nil, err
}
Expand All @@ -65,7 +73,7 @@ func ScopeBindingVariables(configProvider config.ConfigProvider, cloud, deployEn
// while maintaining EV2 conformant system variables.
// This function is useful to process a pipeline.yaml file so that it contains EV2 system variables.
func PreprocessFileForEV2SystemVars(configProvider config.ConfigProvider, cloud, deployEnv string, templateFile string) ([]byte, error) {
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2ConfigReplacements())
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2SystemVariableReplacements())
if err != nil {
return nil, err
}
Expand All @@ -77,7 +85,7 @@ func PreprocessFileForEV2SystemVars(configProvider config.ConfigProvider, cloud,
// This function is useful to process bicepparam files so that they can be used within EV2 together
// with scopebinding.
func PreprocessFileForEV2ScopeBinding(configProvider config.ConfigProvider, cloud, deployEnv string, templateFile string) ([]byte, error) {
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2ConfigReplacements())
vars, err := configProvider.GetVariables(cloud, deployEnv, "", NewEv2SystemVariableReplacements())
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
serviceGroup: Microsoft.Azure.ARO.Test
rolloutName: Test Rollout
resourceGroups:
- name: hcp-underlay-$(regionShortName)
- name: hcp-underlay-$config(regionShortName)
subscription: hcp-$location()
aksCluster: aro-hcp-aks
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
serviceGroup: Microsoft.Azure.ARO.Test
rolloutName: Test Rollout
resourceGroups:
- name: hcp-underlay-$(regionShortName)
- name: hcp-underlay-$config(regionShortName)
subscription: hcp-$location()
aksCluster: aro-hcp-aks
steps:
Expand Down

0 comments on commit 270bf1e

Please sign in to comment.