Skip to content

Commit

Permalink
providers: support for proxmox ve
Browse files Browse the repository at this point in the history
Co-authored-by: bri <[email protected]>
  • Loading branch information
arcln and b- committed Jul 29, 2024
1 parent a96fbce commit c91991c
Show file tree
Hide file tree
Showing 4 changed files with 146 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 @@ -11,6 +11,7 @@ nav_order: 9
### Features

- Support partitioning disk with mounted partitions
- Support Proxmox VE

### Changes

Expand Down
2 changes: 2 additions & 0 deletions docs/supported-platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Ignition is currently supported for the following platforms:
* 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.
* [Nutanix] (`nutanix`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately.
* [OpenStack] (`openstack`) - Ignition will read its configuration from the instance userdata via either metadata service or config drive. Cloud SSH keys are handled separately.
* [Proxmox VE] (`proxmoxve`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately.
* [Equinix Metal] (`packet`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
* [IBM Power Systems Virtual Server] (`powervs`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately.
* [QEMU] (`qemu`) - Ignition will read its configuration from the 'opt/com.coreos/config' key on the QEMU Firmware Configuration Device (available in QEMU 2.4.0 and higher).
Expand Down Expand Up @@ -54,6 +55,7 @@ For most cloud providers, cloud SSH keys and custom network configuration are ha
[KubeVirt]: https://kubevirt.io
[Nutanix]: https://www.nutanix.com/products/ahv
[OpenStack]: https://www.openstack.org/
[Proxmox VE]: https://www.proxmox.com/en/proxmox-virtual-environment/overview
[Equinix Metal]: https://metal.equinix.com/product/
[IBM Power Systems Virtual Server]: https://www.ibm.com/products/power-virtual-server
[QEMU]: https://www.qemu.org/
Expand Down
142 changes: 142 additions & 0 deletions internal/providers/proxmoxve/proxmoxve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright 2019 Red Hat, Inc.
//
// 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.

// The OpenStack provider fetches configurations from the userdata available in
// both the config-drive as well as the network metadata service. Whichever
// responds first is the config that is used.
// NOTE: This provider is still EXPERIMENTAL.

package proxmoxve

import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"time"

"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
"github.com/coreos/ignition/v2/internal/distro"
"github.com/coreos/ignition/v2/internal/log"
"github.com/coreos/ignition/v2/internal/platform"
"github.com/coreos/ignition/v2/internal/providers/util"
"github.com/coreos/ignition/v2/internal/resource"
ut "github.com/coreos/ignition/v2/internal/util"

"github.com/coreos/vcontext/report"
)

const (
cidataPath = "/user-data"
deviceLabel = "cidata"
)

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

func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
var data []byte
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)

dispatch := func(name string, fn func() ([]byte, error)) {
raw, err := fn()
if err != nil {
switch err {
case context.Canceled:
case context.DeadlineExceeded:
f.Logger.Err("timed out while fetching config from %s", name)
default:
f.Logger.Err("failed to fetch config from %s: %v", name, err)
}
return
}

data = raw
cancel()
}

go dispatch(
"config drive (cidata)", func() ([]byte, error) {
return fetchConfigFromDevice(f.Logger, ctx, filepath.Join(distro.DiskByLabelDir(), deviceLabel))
},
)

<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded {
f.Logger.Info("cidata drive was not available in time. Continuing without a config...")
}

return util.ParseConfig(f.Logger, data)
}

func fileExists(path string) bool {
_, err := os.Stat(path)
return (err == nil)
}

func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, path string) ([]byte, error) {
for !fileExists(path) {
logger.Debug("config drive (%q) not found. Waiting...", path)
select {
case <-time.After(time.Second):
case <-ctx.Done():
return nil, ctx.Err()
}
}

logger.Debug("creating temporary mount point")
mnt, err := os.MkdirTemp("", "ignition-configdrive")
if err != nil {
return nil, fmt.Errorf("failed to create temp directory: %v", err)
}
defer os.Remove(mnt)

cmd := exec.Command(distro.MountCmd(), "-o", "ro", "-t", "auto", path, mnt)
if _, err := logger.LogCmd(cmd, "mounting config drive"); err != nil {
return nil, err
}
defer func() {
_ = logger.LogOp(
func() error {
return ut.UmountPath(mnt)
},
"unmounting %q at %q", path, mnt,
)
}()

if !fileExists(filepath.Join(mnt, cidataPath)) {
return nil, nil
}

contents, err := os.ReadFile(filepath.Join(mnt, cidataPath))
if err != nil {
return nil, err
}

header := []byte("#cloud-config\n")
if bytes.HasPrefix(contents, header) {
logger.Debug("config drive (%q) contains a cloud-config configuration, ignoring", path)
return nil, nil
}

return contents, nil
}
1 change: 1 addition & 0 deletions internal/register/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
_ "github.com/coreos/ignition/v2/internal/providers/openstack"
_ "github.com/coreos/ignition/v2/internal/providers/packet"
_ "github.com/coreos/ignition/v2/internal/providers/powervs"
_ "github.com/coreos/ignition/v2/internal/providers/proxmoxve"
_ "github.com/coreos/ignition/v2/internal/providers/qemu"
_ "github.com/coreos/ignition/v2/internal/providers/scaleway"
_ "github.com/coreos/ignition/v2/internal/providers/virtualbox"
Expand Down

0 comments on commit c91991c

Please sign in to comment.