From bb3d78f43a92823f403e516b8d849911b41e4ac3 Mon Sep 17 00:00:00 2001 From: Manoj Surudwad Date: Tue, 24 Sep 2024 00:17:39 +0530 Subject: [PATCH 1/5] bug: allows specific regional location image to be created for GCP --- .goreleaser.yml | 22 ------------------- .../cmd/create-package-bundle.go | 2 ++ cmd/konvoy-image/cmd/gcp.go | 7 ++++++ pkg/app/build_gcp.go | 7 +++--- pkg/app/config.go | 4 ++++ pkg/app/constants.go | 7 +++--- pkg/packer/manifests/gcp/packer.pkr.hcl | 8 ++++++- 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 5c9bd801d..ff3b1ae54 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 @@ -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 diff --git a/cmd/konvoy-image-wrapper/cmd/create-package-bundle.go b/cmd/konvoy-image-wrapper/cmd/create-package-bundle.go index 534e7a301..e134894b1 100644 --- a/cmd/konvoy-image-wrapper/cmd/create-package-bundle.go +++ b/cmd/konvoy-image-wrapper/cmd/create-package-bundle.go @@ -81,6 +81,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 @@ -161,6 +162,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 { diff --git a/cmd/konvoy-image/cmd/gcp.go b/cmd/konvoy-image/cmd/gcp.go index 0ebb02c61..72cce6669 100644 --- a/cmd/konvoy-image/cmd/gcp.go +++ b/cmd/konvoy-image/cmd/gcp.go @@ -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", diff --git a/pkg/app/build_gcp.go b/pkg/app/build_gcp.go index 0500c7b75..a52325cc9 100644 --- a/pkg/app/build_gcp.go +++ b/pkg/app/build_gcp.go @@ -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 { diff --git a/pkg/app/config.go b/pkg/app/config.go index b22b61393..eac7eb75b 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -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) } diff --git a/pkg/app/constants.go b/pkg/app/constants.go index 969c20a69..609903b51 100644 --- a/pkg/app/constants.go +++ b/pkg/app/constants.go @@ -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" diff --git a/pkg/packer/manifests/gcp/packer.pkr.hcl b/pkg/packer/manifests/gcp/packer.pkr.hcl index 9e3d574af..b8e35c6ec 100644 --- a/pkg/packer/manifests/gcp/packer.pkr.hcl +++ b/pkg/packer/manifests/gcp/packer.pkr.hcl @@ -80,6 +80,11 @@ variable "project_id" { default = "" } +variable "image_storage_locations" { + type = string + default = "" +} + variable "region" { type = string default = "" @@ -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]", "-") @@ -267,6 +273,7 @@ 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 @@ -274,7 +281,6 @@ source "googlecompute" "kib_image" { ssh_username = var.ssh_username wait_to_add_ssh_keys = "20s" zone = local.zone - skip_create_image = var.dry_run } From 69dfcda765b2a827c2a5094cb5b0e9ca613cd839 Mon Sep 17 00:00:00 2001 From: Shalin Patel Date: Thu, 7 Nov 2024 14:08:12 -0800 Subject: [PATCH 2/5] fix: revert go releaser changes --- .goreleaser.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index ff3b1ae54..5c9bd801d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,9 +1,14 @@ --- +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 @@ -90,3 +95,20 @@ 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 From d0ae253f58816ed56a013e86e51dd14001db6bd8 Mon Sep 17 00:00:00 2001 From: Shalin Patel Date: Thu, 7 Nov 2024 15:16:03 -0800 Subject: [PATCH 3/5] ci: update GHA secret for GCP credentials --- .github/workflows/gcp-e2e.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gcp-e2e.yaml b/.github/workflows/gcp-e2e.yaml index 06ba902a2..e5cb92c86 100644 --- a/.github/workflows/gcp-e2e.yaml +++ b/.github/workflows/gcp-e2e.yaml @@ -57,7 +57,7 @@ jobs: echo -n "${GOOGLE_APPLICATION_CREDENTIALS_E2E_BASE64}" | base64 --decode >> google-credentials.json echo "GOOGLE_APPLICATION_CREDENTIALS=google-credentials.json" >> $GITHUB_ENV env: - GOOGLE_APPLICATION_CREDENTIALS_E2E_BASE64: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_E2E_BASE64 }} + GOOGLE_APPLICATION_CREDENTIALS_E2E_BASE64: ${{ secrets.GCP_NCN_CI_SERVICE_ACCOUNT_B64 }} - name: Run E2E test for ${{ matrix.os }} with ${{ matrix.buildConfig }} configuration uses: magefile/mage-action@v3 From 8b7f0ce4763d30cd18e056b0d728d7cea81168fa Mon Sep 17 00:00:00 2001 From: Shalin Patel Date: Thu, 7 Nov 2024 15:17:19 -0800 Subject: [PATCH 4/5] build: set image storage location for gcp --- docs/cli/konvoy-image_build_gcp.md | 27 ++++++++++++++------------- magefile.go | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/cli/konvoy-image_build_gcp.md b/docs/cli/konvoy-image_build_gcp.md index a5c946233..2dfc377e7 100644 --- a/docs/cli/konvoy-image_build_gcp.md +++ b/docs/cli/konvoy-image_build_gcp.md @@ -15,19 +15,20 @@ gcp ... images/gcp/centos-79.yaml ### Options ``` - --containerd-version string the version of containerd to install - --dry-run do not create artifacts, or delete them after creating. Recommended for tests. - --extra-vars strings flag passed Ansible's extra-vars - -h, --help help for gcp - --kubernetes-version string The version of kubernetes to install. Example: 1.21.6 - --network string the network to use when creating an image - --overrides strings a comma separated list of override YAML files - --packer-manifest string provide the path to a custom packer manifest - --packer-on-error string [advanced] set error strategy for packer. strategies [cleanup, abort, run-cleanup-provisioner] - --packer-path string the location of the packer binary (default "packer") - --project-id string the project id to use when storing created image - --region string the region in which to launch the instance (default "us-west1") - --work-dir string path to custom work directory generated by the generate command + --containerd-version string the version of containerd to install + --dry-run do not create artifacts, or delete them after creating. Recommended for tests. + --extra-vars strings flag passed Ansible's extra-vars + -h, --help help for gcp + --image-storage-locations strings the location to use when storing created image + --kubernetes-version string The version of kubernetes to install. Example: 1.21.6 + --network string the network to use when creating an image + --overrides strings a comma separated list of override YAML files + --packer-manifest string provide the path to a custom packer manifest + --packer-on-error string [advanced] set error strategy for packer. strategies [cleanup, abort, run-cleanup-provisioner] + --packer-path string the location of the packer binary (default "packer") + --project-id string the project id to use when storing created image + --region string the region in which to launch the instance (default "us-west1") + --work-dir string path to custom work directory generated by the generate command ``` ### Options inherited from parent commands diff --git a/magefile.go b/magefile.go index 19b9dfbd0..99a44c4df 100644 --- a/magefile.go +++ b/magefile.go @@ -182,7 +182,7 @@ func RunE2e(buildOS, buildConfig, buildInfra string, dryRun bool) error { } // extra args for gcp if buildInfra == gcp { - args = append(args, "--project-id=eng-ksphere-platform-e2e", "--network=kib-ssh-network") + args = append(args, "--project-id=ncn-ci-workload", "--network=kib-ssh-network", "--image-storage-locations=us-west1") } fmt.Printf("Running %s with args %v\n", wrapperCmd, args) return sh.RunV(wrapperCmd, args...) From 031bfcb6f6c3b5339454c0cc310ac54c590b6705 Mon Sep 17 00:00:00 2001 From: Shalin Patel Date: Fri, 8 Nov 2024 10:18:07 -0800 Subject: [PATCH 5/5] ci: use GCP infra varaible fro GHA --- .github/workflows/gcp-e2e.yaml | 3 +++ .github/workflows/release-gcp-template.yaml | 3 +++ magefile.go | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gcp-e2e.yaml b/.github/workflows/gcp-e2e.yaml index e5cb92c86..077d13351 100644 --- a/.github/workflows/gcp-e2e.yaml +++ b/.github/workflows/gcp-e2e.yaml @@ -66,3 +66,6 @@ jobs: args: runE2e "${{ matrix.os }}" "${{ matrix.buildConfig }}" gcp true env: GITHUB_TOKEN: ${{ secrets.MESOSPHERECI_USER_TOKEN }} + GCP_PROJECT: ${{ vars.GCP_PROJECT }} + GCP_NETWORK: ${{ vars.GCP_NETWORK }} + GCP_IMAGE_LOCATIONS: ${{ vars.GCP_IMAGE_LOCATIONS }} diff --git a/.github/workflows/release-gcp-template.yaml b/.github/workflows/release-gcp-template.yaml index 980b5f5ca..413c5f58d 100644 --- a/.github/workflows/release-gcp-template.yaml +++ b/.github/workflows/release-gcp-template.yaml @@ -66,3 +66,6 @@ jobs: args: runE2e "${{ matrix.os }}" "${{ matrix.buildConfig }}" gcp false env: GITHUB_TOKEN: ${{ secrets.MESOSPHERECI_USER_TOKEN }} + GCP_PROJECT: ${{ vars.GCP_PROJECT }} + GCP_NETWORK: ${{ vars.GCP_NETWORK }} + GCP_IMAGE_LOCATIONS: ${{ vars.GCP_IMAGE_LOCATIONS }} diff --git a/magefile.go b/magefile.go index 99a44c4df..30da22ea3 100644 --- a/magefile.go +++ b/magefile.go @@ -182,7 +182,10 @@ func RunE2e(buildOS, buildConfig, buildInfra string, dryRun bool) error { } // extra args for gcp if buildInfra == gcp { - args = append(args, "--project-id=ncn-ci-workload", "--network=kib-ssh-network", "--image-storage-locations=us-west1") + args = append(args, + fmt.Sprintf("--project-id=%s", os.Getenv("GCP_PROJECT")), + fmt.Sprintf("--network=%s", os.Getenv("GCP_NETWORK")), + fmt.Sprintf("--image-storage-locations=%s", os.Getenv("GCP_IMAGE_LOCATIONS"))) } fmt.Printf("Running %s with args %v\n", wrapperCmd, args) return sh.RunV(wrapperCmd, args...)