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
43 changes: 19 additions & 24 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ignored = [

[[constraint]]
name = "github.com/coreos/ignition"
version = "0.26.0"
branch = "master"
#version = "0.26.0"

[[constraint]]
name = "github.com/libvirt/libvirt-go"
Expand Down
81 changes: 71 additions & 10 deletions pkg/asset/ignition/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"os"
"path"
"path/filepath"
"reflect"
"strings"
"text/template"

"github.com/coreos/ignition/config/util"
igntypes "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
"github.com/coreos/ignition/config/validate"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -136,10 +138,25 @@ func (a *Bootstrap) Generate(dependencies asset.Parents) error {
igntypes.PasswdUser{Name: "core", SSHAuthorizedKeys: []igntypes.SSHAuthorizedKey{igntypes.SSHAuthorizedKey(installConfig.Config.SSHKey)}},
)

dup := make(map[string]bool)
for _, f := range a.Config.Storage.Files {
if dup[f.Path] {
fmt.Printf("dup %q\n", f.Path)
continue
}
dup[f.Path] = true
}

rpt := validate.ValidateWithoutSource(reflect.ValueOf(a.Config))
if rpt.IsFatal() {
return errors.Errorf("invalid Ignition config found: %v", rpt)
}

data, err := json.Marshal(a.Config)
if err != nil {
return errors.Wrap(err, "failed to Marshal Ignition config")
}
fmt.Println(string(data))
a.File = &asset.File{
Filename: bootstrapIgnFilename,
Data: data,
Expand Down Expand Up @@ -237,9 +254,34 @@ func (a *Bootstrap) addStorageFiles(base string, uri string, templateData *boots
} else {
mode = 0600
}
ign := ignition.FileFromBytes(strings.TrimSuffix(base, ".template"), "root", mode, data)
ign.Append = appendToFile
a.Config.Storage.Files = append(a.Config.Storage.Files, ign)
var ign igntypes.File
if appendToFile {
var appended bool
for _, f := range a.Config.Storage.Files {
if f.Path == strings.TrimSuffix(base, ".template") {
ign = ignition.FileAppendFromBytes(strings.TrimSuffix(base, ".template"), "root", mode, data)
a.Config.Storage.Files = append(a.Config.Storage.Files, ign)
appended = true
break
}
}
if !appended {
ign = ignition.FileAppendFromBytes(strings.TrimSuffix(base, ".template"), "root", mode, data)
a.Config.Storage.Files = append(a.Config.Storage.Files, ign)
}
} else {
var found bool
for _, f := range a.Config.Storage.Files {
if f.Path == strings.TrimSuffix(base, ".template") {
found = true
break
}
}
if !found {
ign = ignition.FileFromBytes(strings.TrimSuffix(base, ".template"), "root", mode, data)
a.Config.Storage.Files = append(a.Config.Storage.Files, ign)
}
}

return nil
}
Expand Down Expand Up @@ -290,22 +332,23 @@ func (a *Bootstrap) addSystemdUnits(uri string, templateData *bootstrapTemplateD
return err
}

dropins := []igntypes.SystemdDropin{}
dropins := []igntypes.Dropin{}
for _, childInfo := range children {
file, err := data.Assets.Open(path.Join(dir, childInfo.Name()))
if err != nil {
return err
}
defer file.Close()

childName, contents, err := readFile(childInfo.Name(), file, templateData)
childName, cbytes, err := readFile(childInfo.Name(), file, templateData)
if err != nil {
return err
}

dropins = append(dropins, igntypes.SystemdDropin{
contents := string(cbytes)
dropins = append(dropins, igntypes.Dropin{
Name: childName,
Contents: string(contents),
Contents: &contents,
})
}

Expand All @@ -319,14 +362,15 @@ func (a *Bootstrap) addSystemdUnits(uri string, templateData *bootstrapTemplateD
}
a.Config.Systemd.Units = append(a.Config.Systemd.Units, unit)
} else {
name, contents, err := readFile(childInfo.Name(), file, templateData)
name, cbytes, err := readFile(childInfo.Name(), file, templateData)
if err != nil {
return err
}

contents := string(cbytes)
unit := igntypes.Unit{
Name: name,
Contents: string(contents),
Contents: &contents,
}
if _, ok := enabled[name]; ok {
unit.Enabled = util.BoolToPtr(true)
Expand Down Expand Up @@ -364,12 +408,21 @@ func readFile(name string, reader io.Reader, templateData interface{}) (finalNam
func (a *Bootstrap) addParentFiles(dependencies asset.Parents) {
// These files are all added with mode 0644, i.e. readable
// by all processes on the system.
dup := make(map[string]bool)
for _, asset := range []asset.WritableAsset{
&manifests.Manifests{},
&manifests.Openshift{},
&machines.Master{},
} {
dependencies.Get(asset)
files := ignition.FilesFromAsset(rootDir, "root", 0644, asset)
for _, f := range files {
if dup[f.Path] {
fmt.Printf("dup %q \n", f.Path)
continue
}
dup[f.Path] = true
}
a.Config.Storage.Files = append(a.Config.Storage.Files, ignition.FilesFromAsset(rootDir, "root", 0644, asset)...)
}

Expand Down Expand Up @@ -421,6 +474,14 @@ func (a *Bootstrap) addParentFiles(dependencies asset.Parents) {
&tls.JournalCertKey{},
} {
dependencies.Get(asset)
files := ignition.FilesFromAsset(rootDir, "root", 0600, asset)
for _, f := range files {
if dup[f.Path] {
fmt.Printf("dup %q \n", f.Path)
continue
}
dup[f.Path] = true
}
a.Config.Storage.Files = append(a.Config.Storage.Files, ignition.FilesFromAsset(rootDir, "root", 0600, asset)...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/ignition/machine/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"os"

igntypes "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/asset"
Expand Down
19 changes: 10 additions & 9 deletions pkg/asset/ignition/machine/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/url"

ignition "github.com/coreos/ignition/config/v2_2/types"
ignition "github.com/coreos/ignition/config/v3_0/types"
"github.com/vincent-petithory/dataurl"

"github.com/openshift/installer/pkg/types"
Expand All @@ -13,18 +13,19 @@ import (
// pointerIgnitionConfig generates a config which references the remote config
// served by the machine config server.
func pointerIgnitionConfig(installConfig *types.InstallConfig, rootCA []byte, role string) *ignition.Config {
source := func() *url.URL {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need for func.
https://play.golang.org/p/kM-DWZ9yCXN

package main

import (
	"fmt"
	"net/url"
)

func main() {
	u := (&url.URL{
		Scheme: "https",
		Host:   fmt.Sprintf("api.%s:22623", "adahiya-0.tt.testing"),
		Path:   fmt.Sprintf("/config/%s", "master"),
	}).String()
	fmt.Println(u)
}

Copy link
Member

Choose a reason for hiding this comment

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

@staebler, looks like this function approach was yours in #206. Do you remember why you took this route? It seems complicated for a string pointer, vs:

source := fmt.Sprintf("https://api.%s:22623/config/%s", installConfig.ClusterDomain(), role)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that was authored by me. That was authored by @crawford.

return &url.URL{
Scheme: "https",
Host: fmt.Sprintf("api.%s:22623", installConfig.ClusterDomain()),
Path: fmt.Sprintf("/config/%s", role),
}
}().String()
return &ignition.Config{
Ignition: ignition.Ignition{
Version: ignition.MaxVersion.String(),
Config: ignition.IgnitionConfig{
Append: []ignition.ConfigReference{{
Source: func() *url.URL {
return &url.URL{
Scheme: "https",
Host: fmt.Sprintf("api.%s:22623", installConfig.ClusterDomain()),
Path: fmt.Sprintf("/config/%s", role),
}
}().String(),
Merge: []ignition.ConfigReference{{
Source: &source,
}},
},
Security: ignition.Security{
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/ignition/machine/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"os"

igntypes "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/asset"
Expand Down
45 changes: 38 additions & 7 deletions pkg/asset/ignition/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ignition
import (
"path/filepath"

ignition "github.com/coreos/ignition/config/v2_2/types"
ignition "github.com/coreos/ignition/config/v3_0/types"
"github.com/vincent-petithory/dataurl"

"github.com/openshift/installer/pkg/asset"
Expand All @@ -13,8 +13,14 @@ import (
// asset.
func FilesFromAsset(pathPrefix string, username string, mode int, asset asset.WritableAsset) []ignition.File {
var files []ignition.File
dup := make(map[string]bool)
for _, f := range asset.Files() {
files = append(files, FileFromBytes(filepath.Join(pathPrefix, f.Filename), username, mode, f.Data))
path := filepath.Join(pathPrefix, f.Filename)
if dup[path] {
continue
}
files = append(files, FileFromBytes(path, username, mode, f.Data))
dup[path] = true
}
return files
}
Expand All @@ -26,18 +32,43 @@ func FileFromString(path string, username string, mode int, contents string) ign

// FileFromBytes creates an ignition-config file with the given contents.
func FileFromBytes(path string, username string, mode int, contents []byte) ignition.File {
source := dataurl.EncodeBytes(contents)
overwrite := true
return ignition.File{
Node: ignition.Node{
Filesystem: "root",
Path: path,
User: &ignition.NodeUser{
Name: username,
Path: path,
User: ignition.NodeUser{
Name: &username,
},
Overwrite: &overwrite,
},
FileEmbedded1: ignition.FileEmbedded1{
Mode: &mode,
Contents: ignition.FileContents{
Source: dataurl.EncodeBytes(contents),
Source: &source,
},
},
}
}

// FileAppendFromBytes ... TODO(runcom)
func FileAppendFromBytes(path string, username string, mode int, contents []byte) ignition.File {
source := dataurl.EncodeBytes(contents)
overwrite := true
return ignition.File{
Node: ignition.Node{
Path: path,
User: ignition.NodeUser{
Name: &username,
},
Overwrite: &overwrite,
},
FileEmbedded1: ignition.FileEmbedded1{
Mode: &mode,
Append: []ignition.FileContents{
{
Source: &source,
},
},
},
}
Expand Down
Loading