Skip to content
Closed
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 install/image-references
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ spec:
- name: machine-os-content
from:
kind: DockerImage
name: registry.svc.ci.openshift.org/rhcos/maipo@sha256:83a6d461628380f1dcc057ffef4909992f593b72c5aa4db2e01c0b130004afea
name: registry.svc.ci.openshift.org/rhcos/maipo@sha256:61dc83d62cfb5054c4c5532bd2478742a0711075ef5151572e63f94babeacc1a
19 changes: 14 additions & 5 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ func GenerateMachineConfigsForRole(config *RenderConfig, role string, path strin
if err != nil {
return nil, fmt.Errorf("failed to read dir %q: %v", path, err)
}

// for each role a machine config is created containing the sshauthorized keys to allow for ssh access
// ex: role = worker -> machine config "00-worker-ssh" created containing user core and ssh key
var tempIgnConfig ignv2_2types.Config
tempIgnConfig := &ignv2_2types.Config{}
tempUser := ignv2_2types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ignv2_2types.SSHAuthorizedKey{ignv2_2types.SSHAuthorizedKey(config.SSHKey)}}
tempIgnConfig.Passwd.Users = append(tempIgnConfig.Passwd.Users, tempUser)

sshConfigName := "00-" + role + "-ssh"
sshMachineConfigForRole := MachineConfigFromIgnConfig(role, sshConfigName, &tempIgnConfig)
sshMachineConfigForRole := generateMachineConfigForName(config, tempIgnConfig, role, sshConfigName)

cfgs := []*mcfgv1.MachineConfig{}
cfgs = append(cfgs, sshMachineConfigForRole)
Expand All @@ -113,10 +115,11 @@ func GenerateMachineConfigsForRole(config *RenderConfig, role string, path strin
}
name := info.Name()
namePath := filepath.Join(path, name)
nameConfig, err := generateMachineConfigForName(config, role, name, namePath)
ignCfg, err := generateIgnConfigForName(config, namePath)
if err != nil {
return nil, err
}
nameConfig := generateMachineConfigForName(config, ignCfg, role, name)
cfgs = append(cfgs, nameConfig)
}

Expand Down Expand Up @@ -170,7 +173,7 @@ func filterTemplates(toFilter map[string]string, path string, config *RenderConf
return filepath.Walk(path, walkFn)
}

func generateMachineConfigForName(config *RenderConfig, role, name, path string) (*mcfgv1.MachineConfig, error) {
func generateIgnConfigForName(config *RenderConfig, path string) (*ignv2_2types.Config, error) {
platform, err := platformFromControllerConfigSpec(config.ControllerConfigSpec)
if err != nil {
return nil, err
Expand Down Expand Up @@ -238,8 +241,14 @@ func generateMachineConfigForName(config *RenderConfig, role, name, path string)
if err != nil {
return nil, fmt.Errorf("error transpiling ct config to Ignition config: %v", err)
}
return ignCfg, nil
}

return MachineConfigFromIgnConfig(role, name, ignCfg), nil
func generateMachineConfigForName(config *RenderConfig, ignCfg *ignv2_2types.Config, role, name string) *mcfgv1.MachineConfig {
mcfg := MachineConfigFromIgnConfig(role, name, ignCfg)
// And inject the osimageurl here
mcfg.Spec.OSImageURL = config.OSImageURL
return mcfg
}

const (
Expand Down
46 changes: 46 additions & 0 deletions test/e2e/osimageurl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package e2e_test

import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/openshift/machine-config-operator/cmd/common"
)

func TestOSImageURL(t *testing.T) {
cb, err := common.NewClientBuilder("")
if err != nil {
t.Fatalf("%#v", err)
}
mcClient := cb.MachineConfigClientOrDie("mc-file-add")

// grab the latest worker- MC
mcp, err := mcClient.MachineconfigurationV1().MachineConfigPools().Get("worker", metav1.GetOptions{})
if err != nil {
t.Fatalf("%#v", err)
}

mc, err := mcClient.MachineconfigurationV1().MachineConfigs().Get(mcp.Status.Configuration.Name, metav1.GetOptions{})
if err != nil {
t.Fatalf("%#v", err)
}

if mc.Spec.OSImageURL == "" {
t.Fatalf("Empty OSImageURL for %s", mc.Name)
}

// grab the latest master- MC
mcp, err = mcClient.MachineconfigurationV1().MachineConfigPools().Get("master", metav1.GetOptions{})
if err != nil {
t.Fatalf("%#v", err)
}
mc, err = mcClient.MachineconfigurationV1().MachineConfigs().Get(mcp.Status.Configuration.Name, metav1.GetOptions{})
if err != nil {
t.Fatalf("%#v", err)
}

if mc.Spec.OSImageURL == "" {
t.Fatalf("Empty OSImageURL for %s", mc.Name)
}
}