Skip to content

Commit

Permalink
update image names
Browse files Browse the repository at this point in the history
  • Loading branch information
MaysaMacedo committed Dec 26, 2024
1 parent ec7505e commit 223c1ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hypershift-operator/controllers/nodepool/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func (c *CAPI) machineTemplateBuilders() (client.Object, func(object client.Obje
case hyperv1.OpenStackPlatform:
template = &capiopenstackv1beta1.OpenStackMachineTemplate{}
var err error
machineTemplateSpec, err = openstack.MachineTemplateSpec(hcluster, nodePool)
machineTemplateSpec, err = openstack.MachineTemplateSpec(hcluster, nodePool, c.releaseImage)
if err != nil {
SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolValidMachineTemplateConditionType,
Expand Down
20 changes: 16 additions & 4 deletions hypershift-operator/controllers/nodepool/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
capiopenstackv1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)

func MachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hyperv1.NodePool) (*capiopenstackv1beta1.OpenStackMachineTemplateSpec, error) {
func MachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hyperv1.NodePool, releaseImage *releaseinfo.ReleaseImage) (*capiopenstackv1beta1.OpenStackMachineTemplateSpec, error) {
openStackMachineTemplate := &capiopenstackv1beta1.OpenStackMachineTemplateSpec{Template: capiopenstackv1beta1.OpenStackMachineTemplateResource{Spec: capiopenstackv1beta1.OpenStackMachineSpec{
Flavor: ptr.To(nodePool.Spec.Platform.OpenStack.Flavor),
}}}
Expand All @@ -27,8 +27,12 @@ func MachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hyperv1.Node
Name: ptr.To(nodePool.Spec.Platform.OpenStack.ImageName),
}
} else {
releaseVersion, err := releaseinfo.OpenStackReleaseImage(releaseImage)
if err != nil {
return nil, err
}
openStackMachineTemplate.Template.Spec.Image.ImageRef = &capiopenstackv1beta1.ResourceReference{
Name: "rhcos-" + hcluster.Name,
Name: "rhcos-" + releaseVersion + "-" + hcluster.Name,
}
}

Expand Down Expand Up @@ -78,9 +82,13 @@ func MachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hyperv1.Node
}

func ReconcileOpenStackImageCR(ctx context.Context, client client.Client, createOrUpdate upsert.CreateOrUpdateFN, hcluster *hyperv1.HostedCluster, release *releaseinfo.ReleaseImage) error {
releaseVersion, err := releaseinfo.OpenStackReleaseImage(release)
if err != nil {
return err
}
openStackImage := orc.Image{
ObjectMeta: metav1.ObjectMeta{
Name: "rhcos-" + hcluster.Name,
Name: "rhcos-" + releaseVersion + "-" + hcluster.Name,
Namespace: hcluster.Namespace,
// TODO: add proper cleanup in CAPI resources cleanup
OwnerReferences: []metav1.OwnerReference{
Expand Down Expand Up @@ -117,9 +125,13 @@ func reconcileOpenStackImageSpec(hcluster *hyperv1.HostedCluster, openStackImage
SecretName: hcluster.Spec.Platform.OpenStack.IdentityRef.Name,
CloudName: hcluster.Spec.Platform.OpenStack.IdentityRef.CloudName,
}
releaseVersion, err := releaseinfo.OpenStackReleaseImage(release)
if err != nil {
return err
}

openStackImageSpec.Resource = &orc.ImageResourceSpec{
Name: "rhcos-" + hcluster.Name,
Name: "rhcos-" + releaseVersion + "-" + hcluster.Name,
Content: &orc.ImageContent{
DiskFormat: "qcow2",
Download: &orc.ImageContentSourceDownload{
Expand Down
12 changes: 12 additions & 0 deletions support/releaseinfo/releaseinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,15 @@ func UnsupportedOpenstackDefaultImage(releaseImage *ReleaseImage) (string, strin

return disk.Location, disk.SHA256, nil
}

func OpenStackReleaseImage(releaseImage *ReleaseImage) (string, error) {
arch, foundArch := releaseImage.StreamMetadata.Architectures["x86_64"]
if !foundArch {
return "", fmt.Errorf("couldn't find OS metadata for architecture %q", "x64_64")
}
openStack, exists := arch.Artifacts["openstack"]
if !exists {
return "", fmt.Errorf("couldn't find OS metadata for openstack")
}
return openStack.Release, nil
}

0 comments on commit 223c1ed

Please sign in to comment.