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 committed Apr 11, 2023
1 parent 2bd7de4 commit e65265f
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nav_order: 9


### 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.239
github.com/beevik/etree v1.1.1-0.20200718192613-4a2f8b9d084c
github.com/containers/libhvee v0.0.2
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 @@ -18,6 +18,8 @@ github.com/beevik/etree v1.1.1-0.20200718192613-4a2f8b9d084c/go.mod h1:0yGO2rna3
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containers/libhvee v0.0.2 h1:eWtbOvpT8bD9jvksMES2yXUmEpcE0zENWkci+bbP7U8=
github.com/containers/libhvee v0.0.2/go.mod h1:bV1MfbuXk/ZLWHiWZpm8aePOR6iJGD1q55guYhH4CnA=
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
61 changes: 61 additions & 0 deletions internal/providers/hyperv/kvp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 (
"github.com/coreos/ignition/v2/internal/platform"
"os/exec"

"github.com/containers/libhvee/pkg/kvp"
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
"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",
Fetch: fetchConfig,
})
}

func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
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 types.Config{}, report.Report{}, err
}

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

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

return util.ParseConfig(f.Logger, []byte(ign))
}
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 e65265f

Please sign in to comment.