From 12c3252b392aedd5406bb02778a92661ff2de47d Mon Sep 17 00:00:00 2001 From: Maxim Timokhin Date: Thu, 18 Nov 2021 20:54:13 +0300 Subject: [PATCH] Add image_pooled option The `--pooled` option allows to create image, optimized for fast deployment. The feature is in preview now, but is very useful for deployment of large number of instances. The option is supported in Yandex CLI client and web application. Implemented as 'image_pooled` option. Not sure about proper naming, but there is already image_min_disk_size. Implementation needs update of Yandex SDK dependency. --- builder/yandex/common_config.go | 2 ++ builder/yandex/config.hcl2spec.go | 2 ++ builder/yandex/step_create_image.go | 1 + docs-partials/builder/yandex/ImageConfig-not-required.mdx | 2 ++ go.mod | 2 +- go.sum | 2 ++ post-processor/yandex-import/post-processor.hcl2spec.go | 2 ++ post-processor/yandex-import/utils.go | 1 + 8 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builder/yandex/common_config.go b/builder/yandex/common_config.go index f5b6f18..44d5b3e 100644 --- a/builder/yandex/common_config.go +++ b/builder/yandex/common_config.go @@ -147,6 +147,8 @@ type ImageConfig struct { ImageMinDiskSizeGb int `mapstructure:"image_min_disk_size_gb" required:"false"` // License IDs that indicate which licenses are attached to resulting image. ImageProductIDs []string `mapstructure:"image_product_ids" required:"false"` + // When true, an image pool will be created for fast creation disks from the image. + ImagePooled bool `mapstructure:"image_pooled" required:"false"` // Skip creating the image. Useful for setting to `true` during a build test stage. Defaults to `false`. SkipCreateImage bool `mapstructure:"skip_create_image" required:"false"` } diff --git a/builder/yandex/config.hcl2spec.go b/builder/yandex/config.hcl2spec.go index 6845776..0f0e87d 100644 --- a/builder/yandex/config.hcl2spec.go +++ b/builder/yandex/config.hcl2spec.go @@ -98,6 +98,7 @@ type FlatConfig struct { ImageLabels map[string]string `mapstructure:"image_labels" required:"false" cty:"image_labels" hcl:"image_labels"` ImageMinDiskSizeGb *int `mapstructure:"image_min_disk_size_gb" required:"false" cty:"image_min_disk_size_gb" hcl:"image_min_disk_size_gb"` ImageProductIDs []string `mapstructure:"image_product_ids" required:"false" cty:"image_product_ids" hcl:"image_product_ids"` + ImagePooled *bool `mapstructure:"image_pooled" required:"false" cty:"image_pooled" hcl:"image_pooled"` SkipCreateImage *bool `mapstructure:"skip_create_image" required:"false" cty:"skip_create_image" hcl:"skip_create_image"` SourceImageFamily *string `mapstructure:"source_image_family" required:"true" cty:"source_image_family" hcl:"source_image_family"` SourceImageFolderID *string `mapstructure:"source_image_folder_id" required:"false" cty:"source_image_folder_id" hcl:"source_image_folder_id"` @@ -207,6 +208,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "image_labels": &hcldec.AttrSpec{Name: "image_labels", Type: cty.Map(cty.String), Required: false}, "image_min_disk_size_gb": &hcldec.AttrSpec{Name: "image_min_disk_size_gb", Type: cty.Number, Required: false}, "image_product_ids": &hcldec.AttrSpec{Name: "image_product_ids", Type: cty.List(cty.String), Required: false}, + "image_pooled": &hcldec.AttrSpec{Name: "image_pooled", Type: cty.Bool, Required: false}, "skip_create_image": &hcldec.AttrSpec{Name: "skip_create_image", Type: cty.Bool, Required: false}, "source_image_family": &hcldec.AttrSpec{Name: "source_image_family", Type: cty.String, Required: false}, "source_image_folder_id": &hcldec.AttrSpec{Name: "source_image_folder_id", Type: cty.String, Required: false}, diff --git a/builder/yandex/step_create_image.go b/builder/yandex/step_create_image.go index d523e3f..09dc7df 100644 --- a/builder/yandex/step_create_image.go +++ b/builder/yandex/step_create_image.go @@ -40,6 +40,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul Family: c.ImageFamily, Description: c.ImageDescription, Labels: c.ImageLabels, + Pooled: c.ImagePooled, MinDiskSize: toBytes(c.ImageMinDiskSizeGb), ProductIds: c.ImageProductIDs, Source: &compute.CreateImageRequest_DiskId{ diff --git a/docs-partials/builder/yandex/ImageConfig-not-required.mdx b/docs-partials/builder/yandex/ImageConfig-not-required.mdx index e4b552c..5cc823b 100644 --- a/docs-partials/builder/yandex/ImageConfig-not-required.mdx +++ b/docs-partials/builder/yandex/ImageConfig-not-required.mdx @@ -15,6 +15,8 @@ - `image_product_ids` ([]string) - License IDs that indicate which licenses are attached to resulting image. +- `image_pooled` (boolean) - Create image optimized for deployment. + - `skip_create_image` (bool) - Skip creating the image. Useful for setting to `true` during a build test stage. Defaults to `false`. diff --git a/go.mod b/go.mod index d80d573..00f1c65 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/hcl/v2 v2.10.1 github.com/hashicorp/packer-plugin-sdk v0.2.9 github.com/stretchr/testify v1.7.0 - github.com/yandex-cloud/go-genproto v0.0.0-20210419102011-ea71516bb3f7 + github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e github.com/yandex-cloud/go-sdk v0.0.0-20210413100926-1c3eb10c58d7 github.com/zclconf/go-cty v1.9.1 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 diff --git a/go.sum b/go.sum index e8b50b1..c730924 100644 --- a/go.sum +++ b/go.sum @@ -560,6 +560,8 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq github.com/yandex-cloud/go-genproto v0.0.0-20210413095726-6b0dcd341e19/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= github.com/yandex-cloud/go-genproto v0.0.0-20210419102011-ea71516bb3f7 h1:qI0iykKTUTAFQ34/7cpnFZefKJTa5vprwPs8ncTkFGQ= github.com/yandex-cloud/go-genproto v0.0.0-20210419102011-ea71516bb3f7/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= +github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e h1:9LPdmD1vqadsDQUva6t2O9MbnyvoOgo8nFNPaOIH5U8= +github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= github.com/yandex-cloud/go-sdk v0.0.0-20210413100926-1c3eb10c58d7 h1:uPMQzYjpkRcn7oWGvFpMKOwgwO4gUm3v7dITULSYw6s= github.com/yandex-cloud/go-sdk v0.0.0-20210413100926-1c3eb10c58d7/go.mod h1:cxZ4BdZRJC1XMqb7x09H26zzy6NB9uL9SfcwqIvYmyw= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/post-processor/yandex-import/post-processor.hcl2spec.go b/post-processor/yandex-import/post-processor.hcl2spec.go index 55d10ef..4dfc5ec 100644 --- a/post-processor/yandex-import/post-processor.hcl2spec.go +++ b/post-processor/yandex-import/post-processor.hcl2spec.go @@ -30,6 +30,7 @@ type FlatConfig struct { ImageLabels map[string]string `mapstructure:"image_labels" required:"false" cty:"image_labels" hcl:"image_labels"` ImageMinDiskSizeGb *int `mapstructure:"image_min_disk_size_gb" required:"false" cty:"image_min_disk_size_gb" hcl:"image_min_disk_size_gb"` ImageProductIDs []string `mapstructure:"image_product_ids" required:"false" cty:"image_product_ids" hcl:"image_product_ids"` + ImagePooled *bool `mapstructure:"image_pooled" required:"false" cty:"image_pooled" hcl:"image_pooled"` SkipCreateImage *bool `mapstructure:"skip_create_image" required:"false" cty:"skip_create_image" hcl:"skip_create_image"` Bucket *string `mapstructure:"bucket" required:"false" cty:"bucket" hcl:"bucket"` ObjectName *string `mapstructure:"object_name" required:"false" cty:"object_name" hcl:"object_name"` @@ -66,6 +67,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "image_description": &hcldec.AttrSpec{Name: "image_description", Type: cty.String, Required: false}, "image_family": &hcldec.AttrSpec{Name: "image_family", Type: cty.String, Required: false}, "image_labels": &hcldec.AttrSpec{Name: "image_labels", Type: cty.Map(cty.String), Required: false}, + "image_pooled": &hcldec.AttrSpec{Name: "image_pooled", Type: cty.Bool, Required: false}, "image_min_disk_size_gb": &hcldec.AttrSpec{Name: "image_min_disk_size_gb", Type: cty.Number, Required: false}, "image_product_ids": &hcldec.AttrSpec{Name: "image_product_ids", Type: cty.List(cty.String), Required: false}, "skip_create_image": &hcldec.AttrSpec{Name: "skip_create_image", Type: cty.Bool, Required: false}, diff --git a/post-processor/yandex-import/utils.go b/post-processor/yandex-import/utils.go index a70564c..0a9ab0c 100644 --- a/post-processor/yandex-import/utils.go +++ b/post-processor/yandex-import/utils.go @@ -72,6 +72,7 @@ func createYCImage(ctx context.Context, driver yandex.Driver, ui packersdk.Ui, i Name: c.ImageConfig.ImageName, Description: c.ImageConfig.ImageDescription, Labels: c.ImageConfig.ImageLabels, + Pooled: c.ImageConfig.ImagePooled, Family: c.ImageConfig.ImageFamily, MinDiskSize: int64(c.ImageMinDiskSizeGb), ProductIds: c.ImageProductIDs,