Skip to content

Commit

Permalink
Fix OCPBUGS-17546: pod catalogsource generated by oc-mirror will cras…
Browse files Browse the repository at this point in the history
…hloopBackOff randomly (#699)

Co-authored-by: skhoury <skhoury@redhat.com>
  • Loading branch information
openshift-cherrypick-robot and sherine-k committed Sep 21, 2023
1 parent 00c48bb commit b45e623
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
25 changes: 6 additions & 19 deletions pkg/cli/mirror/catalog_images.go
Expand Up @@ -225,7 +225,7 @@ func (o *MirrorOptions) processCatalogRefs(ctx context.Context, catalogsByImage
return fmt.Errorf("unable to determine location of cache for image %s. Cache generation failed: %v", ctlgRef, err)
}

configLayerToAdd, err := builder.LayerFromPath("/configs", filepath.Join(artifactDir, config.IndexDir, "index.json"))
configLayerToAdd, err := builder.LayerFromPathWithUidGid("/configs", filepath.Join(artifactDir, config.IndexDir), 0, 0)
if err != nil {
return fmt.Errorf("error creating add layer: %v", err)
}
Expand All @@ -240,20 +240,6 @@ func (o *MirrorOptions) processCatalogRefs(ctx context.Context, catalogsByImage
layersToDelete = append(layersToDelete, deletedConfigLayer)

if withCacheRegeneration {
// read the location of the cache
dat, err := os.ReadFile(filepath.Join(artifactDir, config.OPMCacheLocationPlaceholder))
if err != nil {
return fmt.Errorf("unable to determine location of cache for image %s. Cache generation failed: %v", ctlgRef, err)
}
cacheLocation := string(dat)
cacheLocationElmts := strings.Split(strings.TrimPrefix(cacheLocation, string(os.PathSeparator)), string(os.PathSeparator))

// white out layer /tmp
deletedCacheLayer, err := deleteLayer("/.wh." + cacheLocationElmts[0])
if err != nil {
return fmt.Errorf("error creating deleted cache layer: %v", err)
}
layersToDelete = append(layersToDelete, deletedCacheLayer)

opmCmdPath := filepath.Join(artifactDir, config.OpmBinDir, "opm")
_, err = os.Stat(opmCmdPath)
Expand All @@ -272,7 +258,9 @@ func (o *MirrorOptions) processCatalogRefs(ctx context.Context, catalogsByImage
if err := cmd.Run(); err != nil {
return fmt.Errorf("error regenerating the cache for %v: %v", ctlgRef, err)
}
cacheLayerToAdd, err := builder.LayerFromPathWithUidGid("/tmp/cache", filepath.Join(artifactDir, config.TmpDir), cacheFolderUID, cacheFolderGID)
// Fix OCPBUGS-17546:
// Add the cache under /cache in a new layer (instead of white-out /tmp/cache, which resulted in crashLoopBackoff only on some clusters)
cacheLayerToAdd, err := builder.LayerFromPathWithUidGid("/cache", filepath.Join(artifactDir, config.TmpDir), cacheFolderUID, cacheFolderGID)
if err != nil {
return fmt.Errorf("error creating add layer: %v", err)
}
Expand All @@ -298,10 +286,9 @@ func (o *MirrorOptions) processCatalogRefs(ctx context.Context, catalogsByImage
}
cfg.Config.Labels = labels
// Although it was prefered to keep the entrypoint and command as it was
// we couldnt guarantie that the cache-dir was /tmp/cache, and therefore
// we had to specify the command for the newly built catalog
// we couldnt reuse /tmp/cache as the cache directory (OCPBUGS-17546)
if withCacheRegeneration {
cfg.Config.Cmd = []string{"serve", "/configs", "--cache-dir=/tmp/cache"}
cfg.Config.Cmd = []string{"serve", "/configs", "--cache-dir=/cache"}
} else { // this means that no cache was found in the original catalog (old catalog with opm < 1.25)
cfg.Config.Cmd = []string{"serve", "/configs"}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/image/builder/image_builder.go
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/go-logr/logr"
"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -361,7 +362,7 @@ func LayerFromPathWithUidGid(targetPath, path string, uid int, gid int) (v1.Laye
if !info.IsDir() {
hdr.Size = info.Size()
}

hdr.ChangeTime = time.Now()
if info.Mode().IsDir() {
hdr.Typeflag = tar.TypeDir
} else if info.Mode().IsRegular() {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/lib/check.sh
Expand Up @@ -26,9 +26,9 @@ function check_bundles() {
mv index.json $index_dir

# extract the cache from the tar file
local cache_dir="${extraction_dir}/tmp/cache"
tar xvf $extraction_dir/temp.tar /tmp
mv tmp "${extraction_dir}"
local cache_dir="${extraction_dir}/cache"
tar xvf $extraction_dir/temp.tar /cache
mv cache "${extraction_dir}"

# extract the opm binary from the tar file
local opm_path="${extraction_dir}/opm"
Expand Down

0 comments on commit b45e623

Please sign in to comment.