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

MGMT-19545: Replace seed cluster mirror registries in IBI preparation step #727

Merged
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
5 changes: 5 additions & 0 deletions api/ibiconfig/ibiconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ type IBIPrepareConfig struct {
// Provide the device id like /dev/by-id/ata-xxxxx
InstallationDisk string `json:"installationDisk"`

// ReleaseRegistry is the container image registry that hosts the OpenShift
// release-image content and is used when precaching the cluster's container
// images during the preparation/installation step only.
ReleaseRegistry string `json:"releaseRegistry,omitempty"`
mresvanis marked this conversation as resolved.
Show resolved Hide resolved

// PrecacheBestEffort is a flag to enable best effort precaching.
// +optional
PrecacheBestEffort bool `json:"precacheBestEffort,omitempty"`
Expand Down
10 changes: 8 additions & 2 deletions controllers/prep_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,14 @@ func (r *ImageBasedUpgradeReconciler) launchPrecaching(ctx context.Context, imag
// TODO: if seedInfo.hasProxy we also require that the LCA deployment contain "NO_PROXY" + "HTTP_PROXY" + "HTTPS_PROXY" as env vars. Produce a warning and/or document this.
r.Log.Info("Collected seed info for precache", "seed info", fmt.Sprintf("%+v", seedInfo))

r.Log.Info("Getting mirror registry source registries from cluster")
mirrorRegistrySources, err := lcautils.GetMirrorRegistrySourceRegistries(ctx, r.Client)
if err != nil {
return fmt.Errorf("failed to get mirror registry source registries from cluster %w", err)
}

r.Log.Info("Checking whether to override seed registry")
shouldOverrideRegistry, err := lcautils.ShouldOverrideSeedRegistry(ctx, r.Client, seedInfo.MirrorRegistryConfigured, seedInfo.ReleaseRegistry)
shouldOverrideRegistry, err := lcautils.ShouldOverrideSeedRegistry(seedInfo.MirrorRegistryConfigured, seedInfo.ReleaseRegistry, mirrorRegistrySources)
if err != nil {
return fmt.Errorf("failed to check ShouldOverrideSeedRegistry %w", err)
}
Expand Down Expand Up @@ -611,7 +617,7 @@ func (r *ImageBasedUpgradeReconciler) handlePrep(ctx context.Context, ibu *ibuv1
if err != nil {
if k8serrors.IsNotFound(err) {
r.Log.Info("Launching a new precache job")
if err := r.launchPrecaching(ctx, precache.ImageListFile, ibu); err != nil {
if err := r.launchPrecaching(ctx, common.ContainersListFilePath, ibu); err != nil {
return requeueWithError(fmt.Errorf("failed to launch precaching job: %w", err))
}
// start prep stage precache phase timing
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.4
toolchain go1.22.7

require (
github.com/containers/image/v5 v5.24.2
github.com/coreos/go-semver v0.3.1
github.com/coreos/ignition/v2 v2.20.0
github.com/go-logr/logr v1.4.2
Expand All @@ -17,6 +18,7 @@ require (
github.com/openshift/lvm-operator v0.0.0-20240627192035-bf9fc3ac7ee8
github.com/operator-framework/api v0.23.0
github.com/otiai10/copy v1.14.0
github.com/pelletier/go-toml v1.9.5
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
Expand All @@ -38,16 +40,25 @@ require (
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e // indirect
github.com/containers/storage v1.45.3 // indirect
github.com/diskfs/go-diskfs v1.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.10 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/stolostron/kubernetes-dependency-watches v0.10.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/x448/float16 v0.8.4 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
Expand All @@ -23,6 +25,10 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/clarketm/json v1.17.1 h1:U1IxjqJkJ7bRK4L6dyphmoO840P6bdhPdbbLySourqI=
github.com/clarketm/json v1.17.1/go.mod h1:ynr2LRfb0fQU34l07csRNBTcivjySLLiY1YzQqKVfdo=
github.com/containers/image/v5 v5.24.2 h1:QcMsHBAXBPPnVYo6iEFarvaIpym7sBlwsGHPJlucxN0=
github.com/containers/image/v5 v5.24.2/go.mod h1:oss5F6ssGQz8ZtC79oY+fuzYA3m3zBek9tq9gmhuvHc=
github.com/containers/storage v1.45.3 h1:GbtTvTtp3GW2/tcFg5VhgHXcYMwVn2KfZKiHjf9FAOM=
github.com/containers/storage v1.45.3/go.mod h1:OdRUYHrq1HP6iAo79VxqtYuJzC5j4eA2I60jKOoCT7g=
github.com/coreos/fcct v0.5.0 h1:f/z+MCoR2vULes+MyoPEApQ6iluy/JbXoRi6dahPItQ=
github.com/coreos/fcct v0.5.0/go.mod h1:cbE+j77YSQwFB2fozWVB3qsI2Pi3YiVEbDz/b6Yywdo=
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIRhuC59RB442rXUazKNueVpfJPxg4=
Expand Down Expand Up @@ -54,6 +60,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diskfs/go-diskfs v1.4.0 h1:MAybY6TPD+fmhY+a2qFhmdvMeIKvCqlgh4QIc1uCmBs=
github.com/diskfs/go-diskfs v1.4.0/go.mod h1:G8cyy+ngM+3yKlqjweMmtqvE+TxsnIo1xumbJX1AeLg=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab h1:h1UgjJdAAhj+uPL68n7XASS6bU+07ZX1WJvVS2eyoeY=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk=
Expand Down Expand Up @@ -142,6 +150,8 @@ github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HK
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -157,6 +167,14 @@ github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=
github.com/opencontainers/image-spec v1.1.0-rc2/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/opencontainers/runc v1.1.10 h1:EaL5WeO9lv9wmS6SASjszOeQdSctvpbu0DdBQBizE40=
github.com/opencontainers/runc v1.1.10/go.mod h1:+/R6+KmDlh+hOO8NkjmgkG9Qzvypzk0yXxAPYYR65+M=
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 h1:R5M2qXZiK/mWPMT4VldCOiSL9HIAMuxQZWdG0CSM5+4=
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.11.1 h1:nHFvthhM0qY8/m+vfhJylliSshm8G1jJ2jDMcgULaH8=
github.com/opencontainers/selinux v1.11.1/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/openshift/api v0.0.0-20240423014330-2cb60a113ad1 h1:qo6vX1xwLILWL69tCgGW/ow7gOnBsVnTt3CZheqjB74=
Expand All @@ -179,6 +197,8 @@ github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pin/tftp v2.1.0+incompatible/go.mod h1:xVpZOMCXTy+A5QMjEVN0Glwa1sUvaJhFXbr/aAxuxGY=
Expand Down Expand Up @@ -230,6 +250,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
Expand Down
12 changes: 10 additions & 2 deletions internal/common/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package common

import (
"math"
"path/filepath"

"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -58,6 +59,7 @@ const (
SeedDataDir = "/var/seed_data"
KubeconfigCryptoDir = "kubeconfig-crypto"
ClusterConfigDir = "cluster-configuration"
ContainersListFileName = "containers.list"
SeedClusterInfoFileName = "manifest.json"
SeedReconfigurationFileName = "manifest.json"
ManifestsDir = "manifests"
Expand Down Expand Up @@ -126,8 +128,7 @@ const (
CaBundleDataKey = "ca-bundle.crt"
ClusterAdditionalTrustBundleName = "user-ca-bundle"

IBIPSFile = "/var/tmp/pull-secret.json"
PostDeploymentScriptPath = "/var/tmp/post.sh"
IBIWorkspace = "var/tmp"

ContainerStoragePath = "/var/lib/containers"
)
Expand All @@ -146,6 +147,13 @@ var (
RestoreGvk = schema.GroupVersionKind{Group: "velero.io", Kind: "Restore", Version: "v1"}
)

var (
ContainersListFilePath = filepath.Join(IBIWorkspace, ContainersListFileName)
IBIPostDeploymentScriptPath = filepath.Join(IBIWorkspace, "post.sh")
IBIPullSecretFilePath = filepath.Join(IBIWorkspace, "pull-secret.json")
IBISeedInfoFilePath = filepath.Join(IBIWorkspace, SeedClusterInfoFileName)
)

// CertPrefixes is the list of certificate prefixes to be backed up
// before creating the seed image
var CertPrefixes = []string{
Expand Down
1 change: 0 additions & 1 deletion internal/precache/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
EnvPrecacheSpecFile string = "PRECACHE_SPEC_FILE"
EnvMaxPullThreads string = "MAX_PULL_THREADS"
EnvPrecacheBestEffort string = "PRECACHE_BEST_EFFORT"
ImageListFile = "var/tmp/imageListFile"
)

// Precaching job specs
Expand Down
8 changes: 6 additions & 2 deletions internal/prep/prep.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func getDeploymentFromDeploymentID(deploymentID string) (string, error) {
}

func SetupStateroot(log logr.Logger, ops ops.Ops, ostreeClient ostreeclient.IClient,
rpmOstreeClient rpmostreeclient.IClient, seedImage, expectedVersion, imageListFile string, ibi bool) error {
rpmOstreeClient rpmostreeclient.IClient, seedImage, expectedVersion string, ibi bool) error {
log.Info("Start setupstateroot")

defer ops.UnmountAndRemoveImage(seedImage)
Expand Down Expand Up @@ -246,10 +246,14 @@ func SetupStateroot(log logr.Logger, ops ops.Ops, ostreeClient ostreeclient.ICli
return fmt.Errorf("failed to process etc.deletions: %w", err)
}

if err := common.CopyOutsideChroot(filepath.Join(mountpoint, "containers.list"), imageListFile); err != nil {
if err := common.CopyOutsideChroot(filepath.Join(mountpoint, common.ContainersListFileName), common.ContainersListFilePath); err != nil {
return fmt.Errorf("failed to copy image list file: %w", err)
}

if err := common.CopyOutsideChroot(filepath.Join(mountpoint, common.SeedClusterInfoFileName), common.IBISeedInfoFilePath); err != nil {
return fmt.Errorf("failed to copy %s file: %w", common.SeedClusterInfoFileName, err)
}

log.Info("Stateroot setup done successfully")
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions lca-cli/cmd/ibuStaterootSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"k8s.io/apimachinery/pkg/types"

"github.com/openshift-kni/lifecycle-agent/internal/common"
"github.com/openshift-kni/lifecycle-agent/internal/precache"
"github.com/openshift-kni/lifecycle-agent/internal/prep"
"github.com/openshift-kni/lifecycle-agent/internal/reboot"
lcautils "github.com/openshift-kni/lifecycle-agent/utils"
Expand Down Expand Up @@ -87,7 +86,7 @@ func ibuStaterootSetupRun() error {
}

logger.Info("Setting up stateroot")
if err := prep.SetupStateroot(logger, opsClient, ostreeClient, rpmOstreeClient, ibu.Spec.SeedImageRef.Image, ibu.Spec.SeedImageRef.Version, precache.ImageListFile, false); err != nil {
if err := prep.SetupStateroot(logger, opsClient, ostreeClient, rpmOstreeClient, ibu.Spec.SeedImageRef.Image, ibu.Spec.SeedImageRef.Version, false); err != nil {
return fmt.Errorf("failed to complete stateroot setup: %w", err)
}

Expand Down
69 changes: 57 additions & 12 deletions lca-cli/ibi-preparation/ibipreparation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"path/filepath"

"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/go-logr/logr"
"github.com/pelletier/go-toml"
preinstallUtils "github.com/rh-ecosystem-edge/preinstall-utils/pkg"
"github.com/sirupsen/logrus"

Expand All @@ -17,12 +19,14 @@ import (
"github.com/openshift-kni/lifecycle-agent/internal/prep"
"github.com/openshift-kni/lifecycle-agent/lca-cli/ops"
rpmostreeclient "github.com/openshift-kni/lifecycle-agent/lca-cli/ostreeclient"
"github.com/openshift-kni/lifecycle-agent/lca-cli/seedclusterinfo"
"github.com/openshift-kni/lifecycle-agent/utils"
)

const (
imageListFile = "var/tmp/imageListFile"
rhcosOstreeIndex = 1
rhcosOstreePath = "ostree/deploy/rhcos"
defaultRegistriesConfFile = "/etc/containers/registries.conf"
rhcosOstreeIndex = 1
rhcosOstreePath = "ostree/deploy/rhcos"
)

type IBIPrepare struct {
Expand Down Expand Up @@ -53,7 +57,7 @@ func (i *IBIPrepare) Run() error {
}

i.log.Info("Pulling seed image")
if _, err := i.ops.RunInHostNamespace("podman", "pull", "--authfile", common.IBIPSFile, i.config.SeedImage); err != nil {
if _, err := i.ops.RunInHostNamespace("podman", "pull", "--authfile", common.IBIPullSecretFilePath, i.config.SeedImage); err != nil {
return fmt.Errorf("failed to pull image: %w", err)
}

Expand All @@ -62,15 +66,15 @@ func (i *IBIPrepare) Run() error {
common.OstreeDeployPathPrefix = "/mnt/"
// Setup state root
if err := prep.SetupStateroot(log, i.ops, i.ostreeClient, i.rpmostreeClient,
i.config.SeedImage, i.config.SeedVersion, imageListFile, true); err != nil {
i.config.SeedImage, i.config.SeedVersion, true); err != nil {
return fmt.Errorf("failed to setup stateroot: %w", err)
}

if err := i.precacheFlow(imageListFile); err != nil {
if err := i.precacheFlow(common.ContainersListFilePath, common.IBISeedInfoFilePath, defaultRegistriesConfFile); err != nil {
return fmt.Errorf("failed to precache: %w", err)
}

if err := i.postDeployment(common.PostDeploymentScriptPath); err != nil {
if err := i.postDeployment(common.IBIPostDeploymentScriptPath); err != nil {
return fmt.Errorf("failed to run post deployment: %w", err)
}

Expand All @@ -81,15 +85,34 @@ func (i *IBIPrepare) Run() error {
return i.shutdownNode()
}

func (i *IBIPrepare) precacheFlow(imageListFile string) error {
// TODO: add support for mirror registry
func (i *IBIPrepare) precacheFlow(imageListFile, seedInfoFile, registriesConfFile string) error {
if i.config.PrecacheDisabled {
i.log.Info("Precache disabled, skipping it")
return nil
}

i.log.Info("Precaching imaging")
imageList, err := prep.ReadPrecachingList(imageListFile, "", "", false)
i.log.Info("Checking seed image info")
seedInfo, err := seedclusterinfo.ReadSeedClusterInfoFromFile(seedInfoFile)
if err != nil {
return fmt.Errorf("failed to read seed info: %s, %w", common.PathOutsideChroot(seedInfoFile), err)
}
i.log.Info("Collected seed info for precache: ", fmt.Sprintf("%+v", seedInfo))

i.log.Info("Getting mirror registry source registries")
mirrorRegistrySources, err := mirrorRegistrySourceRegistries(registriesConfFile)
if err != nil {
return fmt.Errorf("failed to get mirror registry source registries: %w", err)
}

i.log.Info("Checking whether to override seed registry")
shouldOverrideSeedRegistry, err := utils.ShouldOverrideSeedRegistry(seedInfo.MirrorRegistryConfigured, seedInfo.ReleaseRegistry, mirrorRegistrySources)
if err != nil {
return fmt.Errorf("failed to check ShouldOverrideSeedRegistry: %w", err)
}
i.log.Info("Should override seed registry", "shouldOverrideSeedRegistry", shouldOverrideSeedRegistry, "releaseRegistry", i.config.ReleaseRegistry)

i.log.Info("Precaching images")
imageList, err := prep.ReadPrecachingList(imageListFile, i.config.ReleaseRegistry, seedInfo.ReleaseRegistry, shouldOverrideSeedRegistry)
if err != nil {
err = fmt.Errorf("failed to read pre-caching image file: %s, %w", common.PathOutsideChroot(imageListFile), err)
return err
Expand All @@ -106,7 +129,7 @@ func (i *IBIPrepare) precacheFlow(imageListFile string) error {
return fmt.Errorf("failed to create status file dir, err %w", err)
}

if err := workload.Precache(imageList, common.IBIPSFile, i.config.PrecacheBestEffort); err != nil {
if err := workload.Precache(imageList, common.IBIPullSecretFilePath, i.config.PrecacheBestEffort); err != nil {
return fmt.Errorf("failed to start precache: %w", err)
}

Expand Down Expand Up @@ -211,3 +234,25 @@ func (i *IBIPrepare) cleanupRhcosSysroot() error {
}
return nil
}

func mirrorRegistrySourceRegistries(registriesConfFile string) ([]string, error) {
content, err := os.ReadFile(registriesConfFile)
if err != nil {
return nil, fmt.Errorf("failed to read registry config file: %w", err)
}

config := &sysregistriesv2.V2RegistriesConf{}

if err := toml.Unmarshal(content, config); err != nil {
return nil, fmt.Errorf("failed to parse registry config: %w", err)
}

sources := make([]string, 0, len(config.Registries))
for _, registry := range config.Registries {
if registry.Location != "" {
sources = append(sources, utils.ExtractRegistryFromImage(registry.Location))
}
}

return sources, nil
}
Loading