@@ -651,17 +651,18 @@ func (e *ClusterE2ETest) CleanupDownloadedArtifactsAndImages(opts ...CommandOpt)
651651 e .Run ("rm" , "-rf" , defaultDownloadArtifactsOutputLocation , defaultDownloadImagesOutputLocation )
652652}
653653
654+ func getBundleManifestLocation () string {
655+ if _ , err := os .Stat (defaultDownloadArtifactsOutputLocation ); err == nil {
656+ return bundleReleasePathFromArtifacts
657+ }
658+ return defaultBundleReleaseManifestFile
659+ }
660+
654661// DownloadImages runs the EKS-A `download images` command with appropriate args.
655662func (e * ClusterE2ETest ) DownloadImages (opts ... CommandOpt ) {
656663 downloadImagesArgs := []string {"download" , "images" , "-o" , defaultDownloadImagesOutputLocation }
657664 if getBundlesOverride () == "true" {
658- var bundleManifestLocation string
659- if _ , err := os .Stat (defaultDownloadArtifactsOutputLocation ); err == nil {
660- bundleManifestLocation = bundleReleasePathFromArtifacts
661- } else {
662- bundleManifestLocation = defaultBundleReleaseManifestFile
663- }
664- downloadImagesArgs = append (downloadImagesArgs , "--bundles-override" , bundleManifestLocation )
665+ downloadImagesArgs = append (downloadImagesArgs , "--bundles-override" , getBundleManifestLocation ())
665666 }
666667 e .RunEKSA (downloadImagesArgs , opts ... )
667668 if _ , err := os .Stat (defaultDownloadImagesOutputLocation ); err != nil {
@@ -676,18 +677,67 @@ func (e *ClusterE2ETest) ImportImages(opts ...CommandOpt) {
676677 clusterConfig := e .ClusterConfig .Cluster
677678 registyMirrorEndpoint , registryMirrorPort := clusterConfig .Spec .RegistryMirrorConfiguration .Endpoint , clusterConfig .Spec .RegistryMirrorConfiguration .Port
678679 registryMirrorHost := net .JoinHostPort (registyMirrorEndpoint , registryMirrorPort )
679- var bundleManifestLocation string
680- if _ , err := os .Stat (defaultDownloadArtifactsOutputLocation ); err == nil {
681- bundleManifestLocation = bundleReleasePathFromArtifacts
682- } else {
683- bundleManifestLocation = defaultBundleReleaseManifestFile
684- }
680+ bundleManifestLocation := getBundleManifestLocation ()
685681 importImagesArgs := []string {"import images" , "--input" , defaultDownloadImagesOutputLocation , "--bundles" , bundleManifestLocation , "--registry" , registryMirrorHost , "--insecure" }
686682 e .RunEKSA (importImagesArgs , opts ... )
687683}
688684
685+ // GetDiagnosticCollectorImage returns the diagnostic collector image from the bundle file,
686+ // or falls back to a hardcoded URI if reading from disk fails.
687+ func (e * ClusterE2ETest ) GetDiagnosticCollectorImage () string {
688+ const fallbackImage = "public.ecr.aws/eks-anywhere/diagnostic-collector:v0.16.2-eks-a-41"
689+
690+ bundleManifestLocation := getBundleManifestLocation ()
691+
692+ // Try to read the bundle file
693+ bundleData , err := os .ReadFile (bundleManifestLocation )
694+ if err != nil {
695+ e .T .Logf ("Could not read bundle file, using fallback image: %v" , err )
696+ return fallbackImage
697+ }
698+
699+ // Try to parse the bundle
700+ var bundles releasev1.Bundles
701+ if err := yaml .Unmarshal (bundleData , & bundles ); err != nil {
702+ e .T .Logf ("Could not parse bundle file, using fallback image: %v" , err )
703+ return fallbackImage
704+ }
705+
706+ // Check if version bundles exist
707+ if len (bundles .Spec .VersionsBundles ) == 0 {
708+ e .T .Log ("No version bundles found in bundle file, using fallback image" )
709+ return fallbackImage
710+ }
711+
712+ return bundles .Spec .VersionsBundles [0 ].Eksa .DiagnosticCollector .VersionedImage ()
713+ }
714+
715+ // GetPackageControllerRepo returns the bundle's package controller chart image.
716+ func (e * ClusterE2ETest ) GetPackageControlleChartRepo () (string , error ) {
717+ bundleManifestLocation := getBundleManifestLocation ()
718+
719+ // Read the bundle file
720+ bundleData , err := os .ReadFile (bundleManifestLocation )
721+ if err != nil {
722+ return "" , fmt .Errorf ("failed to read bundle file %s: %w" , bundleManifestLocation , err )
723+ }
724+
725+ // Parse the bundle
726+ var bundles releasev1.Bundles
727+ if err := yaml .Unmarshal (bundleData , & bundles ); err != nil {
728+ return "" , fmt .Errorf ("failed to parse bundle file: %w" , err )
729+ }
730+
731+ // Get the package controller chart image from the first version bundle
732+ if len (bundles .Spec .VersionsBundles ) == 0 {
733+ return "" , fmt .Errorf ("no version bundles found in bundle file" )
734+ }
735+
736+ return bundles .Spec .VersionsBundles [0 ].PackageController .HelmChart .Image (), nil
737+ }
738+
689739// CopyPackages runs the EKS-A `copy packages` command to copy curated packages to the registry mirror.
690- func (e * ClusterE2ETest ) CopyPackages (packageMirrorAlias string , packageChartRegistry string , packageRegistry string , opts ... CommandOpt ) {
740+ func (e * ClusterE2ETest ) CopyPackages (packageMirrorAlias string , packageRegistry string , opts ... CommandOpt ) {
691741 clusterConfig := e .ClusterConfig .Cluster
692742 registyMirrorEndpoint , registryMirrorPort := clusterConfig .Spec .RegistryMirrorConfiguration .Endpoint , clusterConfig .Spec .RegistryMirrorConfiguration .Port
693743 registryMirrorHost := net .JoinHostPort (registyMirrorEndpoint , registryMirrorPort )
@@ -700,12 +750,12 @@ func (e *ClusterE2ETest) CopyPackages(packageMirrorAlias string, packageChartReg
700750 "copy" , "packages" ,
701751 registryMirrorHost + "/" + packageMirrorAlias ,
702752 "--kube-version" , kubeVersion ,
703- "--src-chart-registry" , packageChartRegistry ,
753+ "--src-chart-registry" , packageRegistry ,
704754 "--src-image-registry" , packageRegistry ,
705755 "--dst-insecure" ,
706756 }
707757
708- e .T .Logf ("Copying curated packages to registry mirror: %s" , registryMirrorHost )
758+ e .T .Logf ("Copying curated packages to registry mirror: %s/%s " , registryMirrorHost , packageMirrorAlias )
709759 e .RunEKSA (copyPackagesArgs , opts ... )
710760}
711761
@@ -1327,22 +1377,6 @@ func (e *ClusterE2ETest) WithCluster(f func(e *ClusterE2ETest)) {
13271377 f (e )
13281378}
13291379
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-
13461380// Like WithCluster but does not delete the cluster. Useful for debugging.
13471381func (e * ClusterE2ETest ) WithPersistentCluster (f func (e * ClusterE2ETest )) {
13481382 configPath := e .KubeconfigFilePath ()
@@ -2188,10 +2222,13 @@ func (e *ClusterE2ETest) ApplyPackageFile(packageName, targetNamespace string, P
21882222func (e * ClusterE2ETest ) CurlEndpoint (endpoint , namespace string , extraCurlArgs ... string ) string {
21892223 ctx := context .Background ()
21902224
2225+ diagnosticCollectorImage := e .GetDiagnosticCollectorImage ()
2226+
21912227 e .T .Log ("Launching pod to curl endpoint" , endpoint )
21922228 randomname := fmt .Sprintf ("%s-%s" , "curl-test" , utilrand .String (7 ))
21932229 curlPodName , err := e .KubectlClient .RunCurlPod (context .TODO (),
2194- namespace , randomname , e .KubeconfigFilePath (), append ([]string {"curl" , endpoint }, extraCurlArgs ... ))
2230+ namespace , randomname , e .KubeconfigFilePath (), diagnosticCollectorImage ,
2231+ append ([]string {"curl" , endpoint }, extraCurlArgs ... ))
21952232 if err != nil {
21962233 e .T .Fatalf ("error launching pod: %s" , err )
21972234 }
0 commit comments