Skip to content
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
78 changes: 27 additions & 51 deletions pkg/asset/registry/registriesconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"regexp"

"github.com/containers/image/pkg/sysregistriesv2"
"github.com/openshift/appliance/pkg/asset/config"
Expand Down Expand Up @@ -81,38 +81,9 @@ func (i *RegistriesConf) Generate(_ context.Context, dependencies asset.Parents)
i.fSys = os.DirFS(envConfig.CacheDir)
}

releaseImagesLocation, releaseLocation := i.getEndpointLocations()
registries := &sysregistriesv2.V2RegistriesConf{
Registries: []sysregistriesv2.Registry{
{
Endpoint: sysregistriesv2.Endpoint{
Location: releaseImagesLocation,
},
Mirrors: []sysregistriesv2.Endpoint{
{
Location: fmt.Sprintf("%s:%d/openshift/release-images", RegistryDomain, RegistryPort),
},
// Mirror for the upgrade registry
{
Location: fmt.Sprintf("%s:%d/openshift/release-images", RegistryDomain, RegistryPortUpgrade),
},
},
},
{
Endpoint: sysregistriesv2.Endpoint{
Location: releaseLocation,
},
Mirrors: []sysregistriesv2.Endpoint{
{
Location: fmt.Sprintf("%s:%d/openshift/release", RegistryDomain, RegistryPort),
},
// Mirror for the upgrade registry
{
Location: fmt.Sprintf("%s:%d/openshift/release", RegistryDomain, RegistryPortUpgrade),
},
},
},
},
registries, err := i.generateRegistries()
if err != nil {
return err
}

registriesData, err := toml.Marshal(registries)
Expand All @@ -128,37 +99,42 @@ func (i *RegistriesConf) Generate(_ context.Context, dependencies asset.Parents)
return nil
}

func (i *RegistriesConf) getEndpointLocations() (string, string) {
releaseImagesLocation := "quay.io/openshift-release-dev/ocp-release"
releaseLocation := "quay.io/openshift-release-dev/ocp-v4.0-art-dev"

func (i *RegistriesConf) generateRegistries() (*sysregistriesv2.V2RegistriesConf, error) {
idmsFile, err := fs.ReadFile(i.fSys, idmsFileName)
if err != nil {
logrus.Debugf("missing IDMS yaml (%v), fallback to defaults.", err)
return releaseImagesLocation, releaseLocation
return nil, err
}

idmsManifests, err := agentManifests.GetMultipleYamls[ImageDigestMirrorSet](idmsFile)
if err != nil {
logrus.Debugf("could not decode YAML for %s (%v), fallback to defaults.", idmsFileName, err)
return releaseImagesLocation, releaseLocation
return nil, err
}

regs := &sysregistriesv2.V2RegistriesConf{}

for _, idms := range idmsManifests {
for _, digestMirrors := range idms.Spec.ImageDigestMirrors {
if len(digestMirrors.Mirrors) == 0 {
continue
for _, idmsMirror := range idms.Spec.ImageDigestMirrors {
r := sysregistriesv2.Registry{
Endpoint: sysregistriesv2.Endpoint{
Location: idmsMirror.Source,
},
}
location := digestMirrors.Mirrors[0]
if strings.HasSuffix(location, "release-images") {
releaseImagesLocation = digestMirrors.Source
} else if strings.HasSuffix(location, "release") {
releaseLocation = digestMirrors.Source
logrus.Debugf("adding mirrors for %s", r.Endpoint.Location)
for _, m := range idmsMirror.Mirrors {
re := regexp.MustCompile(`^[^/]+`)
r.Mirrors = append(r.Mirrors, sysregistriesv2.Endpoint{
Location: re.ReplaceAllString(m, fmt.Sprintf("%s:%d", RegistryDomain, RegistryPort)),
})
r.Mirrors = append(r.Mirrors, sysregistriesv2.Endpoint{
Location: re.ReplaceAllString(m, fmt.Sprintf("%s:%d", RegistryDomain, RegistryPortUpgrade)),
})
}
regs.Registries = append(regs.Registries, r)
}
}
logrus.Debugf("endpoints locations: %s, %s", releaseImagesLocation, releaseLocation)
return releaseImagesLocation, releaseLocation

logrus.Debugf("registries generation completed")
return regs, nil
}

func (i *RegistriesConf) Load(f asset.FileFetcher) (bool, error) {
Expand Down
51 changes: 40 additions & 11 deletions pkg/asset/registry/registriesconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ var _ = Describe("Test RegistriesConf", func() {
}
})

It("OpenShift CI like mirror file", func() {
fakeFileSystem[idmsFileName] = createOpenShiftCIMirrorFile()

err := r.Generate(context.Background(), deps)
Expect(err).NotTo(HaveOccurred())
Expect(string(r.File.Data)).To(Equal("unqualified-search-registries = []\n\n[[registry]]\n location = \"quay-proxy.ci.openshift.org/openshift/ci\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift/release\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift/release\"\n\n[[registry]]\n location = \"registry.build05.ci.openshift.org/ci-op-f7f21dkx/stable\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift/release\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift/release\"\n\n[[registry]]\n location = \"registry.build05.ci.openshift.org/ci-op-f7f21dkx/release\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift/release-images\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift/release-images\"\n"))
})

It("Single Yaml", func() {
fakeFileSystem[idmsFileName] = createSingleYamlIDMSMirrorFile()

Expand All @@ -41,16 +49,37 @@ var _ = Describe("Test RegistriesConf", func() {

err := r.Generate(context.Background(), deps)
Expect(err).NotTo(HaveOccurred())
Expect(string(r.File.Data)).Should(ContainSubstring("registry.ci.openshift.org"))
Expect(string(r.File.Data)).To(Equal("unqualified-search-registries = []\n\n[[registry]]\n location = \"registry.redhat.io/container-native-virtualization\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/container-native-virtualization\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/container-native-virtualization\"\n\n[[registry]]\n location = \"registry.redhat.io/openshift4\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift4\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift4\"\n\n[[registry]]\n location = \"registry.redhat.io/workload-availability\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/workload-availability\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/workload-availability\"\n\n[[registry]]\n location = \"registry.redhat.io/migration-toolkit-virtualization\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/migration-toolkit-virtualization\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/migration-toolkit-virtualization\"\n\n[[registry]]\n location = \"registry.redhat.io/kube-descheduler-operator\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/kube-descheduler-operator\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/kube-descheduler-operator\"\n\n[[registry]]\n location = \"registry.ci.openshift.org/ocp/release\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift/release-images\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift/release-images\"\n\n[[registry]]\n location = \"quay.io/openshift-release-dev/ocp-v4.0-art-dev\"\n prefix = \"\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5000/openshift/release\"\n\n [[registry.mirror]]\n location = \"registry.appliance.openshift.com:5001/openshift/release\"\n"))
})

})

func TestRegistriesConf(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "registriesconf_test")
}

// In an OpenShift CI job, the quay-proxy may be also
// present as an additional mirroring location
func createOpenShiftCIMirrorFile() *fstest.MapFile {
return &fstest.MapFile{
Data: []byte(`apiVersion: config.openshift.io/v1
kind: ImageDigestMirrorSet
metadata:
name: idms-release-0
spec:
imageDigestMirrors:
- mirrors:
- 127.0.0.1:5005/openshift/release
source: quay-proxy.ci.openshift.org/openshift/ci
- mirrors:
- 127.0.0.1:5005/openshift/release
source: registry.build05.ci.openshift.org/ci-op-f7f21dkx/stable
- mirrors:
- 127.0.0.1:5005/openshift/release-images
source: registry.build05.ci.openshift.org/ci-op-f7f21dkx/release
status: {}`)}
}

func createSingleYamlIDMSMirrorFile() *fstest.MapFile {
return &fstest.MapFile{
Data: []byte(
Expand All @@ -61,10 +90,10 @@ metadata:
spec:
imageDigestMirrors:
- mirrors:
- registry.appliance.openshift.com:5000/openshift/release-images
- 127.0.0.1:5005/openshift/release-images
source: registry.ci.openshift.org/ocp/release
- mirrors:
- registry.appliance.openshift.com:5000/openshift/release
- 127.0.0.1:5005/openshift/release
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev
status: {}`)}
}
Expand All @@ -78,19 +107,19 @@ metadata:
spec:
imageDigestMirrors:
- mirrors:
- registry.appliance.openshift.com:5000/container-native-virtualization
- 127.0.0.1:5005/container-native-virtualization
source: registry.redhat.io/container-native-virtualization
- mirrors:
- registry.appliance.openshift.com:5000/openshift4
- 127.0.0.1:5005/openshift4
source: registry.redhat.io/openshift4
- mirrors:
- registry.appliance.openshift.com:5000/workload-availability
- 127.0.0.1:5005/workload-availability
source: registry.redhat.io/workload-availability
- mirrors:
- registry.appliance.openshift.com:5000/migration-toolkit-virtualization
- 127.0.0.1:5005/migration-toolkit-virtualization
source: registry.redhat.io/migration-toolkit-virtualization
- mirrors:
- registry.appliance.openshift.com:5000/kube-descheduler-operator
- 127.0.0.1:5005/kube-descheduler-operator
source: registry.redhat.io/kube-descheduler-operator
status: {}
---
Expand All @@ -101,10 +130,10 @@ metadata:
spec:
imageDigestMirrors:
- mirrors:
- registry.appliance.openshift.com:5000/openshift/release-images
- 127.0.0.1:5005/openshift/release-images
source: registry.ci.openshift.org/ocp/release
- mirrors:
- registry.appliance.openshift.com:5000/openshift/release
- 127.0.0.1:5005/openshift/release
source: quay.io/openshift-release-dev/ocp-v4.0-art-dev
status: {}`)}
}