Skip to content

Commit 244ed6f

Browse files
committed
fix copy packages destination to match import images
1 parent 98b0602 commit 244ed6f

File tree

4 files changed

+112
-51
lines changed

4 files changed

+112
-51
lines changed

test/e2e/curatedpackages.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package e2e
66
import (
77
"context"
88
"fmt"
9+
"os"
910
"path/filepath"
1011
"strconv"
1112
"strings"
@@ -51,8 +52,63 @@ func runDisabledCuratedPackageInstallSimpleFlow(test *framework.ClusterE2ETest)
5152
test.WithCluster(runDisabledCuratedPackage)
5253
}
5354

55+
// addDefaultOCINamespacesFromEnv adds default OCI namespaces from environment variables if they're not already set.
56+
func addDefaultOCINamespacesFromEnv(test *framework.ClusterE2ETest) {
57+
if test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration == nil {
58+
return
59+
}
60+
61+
if len(test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces) > 0 {
62+
return
63+
}
64+
65+
// Check if the required env vars are set before calling DefaultOciNamespaces
66+
if os.Getenv(framework.RegistryMirrorOciNamespacesRegistry1Var) == "" ||
67+
os.Getenv(framework.RegistryMirrorOciNamespacesNamespace1Var) == "" {
68+
return
69+
}
70+
71+
test.T.Log("Adding default OCI namespaces from environment variables")
72+
test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces = framework.DefaultOciNamespaces(test)
73+
}
74+
5475
func runCuratedPackageInstallSimpleFlowRegistryMirror(test *framework.ClusterE2ETest) {
55-
test.WithClusterRegistryMirror(EksaPackagesRegistryMirrorAlias, EksaPackagesSourceRegistry, EksaPackagesRegistry, runCuratedPackageInstall)
76+
test.GenerateClusterConfig()
77+
test.DownloadArtifacts()
78+
test.ExtractDownloadedArtifacts()
79+
80+
// Determine the correct alias from the bundle after download
81+
alias, err := test.DeterminePackageRegistryAlias()
82+
if err != nil {
83+
test.T.Fatalf("Failed to determine package registry alias: %v", err)
84+
}
85+
test.T.Logf("Using registry alias: %s for curated packages", alias)
86+
87+
// Add default OCI namespaces from env vars, then append the curated packages one
88+
if test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration != nil {
89+
addDefaultOCINamespacesFromEnv(test)
90+
91+
test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces = append(
92+
test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces,
93+
v1alpha1.OCINamespace{
94+
Registry: EksaPackagesRegistry,
95+
Namespace: alias,
96+
},
97+
)
98+
}
99+
test.UpdateClusterConfig()
100+
101+
test.DownloadImages()
102+
test.ImportImages()
103+
test.CopyPackages(alias, EksaPackagesSourceRegistry, EksaPackagesRegistry)
104+
105+
bundlePath := "./eks-anywhere-downloads/bundle-release.yaml"
106+
test.CreateCluster(framework.WithBundlesOverride(bundlePath))
107+
defer func() {
108+
test.GenerateSupportBundleIfTestFailed()
109+
test.DeleteCluster(framework.WithBundlesOverride(bundlePath))
110+
}()
111+
runCuratedPackageInstall(test)
56112
}
57113

58114
func runCuratedPackageRemoteClusterInstallSimpleFlow(test *framework.MulticlusterE2ETest) {

test/e2e/vsphere_test.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,11 +2931,7 @@ func TestVSphereKubernetes129UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
29312931
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
29322932
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
29332933
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube129)),
2934-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
2935-
v1alpha1.OCINamespace{
2936-
Registry: EksaPackagesRegistry,
2937-
Namespace: EksaPackagesRegistryMirrorAlias,
2938-
}),
2934+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
29392935
)
29402936
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
29412937
}
@@ -2949,11 +2945,7 @@ func TestVSphereKubernetes134UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
29492945
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
29502946
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
29512947
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube134)),
2952-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
2953-
v1alpha1.OCINamespace{
2954-
Registry: EksaPackagesRegistry,
2955-
Namespace: EksaPackagesRegistryMirrorAlias,
2956-
}),
2948+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
29572949
)
29582950
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
29592951
}
@@ -2967,11 +2959,7 @@ func TestVSphereKubernetes130UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
29672959
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
29682960
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
29692961
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube130)),
2970-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
2971-
v1alpha1.OCINamespace{
2972-
Registry: EksaPackagesRegistry,
2973-
Namespace: EksaPackagesRegistryMirrorAlias,
2974-
}),
2962+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
29752963
)
29762964
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
29772965
}
@@ -2985,11 +2973,7 @@ func TestVSphereKubernetes131UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
29852973
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
29862974
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
29872975
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube131)),
2988-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
2989-
v1alpha1.OCINamespace{
2990-
Registry: EksaPackagesRegistry,
2991-
Namespace: EksaPackagesRegistryMirrorAlias,
2992-
}),
2976+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
29932977
)
29942978
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
29952979
}
@@ -3003,11 +2987,7 @@ func TestVSphereKubernetes132UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
30032987
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
30042988
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
30052989
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube132)),
3006-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
3007-
v1alpha1.OCINamespace{
3008-
Registry: EksaPackagesRegistry,
3009-
Namespace: EksaPackagesRegistryMirrorAlias,
3010-
}),
2990+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
30112991
)
30122992
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
30132993
}
@@ -3021,11 +3001,7 @@ func TestVSphereKubernetes133UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
30213001
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
30223002
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
30233003
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube133)),
3024-
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
3025-
v1alpha1.OCINamespace{
3026-
Registry: EksaPackagesRegistry,
3027-
Namespace: EksaPackagesRegistryMirrorAlias,
3028-
}),
3004+
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
30293005
)
30303006
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
30313007
}

test/framework/cluster.go

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,50 @@ func (e *ClusterE2ETest) ImportImages(opts ...CommandOpt) {
686686
e.RunEKSA(importImagesArgs, opts...)
687687
}
688688

689+
// DeterminePackageRegistryAlias determines the correct registry alias based on the bundle's package controller chart image.
690+
// It returns the alias to use for registry mirror destination paths (x3k6m8v0 for dev, w9m0f3l5 for staging, eks-anywhere for prod).
691+
func (e *ClusterE2ETest) DeterminePackageRegistryAlias() (string, error) {
692+
var bundleManifestLocation string
693+
if _, err := os.Stat(defaultDownloadArtifactsOutputLocation); err == nil {
694+
bundleManifestLocation = bundleReleasePathFromArtifacts
695+
} else {
696+
bundleManifestLocation = defaultBundleReleaseManifestFile
697+
}
698+
699+
// Read the bundle file
700+
bundleData, err := os.ReadFile(bundleManifestLocation)
701+
if err != nil {
702+
return "", fmt.Errorf("failed to read bundle file %s: %w", bundleManifestLocation, err)
703+
}
704+
705+
// Parse the bundle
706+
var bundles releasev1.Bundles
707+
if err := yaml.Unmarshal(bundleData, &bundles); err != nil {
708+
return "", fmt.Errorf("failed to parse bundle file: %w", err)
709+
}
710+
711+
// Get the package controller chart image from the first version bundle
712+
if len(bundles.Spec.VersionsBundles) == 0 {
713+
return "", fmt.Errorf("no version bundles found in bundle file")
714+
}
715+
716+
// Image() returns the URI without the tag: registry/alias/image-name
717+
// Example: public.ecr.aws/x3k6m8v0/eks-anywhere-packages
718+
// We want to extract "x3k6m8v0" (the second-to-last path component)
719+
packageControllerImage := bundles.Spec.VersionsBundles[0].PackageController.HelmChart.Image()
720+
721+
// Split by '/' and get the second-to-last component
722+
// We need at least 3 parts: registry, alias, and image name
723+
parts := strings.Split(packageControllerImage, "/")
724+
if len(parts) < 3 {
725+
return "", fmt.Errorf("invalid package controller image format: %s", packageControllerImage)
726+
}
727+
728+
// The alias is the second-to-last component (last is eks-anywhere-packages)
729+
alias := parts[len(parts)-2]
730+
return alias, nil
731+
}
732+
689733
// CopyPackages runs the EKS-A `copy packages` command to copy curated packages to the registry mirror.
690734
func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageChartRegistry string, packageRegistry string, opts ...CommandOpt) {
691735
clusterConfig := e.ClusterConfig.Cluster
@@ -705,7 +749,7 @@ func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageChartReg
705749
"--dst-insecure",
706750
}
707751

708-
e.T.Logf("Copying curated packages to registry mirror: %s", registryMirrorHost)
752+
e.T.Logf("Copying curated packages to registry mirror: %s/%s", registryMirrorHost, packageMirrorAlias)
709753
e.RunEKSA(copyPackagesArgs, opts...)
710754
}
711755

@@ -1327,22 +1371,6 @@ func (e *ClusterE2ETest) WithCluster(f func(e *ClusterE2ETest)) {
13271371
f(e)
13281372
}
13291373

1330-
// WithClusterRegistryMirror helps with bringing up and tearing down E2E test clusters when using registry mirror.
1331-
func (e *ClusterE2ETest) WithClusterRegistryMirror(packageMirrorAlias string, packageChartRegistry string, packageRegistry string, f func(e *ClusterE2ETest)) {
1332-
e.GenerateClusterConfig()
1333-
e.DownloadArtifacts()
1334-
e.ExtractDownloadedArtifacts()
1335-
e.DownloadImages()
1336-
e.ImportImages()
1337-
e.CopyPackages(packageMirrorAlias, packageChartRegistry, packageRegistry)
1338-
e.CreateCluster(WithBundlesOverride(bundleReleasePathFromArtifacts))
1339-
defer func() {
1340-
e.GenerateSupportBundleIfTestFailed()
1341-
e.DeleteCluster(WithBundlesOverride(bundleReleasePathFromArtifacts))
1342-
}()
1343-
f(e)
1344-
}
1345-
13461374
// Like WithCluster but does not delete the cluster. Useful for debugging.
13471375
func (e *ClusterE2ETest) WithPersistentCluster(f func(e *ClusterE2ETest)) {
13481376
configPath := e.KubeconfigFilePath()

test/framework/registry_mirror.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ func WithRegistryMirrorEndpointAndCert(providerName string) ClusterE2ETestOpt {
6767
// WithRegistryMirrorOciNamespaces sets up e2e for registry mirrors with ocinamespaces.
6868
func WithRegistryMirrorOciNamespaces(providerName string) ClusterE2ETestOpt {
6969
return func(e *ClusterE2ETest) {
70-
ociNamespaces := defaultOciNamespaces(e)
70+
ociNamespaces := DefaultOciNamespaces(e)
7171
setupRegistryMirrorEndpointAndCert(e, providerName, false, ociNamespaces...)
7272
}
7373
}
7474

75-
func defaultOciNamespaces(e *ClusterE2ETest) []v1alpha1.OCINamespace {
75+
// DefaultOciNamespaces returns the default OCI namespaces from environment variables.
76+
func DefaultOciNamespaces(e *ClusterE2ETest) []v1alpha1.OCINamespace {
7677
var ociNamespaces []v1alpha1.OCINamespace
7778

7879
checkRequiredEnvVars(e.T, registryMirrorOciNamespacesRequiredEnvVars)
@@ -139,7 +140,7 @@ func WithAuthenticatedRegistryMirror(providerName string, optNamespaces ...v1alp
139140

140141
var ociNamespaces []v1alpha1.OCINamespace
141142
if len(optNamespaces) > 0 {
142-
ociNamespaces = append(defaultOciNamespaces(e), optNamespaces...)
143+
ociNamespaces = append(DefaultOciNamespaces(e), optNamespaces...)
143144
}
144145

145146
certificate, err := base64.StdEncoding.DecodeString(registryCert)

0 commit comments

Comments
 (0)