Skip to content

Commit

Permalink
chore: de-hardcode list of extra images for image-cache test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
DmitriyMV committed Jan 20, 2025
1 parent bde516f commit 986096c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2025-01-20T16:57:17Z by kres 3b3f992.
# Generated on 2025-01-20T18:03:22Z by kres 3b3f992.

name: default
concurrency:
Expand Down Expand Up @@ -1564,7 +1564,6 @@ jobs:
- name: image-cache
env:
IMAGE_REGISTRY: registry.dev.siderolabs.io
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
PLATFORM: linux/amd64,linux/arm64
PUSH: "true"
run: |
Expand Down
1 change: 0 additions & 1 deletion .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,6 @@ spec:
PLATFORM: linux/amd64,linux/arm64
IMAGE_REGISTRY: registry.dev.siderolabs.io
PUSH: true
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"
- name: e2e-image-cache
command: e2e-qemu
withSudo: true
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ IMAGER_EXTRA_PKGS ?= \
INSTALLER_PKGS ?= $(INSTALLER_ONLY_PKGS) $(IMAGER_EXTRA_PKGS)
IMAGER_ARGS ?=

MORE_IMAGES ?=

CGO_ENABLED ?= 0
GO_BUILDFLAGS ?=
GO_BUILDTAGS ?= tcell_minimal,grpcnotrace
Expand Down Expand Up @@ -491,7 +489,9 @@ uki-certs: talosctl ## Generate test certificates for SecureBoot/PCR Signing

.PHONY: cache-create
cache-create: installer imager ## Generate image cache.
@( $(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
@docker run --entrypoint /usr/local/bin/e2e.test registry.k8s.io/conformance:$(KUBECTL_VERSION) --list-images | \
$(TALOSCTL_EXECUTABLE) images integration --installer-tag=$(IMAGE_TAG) | \
$(TALOSCTL_EXECUTABLE) images cache-create --image-cache-path=/tmp/cache.tar --images=- --force
@crane push /tmp/cache.tar $(REGISTRY_AND_USERNAME)/image-cache:$(IMAGE_TAG)
@$(MAKE) image-iso IMAGER_ARGS="--image-cache=$(REGISTRY_AND_USERNAME)/image-cache:$(IMAGE_TAG) --extra-kernel-arg='console=ttyS0'"

Expand Down
86 changes: 83 additions & 3 deletions cmd/talosctl/cmd/talos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
package talos

import (
"bufio"
"context"
"errors"
"fmt"
"io"
"os"
"slices"
"strings"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -153,6 +156,81 @@ var imageDefaultCmd = &cobra.Command{
},
}

// imageIntegrationCmd represents the integration image command.
var imageIntegrationCmd = &cobra.Command{
Use: "integration",
Short: "List the integration images used by k8s in Talos",
Args: cobra.NoArgs,
Hidden: true,
RunE: func(*cobra.Command, []string) error {
if stat, _ := os.Stdin.Stat(); (stat.Mode() & os.ModeCharDevice) != 0 { //nolint:errcheck
return errors.New("input must be piped")
}

if imageIntegrationCmdFlags.installerTag == "" {
return errors.New("installer tag is required")
}

imgs := images.List(container.NewV1Alpha1(&v1alpha1.Config{
MachineConfig: &v1alpha1.MachineConfig{
MachineKubelet: &v1alpha1.KubeletConfig{},
},
ClusterConfig: &v1alpha1.ClusterConfig{
EtcdConfig: &v1alpha1.EtcdConfig{},
APIServerConfig: &v1alpha1.APIServerConfig{},
ControllerManagerConfig: &v1alpha1.ControllerManagerConfig{},
SchedulerConfig: &v1alpha1.SchedulerConfig{},
CoreDNSConfig: &v1alpha1.CoreDNS{},
ProxyConfig: &v1alpha1.ProxyConfig{},
},
}))

imageNames := []string{
imgs.Flannel,
imgs.CoreDNS,
imgs.Etcd,
imgs.KubeAPIServer,
imgs.KubeControllerManager,
imgs.KubeScheduler,
imgs.KubeProxy,
imgs.Kubelet,
imgs.Pause,
images.DefaultInstallerImageRepository + ":" + imageIntegrationCmdFlags.installerTag,
}

sc := bufio.NewScanner(os.Stdin)

for sc.Scan() {
switch sc := sc.Text(); {
case strings.Contains(sc, "authenticated-"):
// skip authenticated images
case strings.HasPrefix(sc, "invalid.registry.k8s.io"):
// skip invalid images
default:
imageNames = append(imageNames, sc)
}
}

if err := sc.Err(); err != nil {
return fmt.Errorf("error reading from stdin: %w", err)
}

slices.Sort(imageNames)

imageNames = slices.Compact(imageNames)

for _, img := range imageNames {
fmt.Println(img)
}

return nil
},
}

var imageIntegrationCmdFlags struct {
installerTag string
}

// imageCacheCreate represents the image cache create command.
var imageCacheCreateCmd = &cobra.Command{
Use: "cache-create",
Expand Down Expand Up @@ -207,7 +285,7 @@ talosctl images default | talosctl images cache-create --image-cache-path=/tmp/t
},
}

type imageCacheCreateCmdFlagsType struct {
var imageCacheCreateCmdFlags struct {
imageCachePath string
imageLayerCachePath string
platform string
Expand All @@ -218,8 +296,6 @@ type imageCacheCreateCmdFlagsType struct {
force bool
}

var imageCacheCreateCmdFlags imageCacheCreateCmdFlagsType

func init() {
imageCmd.PersistentFlags().StringVar(&imageCmdFlags.namespace, "namespace", "cri", "namespace to use: `system` (etcd and kubelet images) or `cri` for all Kubernetes workloads")
addCommand(imageCmd)
Expand All @@ -228,6 +304,7 @@ func init() {
imageCmd.AddCommand(imageListCmd)
imageCmd.AddCommand(imagePullCmd)
imageCmd.AddCommand(imageCacheCreateCmd)
imageCmd.AddCommand(imageIntegrationCmd)

imageCacheCreateCmd.PersistentFlags().StringVar(&imageCacheCreateCmdFlags.imageCachePath, "image-cache-path", "", "directory to save the image cache in OCI format")
imageCacheCreateCmd.MarkPersistentFlagRequired("image-cache-path") //nolint:errcheck
Expand All @@ -237,4 +314,7 @@ func init() {
imageCacheCreateCmd.MarkPersistentFlagRequired("images") //nolint:errcheck
imageCacheCreateCmd.PersistentFlags().BoolVar(&imageCacheCreateCmdFlags.insecure, "insecure", false, "allow insecure registries")
imageCacheCreateCmd.PersistentFlags().BoolVar(&imageCacheCreateCmdFlags.force, "force", false, "force overwrite of existing image cache")

imageIntegrationCmd.PersistentFlags().StringVar(&imageIntegrationCmdFlags.installerTag, "installer-tag", "", "tag of the installer image to use")
imageIntegrationCmd.MarkPersistentFlagRequired("installer-tag") //nolint:errcheck
}

0 comments on commit 986096c

Please sign in to comment.