Skip to content

Commit

Permalink
providers/applehv: Add Apple Hypervisor
Browse files Browse the repository at this point in the history
* Add applehv platform
* Ignintion read from vsock connection with the host

See coreos/fedora-coreos-tracker#1533 and
coreos/fedora-coreos-tracker#1548

Signed-off-by: Brent Baude <[email protected]>
  • Loading branch information
baude committed Aug 15, 2023
1 parent fccdd1a commit df97d9f
Show file tree
Hide file tree
Showing 41 changed files with 3,880 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,11 +10,11 @@ nav_order: 9


### Features
- Support the native Apple Hypervisor


### Changes


### Bug fixes


Expand Down
6 changes: 6 additions & 0 deletions dracut/30ignition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ install() {
installkernel() {
# required by hyperv platform to read kvp from the kernel
instmods hv_utils

# required by applehv platform to read ignition file through vsock
instmods -c vsock
instmods -c vmw_vsock_virtio_transport_common
instmods -c vmw_vsock_virtio_transport
}

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687
github.com/google/renameio/v2 v2.0.0
github.com/google/uuid v1.3.0
github.com/mdlayher/vsock v1.2.1
github.com/mitchellh/copystructure v1.2.0
github.com/pin/tftp v2.1.0+incompatible
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace
Expand Down Expand Up @@ -40,6 +41,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ=
github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
Expand Down
90 changes: 90 additions & 0 deletions internal/providers/applehv/applehv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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 applehv

import (
"context"
"fmt"
"io"
"net"
"net/http"
"os/exec"


"github.com/coreos/ignition/v2/internal/distro"
"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"
"github.com/mdlayher/vsock"
)

func init() {
platform.Register(platform.Provider{
Name: "applehv",
Fetch: fetchConfig,
})
}

func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
_, err := f.Logger.LogCmd(exec.Command(distro.ModprobeCmd(), "vsock"), "Loading vsock kernel module")
if err != nil {
f.Logger.Err("Failed to install vsocker kernel module: %v", err)
errors := fmt.Errorf("Failed to install vsock kernel module: %v", err)
return types.Config{}, report.Report{}, errors
}
conn, err := vsock.Dial(2, 1024, &vsock.Config{})
if err != nil {
return types.Config{}, report.Report{}, err
}
defer func() {
if err := conn.Close(); err != nil {
f.Logger.Err("unable to close vsock connection: %v", err)
}
}()

req, err := http.NewRequest(http.MethodGet, "http://d/", nil)
if err != nil {
return types.Config{}, report.Report{}, err
}
req.Header.Set("Accept", "application/json")

client := http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
return conn, nil
},
},
}

resp, err := client.Do(req)
if err != nil {
return types.Config{}, report.Report{}, err
}

defer func() {
if err := resp.Body.Close(); err != nil {
f.Logger.Err("unable to close response body: %v", err)
}
}()

b, err := io.ReadAll(resp.Body)
if err != nil {
return types.Config{}, report.Report{}, err
}

return util.ParseConfig(f.Logger, b)
}
1 change: 1 addition & 0 deletions internal/register/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package register

import (
_ "github.com/coreos/ignition/v2/internal/providers/aliyun"
_ "github.com/coreos/ignition/v2/internal/providers/applehv"
_ "github.com/coreos/ignition/v2/internal/providers/aws"
_ "github.com/coreos/ignition/v2/internal/providers/azure"
_ "github.com/coreos/ignition/v2/internal/providers/azurestack"
Expand Down
80 changes: 80 additions & 0 deletions vendor/github.com/mdlayher/socket/CHANGELOG.md

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

9 changes: 9 additions & 0 deletions vendor/github.com/mdlayher/socket/LICENSE.md

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

23 changes: 23 additions & 0 deletions vendor/github.com/mdlayher/socket/README.md

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

23 changes: 23 additions & 0 deletions vendor/github.com/mdlayher/socket/accept.go

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

15 changes: 15 additions & 0 deletions vendor/github.com/mdlayher/socket/accept4.go

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

Loading

0 comments on commit df97d9f

Please sign in to comment.