Skip to content

Commit 5b8b789

Browse files
Use HookOS embedded images in Tinkerbell Templates: (#8708)
* Use HookOS embedded images in Tinkerbell Templates: HookOS now embeds the container images for all Tinkerbell Actions into the HookOS Docker cache. As such, we update all Actions to use the embedded image names. Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com> * Update tests for embedded images: Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com> --------- Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
1 parent c2b4097 commit 5b8b789

File tree

35 files changed

+588
-380
lines changed

35 files changed

+588
-380
lines changed

cmd/eksctl-anywhere/cmd/generate_tinkerbell_template_config.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,10 @@ func NewGenerateTinkerbellTemplateConfig() *cobra.Command {
9494
controlPlaneMachineConfigName := cs.Cluster.Spec.ControlPlaneConfiguration.MachineGroupRef.Name
9595
controlPlaneMachineConfig := cs.TinkerbellMachineConfigs[controlPlaneMachineConfigName]
9696
osFamily := controlPlaneMachineConfig.OSFamily()
97-
98-
// For modular upgrades the version bundle is retrieve per worker node group. However,
99-
// because Tinkerbell action images are the same for every Kubernetes version within
100-
// the same bundle manifest, its OK to just use the root version bundle.
101-
bundle := *cs.RootVersionsBundle().VersionsBundle
102-
10397
osImageURL := cs.TinkerbellDatacenter.Spec.OSImageURL
10498
tinkerbellIP := cs.TinkerbellDatacenter.Spec.TinkerbellIP
10599

106-
cfg := v1alpha1.NewDefaultTinkerbellTemplateConfigCreate(cs.Cluster, bundle, osImageURL,
100+
cfg := v1alpha1.NewDefaultTinkerbellTemplateConfigCreate(cs.Cluster, osImageURL,
107101
opts.BootstrapTinkerbellIP, tinkerbellIP, osFamily)
108102

109103
return yaml.NewK8sEncoder(os.Stdout).Encode(cfg)

internal/pkg/api/tinkerbell.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,6 @@ func WithOsFamilyForAllTinkerbellMachines(value anywherev1.OSFamily) TinkerbellF
9696
}
9797
}
9898

99-
func WithImageUrlForAllTinkerbellMachines(value string) TinkerbellFiller {
100-
return func(config TinkerbellConfig) {
101-
for _, t := range config.templateConfigs {
102-
for _, task := range t.Spec.Template.Tasks {
103-
for _, action := range task.Actions {
104-
if action.Name == "stream-image" {
105-
action.Environment["IMG_URL"] = value
106-
}
107-
}
108-
}
109-
}
110-
}
111-
}
112-
11399
func WithSSHAuthorizedKeyForAllTinkerbellMachines(key string) TinkerbellFiller {
114100
return func(config TinkerbellConfig) {
115101
for _, m := range config.machineConfigs {

pkg/api/v1alpha1/tinkerbelltemplateconfig.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55

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

109
const TinkerbellTemplateConfigKind = "TinkerbellTemplateConfig"
1110

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

15-
// NewDefaultTinkerbellTemplateConfigCreate returns a default TinkerbellTemplateConfig with the
16-
// required Tasks and Actions.
17-
func NewDefaultTinkerbellTemplateConfigCreate(clusterSpec *Cluster, versionBundle v1alpha1.VersionsBundle, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) *TinkerbellTemplateConfig {
14+
// NewDefaultTinkerbellTemplateConfigCreate returns a default TinkerbellTemplateConfig with the required Tasks and Actions.
15+
func NewDefaultTinkerbellTemplateConfigCreate(clusterSpec *Cluster, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP string, osFamily OSFamily) *TinkerbellTemplateConfig {
1816
config := &TinkerbellTemplateConfig{
1917
TypeMeta: metav1.TypeMeta{
2018
Kind: TinkerbellTemplateConfigKind,
@@ -41,7 +39,7 @@ func NewDefaultTinkerbellTemplateConfigCreate(clusterSpec *Cluster, versionBundl
4139
},
4240
}
4341

44-
defaultActions := GetDefaultActionsFromBundle(clusterSpec, versionBundle, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP, osFamily)
42+
defaultActions := DefaultActions(clusterSpec, osImageOverride, tinkerbellLocalIP, tinkerbellLBIP, osFamily)
4543
for _, action := range defaultActions {
4644
action(&config.Spec.Template.Tasks[0].Actions)
4745
}

pkg/api/v1alpha1/tinkerbelltemplateconfig_defaults.go

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66

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

1110
const (
@@ -19,11 +18,16 @@ manage_etc_hosts: localhost
1918
warnings:
2019
dsid_missing_source: off
2120
`
21+
22+
// HookOS embeds container images from the bundle.
23+
// The container images are tagged as below.
24+
actionImage2Disk = "127.0.0.1/embedded/image2disk"
25+
actionWriteFile = "127.0.0.1/embedded/writefile"
26+
actionReboot = "127.0.0.1/embedded/reboot"
2227
)
2328

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

59-
actions := []ActionOpt{withStreamImageAction(b, devicePath, osImageOverride, additionalEnvVar)}
63+
actions := []ActionOpt{withStreamImageAction(devicePath, osImageOverride, additionalEnvVar)}
6064

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

6569
actions = append(actions,
66-
withBottlerocketBootconfigAction(b, partitionPath),
67-
withBottlerocketUserDataAction(b, partitionPath, strings.Join(metadataURLs, ",")),
70+
withBottlerocketBootconfigAction(partitionPath),
71+
withBottlerocketUserDataAction(partitionPath, strings.Join(metadataURLs, ",")),
6872
// Order matters. This action needs to append to an existing user-data.toml file so
6973
// must be after withBottlerocketUserDataAction().
70-
withNetplanAction(b, partitionPath, osFamily),
71-
withRebootAction(b),
74+
withNetplanAction(partitionPath, osFamily),
75+
withRebootAction(),
7276
)
7377
case RedHat:
7478
var mu []string
@@ -79,28 +83,28 @@ func GetDefaultActionsFromBundle(clusterSpec *Cluster, b v1alpha1.VersionsBundle
7983
partitionPath := fmt.Sprintf(paritionPathFmt, "1")
8084

8185
actions = append(actions,
82-
withNetplanAction(b, partitionPath, osFamily),
83-
withDisableCloudInitNetworkCapabilities(b, partitionPath),
84-
withTinkCloudInitAction(b, partitionPath, strings.Join(mu, ",")),
85-
withDsCloudInitAction(b, partitionPath),
86-
withRebootAction(b),
86+
withNetplanAction(partitionPath, osFamily),
87+
withDisableCloudInitNetworkCapabilities(partitionPath),
88+
withTinkCloudInitAction(partitionPath, strings.Join(mu, ",")),
89+
withDsCloudInitAction(partitionPath),
90+
withRebootAction(),
8791
)
8892
default:
8993
partitionPath := fmt.Sprintf(paritionPathFmt, "2")
9094

9195
actions = append(actions,
92-
withNetplanAction(b, partitionPath, osFamily),
93-
withDisableCloudInitNetworkCapabilities(b, partitionPath),
94-
withTinkCloudInitAction(b, partitionPath, strings.Join(metadataURLs, ",")),
95-
withDsCloudInitAction(b, partitionPath),
96-
withRebootAction(b),
96+
withNetplanAction(partitionPath, osFamily),
97+
withDisableCloudInitNetworkCapabilities(partitionPath),
98+
withTinkCloudInitAction(partitionPath, strings.Join(metadataURLs, ",")),
99+
withDsCloudInitAction(partitionPath),
100+
withRebootAction(),
97101
)
98102
}
99103

100104
return actions
101105
}
102106

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

115119
*a = append(*a, tinkerbell.Action{
116-
Name: "stream-image",
117-
Image: b.Tinkerbell.TinkerbellStack.Actions.ImageToDisk.URI,
120+
Name: "stream image to disk",
121+
Image: actionImage2Disk,
118122
Timeout: 600,
119123
Environment: env,
120124
})
121125
}
122126
}
123127

124-
func withNetplanAction(b v1alpha1.VersionsBundle, disk string, osFamily OSFamily) ActionOpt {
128+
func withNetplanAction(disk string, osFamily OSFamily) ActionOpt {
125129
return func(a *[]tinkerbell.Action) {
126130
netplanAction := tinkerbell.Action{
127-
Name: "write-netplan",
128-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
131+
Name: "write netplan config",
132+
Image: actionWriteFile,
129133
Timeout: 90,
130134
Environment: map[string]string{
131135
"DEST_DISK": disk,
@@ -151,11 +155,11 @@ func withNetplanAction(b v1alpha1.VersionsBundle, disk string, osFamily OSFamily
151155
}
152156
}
153157

154-
func withDisableCloudInitNetworkCapabilities(b v1alpha1.VersionsBundle, disk string) ActionOpt {
158+
func withDisableCloudInitNetworkCapabilities(disk string) ActionOpt {
155159
return func(a *[]tinkerbell.Action) {
156160
*a = append(*a, tinkerbell.Action{
157-
Name: "disable-cloud-init-network-capabilities",
158-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
161+
Name: "disable cloud-init network capabilities",
162+
Image: actionWriteFile,
159163
Timeout: 90,
160164
Environment: map[string]string{
161165
"CONTENTS": "network: {config: disabled}",
@@ -171,11 +175,11 @@ func withDisableCloudInitNetworkCapabilities(b v1alpha1.VersionsBundle, disk str
171175
}
172176
}
173177

174-
func withTinkCloudInitAction(b v1alpha1.VersionsBundle, disk string, metadataURLs string) ActionOpt {
178+
func withTinkCloudInitAction(disk, metadataURLs string) ActionOpt {
175179
return func(a *[]tinkerbell.Action) {
176180
*a = append(*a, tinkerbell.Action{
177-
Name: "add-tink-cloud-init-config",
178-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
181+
Name: "add cloud-init config",
182+
Image: actionWriteFile,
179183
Timeout: 90,
180184
Environment: map[string]string{
181185
"DEST_DISK": disk,
@@ -191,11 +195,11 @@ func withTinkCloudInitAction(b v1alpha1.VersionsBundle, disk string, metadataURL
191195
}
192196
}
193197

194-
func withDsCloudInitAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
198+
func withDsCloudInitAction(disk string) ActionOpt {
195199
return func(a *[]tinkerbell.Action) {
196200
*a = append(*a, tinkerbell.Action{
197-
Name: "add-tink-cloud-init-ds-config",
198-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
201+
Name: "add cloud-init ds config",
202+
Image: actionWriteFile,
199203
Timeout: 90,
200204
Environment: map[string]string{
201205
"DEST_DISK": disk,
@@ -211,23 +215,23 @@ func withDsCloudInitAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
211215
}
212216
}
213217

214-
func withRebootAction(b v1alpha1.VersionsBundle) ActionOpt {
218+
func withRebootAction() ActionOpt {
215219
return func(a *[]tinkerbell.Action) {
216220
*a = append(*a, tinkerbell.Action{
217-
Name: "reboot-image",
218-
Image: b.Tinkerbell.TinkerbellStack.Actions.Reboot.URI,
221+
Name: "reboot",
222+
Image: actionReboot,
219223
Timeout: 90,
220224
Pid: "host",
221225
Volumes: []string{"/worker:/worker"},
222226
})
223227
}
224228
}
225229

226-
func withBottlerocketBootconfigAction(b v1alpha1.VersionsBundle, disk string) ActionOpt {
230+
func withBottlerocketBootconfigAction(disk string) ActionOpt {
227231
return func(a *[]tinkerbell.Action) {
228232
*a = append(*a, tinkerbell.Action{
229-
Name: "write-bootconfig",
230-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
233+
Name: "write Bottlerocket bootconfig",
234+
Image: actionWriteFile,
231235
Timeout: 90,
232236
Pid: "host",
233237
Environment: map[string]string{
@@ -244,11 +248,11 @@ func withBottlerocketBootconfigAction(b v1alpha1.VersionsBundle, disk string) Ac
244248
}
245249
}
246250

247-
func withBottlerocketUserDataAction(b v1alpha1.VersionsBundle, disk string, metadataURLs string) ActionOpt {
251+
func withBottlerocketUserDataAction(disk, metadataURLs string) ActionOpt {
248252
return func(a *[]tinkerbell.Action) {
249253
*a = append(*a, tinkerbell.Action{
250-
Name: "write-user-data",
251-
Image: b.Tinkerbell.TinkerbellStack.Actions.WriteFile.URI,
254+
Name: "write Bottlerocket user data",
255+
Image: actionWriteFile,
252256
Timeout: 90,
253257
Pid: "host",
254258
Environment: map[string]string{

0 commit comments

Comments
 (0)