diff --git a/dracut/30ignition/ignition-setup-base.service b/dracut/30ignition/ignition-setup-base.service deleted file mode 100644 index aec6207bb8..0000000000 --- a/dracut/30ignition/ignition-setup-base.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Ignition (setup base config) -Documentation=https://github.com/coreos/ignition -ConditionPathExists=/etc/initrd-release -DefaultDependencies=false -Before=ignition-complete.target - -OnFailure=emergency.target -OnFailureJobMode=isolate - -# Stage order: setup -> fetch-offline [-> fetch] -> disks -> mount -> files. -Before=ignition-fetch-offline.service - -[Service] -Type=oneshot -RemainAfterExit=yes -EnvironmentFile=/run/ignition.env -ExecStart=/usr/sbin/ignition-setup-base diff --git a/dracut/30ignition/ignition-setup-base.sh b/dracut/30ignition/ignition-setup-base.sh deleted file mode 100755 index bc7c189504..0000000000 --- a/dracut/30ignition/ignition-setup-base.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -euo pipefail - -copy_file_if_exists() { - src="${1}"; dst="${2}" - if [ -f "${src}" ]; then - echo "Copying ${src} to ${dst}" - cp "${src}" "${dst}" - else - echo "File ${src} does not exist.. Skipping copy" - fi -} - -destination=/usr/lib/ignition -mkdir -p $destination - -# We will support grabbing a platform specific base.ign config -# from the initrd at /usr/lib/ignition/platform/${PLATFORM_ID}/base.ign -copy_file_if_exists "/usr/lib/ignition/platform/${PLATFORM_ID}/base.ign" "${destination}/base.ign" diff --git a/dracut/30ignition/module-setup.sh b/dracut/30ignition/module-setup.sh index d8c9d514bf..73c23054fe 100755 --- a/dracut/30ignition/module-setup.sh +++ b/dracut/30ignition/module-setup.sh @@ -56,8 +56,6 @@ install() { # Required on system using SELinux inst_multiple -o setfiles - inst_script "$moddir/ignition-setup-base.sh" \ - "/usr/sbin/ignition-setup-base" inst_script "$moddir/ignition-setup-user.sh" \ "/usr/sbin/ignition-setup-user" @@ -82,7 +80,6 @@ install() { "$systemdsystemunitdir/ignition-$x.target" done - install_ignition_unit ignition-setup-base.service install_ignition_unit ignition-setup-user.service install_ignition_unit ignition-fetch.service install_ignition_unit ignition-fetch-offline.service diff --git a/internal/providers/system/system.go b/internal/providers/system/system.go index ec9f831ec4..6c5605e821 100644 --- a/internal/providers/system/system.go +++ b/internal/providers/system/system.go @@ -15,10 +15,13 @@ package system import ( + "fmt" "io/ioutil" "os" "path/filepath" + "strings" + latest "github.com/coreos/ignition/v2/config/v3_3_experimental" "github.com/coreos/ignition/v2/config/v3_3_experimental/types" "github.com/coreos/ignition/v2/internal/distro" "github.com/coreos/ignition/v2/internal/log" @@ -35,7 +38,35 @@ const ( ) func FetchBaseConfig(logger *log.Logger) (types.Config, report.Report, error) { - return fetchConfig(logger, baseFilename) + var fullBaseConfig types.Config + baseConfig, _, err := fetchConfig(logger, baseFilename) + if err != nil { + logger.Err("couldn't fetch base config: %v", err) + return types.Config{}, report.Report{}, err + } + fullBaseConfig = latest.Merge(fullBaseConfig, baseConfig) + + // For merging base.d config fragments + baseDConfig, _, err := fetchBaseConfig(logger, "base.d", fullBaseConfig) + if err != nil { + return types.Config{}, report.Report{}, err + } + + contents, _ := ioutil.ReadDir(distro.SystemConfigDir()) + for _, content := range contents { + if content.IsDir() { + // To check if a `base.$PLATFORM_ID.d` directory exists and + // accordingly proceed with the config merging operation. + if strings.Contains(content.Name(), "base") && len(strings.Split(content.Name(), ".")) == 3 && content.Size() > 0 { + basePlatformDConfig, _, err := fetchBaseConfig(logger, content.Name(), fullBaseConfig) + if err != nil { + return types.Config{}, report.Report{}, err + } + baseDConfig = latest.Merge(baseDConfig, basePlatformDConfig) + } + } + } + return baseDConfig, report.Report{}, nil } func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { @@ -56,3 +87,29 @@ func fetchConfig(logger *log.Logger, filename string) (types.Config, report.Repo } return util.ParseConfig(logger, rawConfig) } + +// fetchBaseConfig is a helper function to merge all the base config fragments inside of a particular directory. +func fetchBaseConfig(logger *log.Logger, dir string, fullBaseConfig types.Config) (types.Config, report.Report, error) { + path := filepath.Join(distro.SystemConfigDir(), dir) + configs, err := ioutil.ReadDir(path) + if os.IsNotExist(err) { + logger.Info("no config dir at %q", path) + return types.Config{}, report.Report{}, err + } else if err != nil { + logger.Err("couldn't read config dir %q: %v", path, err) + return types.Config{}, report.Report{}, err + } + if len(configs) == 0 { + logger.Info("no configs at %q", path) + return types.Config{}, report.Report{}, nil + } + for _, config := range configs { + file := fmt.Sprintf("%s/%s", path, config.Name()) + baseConfig, _, err := fetchConfig(logger, file) + if err != nil { + return types.Config{}, report.Report{}, err + } + fullBaseConfig = latest.Merge(fullBaseConfig, baseConfig) + } + return fullBaseConfig, report.Report{}, nil +}