Skip to content

Commit

Permalink
Add support for HyperV platform
Browse files Browse the repository at this point in the history
This PR adds initial support for the Microsoft HyperV platform.  It uses
HyperV and MS WMI to read key/value pairs as provided by the Windows
host.  Because the size allocation of the value is quite small, the
ignition values will likely be split into at least 2 and more like more
parts which must be read and reassembled in ignition.

Supports:
  * coreos/fedora-coreos-tracker#1411
  * coreos/fedora-coreos-tracker#1424

Signed-off-by: Brent Baude <[email protected]>
  • Loading branch information
baude authored and bgilbert committed Jun 28, 2023
1 parent 153df40 commit 371d0b3
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Starting with this release, ignition-validate binaries are signed with the

### Features

- Support HyperV platform

### Changes

Expand Down
4 changes: 4 additions & 0 deletions docs/supported-platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Ignition is currently only supported for the following platforms:
* [DigitalOcean] (`digitalocean`) - Ignition will read its configuration from the droplet userdata. Cloud SSH keys and network configuration are handled separately.
* [Exoscale] (`exoscale`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
* [Google Cloud] (`gcp`) - Ignition will read its configuration from the instance metadata entry named "user-data". Cloud SSH keys are handled separately.
* [Microsoft HyperV] (`hyperv`) - Ignition will read its configuration from a key named `ignition.config.0` in pool 0 of the Hyper-V Data Exchange Service (KVP). KVP
values are limited to 1 KiB in size, but larger configs can be split into multiple values where the key name is incremented (eg. `ignition.config.0`, `ignition.config.1`, `ignition.config.2`)
on the Windows host. Ignition will reassemble the config from the split values.
* [IBM Cloud] (`ibmcloud`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
* [KubeVirt] (`kubevirt`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately.
* Bare Metal (`metal`) - Use the `ignition.config.url` kernel parameter to provide a URL to the configuration. The URL can use the `http://`, `https://`, `tftp://`, `s3://`, `arn:`, or `gs://` schemes to specify a remote config.
Expand All @@ -41,6 +44,7 @@ For most cloud providers, cloud SSH keys and custom network configuration are ha
[DigitalOcean]: https://www.digitalocean.com/products/droplets/
[Exoscale]: https://www.exoscale.com/compute/
[Google Cloud]: https://cloud.google.com/compute
[Microsoft HyperV]: https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/
[IBM Cloud]: https://www.ibm.com/cloud/vpc
[KubeVirt]: https://kubevirt.io
[Nutanix]: https://www.nutanix.com/products/ahv
Expand Down
5 changes: 5 additions & 0 deletions dracut/30ignition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ install() {
# needed for openstack config drive support
inst_rules 60-cdrom_id.rules
}

installkernel() {
# required by hyperv platform to read kvp from the kernel
instmods -c hv_utils
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
cloud.google.com/go/storage v1.30.1
github.com/aws/aws-sdk-go v1.44.284
github.com/beevik/etree v1.2.0
github.com/containers/libhvee v0.0.5
github.com/coreos/go-semver v0.3.1
github.com/coreos/go-systemd/v22 v22.5.0
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/containers/libhvee v0.0.5 h1:5tUiF2eVe8XbVSPD/Os4dIU1gJWoQgtkQHIjQ5X7wpE=
github.com/containers/libhvee v0.0.5/go.mod h1:AYsyMe44w9ylWWEZNW+IOzA7oZ2i/P9TChNljavhYMI=
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIRhuC59RB442rXUazKNueVpfJPxg4=
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb/go.mod h1:rcFZM3uxVvdyNmsAV2jopgPD1cs5SPWJWU5dOz2LUnw=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
Expand Down
74 changes: 74 additions & 0 deletions internal/providers/hyperv/kvp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2023 Red Hat
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package hyperv

import (
"fmt"
"os/exec"
"path/filepath"

"github.com/containers/libhvee/pkg/kvp"
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
"github.com/coreos/ignition/v2/internal/platform"
"github.com/coreos/ignition/v2/internal/providers/util"
"github.com/coreos/ignition/v2/internal/resource"
"github.com/coreos/vcontext/report"
)

// key represents the prefix key name for finding kvp file parts
// in the key value pairs. it normally will have an integer added to the
// end when looking up keys sequentially
const key = "ignition.config."

func init() {
platform.Register(platform.Provider{
Name: "hyperv",
FetchWithFiles: fetchConfig,
})
}

func fetchConfig(f *resource.Fetcher) ([]types.File, types.Config, report.Report, error) {
var (
kvpFiles []types.File
)

f.Logger.Info("attempting to read from kvp")

// To read key-value pairs from the Windows host, the hv_util kernel module
// must be loaded to create the kernel device itself.
_, err := f.Logger.LogCmd(exec.Command("modprobe", "hv_utils"), "loading hyperv kernel device module")
if err != nil {
return nil, types.Config{}, report.Report{}, err
}

keyValuePairs, err := kvp.GetKeyValuePairs()
if err != nil {
return nil, types.Config{}, report.Report{}, err
}

ign, _, err := keyValuePairs.GetSplitKeyValues(key, kvp.DefaultKVPPoolID)
if err != nil {
return nil, types.Config{}, report.Report{}, err
}

// KVP files are written to the filesystem in /var/lib/hyperv by pool id. We will do the same
// for the first boot as well.
for poolID := range keyValuePairs {
fqWritePath := filepath.Join(kvp.DefaultKVPFilePath, fmt.Sprintf("%s%d", kvp.DefaultKVPBaseName, poolID))
kvpFiles = append(kvpFiles, util.MakeProviderOutputFile(fqWritePath, kvp.DefaultKVPFileWritePermissions, keyValuePairs.EncodePoolFile(poolID)))
}
c, r, err := util.ParseConfig(f.Logger, []byte(ign))
return kvpFiles, c, r, err
}
1 change: 1 addition & 0 deletions internal/register/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "github.com/coreos/ignition/v2/internal/providers/exoscale"
_ "github.com/coreos/ignition/v2/internal/providers/file"
_ "github.com/coreos/ignition/v2/internal/providers/gcp"
_ "github.com/coreos/ignition/v2/internal/providers/hyperv"
_ "github.com/coreos/ignition/v2/internal/providers/ibmcloud"
_ "github.com/coreos/ignition/v2/internal/providers/kubevirt"
_ "github.com/coreos/ignition/v2/internal/providers/metal"
Expand Down
201 changes: 201 additions & 0 deletions vendor/github.com/containers/libhvee/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 371d0b3

Please sign in to comment.