Blame 0001-support-coreos.config.-and-ignition.config.patch

cdb9cf
From 41faa514b2598386c3a0c8a90ebd207e282cd1d5 Mon Sep 17 00:00:00 2001
cdb9cf
From: Michael Nguyen <mnguyen@redhat.com>
cdb9cf
Date: Fri, 1 Mar 2019 12:10:47 -0500
cdb9cf
Subject: [PATCH] support coreos.config.* and ignition.config.*
cdb9cf
cdb9cf
This is backwards compatibility work for spec2x following the changes
cdb9cf
made in #663 to make options more distribution neutral.
cdb9cf
cdb9cf
ref: https://github.com/coreos/ignition/pull/663
cdb9cf
---
cdb9cf
 internal/providers/cmdline/cmdline.go     | 13 ++++++-------
cdb9cf
 internal/providers/vmware/vmware_amd64.go | 20 ++++++++++++++++----
cdb9cf
 2 files changed, 22 insertions(+), 11 deletions(-)
cdb9cf
cdb9cf
diff --git a/internal/providers/cmdline/cmdline.go b/internal/providers/cmdline/cmdline.go
cdb9cf
index 0bdba2d..1a393fb 100644
cdb9cf
--- a/internal/providers/cmdline/cmdline.go
cdb9cf
+++ b/internal/providers/cmdline/cmdline.go
cdb9cf
@@ -32,7 +32,8 @@ import (
cdb9cf
 )
cdb9cf
 
cdb9cf
 const (
cdb9cf
-	cmdlineUrlFlag = "coreos.config.url"
cdb9cf
+	cmdlineUrlFlagLegacy = "coreos.config.url"
cdb9cf
+	cmdlineUrlFlag       = "ignition.config.url"
cdb9cf
 )
cdb9cf
 
cdb9cf
 func FetchConfig(f resource.Fetcher) (types.Config, report.Report, error) {
cdb9cf
@@ -83,12 +84,10 @@ func parseCmdline(cmdline []byte) (url string) {
cdb9cf
 		parts := strings.SplitN(strings.TrimSpace(arg), "=", 2)
cdb9cf
 		key := parts[0]
cdb9cf
 
cdb9cf
-		if key != cmdlineUrlFlag {
cdb9cf
-			continue
cdb9cf
-		}
cdb9cf
-
cdb9cf
-		if len(parts) == 2 {
cdb9cf
-			url = parts[1]
cdb9cf
+		if key == cmdlineUrlFlagLegacy || key == cmdlineUrlFlag {
cdb9cf
+			if len(parts) == 2 {
cdb9cf
+				url = parts[1]
cdb9cf
+			}
cdb9cf
 		}
cdb9cf
 	}
cdb9cf
 
cdb9cf
diff --git a/internal/providers/vmware/vmware_amd64.go b/internal/providers/vmware/vmware_amd64.go
cdb9cf
index e26baf0..9c0ffc7 100644
cdb9cf
--- a/internal/providers/vmware/vmware_amd64.go
cdb9cf
+++ b/internal/providers/vmware/vmware_amd64.go
cdb9cf
@@ -54,6 +54,8 @@ func fetchRawConfig(f resource.Fetcher) (config, error) {
cdb9cf
 
cdb9cf
 	var ovfData string
cdb9cf
 	var ovfEncoding string
cdb9cf
+	var ovfDataKey string
cdb9cf
+	var ovfEncodingKey string
cdb9cf
 
cdb9cf
 	ovfEnv, err := info.String("ovfenv", "")
cdb9cf
 	if err != nil {
cdb9cf
@@ -65,17 +67,27 @@ func fetchRawConfig(f resource.Fetcher) (config, error) {
cdb9cf
 			f.Logger.Warning("failed to parse OVF environment: %v. Continuing...", err)
cdb9cf
 		}
cdb9cf
 
cdb9cf
-		ovfData = env.Properties["guestinfo.coreos.config.data"]
cdb9cf
-		ovfEncoding = env.Properties["guestinfo.coreos.config.data.encoding"]
cdb9cf
+		if _, ok := env.Properties["guestinfo.coreos.config.data"]; ok {
cdb9cf
+			ovfDataKey = "guestinfo.coreos.config.data"
cdb9cf
+			ovfEncodingKey = "guestinfo.coreos.config.data.encoding"
cdb9cf
+		} else if _, ok := env.Properties["guestinfo.ignition.config.data"]; ok {
cdb9cf
+			ovfDataKey = "guestinfo.ignition.config.data"
cdb9cf
+			ovfEncodingKey = "guestinfo.ignition.config.data.encoding"
cdb9cf
+		} else {
cdb9cf
+			f.Logger.Debug("failed to find guestinfo ignition properties")
cdb9cf
+		}
cdb9cf
+
cdb9cf
+		ovfData = env.Properties[ovfDataKey]
cdb9cf
+		ovfEncoding = env.Properties[ovfEncodingKey]
cdb9cf
 	}
cdb9cf
 
cdb9cf
-	data, err := info.String("coreos.config.data", ovfData)
cdb9cf
+	data, err := info.String(ovfDataKey[len("guestinfo."):], ovfData)
cdb9cf
 	if err != nil {
cdb9cf
 		f.Logger.Debug("failed to fetch config: %v", err)
cdb9cf
 		return config{}, err
cdb9cf
 	}
cdb9cf
 
cdb9cf
-	encoding, err := info.String("coreos.config.data.encoding", ovfEncoding)
cdb9cf
+	encoding, err := info.String(ovfEncodingKey[len("guestinfo."):], ovfEncoding)
cdb9cf
 	if err != nil {
cdb9cf
 		f.Logger.Debug("failed to fetch config encoding: %v", err)
cdb9cf
 		return config{}, err
cdb9cf
-- 
cdb9cf
2.19.1
cdb9cf