Skip to content

Commit

Permalink
update ownerref
Browse files Browse the repository at this point in the history
  • Loading branch information
MaysaMacedo committed Dec 27, 2024
1 parent 97a5e4a commit 3be9453
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 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 @@ -1325,5 +1325,5 @@ func (r *NodePoolReconciler) getMachinesForNodePool(ctx context.Context, nodePoo
}

func (c *CAPI) reconcileORCResources(ctx context.Context) error {
return openstack.ReconcileOpenStackImageCR(ctx, c.Client, c.CreateOrUpdate, c.hostedCluster, c.releaseImage, c.controlplaneNamespace)
return openstack.ReconcileOpenStackImageCR(ctx, c.Client, c.CreateOrUpdate, c.hostedCluster, c.releaseImage, c.nodePool)
}
27 changes: 22 additions & 5 deletions hypershift-operator/controllers/nodepool/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openstack
import (
"context"
"fmt"
"strings"

hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/openshift/hypershift/support/openstackutil"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/upsert"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
capiopenstackv1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
)
Expand Down Expand Up @@ -81,22 +83,37 @@ func MachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hyperv1.Node
return openStackMachineTemplate, nil
}

func ReconcileOpenStackImageCR(ctx context.Context, client client.Client, createOrUpdate upsert.CreateOrUpdateFN, hcluster *hyperv1.HostedCluster, release *releaseinfo.ReleaseImage, controlPlaneNamespace string) error {
func getOpenStackClusterForHostedCluster(ctx context.Context, c client.Client, hcluster *hyperv1.HostedCluster, controlPlaneNamespace string) (capiopenstackv1beta1.OpenStackCluster, error) {
cluster := capiopenstackv1beta1.OpenStackCluster{}

if err := c.Get(ctx, types.NamespacedName{Namespace: controlPlaneNamespace, Name: hcluster.Name}, &cluster); err != nil {
return cluster, fmt.Errorf("failed to list Machines: %w", err)
}

return cluster, nil
}

func ReconcileOpenStackImageCR(ctx context.Context, client client.Client, createOrUpdate upsert.CreateOrUpdateFN, hcluster *hyperv1.HostedCluster, release *releaseinfo.ReleaseImage, nodePool *hyperv1.NodePool) error {
releaseVersion, err := releaseinfo.OpenStackReleaseImage(release)
if err != nil {
return err
}
controlPlaneNamespace := fmt.Sprintf("%s-%s", nodePool.Namespace, strings.ReplaceAll(nodePool.Spec.ClusterName, ".", "-"))
openstackCluster, err := getOpenStackClusterForHostedCluster(ctx, client, hcluster, controlPlaneNamespace)
if err != nil {
return err
}
openStackImage := orc.Image{
ObjectMeta: metav1.ObjectMeta{
Name: "rhcos-" + releaseVersion + "-" + hcluster.Name,
Namespace: controlPlaneNamespace,
// TODO: add proper cleanup in CAPI resources cleanup
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: hcluster.APIVersion,
Kind: hcluster.Kind,
Name: hcluster.Name,
UID: hcluster.UID,
APIVersion: openstackCluster.APIVersion,
Kind: openstackCluster.Kind,
Name: openstackCluster.Name,
UID: openstackCluster.UID,
},
},
},
Expand Down

0 comments on commit 3be9453

Please sign in to comment.