Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/server/bootstrap_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (bsc *bootstrapServer) GetConfig(cr poolRequest) (*igntypes.Config, error)

appenders := getAppenders(currConf, bsc.kubeconfigFunc, mc.Spec.OSImageURL)
for _, a := range appenders {
if err := a(&mc.Spec.Config); err != nil {
if err := a(mc); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/cluster_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (cs *clusterServer) GetConfig(cr poolRequest) (*igntypes.Config, error) {

appenders := getAppenders(currConf, cs.kubeconfigFunc, mc.Spec.OSImageURL)
for _, a := range appenders {
if err := a(&mc.Spec.Config); err != nil {
if err := a(mc); err != nil {
return nil, err
}
}
Expand Down
33 changes: 29 additions & 4 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const (
// of the KubeConfig file on the machine.
defaultMachineKubeConfPath = "/etc/kubernetes/kubeconfig"

// machineConfigContentPath contains the raw machine-config content
// served by the MCS. This is extremely useful when debugging drifts
// between the installer and the MCO itself.
// This is different than /etc/machine-config-daemon/currentconfig written
// by the MCD but it's gonna be the same 99% of the time. The reason we
// need this is that on bootstrap + first install we don't have the MCD
// running and writing that file.
machineConfigContentPath = "/etc/mcs-machine-config-content.json"

// defaultFileSystem defines the default file system to be
// used for writing the ignition files created by the
// server.
Expand All @@ -27,7 +36,7 @@ const (
type kubeconfigFunc func() (kubeconfigData []byte, rootCAData []byte, err error)

// appenderFunc appends Config.
type appenderFunc func(*igntypes.Config) error
type appenderFunc func(*mcfgv1.MachineConfig) error

// Server defines the interface that is implemented by different
// machine config server implementations.
Expand All @@ -38,11 +47,14 @@ type Server interface {
func getAppenders(currMachineConfig string, f kubeconfigFunc, osimageurl string) []appenderFunc {
appenders := []appenderFunc{
// append machine annotations file.
func(config *igntypes.Config) error { return appendNodeAnnotations(config, currMachineConfig) },
func(mc *mcfgv1.MachineConfig) error { return appendNodeAnnotations(&mc.Spec.Config, currMachineConfig) },
// append pivot
func(config *igntypes.Config) error { return appendInitialPivot(config, osimageurl) },
func(mc *mcfgv1.MachineConfig) error { return appendInitialPivot(&mc.Spec.Config, osimageurl) },
// append kubeconfig.
func(config *igntypes.Config) error { return appendKubeConfig(config, f) },
func(mc *mcfgv1.MachineConfig) error { return appendKubeConfig(&mc.Spec.Config, f) },
// append the machineconfig content
//nolint:gocritic
func(mc *mcfgv1.MachineConfig) error { return appendInitialMachineConfig(mc) },
}
return appenders
}
Expand Down Expand Up @@ -92,6 +104,19 @@ WantedBy=multi-user.target
return nil
}

// appendInitialMachineConfig saves the full serialized MachineConfig that was served
// by the MCS when the node first booted. This currently is only used as a debugging aid
// in cases where there is unexpected "drift" between the initial bootstrap MC/Ignition and the one
// computed by the cluster.
func appendInitialMachineConfig(mc *mcfgv1.MachineConfig) error {
mcJSON, err := json.MarshalIndent(mc, "", " ")
if err != nil {
return err
}
appendFileToIgnition(&mc.Spec.Config, machineConfigContentPath, string(mcJSON))
return nil
}

func appendKubeConfig(conf *igntypes.Config, f kubeconfigFunc) error {
kcData, _, err := f()
if err != nil {
Expand Down