Skip to content

Commit b9a8ad6

Browse files
committed
chore: de-hardcode list of extra images for image-cache test
Get the image list using `registry.k8s.io/conformance` image instead of hardcoding it. Add new command `talosctl image integration` to create a proper list of k8s integration images for `talosctl images cache-create` command. Signed-off-by: Dmitriy Matrenichev <[email protected]>
1 parent 683153a commit b9a8ad6

File tree

7 files changed

+105
-16
lines changed

7 files changed

+105
-16
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,6 @@ jobs:
15641564
- name: image-cache
15651565
env:
15661566
IMAGE_REGISTRY: registry.dev.siderolabs.io
1567-
MORE_IMAGES: alpine;registry.k8s.io/conformance:v1.32.1;registry.k8s.io/e2e-test-images/busybox:1.36.1-1;registry.k8s.io/e2e-test-images/agnhost:2.53;registry.k8s.io/e2e-test-images/httpd:2.4.38-4;registry.k8s.io/e2e-test-images/nonewprivs:1.3;registry.k8s.io/e2e-test-images/jessie-dnsutils:1.7;registry.k8s.io/e2e-test-images/nautilus:1.7;registry.k8s.io/e2e-test-images/sample-apiserver:1.29.2;registry.k8s.io/e2e-test-images/nginx:1.14-4;registry.k8s.io/etcd:3.5.16-0;registry.k8s.io/e2e-test-images/httpd:2.4.39-4
15681567
PLATFORM: linux/amd64,linux/arm64
15691568
PUSH: "true"
15701569
run: |

.kres.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,6 @@ spec:
16511651
PLATFORM: linux/amd64,linux/arm64
16521652
IMAGE_REGISTRY: registry.dev.siderolabs.io
16531653
PUSH: true
1654-
MORE_IMAGES: "alpine;registry.k8s.io/conformance:v1.32.1;registry.k8s.io/e2e-test-images/busybox:1.36.1-1;registry.k8s.io/e2e-test-images/agnhost:2.53;registry.k8s.io/e2e-test-images/httpd:2.4.38-4;registry.k8s.io/e2e-test-images/nonewprivs:1.3;registry.k8s.io/e2e-test-images/jessie-dnsutils:1.7;registry.k8s.io/e2e-test-images/nautilus:1.7;registry.k8s.io/e2e-test-images/sample-apiserver:1.29.2;registry.k8s.io/e2e-test-images/nginx:1.14-4;registry.k8s.io/etcd:3.5.16-0;registry.k8s.io/e2e-test-images/httpd:2.4.39-4"
16551654
- name: e2e-image-cache
16561655
command: e2e-qemu
16571656
withSudo: true

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ IMAGER_EXTRA_PKGS ?= \
150150
INSTALLER_PKGS ?= $(INSTALLER_ONLY_PKGS) $(IMAGER_EXTRA_PKGS)
151151
IMAGER_ARGS ?=
152152

153-
MORE_IMAGES ?=
154-
155153
CGO_ENABLED ?= 0
156154
GO_BUILDFLAGS ?=
157155
GO_BUILDTAGS ?= tcell_minimal,grpcnotrace
@@ -491,7 +489,9 @@ uki-certs: talosctl ## Generate test certificates for SecureBoot/PCR Signing
491489

492490
.PHONY: cache-create
493491
cache-create: installer imager ## Generate image cache.
494-
@( $(TALOSCTL_EXECUTABLE) images default | grep -v 'siderolabs/installer'; echo "$(REGISTRY_AND_USERNAME)/installer:$(IMAGE_TAG)"; echo "$(MORE_IMAGES)" | tr ';' '\n' ) | $(TALOSCTL_EXECUTABLE) images cache-create --image-cache-path=/tmp/cache.tar --images=- --force
492+
@docker run --entrypoint /usr/local/bin/e2e.test registry.k8s.io/conformance:$(KUBECTL_VERSION) --list-images | \
493+
$(TALOSCTL_EXECUTABLE) images integration --installer-tag=$(IMAGE_TAG) --registry-and-user=$(REGISTRY_AND_USERNAME) | \
494+
$(TALOSCTL_EXECUTABLE) images cache-create --image-cache-path=/tmp/cache.tar --images=- --force
495495
@crane push /tmp/cache.tar $(REGISTRY_AND_USERNAME)/image-cache:$(IMAGE_TAG)
496496
@$(MAKE) image-iso IMAGER_ARGS="--image-cache=$(REGISTRY_AND_USERNAME)/image-cache:$(IMAGE_TAG) --extra-kernel-arg='console=ttyS0'"
497497

cmd/talosctl/cmd/talos/image.go

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
package talos
66

77
import (
8+
"bufio"
89
"context"
10+
"errors"
911
"fmt"
1012
"io"
1113
"os"
14+
"slices"
1215
"strings"
1316
"text/tabwriter"
1417
"time"
@@ -153,6 +156,89 @@ var imageDefaultCmd = &cobra.Command{
153156
},
154157
}
155158

159+
// imageIntegrationCmd represents the integration image command.
160+
var imageIntegrationCmd = &cobra.Command{
161+
Use: "integration",
162+
Short: "List the integration images used by k8s in Talos",
163+
Args: cobra.NoArgs,
164+
Hidden: true,
165+
RunE: func(*cobra.Command, []string) error {
166+
if stat, _ := os.Stdin.Stat(); (stat.Mode() & os.ModeCharDevice) != 0 { //nolint:errcheck
167+
return errors.New("input must be piped")
168+
}
169+
170+
if imageIntegrationCmdFlags.installerTag == "" {
171+
return errors.New("installer tag is required")
172+
}
173+
174+
if imageIntegrationCmdFlags.registryAndUser == "" {
175+
return errors.New("registry and user string is required")
176+
}
177+
178+
imgs := images.List(container.NewV1Alpha1(&v1alpha1.Config{
179+
MachineConfig: &v1alpha1.MachineConfig{
180+
MachineKubelet: &v1alpha1.KubeletConfig{},
181+
},
182+
ClusterConfig: &v1alpha1.ClusterConfig{
183+
EtcdConfig: &v1alpha1.EtcdConfig{},
184+
APIServerConfig: &v1alpha1.APIServerConfig{},
185+
ControllerManagerConfig: &v1alpha1.ControllerManagerConfig{},
186+
SchedulerConfig: &v1alpha1.SchedulerConfig{},
187+
CoreDNSConfig: &v1alpha1.CoreDNS{},
188+
ProxyConfig: &v1alpha1.ProxyConfig{},
189+
},
190+
}))
191+
192+
imageNames := []string{
193+
imgs.Flannel,
194+
imgs.CoreDNS,
195+
imgs.Etcd,
196+
imgs.KubeAPIServer,
197+
imgs.KubeControllerManager,
198+
imgs.KubeScheduler,
199+
imgs.KubeProxy,
200+
imgs.Kubelet,
201+
imgs.Pause,
202+
"registry.k8s.io/conformance:v" + constants.DefaultKubernetesVersion,
203+
"docker.io/library/alpine:latest",
204+
imageIntegrationCmdFlags.registryAndUser + "/installer:" +
205+
imageIntegrationCmdFlags.installerTag,
206+
}
207+
208+
sc := bufio.NewScanner(os.Stdin)
209+
210+
for sc.Scan() {
211+
switch sc := sc.Text(); {
212+
case strings.Contains(sc, "authenticated-"):
213+
// skip authenticated images
214+
case strings.HasPrefix(sc, "invalid.registry.k8s.io"):
215+
// skip invalid images
216+
default:
217+
imageNames = append(imageNames, sc)
218+
}
219+
}
220+
221+
if err := sc.Err(); err != nil {
222+
return fmt.Errorf("error reading from stdin: %w", err)
223+
}
224+
225+
slices.Sort(imageNames)
226+
227+
imageNames = slices.Compact(imageNames)
228+
229+
for _, img := range imageNames {
230+
fmt.Println(img)
231+
}
232+
233+
return nil
234+
},
235+
}
236+
237+
var imageIntegrationCmdFlags struct {
238+
installerTag string
239+
registryAndUser string
240+
}
241+
156242
// imageCacheCreate represents the image cache create command.
157243
var imageCacheCreateCmd = &cobra.Command{
158244
Use: "cache-create",
@@ -207,7 +293,7 @@ talosctl images default | talosctl images cache-create --image-cache-path=/tmp/t
207293
},
208294
}
209295

210-
type imageCacheCreateCmdFlagsType struct {
296+
var imageCacheCreateCmdFlags struct {
211297
imageCachePath string
212298
imageLayerCachePath string
213299
platform string
@@ -218,8 +304,6 @@ type imageCacheCreateCmdFlagsType struct {
218304
force bool
219305
}
220306

221-
var imageCacheCreateCmdFlags imageCacheCreateCmdFlagsType
222-
223307
func init() {
224308
imageCmd.PersistentFlags().StringVar(&imageCmdFlags.namespace, "namespace", "cri", "namespace to use: `system` (etcd and kubelet images) or `cri` for all Kubernetes workloads")
225309
addCommand(imageCmd)
@@ -228,6 +312,7 @@ func init() {
228312
imageCmd.AddCommand(imageListCmd)
229313
imageCmd.AddCommand(imagePullCmd)
230314
imageCmd.AddCommand(imageCacheCreateCmd)
315+
imageCmd.AddCommand(imageIntegrationCmd)
231316

232317
imageCacheCreateCmd.PersistentFlags().StringVar(&imageCacheCreateCmdFlags.imageCachePath, "image-cache-path", "", "directory to save the image cache in OCI format")
233318
imageCacheCreateCmd.MarkPersistentFlagRequired("image-cache-path") //nolint:errcheck
@@ -237,4 +322,9 @@ func init() {
237322
imageCacheCreateCmd.MarkPersistentFlagRequired("images") //nolint:errcheck
238323
imageCacheCreateCmd.PersistentFlags().BoolVar(&imageCacheCreateCmdFlags.insecure, "insecure", false, "allow insecure registries")
239324
imageCacheCreateCmd.PersistentFlags().BoolVar(&imageCacheCreateCmdFlags.force, "force", false, "force overwrite of existing image cache")
325+
326+
imageIntegrationCmd.PersistentFlags().StringVar(&imageIntegrationCmdFlags.installerTag, "installer-tag", "", "tag of the installer image to use")
327+
imageIntegrationCmd.MarkPersistentFlagRequired("installer-tag") //nolint:errcheck
328+
imageIntegrationCmd.PersistentFlags().StringVar(&imageIntegrationCmdFlags.registryAndUser, "registry-and-user", "", "registry and user to use for the images")
329+
imageIntegrationCmd.MarkPersistentFlagRequired("registry-and-user") //nolint:errcheck
240330
}

hack/test/patches/image-cache.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ name: IMAGECACHE
2323
provisioning:
2424
diskSelector:
2525
match: 'system_disk'
26+
maxSize: 3GiB
2627
grow: true

internal/app/machined/pkg/controllers/cri/image_cache_config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,11 @@ func (ctrl *ImageCacheConfigController) analyzeImageCacheVolumes(ctx context.Con
366366
case VolumeImageCacheISO:
367367
isoReady = true
368368
copySource = root.ValueOr("")
369+
logger = logger.With(zap.String("iso_size", volumeStatus.TypedSpec().PrettySize))
369370
case VolumeImageCacheDISK:
370371
diskReady = true
371372
copyTarget = root.ValueOr("")
373+
logger = logger.With(zap.String("disk_size", volumeStatus.TypedSpec().PrettySize))
372374
}
373375
}
374376

@@ -379,6 +381,8 @@ func (ctrl *ImageCacheConfigController) analyzeImageCacheVolumes(ctx context.Con
379381
}
380382
}
381383

384+
logger = logger.With(zap.Bool("all_ready", allReady))
385+
382386
var copyStatus cri.ImageCacheCopyStatus
383387

384388
switch {
@@ -462,12 +466,8 @@ func (ctrl *ImageCacheConfigController) copyImageCache(ctx context.Context, logg
462466
if err := filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
463467
if err != nil {
464468
return fmt.Errorf("error walking source directory: %w", err)
465-
}
466-
467-
select {
468-
case <-ctx.Done():
469-
return ctx.Err()
470-
default:
469+
} else if err = ctx.Err(); err != nil {
470+
return err
471471
}
472472

473473
relPath, err := filepath.Rel(source, path)
@@ -537,7 +537,7 @@ func copyFileSafe(src, dst string) error {
537537
defer dstFile.Close() //nolint:errcheck
538538

539539
if _, err = io.Copy(dstFile, srcFile); err != nil {
540-
return fmt.Errorf("error copying file: %w", err)
540+
return fmt.Errorf("error copying file: %w, source size is %d", err, srcStat.Size())
541541
}
542542

543543
if err = dstFile.Close(); err != nil {

internal/integration/cli/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (suite *ListSuite) TestDepth() {
5151

5252
if stdout, _ := suite.RunCLI(imageCacheQuery); strings.Contains(stdout, "ready") {
5353
// Image cache paths parts are longer
54-
maxSeps = 8
54+
maxSeps = 9
5555
}
5656

5757
// checks that enough separators are encountered in the output

0 commit comments

Comments
 (0)