Skip to content

Commit

Permalink
mantle/gcp: support c3 metal instance types
Browse files Browse the repository at this point in the history
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 coreos/fedora-coreos-tracker#1794
  • Loading branch information
dustymabe committed Sep 13, 2024
1 parent 51dc4ab commit 93e6e82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mantle/cmd/kola/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions mantle/platform/api/gcloud/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions mantle/platform/api/gcloud/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 == "" {
Expand Down

0 comments on commit 93e6e82

Please sign in to comment.