Skip to content

Commit

Permalink
frontend: Modify BuildCSCluster parameters
Browse files Browse the repository at this point in the history
Take the whole request header instead of just the tenant ID.
  • Loading branch information
Matthew Barnes authored and SudoBrendan committed Dec 17, 2024
1 parent e63e010 commit a6094bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 1 addition & 8 deletions frontend/pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,6 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request
return
}

tenantID := request.Header.Get(arm.HeaderNameHomeTenantID)
if tenantID == "" {
f.logger.Error("Missing " + arm.HeaderNameHomeTenantID + " header")
arm.WriteInternalServerError(writer)
return
}

f.logger.Info(fmt.Sprintf("%s: ArmResourceCreateOrUpdate", versionedInterface))

doc, err := f.dbClient.GetResourceDoc(ctx, resourceID)
Expand Down Expand Up @@ -432,7 +425,7 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request
versionedRequestCluster.Normalize(hcpCluster)

hcpCluster.Name = request.PathValue(PathSegmentResourceName)
csCluster, err := f.BuildCSCluster(resourceID, tenantID, hcpCluster, updating)
csCluster, err := f.BuildCSCluster(resourceID, request.Header, hcpCluster, updating)
if err != nil {
f.logger.Error(err.Error())
arm.WriteInternalServerError(writer)
Expand Down
5 changes: 4 additions & 1 deletion frontend/pkg/frontend/node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ func TestCreateNodePool(t *testing.T) {
}
hcpCluster := api.NewDefaultHCPOpenShiftCluster()

requestHeader := make(http.Header)
requestHeader.Add(arm.HeaderNameHomeTenantID, dummyTenantId)

hcpCluster.Name = dummyClusterName
csCluster, _ := f.BuildCSCluster(clusterResouceID, dummyTenantId, hcpCluster, false)
csCluster, _ := f.BuildCSCluster(clusterResouceID, requestHeader, hcpCluster, false)

if test.subDoc != nil {
err := f.dbClient.CreateSubscriptionDoc(context.TODO(), test.subDoc)
Expand Down
11 changes: 9 additions & 2 deletions frontend/pkg/frontend/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package frontend

import (
"context"
"fmt"
"net/http"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
configv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -130,7 +132,12 @@ func ensureManagedResourceGroupName(hcpCluster *api.HCPOpenShiftCluster) string
}

// BuildCSCluster creates a CS Cluster object from an HCPOpenShiftCluster object
func (f *Frontend) BuildCSCluster(resourceID *arm.ResourceID, tenantID string, hcpCluster *api.HCPOpenShiftCluster, updating bool) (*cmv1.Cluster, error) {
func (f *Frontend) BuildCSCluster(resourceID *arm.ResourceID, requestHeader http.Header, hcpCluster *api.HCPOpenShiftCluster, updating bool) (*cmv1.Cluster, error) {

// Ensure required headers are present.
if requestHeader.Get(arm.HeaderNameHomeTenantID) == "" {
return nil, fmt.Errorf("Missing " + arm.HeaderNameHomeTenantID + " header")
}

clusterBuilder := cmv1.NewCluster()

Expand Down Expand Up @@ -170,7 +177,7 @@ func (f *Frontend) BuildCSCluster(resourceID *arm.ResourceID, tenantID string, h
EtcdEncryption(hcpCluster.Properties.Spec.EtcdEncryption)

azureBuilder := cmv1.NewAzure().
TenantID(tenantID).
TenantID(requestHeader.Get(arm.HeaderNameHomeTenantID)).
SubscriptionID(resourceID.SubscriptionID).
ResourceGroupName(resourceID.ResourceGroupName).
ResourceName(hcpCluster.Name).
Expand Down

0 comments on commit a6094bc

Please sign in to comment.