diff --git a/docs/deploy-full-rp-service-in-dev.md b/docs/deploy-full-rp-service-in-dev.md index 2f941e5447f..459e682ac60 100644 --- a/docs/deploy-full-rp-service-in-dev.md +++ b/docs/deploy-full-rp-service-in-dev.md @@ -334,7 +334,7 @@ export RESOURCEGROUP=myResourceGroup ``` -1. Create the if it doesn't exist +1. Create the resource group if it doesn't exist ```bash az group create --resource-group $RESOURCEGROUP --location $LOCATION ``` diff --git a/hack/cluster/cluster.go b/hack/cluster/cluster.go index d64b6cf1a21..fd822d32dd2 100644 --- a/hack/cluster/cluster.go +++ b/hack/cluster/cluster.go @@ -17,28 +17,12 @@ import ( msgraph_errors "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models/odataerrors" utillog "github.com/Azure/ARO-RP/pkg/util/log" "github.com/Azure/ARO-RP/pkg/util/version" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" ) const ( Cluster = "CLUSTER" ) -func main() { - log := utillog.GetLogger() - - if err := run(context.Background(), log); err != nil { - if oDataError, ok := err.(msgraph_errors.ODataErrorable); ok { - spew.Dump(oDataError.GetErrorEscaped()) - } - log.Fatal(err) - } -} - func run(ctx context.Context, log *logrus.Entry) error { if len(os.Args) != 2 { return fmt.Errorf("usage: CLUSTER=x %s {create,createApp,deleteApp,delete}", os.Args[0]) @@ -53,43 +37,11 @@ func run(ctx context.Context, log *logrus.Entry) error { return err } - clusterName := os.Getenv(Cluster) - vnetName := fmt.Sprintf("%s-vnet", clusterName) - resourceGroup := os.Getenv("RESOURCEGROUP") - location := os.Getenv("LOCATION") - - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - - resourceClient, err := armresources.NewResourceGroupsClient(os.Getenv("AZURE_SUBSCRIPTION_ID"), cred, nil) - if err != nil { - log.Fatalf("failed to create resource group client: %v", err) - } - - vnetClient, err := armnetwork.NewVirtualNetworksClient(os.Getenv("AZURE_SUBSCRIPTION_ID"), cred, nil) - if err != nil { - log.Fatalf("failed to create virtual network client: %v", err) - } - - // Create the resource group - log.Infof("Creating resource group %s in location %s...\n", resourceGroup, location) - _, err = resourceClient.CreateOrUpdate(ctx, resourceGroup, armresources.ResourceGroup{ - Location: to.Ptr(location), - }, nil) - if err != nil { - log.Fatalf("failed to create resource group: %v", err) + vnetResourceGroup := os.Getenv("RESOURCEGROUP") // TODO: remove this when we deploy and peer a vnet per cluster create + if os.Getenv("CI") != "" { + vnetResourceGroup = os.Getenv(Cluster) } - - // Create the virtual network - log.Infof("Creating virtual network %s in resource group %s...\n", vnetName, resourceGroup) - err = createVNet(ctx, log, vnetClient, resourceGroup, vnetName, location) - if err != nil { - return err - } - - log.Infof("Created virtual network %s in resource group %s\n", vnetName, resourceGroup) + clusterName := os.Getenv(Cluster) osClusterVersion := os.Getenv("OS_CLUSTER_VERSION") if osClusterVersion == "" { @@ -106,67 +58,25 @@ func run(ctx context.Context, log *logrus.Entry) error { switch strings.ToLower(os.Args[1]) { case "create": - err = c.Create(ctx, resourceGroup, clusterName, osClusterVersion) - if err != nil { - // If cluster creation fails, delete the created VNet - deleteVNet(ctx, log, vnetClient, resourceGroup, vnetName) - } - return err + return c.Create(ctx, vnetResourceGroup, clusterName, osClusterVersion) case "createapp": return c.CreateApp(ctx, clusterName) case "deleteapp": return c.DeleteApp(ctx) case "delete": - err = c.Delete(ctx, resourceGroup, clusterName) - if err == nil { - // If cluster deletion succeeds, delete the created VNet - deleteVNet(ctx, log, vnetClient, resourceGroup, vnetName) - } - return err + return c.Delete(ctx, vnetResourceGroup, clusterName) default: return fmt.Errorf("invalid command %s", os.Args[1]) } } -func createVNet(ctx context.Context, log *logrus.Entry, vnetClient *armnetwork.VirtualNetworksClient, resourceGroup string, vnetName string, location string) error { - _, err := vnetClient.BeginCreateOrUpdate(ctx, resourceGroup, vnetName, armnetwork.VirtualNetwork{ - Location: to.Ptr(location), - Properties: &armnetwork.VirtualNetworkPropertiesFormat{ - AddressSpace: &armnetwork.AddressSpace{ - AddressPrefixes: []*string{ - to.Ptr("10.0.0.0/16"), - }, - }, - Subnets: []*armnetwork.Subnet{ - { - Name: to.Ptr("master"), - Properties: &armnetwork.SubnetPropertiesFormat{ - AddressPrefix: to.Ptr("10.0.0.0/24"), - }, - }, - { - Name: to.Ptr("worker"), - Properties: &armnetwork.SubnetPropertiesFormat{ - AddressPrefix: to.Ptr("10.0.1.0/24"), - }, - }, - }, - }, - }, nil) - if err != nil { - log.Errorf("Failed to create VNet: %v", err) - return err - } - log.Infof("Created VNet %s in resource group %s", vnetName, resourceGroup) - return nil -} +func main() { + log := utillog.GetLogger() -func deleteVNet(ctx context.Context, log *logrus.Entry, vnetClient *armnetwork.VirtualNetworksClient, resourceGroup string, vnetName string) error { - _, err := vnetClient.BeginDelete(ctx, resourceGroup, vnetName, nil) - if err != nil { - log.Errorf("Failed to delete VNet: %v", err) - return err + if err := run(context.Background(), log); err != nil { + if oDataError, ok := err.(msgraph_errors.ODataErrorable); ok { + spew.Dump(oDataError.GetErrorEscaped()) + } + log.Fatal(err) } - log.Infof("Deleted VNet %s in resource group %s", vnetName, resourceGroup) - return nil } diff --git a/setup_resources.sh b/setup_resources.sh index 5b3890b0e38..4a9ab3ed456 100755 --- a/setup_resources.sh +++ b/setup_resources.sh @@ -65,7 +65,7 @@ add_openshift_version() { } # Add the required OpenShift version -add_openshift_version "4.10.28" "test.com/a:b" "test.com/a:b" +add_openshift_version "4.13.40" "test.com/a:b" "test.com/a:b" # Delete the existing cluster if it exists echo "Deleting the existing cluster if it exists..."