daemon: More methods for getting MCs
@@ -3,6 +3,7 @@ package daemon
import (
"fmt"
"io/ioutil"
+ "net/http"
"os"
"path/filepath"
"strings"
@@ -11,6 +12,7 @@ import (
ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
"github.com/golang/glog"
drain "github.com/openshift/kubernetes-drain"
+ "github.com/openshift/machine-config-operator/lib/resourceread"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
mcfgclientv1 "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1"
@@ -420,6 +422,38 @@ func (dn *Daemon) Close() {
dn.loginClient.Close()
}
+// getMachineConfigFromFile parses a valid machine config file in yaml format and returns
+// a MachineConfig struct.
+func (dn *Daemon) getMachineConfigFromFile(filePath string) (*mcfgv1.MachineConfig, error) {
+ data, err := dn.fileSystemClient.ReadFile(filePath)
+ if err != nil {
+ return nil, err
+ }
+ config := resourceread.ReadMachineConfigV1OrDie(data)
+ return config, nil
+}
+
+// getMachineConfigFromURL reads a remote MC in yaml format and returns a MachineConfig struct.
+func (dn *Daemon) getMachineConfigFromURL(url string) (*mcfgv1.MachineConfig, error) {
+ // Make a request to the remote URL
+ resp, err := http.Get(url)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ // Read the body content from the request
+ body, err := dn.fileSystemClient.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ // Unmarshal the body into the machineConfig
+ config := resourceread.ReadMachineConfigV1OrDie(body)
+
+ return config, nil
+}
+
func getMachineConfig(client mcfgclientv1.MachineConfigInterface, name string) (*mcfgv1.MachineConfig, error) {
return client.Get(name, metav1.GetOptions{})
}
