From 93e6e82c984763f8ebcca59865cb9bae9f005bcd Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Fri, 13 Sep 2024 09:07:45 -0400 Subject: [PATCH] mantle/gcp: support c3 metal instance types This requires the IDPF guest OS feature flag to be set when creating GCP images and also a TERMINATE maintenance policy and hyperdisk storage. With this change, after uploading a disk you can then test with kola with something like: ``` cosa kola run -p=gcp \ --gcp-json-key=key.json \ --gcp-project=project \ --gcp-machinetype=c3-highcpu-192-metal \ --gcp-zone=us-central1-c basic ``` Related to https://github.com/coreos/fedora-coreos-tracker/issues/1794 --- mantle/cmd/kola/options.go | 14 +++++++++++++- mantle/platform/api/gcloud/compute.go | 6 ++++++ mantle/platform/api/gcloud/image.go | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mantle/cmd/kola/options.go b/mantle/cmd/kola/options.go index 2220a38829..26863dc4da 100644 --- a/mantle/cmd/kola/options.go +++ b/mantle/cmd/kola/options.go @@ -120,7 +120,7 @@ func init() { sv(&kola.GCPOptions.Project, "gcp-project", "fedora-coreos-devel", "GCP project name") sv(&kola.GCPOptions.Zone, "gcp-zone", "us-central1-a", "GCP zone name") sv(&kola.GCPOptions.MachineType, "gcp-machinetype", "", "GCP machine type") - sv(&kola.GCPOptions.DiskType, "gcp-disktype", "pd-ssd", "GCP disk type") + sv(&kola.GCPOptions.DiskType, "gcp-disktype", "", "GCP disk type (default pd-ssd)") sv(&kola.GCPOptions.Network, "gcp-network", "default", "GCP network") sv(&kola.GCPOptions.ServiceAcct, "gcp-service-account", "", "GCP service account to attach to instance (default project default)") bv(&kola.GCPOptions.ServiceAuth, "gcp-service-auth", false, "for non-interactive auth when running within GCP") @@ -257,6 +257,18 @@ func syncOptionsImpl(useCosa bool) error { } fmt.Printf("Using %s instance type\n", kola.GCPOptions.MachineType) } + // Set the disktype for gcp based on the instance type. metal + // instances require hyperdisk storage, all other should be able + // to use pd-ssd. + // https://cloud.google.com/compute/docs/general-purpose-machines#c3_disks + if kolaPlatform == "gcp" && kola.GCPOptions.DiskType == "" { + if strings.HasSuffix(kola.GCPOptions.MachineType, "metal") { + kola.GCPOptions.DiskType = "hyperdisk-balanced" + } else { + kola.GCPOptions.DiskType = "pd-ssd" + } + fmt.Printf("Using %s disktype for gcp instance\n", kola.GCPOptions.DiskType) + } // if no external dirs were given, automatically add the working directory; // does nothing if ./tests/kola/ doesn't exist diff --git a/mantle/platform/api/gcloud/compute.go b/mantle/platform/api/gcloud/compute.go index 9daef94f28..1cbddc5907 100644 --- a/mantle/platform/api/gcloud/compute.go +++ b/mantle/platform/api/gcloud/compute.go @@ -162,6 +162,12 @@ func (a *API) mkinstance(userdata, name string, keys []*agent.Key, opts platform return nil, fmt.Errorf("Does not support confidential type %s, should be: sev, sev_snp\n", a.options.ConfidentialType) } } + // metal instances can only have a TERMINATE maintenance policy + if strings.HasSuffix(a.options.MachineType, "metal") { + instance.Scheduling = &compute.Scheduling{ + OnHostMaintenance: "TERMINATE", + } + } // attach aditional disk for _, spec := range opts.AdditionalDisks { plog.Debugf("Parsing disk spec %q\n", spec) diff --git a/mantle/platform/api/gcloud/image.go b/mantle/platform/api/gcloud/image.go index e60d6a9944..aac05654b1 100644 --- a/mantle/platform/api/gcloud/image.go +++ b/mantle/platform/api/gcloud/image.go @@ -86,6 +86,7 @@ func (a *API) CreateImage(spec *ImageSpec, overwrite bool) (*compute.Operation, } } + // https://cloud.google.com/compute/docs/images/create-custom#guest-os-features features := []*compute.GuestOsFeature{ // https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images { @@ -106,6 +107,10 @@ func (a *API) CreateImage(spec *ImageSpec, overwrite bool) (*compute.Operation, { Type: "SEV_SNP_CAPABLE", }, + // https://cloud.google.com/compute/docs/networking/using-idpf + { + Type: "IDPF", + }, } if spec.Architecture == "" {