Skip to content

Commit

Permalink
Fix sig replica count - use shallow replication in acc test - fix units
Browse files Browse the repository at this point in the history
  • Loading branch information
JenGoldstrich committed Sep 29, 2023
1 parent 8c67ffe commit a883f0c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
4 changes: 2 additions & 2 deletions builder/azure/arm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type SharedImageGalleryDestination struct {
// Set to true if publishing to a Specialized Gallery, this skips a call to set the build VM's OS state as Generalized
SigDestinationSpecialized bool `mapstructure:"specialized"`
// Set to true if you want to publish using Shallow Replication, this is faster but skips copying the full image to the gallery image region, read more about Shallow Replication [here](https://learn.microsoft.com/en-us/azure/virtual-machines/shared-image-galleries?tabs=azure-cli#shallow-replication)
SigDestinationShallowReplicationMode bool `mapstructure:"shallow_replication"`
SigDestinationShallowReplicationMode bool `mapstructure:"shallow_replication" required:"false"`
}

type Spot struct {
Expand Down Expand Up @@ -217,7 +217,7 @@ type Config struct {
// The number of replicas of the Image Version to be created per region. This
// property would take effect for a region when regionalReplicaCount is not specified.
// Replica count must be between 1 and 100, but 50 replicas should be sufficient for most use cases.
SharedGalleryImageVersionReplicaCount int32 `mapstructure:"shared_image_gallery_replica_count" required:"false"`
SharedGalleryImageVersionReplicaCount int64 `mapstructure:"shared_image_gallery_replica_count" required:"false"`
// If set to true, Virtual Machines deployed from the latest version of the
// Image Definition won't use this Image Version.
SharedGalleryImageVersionExcludeFromLatest bool `mapstructure:"shared_gallery_image_version_exclude_from_latest" required:"false"`
Expand Down
5 changes: 4 additions & 1 deletion builder/azure/arm/step_publish_to_shared_image_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *StepPublishToSharedImageGallery) publishToSig(publishArgs PublishArgs)
}
}
replicationMode := galleryimageversions.ReplicationModeFull
if true {
if publishArgs.shallowReplicationMode {
replicationMode = galleryimageversions.ReplicationModeShallow
}
galleryImageVersion := galleryimageversions.GalleryImageVersion{
Expand Down Expand Up @@ -207,6 +207,9 @@ func (s *StepPublishToSharedImageGallery) Run(ctx context.Context, stateBag mult
s.say(fmt.Sprintf(" -> SIG image version exclude from latest : '%t'", miSGImageVersionExcludeFromLatest))
s.say(fmt.Sprintf(" -> SIG replica count [1, 100] : '%d'", miSigReplicaCount))
shallowReplicationMode := stateBag.Get(constants.ArmSharedImageGalleryDestinationShallowReplication).(bool)
if shallowReplicationMode {
s.say(" -> Creating SIG Image with Shallow Replication")
}
subscriptionID := stateBag.Get(constants.ArmSharedImageGalleryDestinationSubscription).(string)
createdGalleryImageVersionID, err := s.publish(
PublishArgs{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) {
var testSubject = &StepPublishToSharedImageGallery{
publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) {
publish: func(PublishArgs) (string, error) {
return "test", nil
},
say: func(message string) {},
Expand All @@ -37,7 +37,7 @@ func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) {

func TestStepPublishToSharedImageGalleryShouldPublishForManagedImageWithSig(t *testing.T) {
var testSubject = &StepPublishToSharedImageGallery{
publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) {
publish: func(PublishArgs) (string, error) {
return "", nil
},
say: func(message string) {},
Expand All @@ -58,7 +58,7 @@ func TestStepPublishToSharedImageGalleryShouldPublishForManagedImageWithSig(t *t

func TestStepPublishToSharedImageGalleryShouldPublishForNonManagedImageWithSig(t *testing.T) {
var testSubject = &StepPublishToSharedImageGallery{
publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) {
publish: func(PublishArgs) (string, error) {
return "", nil
},
say: func(message string) {},
Expand Down
29 changes: 15 additions & 14 deletions builder/azure/arm/testdata/arm_linux_specialized.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

variable "ssh_private_key_location" {
default = "${env("ARM_SSH_PRIVATE_KEY_FILE")}"
type = string
type = string
}

source "azure-arm" "linux-sig" {
image_offer = "0001-com-ubuntu-server-jammy"
image_publisher = "canonical"
image_sku = "22_04-lts-arm64"
use_azure_cli_auth = true
location = "South Central US"
vm_size = "Standard_D4ps_v5"
ssh_username = "packer"
image_offer = "0001-com-ubuntu-server-jammy"
image_publisher = "canonical"
image_sku = "22_04-lts-arm64"
use_azure_cli_auth = true
location = "South Central US"
vm_size = "Standard_D4ps_v5"
ssh_username = "packer"
ssh_private_key_file = var.ssh_private_key_location
communicator = "ssh"
communicator = "ssh"
shared_image_gallery_destination {
image_name = "arm-linux-specialized-sig"
gallery_name = "acctestgallery"
image_version = "1.0.0"
resource_group = "packer-acceptance-test"
specialized = true
image_name = "arm-linux-specialized-sig"
gallery_name = "acctestgallery"
image_version = "1.0.0"
resource_group = "packer-acceptance-test"
specialized = true
shallow_replication = true
}

os_type = "Linux"
Expand Down
29 changes: 15 additions & 14 deletions builder/azure/arm/testdata/child_from_specialized_parent.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

variable "subscription" {
default = "${env("ARM_SUBSCRIPTION_ID")}"
type = string
default = "${env("ARM_SUBSCRIPTION_ID")}"
type = string
sensitive = true
}

variable "ssh_private_key_location" {
default = "${env("ARM_SSH_PRIVATE_KEY_FILE")}"
type = string
type = string
}

source "azure-arm" "linux-sig" {
use_azure_cli_auth = true
location = "South Central US"
vm_size = "Standard_D4ps_v5"
ssh_username = "packer"
use_azure_cli_auth = true
location = "South Central US"
vm_size = "Standard_D4ps_v5"
ssh_username = "packer"
ssh_private_key_file = var.ssh_private_key_location
communicator = "ssh"
shared_image_gallery{
communicator = "ssh"
shared_image_gallery {
subscription = var.subscription
image_name = "arm-linux-specialized-sig"
gallery_name = "acctestgallery"
image_version = "1.0.0"
resource_group = "packer-acceptance-test"
}
shared_image_gallery_destination {
image_name = "arm-linux-specialized-sig"
gallery_name = "acctestgallery"
image_version = "1.0.1"
resource_group = "packer-acceptance-test"
specialized = true
image_name = "arm-linux-specialized-sig"
gallery_name = "acctestgallery"
image_version = "1.0.1"
resource_group = "packer-acceptance-test"
specialized = true
shallow_replication = true
}

os_type = "Linux"
Expand Down

0 comments on commit a883f0c

Please sign in to comment.