From 48c1e5e8ab83cd637f39086665038e36162b7b8d Mon Sep 17 00:00:00 2001 From: Mohamed Chiheb Ben Jemaa Date: Thu, 17 Oct 2024 15:43:10 +0200 Subject: [PATCH] providers: add support for ionos cloud Add support for IONOS Cloud Add check to ignore cloud-config --- docs/release-notes.md | 1 + docs/supported-platforms.md | 2 + internal/providers/ionoscloud/ionoscloud.go | 60 +++++++++++++++++++++ internal/register/providers.go | 1 + 4 files changed, 64 insertions(+) create mode 100644 internal/providers/ionoscloud/ionoscloud.go diff --git a/docs/release-notes.md b/docs/release-notes.md index 55e79a59f..11b3ea35c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,7 @@ nav_order: 9 - Support partitioning disk with mounted partitions - Support Proxmox VE - Support gzipped Akamai user_data +- Support IONOS Cloud ### Changes diff --git a/docs/supported-platforms.md b/docs/supported-platforms.md index eef319b22..4380c706d 100644 --- a/docs/supported-platforms.md +++ b/docs/supported-platforms.md @@ -20,6 +20,7 @@ Ignition is currently supported for the following platforms: * [Hetzner Cloud] (`hetzner`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately. * [Microsoft Hyper-V] (`hyperv`) - Ignition will read its configuration from the `ignition.config` key in pool 0 of the Hyper-V Data Exchange Service (KVP). Values are limited to approximately 1 KiB of text, so Ignition can also read and concatenate multiple keys named `ignition.config.0`, `ignition.config.1`, and so on. * [IBM Cloud] (`ibmcloud`) - Ignition will read its configuration from the instance userdata. Cloud SSH keys are handled separately. +* [IONOS Cloud] (`ionoscloud`) - 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. * [Nutanix] (`nutanix`) - Ignition will read its configuration from the instance userdata via config drive. Cloud SSH keys are handled separately. @@ -52,6 +53,7 @@ For most cloud providers, cloud SSH keys and custom network configuration are ha [Hetzner Cloud]: https://www.hetzner.com/cloud [Microsoft Hyper-V]: https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/ [IBM Cloud]: https://www.ibm.com/cloud/vpc +[IONOS Cloud]: https://cloud.ionos.com/ [KubeVirt]: https://kubevirt.io [Nutanix]: https://www.nutanix.com/products/ahv [OpenStack]: https://www.openstack.org/ diff --git a/internal/providers/ionoscloud/ionoscloud.go b/internal/providers/ionoscloud/ionoscloud.go new file mode 100644 index 000000000..906bc3d53 --- /dev/null +++ b/internal/providers/ionoscloud/ionoscloud.go @@ -0,0 +1,60 @@ +// 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 IONOSCloud provider fetches configurations from the userdata available in +// the injected file /var/lib/cloud/seed/nocloud/user-data. +// NOTE: This provider is still EXPERIMENTAL. + +package ionoscloud + +import ( + "bytes" + "os" + + "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" +) + +const ( + defaultFilename = "/var/lib/cloud/seed/nocloud/user-data" +) + +func init() { + platform.Register(platform.Provider{ + Name: "ionoscloud", + Fetch: fetchConfig, + }) +} + +func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { + f.Logger.Info("using config file at %q", defaultFilename) + + rawConfig, err := os.ReadFile(defaultFilename) + if err != nil { + f.Logger.Err("couldn't read config %q: %v", defaultFilename, err) + return types.Config{}, report.Report{}, err + } + + header := []byte("#cloud-config\n") + if bytes.HasPrefix(rawConfig, header) { + f.Logger.Debug("config drive (%q) contains a cloud-config configuration, ignoring", defaultFilename) + return types.Config{}, report.Report{}, err + } + + return util.ParseConfig(f.Logger, rawConfig) +} diff --git a/internal/register/providers.go b/internal/register/providers.go index bda4b7cfe..63249c7df 100644 --- a/internal/register/providers.go +++ b/internal/register/providers.go @@ -29,6 +29,7 @@ import ( _ "github.com/coreos/ignition/v2/internal/providers/hetzner" _ "github.com/coreos/ignition/v2/internal/providers/hyperv" _ "github.com/coreos/ignition/v2/internal/providers/ibmcloud" + _ "github.com/coreos/ignition/v2/internal/providers/ionoscloud" _ "github.com/coreos/ignition/v2/internal/providers/kubevirt" _ "github.com/coreos/ignition/v2/internal/providers/metal" _ "github.com/coreos/ignition/v2/internal/providers/nutanix"