diff --git a/frontend/Makefile b/frontend/Makefile index cb32d0b6f..15c2ad77d 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -14,7 +14,7 @@ frontend: go build -o aro-hcp-frontend . run: - ./aro-hcp-frontend --use-cache --region eastus --clusters-service-url http://localhost:8000 + ./aro-hcp-frontend --use-cache --region ${REGION} --clusters-service-url http://localhost:8000 clean: rm -f aro-hcp-frontend diff --git a/frontend/README.md b/frontend/README.md index fb8e6ad91..07b2c6add 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -57,7 +57,7 @@ make undeploy-private Update a subscription state (Must be **Registered** for other calls to function) ```bash -curl -X PUT localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID?api-version=2.0 --json '{"state":"Registered"}' +curl -X PUT localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000?api-version=2.0 --json '{"state":"Registered"}' ``` List the Operations for the Provider @@ -68,30 +68,30 @@ curl -X GET "localhost:8443/providers/Microsoft.RedHatOpenshift/operations?api-v List HcpOpenShiftVersions Resources by Location ```bash -curl -X GET "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/locations/YOUR_LOCATION/providers/Microsoft.RedHatOpenshift/hcpOpenShiftVersions?api-version=2024-06-10-preview" +curl -X GET "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/locations/YOUR_LOCATION/providers/Microsoft.RedHatOpenshift/hcpOpenShiftVersions?api-version=2024-06-10-preview" ``` List HcpOpenShiftClusterResource Resources by Subscription ID ```bash -curl -X GET "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters?api-version=2024-06-10-preview" +curl -X GET "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters?api-version=2024-06-10-preview" ``` Get a HcpOpenShiftClusterResource ```bash -curl -X GET "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP_NAME/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" +curl -X GET "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" ``` Create or Update a HcpOpenShiftClusterResource ```bash -curl -X PUT "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP_NAME/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" --json @cluster.json +curl -X PUT "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" --json @cluster.json ``` Delete a HcpOpenShiftClusterResource ```bash -curl -X DELETE "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP_NAME/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" +curl -X DELETE "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/YOUR_CLUSTER_NAME?api-version=2024-06-10-preview" ``` Execute deployment preflight checks ```bash -curl -X POST "localhost:8443/subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP_NAME/providers/Microsoft.RedHatOpenshift/deployments/YOUR_DEPLOYMENT_NAME/preflight?api-version=2020-06-01" --json preflight.json +curl -X POST "localhost:8443/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.RedHatOpenshift/deployments/YOUR_DEPLOYMENT_NAME/preflight?api-version=2020-06-01" --json preflight.json ``` diff --git a/frontend/go.mod b/frontend/go.mod index ef6840154..be02e582e 100644 --- a/frontend/go.mod +++ b/frontend/go.mod @@ -6,6 +6,7 @@ toolchain go1.22.2 require ( github.com/Azure/ARO-HCP/internal v0.0.0-00010101000000-000000000000 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.2 github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.0.1 github.com/google/go-cmp v0.6.0 @@ -19,7 +20,6 @@ require ( require ( github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect github.com/aymerick/douceur v0.2.0 // indirect diff --git a/frontend/pkg/frontend/frontend.go b/frontend/pkg/frontend/frontend.go index 378ae83f4..d964a2df0 100644 --- a/frontend/pkg/frontend/frontend.go +++ b/frontend/pkg/frontend/frontend.go @@ -275,8 +275,20 @@ func (f *Frontend) ArmResourceRead(writer http.ResponseWriter, request *http.Req } } - cluster, _ := f.conn.ClustersMgmt().V1().Clusters().Cluster(doc.ClusterID).Get().Send() - hcpCluster, _ := ocm.ConvertCStoFrontend(*cluster.Body()) + cluster, err := f.conn.ClustersMgmt().V1().Clusters().Cluster(doc.ClusterID).Get().Send() + if err != nil { + f.logger.Error(fmt.Sprintf("cluster not found in clusters-service: %v", err)) + writer.WriteHeader(http.StatusNoContent) + return + } + + hcpCluster, err := ocm.ConvertCStoHCPOpenShiftCluster(cluster.Body()) + if err != nil { + // Should never happen currently + f.logger.Error(err.Error()) + arm.WriteInternalServerError(writer) + return + } versionedResource := versionedInterface.NewHCPOpenShiftCluster(hcpCluster) resp, err := json.Marshal(versionedResource) @@ -343,7 +355,13 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request return } if csResp.Body() != nil { - hcpCluster, _ = ocm.ConvertCStoFrontend(*csResp.Body()) + hcpCluster, err = ocm.ConvertCStoHCPOpenShiftCluster(csResp.Body()) + if err != nil { + // Should never happen currently + f.logger.Error(err.Error()) + arm.WriteInternalServerError(writer) + return + } } } versionedCurrentCluster := versionedInterface.NewHCPOpenShiftCluster(hcpCluster) diff --git a/frontend/pkg/frontend/middleware_validatestatic.go b/frontend/pkg/frontend/middleware_validatestatic.go index f13b12851..82216c015 100644 --- a/frontend/pkg/frontend/middleware_validatestatic.go +++ b/frontend/pkg/frontend/middleware_validatestatic.go @@ -53,17 +53,19 @@ func MiddlewareValidateStatic(w http.ResponseWriter, r *http.Request, next http. } } - if resourceID.Name != "" && resourceID.ResourceType.String() != "Microsoft.Resources/subscriptions" { - if !rxResourceName.MatchString(resourceID.Name) { - arm.WriteError(w, http.StatusBadRequest, - arm.CloudErrorInvalidResourceName, - resourceID.String(), - "The Resource '%s/%s' under resource group '%s' is invalid.", - resourceID.ResourceType, resourceID.Name, - resourceID.ResourceGroupName) - return + if resourceID.Name != "" { + if !rxResourceName.MatchString(resourceID.Name) { + arm.WriteError(w, http.StatusBadRequest, + arm.CloudErrorInvalidResourceName, + resourceID.String(), + "The Resource '%s/%s' under resource group '%s' is invalid.", + resourceID.ResourceType, resourceID.Name, + resourceID.ResourceGroupName) + return + } } } } + next(w, r) } diff --git a/frontend/pkg/ocm/ocm.go b/frontend/pkg/ocm/ocm.go index 05ae3affc..346a76c3a 100644 --- a/frontend/pkg/ocm/ocm.go +++ b/frontend/pkg/ocm/ocm.go @@ -16,9 +16,9 @@ const ( csCCSEnabled bool = true ) -// ConvertCStoFrontend converts a CS Cluster object into HCPOpenShiftCluster object -func ConvertCStoFrontend(cluster cmv1.Cluster) (*api.HCPOpenShiftCluster, error) { - hcpcluster := api.HCPOpenShiftCluster{ +// ConvertCStoHCPOpenShiftCluster converts a CS Cluster object into HCPOpenShiftCluster object +func ConvertCStoHCPOpenShiftCluster(cluster *cmv1.Cluster) (*api.HCPOpenShiftCluster, error) { + hcpcluster := &api.HCPOpenShiftCluster{ TrackedResource: arm.TrackedResource{ Location: "", Tags: nil, @@ -83,12 +83,18 @@ func ConvertCStoFrontend(cluster cmv1.Cluster) (*api.HCPOpenShiftCluster, error) Enabled: false, ExternalAuths: []*v1.OIDCProvider{}, }, - Ingress: []*api.IngressProfile{}, + Ingress: []*api.IngressProfile{ + { + IP: "", + URL: "", + Visibility: "", + }, + }, }, }, } - return &hcpcluster, nil + return hcpcluster, nil } // BuildCSCluster creates a CS Cluster object from an HCPOpenShiftCluster object