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
4 changes: 2 additions & 2 deletions pkg/executables/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ func (k *Kubectl) ValidatePods(ctx context.Context, kubeconfig string) error {
}

// RunCurlPod will run Kubectl with an image (with curl installed) and the command you pass in.
func (k *Kubectl) RunCurlPod(ctx context.Context, namespace, name, kubeconfig string, command []string) (string, error) {
params := []string{"run", name, "--image=public.ecr.aws/eks-anywhere/diagnostic-collector:v0.16.2-eks-a-41", "-o", "json", "--kubeconfig", kubeconfig, "--namespace", namespace, "--restart=Never", "--"}
func (k *Kubectl) RunCurlPod(ctx context.Context, namespace, name, kubeconfig, image string, command []string) (string, error) {
params := []string{"run", name, "--image=" + image, "-o", "json", "--kubeconfig", kubeconfig, "--namespace", namespace, "--restart=Never", "--"}
params = append(params, command...)
_, err := k.Execute(ctx, params...)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/executables/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3763,9 +3763,10 @@ func TestRunCurlPod(t *testing.T) {
t.Parallel()
tt := newKubectlTest(t)
var b bytes.Buffer
expectedParam := []string{"run", "testpod-123", "--image=public.ecr.aws/eks-anywhere/diagnostic-collector:v0.16.2-eks-a-41", "-o", "json", "--kubeconfig", "c.kubeconfig", "--namespace", "eksa-packages", "--restart=Never", "--", "pwd"}
testImage := "public.ecr.aws/eks-anywhere/diagnostic-collector:v0.16.2-eks-a-41"
expectedParam := []string{"run", "testpod-123", "--image=" + testImage, "-o", "json", "--kubeconfig", "c.kubeconfig", "--namespace", "eksa-packages", "--restart=Never", "--", "pwd"}
tt.e.EXPECT().Execute(gomock.Any(), gomock.Eq(expectedParam)).Return(b, nil).AnyTimes()
if _, err := tt.k.RunCurlPod(tt.ctx, "eksa-packages", "testpod-123", tt.cluster.KubeconfigFile, []string{"pwd"}); err != nil {
if _, err := tt.k.RunCurlPod(tt.ctx, "eksa-packages", "testpod-123", tt.cluster.KubeconfigFile, testImage, []string{"pwd"}); err != nil {
t.Errorf("Kubectl.RunCurlPod() error = %v, want nil", err)
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

const (
EksaPackagesRegistryMirrorAlias = "curated-packages"
EksaPackagesSourceRegistry = "public.ecr.aws/x3k6m8v0"
EksaPackageBundleURI = "oci://" + EksaPackagesSourceRegistry + "/eks-anywhere-packages-bundles"
EksaPackagesNamespace = "eksa-packages"
EksaPackagesRegistry = "067575901363.dkr.ecr.us-west-2.amazonaws.com"
EksaPackagesDevPublicRegistryAlias = "x3k6m8v0"
EksaPackagesStagingPublicRegistryAlias = "w9m0f3l5"
EksaPackagesDevPrivateRegistry = "067575901363.dkr.ecr.us-west-2.amazonaws.com"
EksaPackagesStagingPrivateRegistry = "724423470321.dkr.ecr.us-west-2.amazonaws.com"
EksaPackagesNamespace = "eksa-packages"

clusterNamespace = "test-namespace"

Expand Down
71 changes: 61 additions & 10 deletions test/e2e/curatedpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (

func runCuratedPackageInstall(test *framework.ClusterE2ETest) {
test.SetPackageBundleActive()
err := WaitForPackageToBeInstalled(test, context.Background(), "eks-anywhere-packages", 3*time.Minute)
err := WaitForPackageToBeInstalled(test, context.Background(), "eks-anywhere-packages", 15*time.Minute)
if err != nil {
test.T.Fatalf("packages controller not in installed state: %s", err)
}
err = WaitForPackageToBeInstalled(test, context.Background(), "eks-anywhere-packages-crds", 3*time.Minute)
err = WaitForPackageToBeInstalled(test, context.Background(), "eks-anywhere-packages-crds", 15*time.Minute)
if err != nil {
test.T.Fatalf("packages controller crds not in installed state: %s", err)
}
Expand All @@ -51,8 +51,66 @@ func runDisabledCuratedPackageInstallSimpleFlow(test *framework.ClusterE2ETest)
test.WithCluster(runDisabledCuratedPackage)
}

// addDefaultOCINamespacesFromEnv adds default OCI namespaces from environment variables if they're not already set.
func addDefaultOCINamespacesFromEnv(test *framework.ClusterE2ETest) {
if test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration == nil {
return
}

if len(test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces) > 0 {
return
}

test.T.Log("Adding default OCI namespaces from environment variables")
test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces = framework.DefaultOciNamespaces(test)
}

func runCuratedPackageInstallSimpleFlowRegistryMirror(test *framework.ClusterE2ETest) {
test.WithClusterRegistryMirror(EksaPackagesRegistryMirrorAlias, EksaPackagesSourceRegistry, EksaPackagesRegistry, runCuratedPackageInstall)
test.GenerateClusterConfig()
test.DownloadArtifacts()
test.ExtractDownloadedArtifacts()

// Determine the correct alias from the bundle after download
packageControllerChartRepo, err := test.GetPackageControlleChartRepo()
if err != nil {
test.T.Fatalf("Failed to determine package controller repo: %v", err)
}

var pkgRegistry, alias string
if strings.Contains(packageControllerChartRepo, EksaPackagesDevPublicRegistryAlias) {
pkgRegistry = EksaPackagesDevPrivateRegistry
alias = EksaPackagesDevPublicRegistryAlias
}
if strings.Contains(packageControllerChartRepo, EksaPackagesStagingPublicRegistryAlias) {
pkgRegistry = EksaPackagesStagingPrivateRegistry
alias = EksaPackagesStagingPublicRegistryAlias
}

// Add default OCI namespaces from env vars, then append the curated packages one
if test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration != nil {
addDefaultOCINamespacesFromEnv(test)

test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces = append(
test.ClusterConfig.Cluster.Spec.RegistryMirrorConfiguration.OCINamespaces,
v1alpha1.OCINamespace{
Registry: pkgRegistry,
Namespace: alias,
},
)
}
test.UpdateClusterConfig()

test.DownloadImages()
test.ImportImages()
test.CopyPackages(alias, pkgRegistry)

bundlePath := "./eks-anywhere-downloads/bundle-release.yaml"
test.CreateCluster(framework.WithBundlesOverride(bundlePath))
defer func() {
test.GenerateSupportBundleIfTestFailed()
test.DeleteCluster(framework.WithBundlesOverride(bundlePath))
}()
runCuratedPackageInstall(test)
}

func runCuratedPackageRemoteClusterInstallSimpleFlow(test *framework.MulticlusterE2ETest) {
Expand Down Expand Up @@ -215,13 +273,6 @@ func GetLatestBundleFromCluster(test *framework.ClusterE2ETest) (string, error)
return strings.Trim(bundle, "'"), nil
}

// packageBundleURI uses a KubernetesVersion argument to complete a package
// bundle URI by adding the approprate tag.
func packageBundleURI(version v1alpha1.KubernetesVersion) string {
tag := "v" + strings.Replace(string(version), ".", "-", 1) + "-latest"
return fmt.Sprintf("%s:%s", EksaPackageBundleURI, tag)
}

func withCluster(cluster *framework.ClusterE2ETest) *types.Cluster {
return &types.Cluster{
Name: cluster.ClusterName,
Expand Down
36 changes: 6 additions & 30 deletions test/e2e/vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2930,11 +2930,7 @@ func TestVSphereKubernetes129UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube129)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand All @@ -2948,11 +2944,7 @@ func TestVSphereKubernetes134UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube134)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand All @@ -2966,11 +2958,7 @@ func TestVSphereKubernetes130UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube130)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand All @@ -2984,11 +2972,7 @@ func TestVSphereKubernetes131UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube131)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand All @@ -3002,11 +2986,7 @@ func TestVSphereKubernetes132UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube132)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand All @@ -3020,11 +3000,7 @@ func TestVSphereKubernetes133UbuntuAuthenticatedRegistryMirrorCuratedPackagesSim
framework.WithClusterFiller(api.WithWorkerNodeCount(1)),
framework.WithClusterFiller(api.WithExternalEtcdTopology(1)),
framework.WithClusterFiller(api.WithKubernetesVersion(v1alpha1.Kube133)),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName,
v1alpha1.OCINamespace{
Registry: EksaPackagesRegistry,
Namespace: EksaPackagesRegistryMirrorAlias,
}),
framework.WithAuthenticatedRegistryMirror(constants.VSphereProviderName),
)
runCuratedPackageInstallSimpleFlowRegistryMirror(test)
}
Expand Down
103 changes: 70 additions & 33 deletions test/framework/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,17 +651,18 @@ func (e *ClusterE2ETest) CleanupDownloadedArtifactsAndImages(opts ...CommandOpt)
e.Run("rm", "-rf", defaultDownloadArtifactsOutputLocation, defaultDownloadImagesOutputLocation)
}

func getBundleManifestLocation() string {
if _, err := os.Stat(defaultDownloadArtifactsOutputLocation); err == nil {
return bundleReleasePathFromArtifacts
}
return defaultBundleReleaseManifestFile
}

// DownloadImages runs the EKS-A `download images` command with appropriate args.
func (e *ClusterE2ETest) DownloadImages(opts ...CommandOpt) {
downloadImagesArgs := []string{"download", "images", "-o", defaultDownloadImagesOutputLocation}
if getBundlesOverride() == "true" {
var bundleManifestLocation string
if _, err := os.Stat(defaultDownloadArtifactsOutputLocation); err == nil {
bundleManifestLocation = bundleReleasePathFromArtifacts
} else {
bundleManifestLocation = defaultBundleReleaseManifestFile
}
downloadImagesArgs = append(downloadImagesArgs, "--bundles-override", bundleManifestLocation)
downloadImagesArgs = append(downloadImagesArgs, "--bundles-override", getBundleManifestLocation())
}
e.RunEKSA(downloadImagesArgs, opts...)
if _, err := os.Stat(defaultDownloadImagesOutputLocation); err != nil {
Expand All @@ -676,18 +677,67 @@ func (e *ClusterE2ETest) ImportImages(opts ...CommandOpt) {
clusterConfig := e.ClusterConfig.Cluster
registyMirrorEndpoint, registryMirrorPort := clusterConfig.Spec.RegistryMirrorConfiguration.Endpoint, clusterConfig.Spec.RegistryMirrorConfiguration.Port
registryMirrorHost := net.JoinHostPort(registyMirrorEndpoint, registryMirrorPort)
var bundleManifestLocation string
if _, err := os.Stat(defaultDownloadArtifactsOutputLocation); err == nil {
bundleManifestLocation = bundleReleasePathFromArtifacts
} else {
bundleManifestLocation = defaultBundleReleaseManifestFile
}
bundleManifestLocation := getBundleManifestLocation()
importImagesArgs := []string{"import images", "--input", defaultDownloadImagesOutputLocation, "--bundles", bundleManifestLocation, "--registry", registryMirrorHost, "--insecure"}
e.RunEKSA(importImagesArgs, opts...)
}

// GetDiagnosticCollectorImage returns the diagnostic collector image from the bundle file,
// or falls back to a hardcoded URI if reading from disk fails.
func (e *ClusterE2ETest) GetDiagnosticCollectorImage() string {
const fallbackImage = "public.ecr.aws/eks-anywhere/diagnostic-collector:v0.16.2-eks-a-41"

bundleManifestLocation := getBundleManifestLocation()

// Try to read the bundle file
bundleData, err := os.ReadFile(bundleManifestLocation)
if err != nil {
e.T.Logf("Could not read bundle file, using fallback image: %v", err)
return fallbackImage
}

// Try to parse the bundle
var bundles releasev1.Bundles
if err := yaml.Unmarshal(bundleData, &bundles); err != nil {
e.T.Logf("Could not parse bundle file, using fallback image: %v", err)
return fallbackImage
}

// Check if version bundles exist
if len(bundles.Spec.VersionsBundles) == 0 {
e.T.Log("No version bundles found in bundle file, using fallback image")
return fallbackImage
}

return bundles.Spec.VersionsBundles[0].Eksa.DiagnosticCollector.VersionedImage()
}

// GetPackageControllerRepo returns the bundle's package controller chart image.
func (e *ClusterE2ETest) GetPackageControlleChartRepo() (string, error) {
bundleManifestLocation := getBundleManifestLocation()

// Read the bundle file
bundleData, err := os.ReadFile(bundleManifestLocation)
if err != nil {
return "", fmt.Errorf("failed to read bundle file %s: %w", bundleManifestLocation, err)
}

// Parse the bundle
var bundles releasev1.Bundles
if err := yaml.Unmarshal(bundleData, &bundles); err != nil {
return "", fmt.Errorf("failed to parse bundle file: %w", err)
}

// Get the package controller chart image from the first version bundle
if len(bundles.Spec.VersionsBundles) == 0 {
return "", fmt.Errorf("no version bundles found in bundle file")
}

return bundles.Spec.VersionsBundles[0].PackageController.HelmChart.Image(), nil
}

// CopyPackages runs the EKS-A `copy packages` command to copy curated packages to the registry mirror.
func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageChartRegistry string, packageRegistry string, opts ...CommandOpt) {
func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageRegistry string, opts ...CommandOpt) {
clusterConfig := e.ClusterConfig.Cluster
registyMirrorEndpoint, registryMirrorPort := clusterConfig.Spec.RegistryMirrorConfiguration.Endpoint, clusterConfig.Spec.RegistryMirrorConfiguration.Port
registryMirrorHost := net.JoinHostPort(registyMirrorEndpoint, registryMirrorPort)
Expand All @@ -700,12 +750,12 @@ func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageChartReg
"copy", "packages",
registryMirrorHost + "/" + packageMirrorAlias,
"--kube-version", kubeVersion,
"--src-chart-registry", packageChartRegistry,
"--src-chart-registry", packageRegistry,
"--src-image-registry", packageRegistry,
"--dst-insecure",
}

e.T.Logf("Copying curated packages to registry mirror: %s", registryMirrorHost)
e.T.Logf("Copying curated packages to registry mirror: %s/%s", registryMirrorHost, packageMirrorAlias)
e.RunEKSA(copyPackagesArgs, opts...)
}

Expand Down Expand Up @@ -1327,22 +1377,6 @@ func (e *ClusterE2ETest) WithCluster(f func(e *ClusterE2ETest)) {
f(e)
}

// WithClusterRegistryMirror helps with bringing up and tearing down E2E test clusters when using registry mirror.
func (e *ClusterE2ETest) WithClusterRegistryMirror(packageMirrorAlias string, packageChartRegistry string, packageRegistry string, f func(e *ClusterE2ETest)) {
e.GenerateClusterConfig()
e.DownloadArtifacts()
e.ExtractDownloadedArtifacts()
e.DownloadImages()
e.ImportImages()
e.CopyPackages(packageMirrorAlias, packageChartRegistry, packageRegistry)
e.CreateCluster(WithBundlesOverride(bundleReleasePathFromArtifacts))
defer func() {
e.GenerateSupportBundleIfTestFailed()
e.DeleteCluster(WithBundlesOverride(bundleReleasePathFromArtifacts))
}()
f(e)
}

// Like WithCluster but does not delete the cluster. Useful for debugging.
func (e *ClusterE2ETest) WithPersistentCluster(f func(e *ClusterE2ETest)) {
configPath := e.KubeconfigFilePath()
Expand Down Expand Up @@ -2188,10 +2222,13 @@ func (e *ClusterE2ETest) ApplyPackageFile(packageName, targetNamespace string, P
func (e *ClusterE2ETest) CurlEndpoint(endpoint, namespace string, extraCurlArgs ...string) string {
ctx := context.Background()

diagnosticCollectorImage := e.GetDiagnosticCollectorImage()

e.T.Log("Launching pod to curl endpoint", endpoint)
randomname := fmt.Sprintf("%s-%s", "curl-test", utilrand.String(7))
curlPodName, err := e.KubectlClient.RunCurlPod(context.TODO(),
namespace, randomname, e.KubeconfigFilePath(), append([]string{"curl", endpoint}, extraCurlArgs...))
namespace, randomname, e.KubeconfigFilePath(), diagnosticCollectorImage,
append([]string{"curl", endpoint}, extraCurlArgs...))
if err != nil {
e.T.Fatalf("error launching pod: %s", err)
}
Expand Down
7 changes: 4 additions & 3 deletions test/framework/registry_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ func WithRegistryMirrorEndpointAndCert(providerName string) ClusterE2ETestOpt {
// WithRegistryMirrorOciNamespaces sets up e2e for registry mirrors with ocinamespaces.
func WithRegistryMirrorOciNamespaces(providerName string) ClusterE2ETestOpt {
return func(e *ClusterE2ETest) {
ociNamespaces := defaultOciNamespaces(e)
ociNamespaces := DefaultOciNamespaces(e)
setupRegistryMirrorEndpointAndCert(e, providerName, false, ociNamespaces...)
}
}

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

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

var ociNamespaces []v1alpha1.OCINamespace
if len(optNamespaces) > 0 {
ociNamespaces = append(defaultOciNamespaces(e), optNamespaces...)
ociNamespaces = append(DefaultOciNamespaces(e), optNamespaces...)
}

certificate, err := base64.StdEncoding.DecodeString(registryCert)
Expand Down
Loading