diff --git a/hypershift-operator/controllers/nodepool/nodepool_controller.go b/hypershift-operator/controllers/nodepool/nodepool_controller.go index 382098511c00..8835e8e479d5 100644 --- a/hypershift-operator/controllers/nodepool/nodepool_controller.go +++ b/hypershift-operator/controllers/nodepool/nodepool_controller.go @@ -699,6 +699,9 @@ func isAutoscalingEnabled(nodePool *hyperv1.NodePool) bool { } func defaultNodePoolAMI(region string, specifiedArch string, releaseImage *releaseinfo.ReleaseImage) (string, error) { + if releaseImage.StreamMetadata == nil { + return "", fmt.Errorf("release image stream metadata is nil") + } arch, foundArch := releaseImage.StreamMetadata.Architectures[hyperv1.ArchAliases[specifiedArch]] if !foundArch { return "", fmt.Errorf("couldn't find OS metadata for architecture %q", specifiedArch) diff --git a/hypershift-operator/controllers/nodepool/nodepool_controller_test.go b/hypershift-operator/controllers/nodepool/nodepool_controller_test.go index edfc83ef57a1..1f2320929859 100644 --- a/hypershift-operator/controllers/nodepool/nodepool_controller_test.go +++ b/hypershift-operator/controllers/nodepool/nodepool_controller_test.go @@ -567,6 +567,15 @@ func TestDefaultNodePoolAMI(t *testing.T) { specifiedArch: "arm64", expectedImage: "", }, + { + name: "fail because stream metadata is nil", + region: "us-east-1", + specifiedArch: "amd64", + releaseImage: &releaseinfo.ReleaseImage{ + StreamMetadata: nil, + }, + expectedImage: "", + }, } for _, tc := range testCases { @@ -596,7 +605,9 @@ func TestDefaultNodePoolAMI(t *testing.T) { } ctx := t.Context() - tc.releaseImage = fakereleaseprovider.GetReleaseImage(ctx, hc, client, releaseProvider) + if tc.releaseImage == nil { + tc.releaseImage = fakereleaseprovider.GetReleaseImage(ctx, hc, client, releaseProvider) + } tc.image, tc.err = defaultNodePoolAMI(tc.region, tc.specifiedArch, tc.releaseImage) if strings.Contains(tc.name, "successfully") { @@ -608,6 +619,9 @@ func TestDefaultNodePoolAMI(t *testing.T) { } else if strings.Contains(tc.name, "fail because architecture") { g.Expect(tc.image).To(BeEmpty()) g.Expect(tc.err.Error()).To(Equal("couldn't find OS metadata for architecture \"" + tc.specifiedArch + "\"")) + } else if strings.Contains(tc.name, "stream metadata is nil") { + g.Expect(tc.image).To(BeEmpty()) + g.Expect(tc.err.Error()).To(Equal("release image stream metadata is nil")) } else { g.Expect(tc.image).To(BeEmpty()) g.Expect(tc.err.Error()).To(Equal("release image metadata has no image for region \"" + tc.region + "\"")) diff --git a/hypershift-operator/controllers/nodepool/token.go b/hypershift-operator/controllers/nodepool/token.go index 2a9f9023e2c2..9f0b759a4db6 100644 --- a/hypershift-operator/controllers/nodepool/token.go +++ b/hypershift-operator/controllers/nodepool/token.go @@ -135,7 +135,9 @@ func NewToken(ctx context.Context, configGenerator *ConfigGenerator, cpoCapabili globalconfig.ReconcileProxyConfigWithStatusFromHostedCluster(proxy, configGenerator.hostedCluster) ami := "" - if configGenerator.hostedCluster.Spec.Platform.AWS != nil { + if configGenerator.nodePool.Spec.Platform.AWS != nil && configGenerator.nodePool.Spec.Platform.AWS.AMI != "" { + ami = configGenerator.nodePool.Spec.Platform.AWS.AMI + } else if configGenerator.hostedCluster.Spec.Platform.AWS != nil { ami, err = defaultNodePoolAMI(configGenerator.hostedCluster.Spec.Platform.AWS.Region, configGenerator.nodePool.Spec.Arch, configGenerator.releaseImage) if err != nil { return nil, err