Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(release-2.14): allows specific regional location image to be created for GCP #1224

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/gcp-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
3 changes: 3 additions & 0 deletions .github/workflows/release-gcp-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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
27 changes: 14 additions & 13 deletions docs/cli/konvoy-image_build_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ 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,
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...)
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
Loading