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: 2 additions & 0 deletions cmd/static-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func loadStaticNMState(fsys fs.FS, env *env.EnvInputs, nmstateDir string, imageS
if err != nil {
return errors.WithMessagef(err, "problem reading %s", path.Join(nmstateDir, f.Name()))
}
hostname := strings.TrimSuffix(f.Name(), path.Ext(f.Name()))
igBuilder, err := ignition.New(b, registries,
env.IronicBaseURL,
env.IronicAgentImage,
Expand All @@ -78,6 +79,7 @@ func loadStaticNMState(fsys fs.FS, env *env.EnvInputs, nmstateDir string, imageS
env.HttpProxy,
env.HttpsProxy,
env.NoProxy,
hostname,
)
if err != nil {
return errors.WithMessage(err, "failed to configure ignition")
Expand Down
12 changes: 10 additions & 2 deletions pkg/ignition/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ignition
import (
"encoding/json"
"errors"
"fmt"
"os/exec"
"strings"

Expand Down Expand Up @@ -30,9 +31,10 @@ type ignitionBuilder struct {
httpProxy string
httpsProxy string
noProxy string
hostname string
}

func New(nmStateData, registriesConf []byte, ironicBaseURL, ironicAgentImage, ironicAgentPullSecret, ironicRAMDiskSSHKey, ipOptions, httpProxy, httpsProxy, noProxy string) (*ignitionBuilder, error) {
func New(nmStateData, registriesConf []byte, ironicBaseURL, ironicAgentImage, ironicAgentPullSecret, ironicRAMDiskSSHKey, ipOptions string, httpProxy, httpsProxy, noProxy string, hostname string) (*ignitionBuilder, error) {
if ironicBaseURL == "" {
return nil, errors.New("ironicBaseURL is required")
}
Expand All @@ -51,6 +53,7 @@ func New(nmStateData, registriesConf []byte, ironicBaseURL, ironicAgentImage, ir
httpProxy: httpProxy,
httpsProxy: httpsProxy,
noProxy: noProxy,
hostname: hostname,
}, nil
}

Expand Down Expand Up @@ -99,10 +102,15 @@ func (b *ignitionBuilder) Generate() ([]byte, error) {
"/etc/NetworkManager/conf.d/clientid.conf",
0644, false,
[]byte("[connection]\nipv6.dhcp-duid=ll\nipv6.dhcp-iaid=mac")))

update_hostname := fmt.Sprintf(`
[[ "$DHCP6_FQDN_FQDN" =~ "." ]] && hostnamectl set-hostname --static --transient $DHCP6_FQDN_FQDN
[[ "$(< /proc/sys/kernel/hostname)" =~ (localhost|localhost.localdomain) ]] && hostnamectl set-hostname --transient %s`, b.hostname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's enough to do =~ localhost

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but they both incorrectly match all kinds of rubbish (like test.definitely-not-a-localhost-domain.example.com (the correct regex is (^|\\.)localhost(\\.localdomain)?\\.?$), so there's no point doing it wrong and differently to https://github.com/openshift/machine-config-operator/blob/47436bdb7b8c49425d6813abca594485171e1221/templates/common/_base/files/usr-local-bin-mco-hostname.yaml#L17.


config.Storage.Files = append(config.Storage.Files, ignitionFileEmbed(
"/etc/NetworkManager/dispatcher.d/01-hostname",
0744, false,
[]byte("[[ \"$DHCP6_FQDN_FQDN\" =~ \".\" ]] && hostnamectl set-hostname --static --transient $DHCP6_FQDN_FQDN")))
[]byte(update_hostname)))

if len(b.registriesConf) > 0 {
registriesFile := ignitionFileEmbed("/etc/containers/registries.conf",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ignition/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGenerateRegistries(t *testing.T) {
builder, err := New([]byte{}, []byte(registries),
"http://ironic.example.com",
"quay.io/openshift-release-dev/ironic-ipa-image",
"", "", "", "", "", "")
"", "", "", "", "", "", "virthost")
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/imageprovider/rhcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (ip *rhcosImageProvider) SupportsFormat(format metal3.ImageFormat) bool {
}
}

func (ip *rhcosImageProvider) buildIgnitionConfig(networkData imageprovider.NetworkData) ([]byte, error) {
func (ip *rhcosImageProvider) buildIgnitionConfig(networkData imageprovider.NetworkData, hostname string) ([]byte, error) {
nmstateData := networkData["nmstate"]

builder, err := ignition.New(nmstateData, ip.RegistriesConf,
Expand All @@ -57,6 +57,7 @@ func (ip *rhcosImageProvider) buildIgnitionConfig(networkData imageprovider.Netw
ip.EnvInputs.HttpProxy,
ip.EnvInputs.HttpsProxy,
ip.EnvInputs.NoProxy,
hostname,
)
if err != nil {
return nil, imageprovider.BuildInvalidError(err)
Expand Down Expand Up @@ -84,7 +85,7 @@ func imageKey(data imageprovider.ImageData) string {
}

func (ip *rhcosImageProvider) BuildImage(data imageprovider.ImageData, networkData imageprovider.NetworkData, log logr.Logger) (string, error) {
ignitionConfig, err := ip.buildIgnitionConfig(networkData)
ignitionConfig, err := ip.buildIgnitionConfig(networkData, data.ImageMetadata.Name)
if err != nil {
return "", err
}
Expand Down