Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HookOS embedded images in Tinkerbell Templates: #8708

Merged
merged 2 commits into from
Sep 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@
controlPlaneMachineConfigName := cs.Cluster.Spec.ControlPlaneConfiguration.MachineGroupRef.Name
controlPlaneMachineConfig := cs.TinkerbellMachineConfigs[controlPlaneMachineConfigName]
osFamily := controlPlaneMachineConfig.OSFamily()

// For modular upgrades the version bundle is retrieve per worker node group. However,
// because Tinkerbell action images are the same for every Kubernetes version within
// the same bundle manifest, its OK to just use the root version bundle.
bundle := *cs.RootVersionsBundle().VersionsBundle

osImageURL := cs.TinkerbellDatacenter.Spec.OSImageURL
tinkerbellIP := cs.TinkerbellDatacenter.Spec.TinkerbellIP

cfg := v1alpha1.NewDefaultTinkerbellTemplateConfigCreate(cs.Cluster, bundle, osImageURL,
cfg := v1alpha1.NewDefaultTinkerbellTemplateConfigCreate(cs.Cluster, osImageURL,

Check warning on line 100 in cmd/eksctl-anywhere/cmd/generate_tinkerbell_template_config.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/generate_tinkerbell_template_config.go#L100

Added line #L100 was not covered by tests
opts.BootstrapTinkerbellIP, tinkerbellIP, osFamily)

return yaml.NewK8sEncoder(os.Stdout).Encode(cfg)
Expand Down
14 changes: 0 additions & 14 deletions internal/pkg/api/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,6 @@ func WithOsFamilyForAllTinkerbellMachines(value anywherev1.OSFamily) TinkerbellF
}
}

func WithImageUrlForAllTinkerbellMachines(value string) TinkerbellFiller {
return func(config TinkerbellConfig) {
for _, t := range config.templateConfigs {
for _, task := range t.Spec.Template.Tasks {
for _, action := range task.Actions {
if action.Name == "stream-image" {
action.Environment["IMG_URL"] = value
}
}
}
}
}
}

func WithSSHAuthorizedKeyForAllTinkerbellMachines(key string) TinkerbellFiller {
return func(config TinkerbellConfig) {
for _, m := range config.machineConfigs {
Expand Down
8 changes: 3 additions & 5 deletions pkg/api/v1alpha1/tinkerbelltemplateconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const TinkerbellTemplateConfigKind = "TinkerbellTemplateConfig"

// +kubebuilder:object:generate=false
type ActionOpt func(action *[]tinkerbell.Action)

// NewDefaultTinkerbellTemplateConfigCreate returns a default TinkerbellTemplateConfig with the
// required Tasks and Actions.
func NewDefaultTinkerbellTemplateConfigCreate(clusterSpec *Cluster, versionBundle v1alpha1.VersionsBundle, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) *TinkerbellTemplateConfig {
// NewDefaultTinkerbellTemplateConfigCreate returns a default TinkerbellTemplateConfig with the required Tasks and Actions.
func NewDefaultTinkerbellTemplateConfigCreate(clusterSpec *Cluster, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) *TinkerbellTemplateConfig {

Check warning on line 15 in pkg/api/v1alpha1/tinkerbelltemplateconfig.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/tinkerbelltemplateconfig.go#L15

Added line #L15 was not covered by tests
config := &TinkerbellTemplateConfig{
TypeMeta: metav1.TypeMeta{
Kind: TinkerbellTemplateConfigKind,
Expand All @@ -41,7 +39,7 @@
},
}

defaultActions := GetDefaultActionsFromBundle(clusterSpec, versionBundle, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP, osFamily)
defaultActions := DefaultActions(clusterSpec, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP, osFamily)

Check warning on line 42 in pkg/api/v1alpha1/tinkerbelltemplateconfig.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/tinkerbelltemplateconfig.go#L42

Added line #L42 was not covered by tests
for _, action := range defaultActions {
action(&config.Spec.Template.Tasks[0].Actions)
}
Expand Down
90 changes: 47 additions & 43 deletions pkg/api/v1alpha1/tinkerbelltemplateconfig_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const (
Expand All @@ -19,11 +18,16 @@ manage_etc_hosts: localhost
warnings:
dsid_missing_source: off
`

// HookOS embeds container images from the bundle.
// The container images are tagged as below.
actionImage2Disk = "127.0.0.1/embedded/image2disk"
actionWriteFile = "127.0.0.1/embedded/writefile"
actionReboot = "127.0.0.1/embedded/reboot"
)

// GetDefaultActionsFromBundle constructs a set of default actions for the given osFamily using the
// bundle as the source of action images.
func GetDefaultActionsFromBundle(clusterSpec *Cluster, b v1alpha1.VersionsBundle, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) []ActionOpt {
// DefaultActions constructs a set of default actions for the given osFamily.
func DefaultActions(clusterSpec *Cluster, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) []ActionOpt {
// The metadata string will have two URLs:
// 1. one that will be used initially for bootstrap and will point to hegel running on kind.
// 2. one that will be used when the workload cluster is up and will point to hegel running on
Expand Down Expand Up @@ -56,19 +60,19 @@ func GetDefaultActionsFromBundle(clusterSpec *Cluster, b v1alpha1.VersionsBundle
devicePath := "{{ index .Hardware.Disks 0 }}"
paritionPathFmt := "{{ formatPartition ( index .Hardware.Disks 0 ) %s }}"

actions := []ActionOpt{withStreamImageAction(b, devicePath, osImageOverride, additionalEnvVar)}
actions := []ActionOpt{withStreamImageAction(devicePath, osImageOverride, additionalEnvVar)}

switch osFamily {
case Bottlerocket:
partitionPath := fmt.Sprintf(paritionPathFmt, "12")

actions = append(actions,
withBottlerocketBootconfigAction(b, partitionPath),
withBottlerocketUserDataAction(b, partitionPath, strings.Join(metadataURLs, ",")),
withBottlerocketBootconfigAction(partitionPath),
withBottlerocketUserDataAction(partitionPath, strings.Join(metadataURLs, ",")),
// Order matters. This action needs to append to an existing user-data.toml file so
// must be after withBottlerocketUserDataAction().
withNetplanAction(b, partitionPath, osFamily),
withRebootAction(b),
withNetplanAction(partitionPath, osFamily),
withRebootAction(),
)
case RedHat:
var mu []string
Expand All @@ -79,28 +83,28 @@ func GetDefaultActionsFromBundle(clusterSpec *Cluster, b v1alpha1.VersionsBundle
partitionPath := fmt.Sprintf(paritionPathFmt, "1")

actions = append(actions,
withNetplanAction(b, partitionPath, osFamily),
withDisableCloudInitNetworkCapabilities(b, partitionPath),
withTinkCloudInitAction(b, partitionPath, strings.Join(mu, ",")),
withDsCloudInitAction(b, partitionPath),
withRebootAction(b),
withNetplanAction(partitionPath, osFamily),
withDisableCloudInitNetworkCapabilities(partitionPath),
withTinkCloudInitAction(partitionPath, strings.Join(mu, ",")),
withDsCloudInitAction(partitionPath),
withRebootAction(),
)
default:
partitionPath := fmt.Sprintf(paritionPathFmt, "2")

actions = append(actions,
withNetplanAction(b, partitionPath, osFamily),
withDisableCloudInitNetworkCapabilities(b, partitionPath),
withTinkCloudInitAction(b, partitionPath, strings.Join(metadataURLs, ",")),
withDsCloudInitAction(b, partitionPath),
withRebootAction(b),
withNetplanAction(partitionPath, osFamily),
withDisableCloudInitNetworkCapabilities(partitionPath),
withTinkCloudInitAction(partitionPath, strings.Join(metadataURLs, ",")),
withDsCloudInitAction(partitionPath),
withRebootAction(),
)
}

return actions
}

func withStreamImageAction(b v1alpha1.VersionsBundle, disk, imageURL string, additionalEnvVar map[string]string) ActionOpt {
func withStreamImageAction(disk, imageURL string, additionalEnvVar map[string]string) ActionOpt {
return func(a *[]tinkerbell.Action) {
env := map[string]string{
"DEST_DISK": disk,
Expand All @@ -113,19 +117,19 @@ func withStreamImageAction(b v1alpha1.VersionsBundle, disk, imageURL string, add
}

*a = append(*a, tinkerbell.Action{
Name: "stream-image",
Image: b.Tinkerbell.TinkerbellStack.Actions.ImageToDisk.URI,
Name: "stream image to disk",
Image: actionImage2Disk,
Timeout: 600,
Environment: env,
})
}
}

func withNetplanAction(b v1alpha1.VersionsBundle, disk string, osFamily OSFamily) ActionOpt {
func withNetplanAction(disk string, osFamily OSFamily) ActionOpt {
return func(a *[]tinkerbell.Action) {
netplanAction := tinkerbell.Action{
Name: "write-netplan",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "write netplan config",
Image: actionWriteFile,
Timeout: 90,
Environment: map[string]string{
"DEST_DISK": disk,
Expand All @@ -151,11 +155,11 @@ func withNetplanAction(b v1alpha1.VersionsBundle, disk string, osFamily OSFamily
}
}

func withDisableCloudInitNetworkCapabilities(b v1alpha1.VersionsBundle, disk string) ActionOpt {
func withDisableCloudInitNetworkCapabilities(disk string) ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "disable-cloud-init-network-capabilities",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "disable cloud-init network capabilities",
Image: actionWriteFile,
Timeout: 90,
Environment: map[string]string{
"CONTENTS": "network: {config: disabled}",
Expand All @@ -171,11 +175,11 @@ func withDisableCloudInitNetworkCapabilities(b v1alpha1.VersionsBundle, disk str
}
}

func withTinkCloudInitAction(b v1alpha1.VersionsBundle, disk string, metadataURLs string) ActionOpt {
func withTinkCloudInitAction(disk, metadataURLs string) ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "add-tink-cloud-init-config",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "add cloud-init config",
Image: actionWriteFile,
Timeout: 90,
Environment: map[string]string{
"DEST_DISK": disk,
Expand All @@ -191,11 +195,11 @@ func withTinkCloudInitAction(b v1alpha1.VersionsBundle, disk string, metadataURL
}
}

func withDsCloudInitAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
func withDsCloudInitAction(disk string) ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "add-tink-cloud-init-ds-config",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "add cloud-init ds config",
Image: actionWriteFile,
Timeout: 90,
Environment: map[string]string{
"DEST_DISK": disk,
Expand All @@ -211,23 +215,23 @@ func withDsCloudInitAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
}
}

func withRebootAction(b v1alpha1.VersionsBundle) ActionOpt {
func withRebootAction() ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "reboot-image",
Image: b.Tinkerbell.TinkerbellStack.Actions.Reboot.URI,
Name: "reboot",
Image: actionReboot,
Timeout: 90,
Pid: "host",
Volumes: []string{"/worker:/worker"},
})
}
}

func withBottlerocketBootconfigAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
func withBottlerocketBootconfigAction(disk string) ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "write-bootconfig",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "write Bottlerocket bootconfig",
Image: actionWriteFile,
Timeout: 90,
Pid: "host",
Environment: map[string]string{
Expand All @@ -244,11 +248,11 @@ func withBottlerocketBootconfigAction(b v1alpha1.VersionsBundle, disk string) Ac
}
}

func withBottlerocketUserDataAction(b v1alpha1.VersionsBundle, disk string, metadataURLs string) ActionOpt {
func withBottlerocketUserDataAction(disk, metadataURLs string) ActionOpt {
return func(a *[]tinkerbell.Action) {
*a = append(*a, tinkerbell.Action{
Name: "write-user-data",
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
Name: "write Bottlerocket user data",
Image: actionWriteFile,
Timeout: 90,
Pid: "host",
Environment: map[string]string{
Expand Down
Loading
Loading