Skip to content

Commit

Permalink
add ACR replica in different region
Browse files Browse the repository at this point in the history
  • Loading branch information
jfchevrette committed Dec 17, 2024
1 parent f26a94a commit 27b48f4
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/config.msft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defaults:
subscription: hcp-{{ .ctx.region }}
manageTokenCustomRole: false
region: uksouth
drRegion: ukwest # (TODO): change to actual region we want to use
globalMSIName: "global-ev2-identity"

# General AKS config
Expand Down
6 changes: 5 additions & 1 deletion config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
"region": {
"type": "string"
},
"drRegion": {
"type": "string"
},
"globalMSIName": {
"type": "string",
"description": "The name of the MSI that will be used for ev2"
Expand All @@ -193,7 +196,8 @@
"rg",
"subscription",
"manageTokenCustomRole",
"region"
"region",
"drRegion"
]
},
"hypershift": {
Expand Down
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defaults:
subscription: ARO Hosted Control Planes (EA Subscription 1)
manageTokenCustomRole: true
region: westus3
drRegion: eastus2 # (TODO): change to actual region we want to use
globalMSIName: "global-rollout-identity"

# General AKS config
Expand Down
1 change: 1 addition & 0 deletions config/public-cloud-cs-pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"imageTag": ""
},
"global": {
"drRegion": "eastus2",
"globalMSIName": "global-rollout-identity",
"manageTokenCustomRole": true,
"region": "westus3",
Expand Down
1 change: 1 addition & 0 deletions config/public-cloud-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"imageTag": ""
},
"global": {
"drRegion": "eastus2",
"globalMSIName": "global-rollout-identity",
"manageTokenCustomRole": true,
"region": "westus3",
Expand Down
1 change: 1 addition & 0 deletions config/public-cloud-msft-int.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"imageTag": "0b3c08f"
},
"global": {
"drRegion": "ukwest",
"globalMSIName": "global-ev2-identity",
"manageTokenCustomRole": false,
"region": "uksouth",
Expand Down
1 change: 1 addition & 0 deletions config/public-cloud-personal-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"imageTag": ""
},
"global": {
"drRegion": "eastus2",
"globalMSIName": "global-rollout-identity",
"manageTokenCustomRole": true,
"region": "westus3",
Expand Down
2 changes: 2 additions & 0 deletions dev-infrastructure/configurations/global-acr.tmpl.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ param ocpAcrName = '{{ .ocpAcrName }}'
param ocpAcrSku = 'Premium'

param location = '{{ .global.region }}'
param replicaLocation = '{{ .global.drRegion }}'

10 changes: 10 additions & 0 deletions dev-infrastructure/modules/acr/acr.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ param acrName string
@description('Location of the registry.')
param location string = resourceGroup().location

@description('Location of the registry\'s replica.')
param replicaLocation string = ''

@description('Service tier of the Azure Container Registry.')
param acrSku string

Expand Down Expand Up @@ -39,6 +42,13 @@ resource acrResource 'Microsoft.ContainerRegistry/registries@2023-11-01-preview'
}
}

resource acrReplicaResource 'Microsoft.ContainerRegistry/registries/replications@2023-11-01-preview' = if (replicaLocation != '') {
parent: acrResource
name: '${acrName}-replica'
location: replicaLocation
properties: {}
}

// Assign the AcrPull Role to the ${acrName}-pull-identity
var acrPullRoleId = '7f951dda-4ed3-4680-a7ca-43fe172d538d'

Expand Down
3 changes: 3 additions & 0 deletions dev-infrastructure/templates/global-acr.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ param svcAcrName string
param svcAcrSku string

param location string
param replicaLocation string

module ocpAcr '../modules/acr/acr.bicep' = {
name: ocpAcrName
params: {
acrName: ocpAcrName
acrSku: ocpAcrSku
location: location
replicaLocation: replicaLocation
}
}

Expand All @@ -25,5 +27,6 @@ module svcAcr '../modules/acr/acr.bicep' = {
acrName: svcAcrName
acrSku: svcAcrSku
location: location
replicaLocation: replicaLocation
}
}
1 change: 1 addition & 0 deletions tooling/templatize/cmd/generate/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestRawOptions(t *testing.T) {
opts := &RawGenerationOptions{
RolloutOptions: &options.RawRolloutOptions{
Region: "uksouth",
DrRegion: "ukwest",
RegionShort: "abcde",
Stamp: "fghij",
BaseOptions: &options.RawOptions{
Expand Down
1 change: 1 addition & 0 deletions tooling/templatize/cmd/pipeline/inspect/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (o *InspectOptions) RunInspect(ctx context.Context) error {
rolloutOptions.Region,
config.NewConfigReplacements(
rolloutOptions.Region,
rolloutOptions.DrRegion,
rolloutOptions.RegionShort,
rolloutOptions.Stamp,
),
Expand Down
1 change: 1 addition & 0 deletions tooling/templatize/cmd/pipeline/run/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (o *RunOptions) RunPipeline(ctx context.Context) error {
rolloutOptions.Region,
config.NewConfigReplacements(
rolloutOptions.Region,
rolloutOptions.DrRegion,
rolloutOptions.RegionShort,
rolloutOptions.Stamp,
),
Expand Down
5 changes: 4 additions & 1 deletion tooling/templatize/cmd/rolloutoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewRolloutOptions(config config.Variables) *RolloutOptions {
func EV2RolloutOptions() *RawRolloutOptions {
return &RawRolloutOptions{
Region: "$location()",
DrRegion: "$(drRegion)",
RegionShort: "$(regionShort)",
Stamp: "$stamp()",
}
Expand All @@ -36,6 +37,7 @@ func BindRolloutOptions(opts *RawRolloutOptions, cmd *cobra.Command) error {
return fmt.Errorf("failed to bind options: %w", err)
}
cmd.Flags().StringVar(&opts.Region, "region", opts.Region, "resources location")
cmd.Flags().StringVar(&opts.Region, "dr-region", opts.DrRegion, "disaster recovery location")
cmd.Flags().StringVar(&opts.RegionShort, "region-short", opts.RegionShort, "short region string")
cmd.Flags().StringVar(&opts.Stamp, "stamp", opts.Stamp, "stamp")
cmd.Flags().StringToStringVar(&opts.ExtraVars, "extra-args", opts.ExtraVars, "Extra arguments to be used config templating")
Expand All @@ -45,6 +47,7 @@ func BindRolloutOptions(opts *RawRolloutOptions, cmd *cobra.Command) error {
// RawRolloutOptions holds input values.
type RawRolloutOptions struct {
Region string
DrRegion string
RegionShort string
Stamp string
ExtraVars map[string]string
Expand Down Expand Up @@ -93,7 +96,7 @@ func (o *ValidatedRolloutOptions) Complete() (*RolloutOptions, error) {
return nil, err
}

variables, err := completed.ConfigProvider.GetVariables(o.Cloud, o.DeployEnv, o.Region, config.NewConfigReplacements(o.Region, o.RegionShort, o.Stamp))
variables, err := completed.ConfigProvider.GetVariables(o.Cloud, o.DeployEnv, o.Region, config.NewConfigReplacements(o.Region, o.DrRegion, o.RegionShort, o.Stamp))
if err != nil {
return nil, fmt.Errorf("failed to get variables: %w", err)
}
Expand Down
7 changes: 5 additions & 2 deletions tooling/templatize/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import (
)

func DefaultConfigReplacements() *ConfigReplacements {
return NewConfigReplacements("", "", "")
return NewConfigReplacements("", "", "", "")
}

func NewConfigReplacements(regionReplacement, regionShortReplacement, stampReplacement string) *ConfigReplacements {
func NewConfigReplacements(regionReplacement, drRegionReplacement, regionShortReplacement, stampReplacement string) *ConfigReplacements {
return &ConfigReplacements{
RegionReplacement: regionReplacement,
DrRegionReplacement: drRegionReplacement,
RegionShortReplacement: regionShortReplacement,
StampReplacement: stampReplacement,
}
}

type ConfigReplacements struct {
RegionReplacement string
DrRegionReplacement string
RegionShortReplacement string
StampReplacement string
}
Expand All @@ -34,6 +36,7 @@ func (c *ConfigReplacements) AsMap() map[string]interface{} {
return map[string]interface{}{
"ctx": map[string]interface{}{
"region": c.RegionReplacement,
"drRegion": c.DrRegionReplacement,
"regionShort": c.RegionShortReplacement,
"stamp": c.StampReplacement,
},
Expand Down
3 changes: 2 additions & 1 deletion tooling/templatize/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (

func TestConfigProvider(t *testing.T) {
region := "uksouth"
drRegion := "ukwest"
regionShort := "uks"
stamp := "1"

configProvider := NewConfigProvider("../../testdata/config.yaml")

variables, err := configProvider.GetVariables("public", "int", region, NewConfigReplacements(region, regionShort, stamp))
variables, err := configProvider.GetVariables("public", "int", region, NewConfigReplacements(region, drRegion, regionShort, stamp))
assert.NoError(t, err)
assert.NotNil(t, variables)

Expand Down
1 change: 1 addition & 0 deletions tooling/templatize/pkg/ev2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func NewEv2ConfigReplacements() *config.ConfigReplacements {
return config.NewConfigReplacements(
"$location()",
"$(drRegion)",
"$(regionShortName)",
"$stamp()",
)
Expand Down
4 changes: 2 additions & 2 deletions tooling/templatize/pkg/pipeline/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestDeepCopy(t *testing.T) {
configProvider := config.NewConfigProvider("../../testdata/config.yaml")
vars, err := configProvider.GetVariables("public", "int", "", config.NewConfigReplacements("r", "sr", "s"))
vars, err := configProvider.GetVariables("public", "int", "", config.NewConfigReplacements("r", "dr", "sr", "s"))
if err != nil {
t.Errorf("failed to get variables: %v", err)
}
Expand All @@ -38,7 +38,7 @@ func TestDeepCopy(t *testing.T) {

func TestAbsoluteFilePath(t *testing.T) {
configProvider := config.NewConfigProvider("../../testdata/config.yaml")
vars, err := configProvider.GetVariables("public", "int", "", config.NewConfigReplacements("r", "sr", "s"))
vars, err := configProvider.GetVariables("public", "int", "", config.NewConfigReplacements("r", "dr", "sr", "s"))
if err != nil {
t.Errorf("failed to get variables: %v", err)
}
Expand Down

0 comments on commit 27b48f4

Please sign in to comment.