Skip to content

Commit

Permalink
bug: allows specific regional location image to be created for GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
manoj-nutanix committed Sep 23, 2024
1 parent 4926074 commit 8833dc5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
22 changes: 0 additions & 22 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
---
version: 2
before:
hooks:
- go mod download
- go mod tidy

# NOTE(jkoelker) the changelog is managed by `release-please`
changelog:
disable: true

builds:
- main: ./cmd/konvoy-image/main.go
id: konvoy-image
Expand Down Expand Up @@ -95,20 +90,3 @@ release:
prerelease: auto
ids:
- konvoy-image-bundle

notarize:
macos:
- enabled: '{{ isEnvSet "NOTARIZE_DARWIN_BINARY"}}'
ids:
- konvoy-image
- konvoy-image-wrapper
sign:
certificate: "{{.Env.MACOS_SIGN_P12}}"
password: "{{.Env.MACOS_SIGN_PASSWORD}}"

notarize:
issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
key: "{{.Env.MACOS_NOTARY_KEY}}"
wait: true
timeout: 20m
2 changes: 2 additions & 0 deletions cmd/konvoy-image-wrapper/cmd/create-package-bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func getKubernetesVerisonFromAnsible() (string, error) {
return kubeVersion, nil
}

//nolint:funlen // no need to split this function
func (r *Runner) CreatePackageBundle(args []string) error {
var (
osFlag string
Expand Down Expand Up @@ -153,6 +154,7 @@ func (r *Runner) CreatePackageBundle(args []string) error {
fetchKubernetesRPMs = false
}
if eusReposFlag {
//nolint:goconst // this is a flag
r.env["EUS_REPOS"] = "true"
}
if fetchKubernetesRPMs {
Expand Down
7 changes: 7 additions & 0 deletions cmd/konvoy-image/cmd/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func addGCPArgs(fs *flag.FlagSet, gcp *app.GCPArgs) {
"the project id to use when storing created image",
)

fs.StringSliceVar(
&gcp.ImageLocation,
"image-storage-locations",
[]string{},
"the location to use when storing created image",
)

fs.StringVar(
&gcp.Network,
"network",
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/build_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

type GCPArgs struct {
ProjectID string // the project ID to which the source VM belongs.
Region string // the region where the source VM is located.
Network string // the network in which to load image creation, should have .
ProjectID string // the project ID to which the source VM belongs.
Region string // the region where the source VM is located.
Network string // the network in which to load image creation, should have .
ImageLocation []string // the location where the image will be stored.
}

func ensureGCP() error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ func MergeGCPUserArgs(config Config, gcpArgs *GCPArgs) error {
return fmt.Errorf("failed to set %s: %w", PackerGCPProjectIDPath, err)
}

if err := config.Set(PackerGCPImageLocationPath, gcpArgs.ImageLocation); err != nil {
return fmt.Errorf("failed to set %s: %w", PackerGCPImageLocationPath, err)
}

if err := config.Set(PackerGCPNetworkPath, gcpArgs.Network); err != nil {
return fmt.Errorf("failed to set %s: %w", PackerGCPNetworkPath, err)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ const (
PackerAzureTenantIDPath = "/packer/tenant_id"
PackerAzureCloudEndpointPath = "/packer/cloud_environment_name"

PackerGCPProjectIDPath = "/packer/project_id"
PackerGCPNetworkPath = "/packer/network"
PackerGCPRegionPath = "/packer/region"
PackerGCPProjectIDPath = "/packer/project_id"
PackerGCPNetworkPath = "/packer/network"
PackerGCPRegionPath = "/packer/region"
PackerGCPImageLocationPath = "/packer/image_storage_locations"

PackerVSphereTemplatePath = "/packer/template"
PackerVSphereClusterPath = "/packer/cluster"
Expand Down
8 changes: 7 additions & 1 deletion pkg/packer/manifests/gcp/packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ variable "project_id" {
default = ""
}

variable "image_storage_locations" {
type = string
default = ""
}

variable "region" {
type = string
default = ""
Expand Down Expand Up @@ -238,6 +243,7 @@ locals {
ansible_extra_vars = "${var.ansible_extra_vars}"
build_timestamp = local.timestamp
zone = "${var.region}-a"
image_storage_locations = split(",", var.image_storage_locations)
generated_image_name = "konvoy-${var.build_name}-${var.kubernetes_full_version}-${local.build_timestamp}"
# clean_resource_name https://github.com/hashicorp/packer-plugin-googlecompute/blob/81d8d5a740c0d7fb0b02be93133ac17a11557f34/builder/googlecompute/template_funcs.go#L20
image_name = regex_replace(lower(local.generated_image_name), "[^-a-z0-9]", "-")
Expand Down Expand Up @@ -267,14 +273,14 @@ source "googlecompute" "kib_image" {
image_name = local.image_name
network = var.network
project_id = var.project_id
image_storage_locations = local.image_storage_locations
region = var.region
source_image = var.source_image
source_image_family = var.distribution_family
ssh_key_exchange_algorithms = ["[email protected]", "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1"]
ssh_username = var.ssh_username
wait_to_add_ssh_keys = "20s"
zone = local.zone

skip_create_image = var.dry_run
}

Expand Down

0 comments on commit 8833dc5

Please sign in to comment.