зеркало из https://github.com/Azure/ARO-RP.git
add NewCoreForCI
This commit is contained in:
Родитель
b9d630572c
Коммит
f685abb2d4
|
@ -31,7 +31,7 @@ func getAuth(key string) (*types.DockerAuthConfig, error) {
|
|||
}
|
||||
|
||||
func mirror(ctx context.Context, log *logrus.Entry) error {
|
||||
env, err := env.NewCore(ctx, log)
|
||||
env, err := env.NewCoreForCI(ctx, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -13,9 +13,8 @@ import (
|
|||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/util/cluster"
|
||||
"github.com/Azure/ARO-RP/pkg/util/deployment"
|
||||
"github.com/Azure/ARO-RP/pkg/util/instancemetadata"
|
||||
utillog "github.com/Azure/ARO-RP/pkg/util/log"
|
||||
)
|
||||
|
||||
|
@ -32,17 +31,14 @@ func run(ctx context.Context, log *logrus.Entry) error {
|
|||
}
|
||||
}
|
||||
|
||||
deploymentMode := deployment.NewMode()
|
||||
log.Infof("running in %s mode", deploymentMode)
|
||||
|
||||
instancemetadata, err := instancemetadata.NewDev()
|
||||
env, err := env.NewCore(ctx, log)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := cluster.New(log, deploymentMode, instancemetadata, false)
|
||||
c, err := cluster.New(log, env, false)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
switch strings.ToLower(os.Args[1]) {
|
||||
|
|
|
@ -41,10 +41,9 @@ func NewCore(ctx context.Context, log *logrus.Entry) (Core, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
switch im.Environment().Name {
|
||||
case azure.PublicCloud.Name, azure.USGovernmentCloud.Name:
|
||||
default:
|
||||
return nil, errors.New("unsupported Azure cloud environment")
|
||||
err = validateCloudEnvironment(im.Environment().Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rpauthorizer, err := rpauthorizer.New(deploymentMode, im)
|
||||
|
@ -59,3 +58,37 @@ func NewCore(ctx context.Context, log *logrus.Entry) (Core, error) {
|
|||
deploymentMode: deploymentMode,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewCoreForCI returns an env.Core which respects RP_MODE but always uses
|
||||
// AZURE_* environment variables instead of IMDS. This is used for entrypoints
|
||||
// which may run on CI VMs. CI VMs don't currently have MSI and hence cannot
|
||||
// resolve their tenant ID, and also may access resources in a different tenant
|
||||
// (e.g. AME).
|
||||
func NewCoreForCI(ctx context.Context, log *logrus.Entry) (Core, error) {
|
||||
deploymentMode := deployment.NewMode()
|
||||
log.Infof("running in %s mode", deploymentMode)
|
||||
|
||||
im, err := instancemetadata.NewDev()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = validateCloudEnvironment(im.Environment().Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &core{
|
||||
InstanceMetadata: im,
|
||||
deploymentMode: deploymentMode,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func validateCloudEnvironment(name string) error {
|
||||
switch name {
|
||||
case azure.PublicCloud.Name, azure.USGovernmentCloud.Name:
|
||||
return nil
|
||||
default:
|
||||
return errors.New("unsupported Azure cloud environment")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
mgmtredhatopenshift "github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/2020-04-30/redhatopenshift"
|
||||
"github.com/Azure/ARO-RP/pkg/deploy"
|
||||
"github.com/Azure/ARO-RP/pkg/deploy/generator"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/util/arm"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/graphrbac"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/authorization"
|
||||
|
@ -32,17 +33,14 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift"
|
||||
"github.com/Azure/ARO-RP/pkg/util/deployment"
|
||||
"github.com/Azure/ARO-RP/pkg/util/instancemetadata"
|
||||
"github.com/Azure/ARO-RP/pkg/util/rbac"
|
||||
"github.com/Azure/ARO-RP/pkg/util/subnet"
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
instancemetadata.InstanceMetadata
|
||||
|
||||
log *logrus.Entry
|
||||
deploymentMode deployment.Mode
|
||||
ci bool
|
||||
log *logrus.Entry
|
||||
env env.Core
|
||||
ci bool
|
||||
|
||||
deployments features.DeploymentsClient
|
||||
groups features.ResourceGroupsClient
|
||||
|
@ -73,8 +71,8 @@ func (errs errors) Error() string {
|
|||
return sb.String()
|
||||
}
|
||||
|
||||
func New(log *logrus.Entry, deploymentMode deployment.Mode, im instancemetadata.InstanceMetadata, ci bool) (*Cluster, error) {
|
||||
if deploymentMode == deployment.Development {
|
||||
func New(log *logrus.Entry, env env.Core, ci bool) (*Cluster, error) {
|
||||
if env.DeploymentMode() == deployment.Development {
|
||||
for _, key := range []string{
|
||||
"AZURE_FP_CLIENT_ID",
|
||||
} {
|
||||
|
@ -89,38 +87,37 @@ func New(log *logrus.Entry, deploymentMode deployment.Mode, im instancemetadata.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
graphAuthorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(im.Environment().GraphEndpoint)
|
||||
graphAuthorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(env.Environment().GraphEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Cluster{
|
||||
log: log,
|
||||
deploymentMode: deploymentMode,
|
||||
InstanceMetadata: im,
|
||||
ci: ci,
|
||||
log: log,
|
||||
env: env,
|
||||
ci: ci,
|
||||
|
||||
deployments: features.NewDeploymentsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
groups: features.NewResourceGroupsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
openshiftclusters: redhatopenshift.NewOpenShiftClustersClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
applications: graphrbac.NewApplicationsClient(im.Environment(), im.TenantID(), graphAuthorizer),
|
||||
serviceprincipals: graphrbac.NewServicePrincipalClient(im.Environment(), im.TenantID(), graphAuthorizer),
|
||||
securitygroups: network.NewSecurityGroupsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
subnets: network.NewSubnetsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
routetables: network.NewRouteTablesClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
roleassignments: authorization.NewRoleAssignmentsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
deployments: features.NewDeploymentsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
groups: features.NewResourceGroupsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
openshiftclusters: redhatopenshift.NewOpenShiftClustersClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
applications: graphrbac.NewApplicationsClient(env.Environment(), env.TenantID(), graphAuthorizer),
|
||||
serviceprincipals: graphrbac.NewServicePrincipalClient(env.Environment(), env.TenantID(), graphAuthorizer),
|
||||
securitygroups: network.NewSecurityGroupsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
subnets: network.NewSubnetsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
routetables: network.NewRouteTablesClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
roleassignments: authorization.NewRoleAssignmentsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
||||
_, err := c.openshiftclusters.Get(ctx, c.ResourceGroup(), clusterName)
|
||||
_, err := c.openshiftclusters.Get(ctx, c.env.ResourceGroup(), clusterName)
|
||||
if err == nil {
|
||||
c.log.Print("cluster already exists, skipping create")
|
||||
return nil
|
||||
}
|
||||
|
||||
var fpClientID string
|
||||
switch c.deploymentMode {
|
||||
switch c.env.DeploymentMode() {
|
||||
case deployment.Integration:
|
||||
fpClientID = firstPartyClientIDIntegration
|
||||
case deployment.Production:
|
||||
|
@ -150,8 +147,8 @@ func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
|||
|
||||
if c.ci {
|
||||
c.log.Infof("creating resource group")
|
||||
_, err = c.groups.CreateOrUpdate(ctx, c.ResourceGroup(), mgmtfeatures.ResourceGroup{
|
||||
Location: to.StringPtr(c.Location()),
|
||||
_, err = c.groups.CreateOrUpdate(ctx, c.env.ResourceGroup(), mgmtfeatures.ResourceGroup{
|
||||
Location: to.StringPtr(c.env.Location()),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -182,7 +179,7 @@ func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
|||
defer cancel()
|
||||
|
||||
c.log.Info("predeploying ARM template")
|
||||
err = c.deployments.CreateOrUpdateAndWait(armctx, c.ResourceGroup(), clusterName, mgmtfeatures.Deployment{
|
||||
err = c.deployments.CreateOrUpdateAndWait(armctx, c.env.ResourceGroup(), clusterName, mgmtfeatures.Deployment{
|
||||
Properties: &mgmtfeatures.DeploymentProperties{
|
||||
Template: template,
|
||||
Parameters: parameters,
|
||||
|
@ -195,8 +192,8 @@ func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
|||
|
||||
c.log.Info("creating role assignments")
|
||||
for _, scope := range []string{
|
||||
"/subscriptions/" + c.SubscriptionID() + "/resourceGroups/" + c.ResourceGroup() + "/providers/Microsoft.Network/virtualNetworks/dev-vnet",
|
||||
"/subscriptions/" + c.SubscriptionID() + "/resourceGroups/" + c.ResourceGroup() + "/providers/Microsoft.Network/routeTables/" + clusterName + "-rt",
|
||||
"/subscriptions/" + c.env.SubscriptionID() + "/resourceGroups/" + c.env.ResourceGroup() + "/providers/Microsoft.Network/virtualNetworks/dev-vnet",
|
||||
"/subscriptions/" + c.env.SubscriptionID() + "/resourceGroups/" + c.env.ResourceGroup() + "/providers/Microsoft.Network/routeTables/" + clusterName + "-rt",
|
||||
} {
|
||||
for _, principalID := range []string{spID, fpSPID} {
|
||||
for i := 0; i < 5; i++ {
|
||||
|
@ -206,7 +203,7 @@ func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
|||
uuid.NewV4().String(),
|
||||
mgmtauthorization.RoleAssignmentCreateParameters{
|
||||
RoleAssignmentProperties: &mgmtauthorization.RoleAssignmentProperties{
|
||||
RoleDefinitionID: to.StringPtr("/subscriptions/" + c.SubscriptionID() + "/providers/Microsoft.Authorization/roleDefinitions/" + rbac.RoleNetworkContributor),
|
||||
RoleDefinitionID: to.StringPtr("/subscriptions/" + c.env.SubscriptionID() + "/providers/Microsoft.Authorization/roleDefinitions/" + rbac.RoleNetworkContributor),
|
||||
PrincipalID: &principalID,
|
||||
PrincipalType: mgmtauthorization.ServicePrincipal,
|
||||
},
|
||||
|
@ -257,7 +254,7 @@ func (c *Cluster) Create(ctx context.Context, clusterName string) error {
|
|||
func (c *Cluster) Delete(ctx context.Context, clusterName string) error {
|
||||
var errs errors
|
||||
|
||||
oc, err := c.openshiftclusters.Get(ctx, c.ResourceGroup(), clusterName)
|
||||
oc, err := c.openshiftclusters.Get(ctx, c.env.ResourceGroup(), clusterName)
|
||||
if err == nil {
|
||||
err = c.deleteRoleAssignments(ctx, *oc.OpenShiftClusterProperties.ServicePrincipalProfile.ClientID)
|
||||
if err != nil {
|
||||
|
@ -270,17 +267,17 @@ func (c *Cluster) Delete(ctx context.Context, clusterName string) error {
|
|||
}
|
||||
|
||||
c.log.Print("deleting cluster")
|
||||
err = c.openshiftclusters.DeleteAndWait(ctx, c.ResourceGroup(), clusterName)
|
||||
err = c.openshiftclusters.DeleteAndWait(ctx, c.env.ResourceGroup(), clusterName)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if c.ci {
|
||||
_, err = c.groups.Get(ctx, c.ResourceGroup())
|
||||
_, err = c.groups.Get(ctx, c.env.ResourceGroup())
|
||||
if err == nil {
|
||||
c.log.Print("deleting resource group")
|
||||
err = c.groups.DeleteAndWait(ctx, c.ResourceGroup())
|
||||
err = c.groups.DeleteAndWait(ctx, c.env.ResourceGroup())
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
@ -288,24 +285,24 @@ func (c *Cluster) Delete(ctx context.Context, clusterName string) error {
|
|||
} else {
|
||||
// Deleting the deployment does not clean up the associated resources
|
||||
c.log.Info("deleting deployment")
|
||||
err = c.deployments.DeleteAndWait(ctx, c.ResourceGroup(), clusterName)
|
||||
err = c.deployments.DeleteAndWait(ctx, c.env.ResourceGroup(), clusterName)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
c.log.Info("deleting master/worker subnets")
|
||||
err = c.subnets.DeleteAndWait(ctx, c.ResourceGroup(), "dev-vnet", clusterName+"-master")
|
||||
err = c.subnets.DeleteAndWait(ctx, c.env.ResourceGroup(), "dev-vnet", clusterName+"-master")
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
err = c.subnets.DeleteAndWait(ctx, c.ResourceGroup(), "dev-vnet", clusterName+"-worker")
|
||||
err = c.subnets.DeleteAndWait(ctx, c.env.ResourceGroup(), "dev-vnet", clusterName+"-worker")
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
c.log.Info("deleting route table")
|
||||
err = c.routetables.DeleteAndWait(ctx, c.ResourceGroup(), clusterName+"-rt")
|
||||
err = c.routetables.DeleteAndWait(ctx, c.env.ResourceGroup(), clusterName+"-rt")
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
@ -325,7 +322,7 @@ func (c *Cluster) createCluster(ctx context.Context, clusterName, clientID, clie
|
|||
OpenShiftClusterProperties: &mgmtredhatopenshift.OpenShiftClusterProperties{
|
||||
ClusterProfile: &mgmtredhatopenshift.ClusterProfile{
|
||||
Domain: to.StringPtr(strings.ToLower(clusterName)),
|
||||
ResourceGroupID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", c.SubscriptionID(), "aro-"+clusterName)),
|
||||
ResourceGroupID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", c.env.SubscriptionID(), "aro-"+clusterName)),
|
||||
},
|
||||
ServicePrincipalProfile: &mgmtredhatopenshift.ServicePrincipalProfile{
|
||||
ClientID: to.StringPtr(clientID),
|
||||
|
@ -337,14 +334,14 @@ func (c *Cluster) createCluster(ctx context.Context, clusterName, clientID, clie
|
|||
},
|
||||
MasterProfile: &mgmtredhatopenshift.MasterProfile{
|
||||
VMSize: mgmtredhatopenshift.StandardD8sV3,
|
||||
SubnetID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/dev-vnet/subnets/%s-master", c.SubscriptionID(), c.ResourceGroup(), clusterName)),
|
||||
SubnetID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/dev-vnet/subnets/%s-master", c.env.SubscriptionID(), c.env.ResourceGroup(), clusterName)),
|
||||
},
|
||||
WorkerProfiles: &[]mgmtredhatopenshift.WorkerProfile{
|
||||
{
|
||||
Name: to.StringPtr("worker"),
|
||||
VMSize: mgmtredhatopenshift.VMSize1StandardD4sV3,
|
||||
DiskSizeGB: to.Int32Ptr(128),
|
||||
SubnetID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/dev-vnet/subnets/%s-worker", c.SubscriptionID(), c.ResourceGroup(), clusterName)),
|
||||
SubnetID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/dev-vnet/subnets/%s-worker", c.env.SubscriptionID(), c.env.ResourceGroup(), clusterName)),
|
||||
Count: to.Int32Ptr(3),
|
||||
},
|
||||
},
|
||||
|
@ -358,14 +355,14 @@ func (c *Cluster) createCluster(ctx context.Context, clusterName, clientID, clie
|
|||
},
|
||||
},
|
||||
},
|
||||
Location: to.StringPtr(c.Location()),
|
||||
Location: to.StringPtr(c.env.Location()),
|
||||
}
|
||||
|
||||
if c.deploymentMode == deployment.Development {
|
||||
if c.env.DeploymentMode() == deployment.Development {
|
||||
(*oc.WorkerProfiles)[0].VMSize = mgmtredhatopenshift.VMSize1StandardD2sV3
|
||||
}
|
||||
|
||||
return c.openshiftclusters.CreateOrUpdateAndWait(ctx, c.ResourceGroup(), clusterName, oc)
|
||||
return c.openshiftclusters.CreateOrUpdateAndWait(ctx, c.env.ResourceGroup(), clusterName, oc)
|
||||
}
|
||||
|
||||
func (c *Cluster) fixupNSGs(ctx context.Context, clusterName string) error {
|
||||
|
@ -416,7 +413,7 @@ func (c *Cluster) fixupNSGs(ctx context.Context, clusterName string) error {
|
|||
}
|
||||
|
||||
for _, fix := range fixes {
|
||||
subnet, err := c.subnets.Get(ctx, c.ResourceGroup(), "dev-vnet", fix.subnetName, "")
|
||||
subnet, err := c.subnets.Get(ctx, c.env.ResourceGroup(), "dev-vnet", fix.subnetName, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -425,7 +422,7 @@ func (c *Cluster) fixupNSGs(ctx context.Context, clusterName string) error {
|
|||
ID: &fix.nsgID,
|
||||
}
|
||||
|
||||
err = c.subnets.CreateOrUpdateAndWait(ctx, c.ResourceGroup(), "dev-vnet", fix.subnetName, subnet)
|
||||
err = c.subnets.CreateOrUpdateAndWait(ctx, c.env.ResourceGroup(), "dev-vnet", fix.subnetName, subnet)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -443,7 +440,7 @@ func (c *Cluster) deleteRoleAssignments(ctx context.Context, appID string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
roleAssignments, err := c.roleassignments.ListForResourceGroup(ctx, c.ResourceGroup(), fmt.Sprintf("principalId eq '%s'", spObjID))
|
||||
roleAssignments, err := c.roleassignments.ListForResourceGroup(ctx, c.env.ResourceGroup(), fmt.Sprintf("principalId eq '%s'", spObjID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ var _ = Describe("[Admin API] List clusters action", func() {
|
|||
ctx := context.Background()
|
||||
resourceID := resourceIDFromEnv()
|
||||
|
||||
path := fmt.Sprintf("/subscriptions/%s/providers/Microsoft.RedHatOpenShift/openShiftClusters", im.SubscriptionID())
|
||||
path := fmt.Sprintf("/subscriptions/%s/providers/Microsoft.RedHatOpenShift/openShiftClusters", _env.SubscriptionID())
|
||||
testAdminClustersList(ctx, path, resourceID)
|
||||
})
|
||||
|
||||
|
@ -47,7 +47,7 @@ var _ = Describe("[Admin API] List clusters action", func() {
|
|||
ctx := context.Background()
|
||||
resourceID := resourceIDFromEnv()
|
||||
|
||||
path := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RedHatOpenShift/openShiftClusters", im.SubscriptionID(), im.ResourceGroup())
|
||||
path := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RedHatOpenShift/openShiftClusters", _env.SubscriptionID(), _env.ResourceGroup())
|
||||
testAdminClustersList(ctx, path, resourceID)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@ var _ = Describe("[Admin API] VM redeploy action", func() {
|
|||
resourceID := resourceIDFromEnv()
|
||||
|
||||
By("getting the resource group where the VM instances live in")
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, im.ResourceGroup(), clusterName)
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, _env.ResourceGroup(), clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
clusterResourceGroup := stringutils.LastTokenByte(*oc.OpenShiftClusterProperties.ClusterProfile.ResourceGroupID, '/')
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ var _ = Describe("[Admin API] List Azure resources action", func() {
|
|||
resourceID := resourceIDFromEnv()
|
||||
|
||||
By("getting the resource group where cluster resources live in")
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, im.ResourceGroup(), clusterName)
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, _env.ResourceGroup(), clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
clusterResourceGroup := stringutils.LastTokenByte(*oc.OpenShiftClusterProperties.ClusterProfile.ResourceGroupID, '/')
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ var _ = Describe("List clusters", func() {
|
|||
Specify("the test cluster should be in the returned listByResourceGroup", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
ocList, err := clients.OpenshiftClusters.ListByResourceGroup(ctx, im.ResourceGroup())
|
||||
ocList, err := clients.OpenshiftClusters.ListByResourceGroup(ctx, _env.ResourceGroup())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
//Expect(len(ocList.Value)).To(Greater(1)))
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ var _ = Describe("Scale nodes", func() {
|
|||
Specify("node count should match the cluster resource and nodes should be ready", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, im.ResourceGroup(), clusterName)
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, _env.ResourceGroup(), clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
expectedNodeCount := 3 // for masters
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd/api"
|
||||
"k8s.io/client-go/tools/clientcmd/api/latest"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
|
||||
|
@ -30,7 +31,6 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift"
|
||||
"github.com/Azure/ARO-RP/pkg/util/cluster"
|
||||
"github.com/Azure/ARO-RP/pkg/util/deployment"
|
||||
"github.com/Azure/ARO-RP/pkg/util/instancemetadata"
|
||||
"github.com/Azure/ARO-RP/test/util/kubeadminkubeconfig"
|
||||
)
|
||||
|
||||
|
@ -50,15 +50,14 @@ type clientSet struct {
|
|||
}
|
||||
|
||||
var (
|
||||
log *logrus.Entry
|
||||
deploymentMode deployment.Mode
|
||||
im instancemetadata.InstanceMetadata
|
||||
clusterName string
|
||||
clients *clientSet
|
||||
log *logrus.Entry
|
||||
_env env.Core
|
||||
clusterName string
|
||||
clients *clientSet
|
||||
)
|
||||
|
||||
func skipIfNotInDevelopmentEnv() {
|
||||
if deploymentMode != deployment.Development {
|
||||
if _env.DeploymentMode() != deployment.Development {
|
||||
Skip("skipping tests in non-development environment")
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +65,7 @@ func skipIfNotInDevelopmentEnv() {
|
|||
func resourceIDFromEnv() string {
|
||||
return fmt.Sprintf(
|
||||
"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RedHatOpenShift/openShiftClusters/%s",
|
||||
im.SubscriptionID(), im.ResourceGroup(), clusterName)
|
||||
_env.SubscriptionID(), _env.ResourceGroup(), clusterName)
|
||||
}
|
||||
|
||||
func newClientSet(ctx context.Context) (*clientSet, error) {
|
||||
|
@ -75,7 +74,7 @@ func newClientSet(ctx context.Context) (*clientSet, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
configv1, err := kubeadminkubeconfig.Get(ctx, log, im, authorizer, resourceIDFromEnv())
|
||||
configv1, err := kubeadminkubeconfig.Get(ctx, log, _env, authorizer, resourceIDFromEnv())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -114,12 +113,12 @@ func newClientSet(ctx context.Context) (*clientSet, error) {
|
|||
}
|
||||
|
||||
return &clientSet{
|
||||
OpenshiftClusters: redhatopenshift.NewOpenShiftClustersClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
Operations: redhatopenshift.NewOperationsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
VirtualMachines: compute.NewVirtualMachinesClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
Resources: features.NewResourcesClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
ActivityLogs: insights.NewActivityLogsClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
VirtualNetworks: network.NewVirtualNetworksClient(im.Environment(), im.SubscriptionID(), authorizer),
|
||||
OpenshiftClusters: redhatopenshift.NewOpenShiftClustersClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
Operations: redhatopenshift.NewOperationsClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
VirtualMachines: compute.NewVirtualMachinesClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
Resources: features.NewResourcesClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
ActivityLogs: insights.NewActivityLogsClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
VirtualNetworks: network.NewVirtualNetworksClient(_env.Environment(), _env.SubscriptionID(), authorizer),
|
||||
|
||||
RestConfig: restconfig,
|
||||
Kubernetes: cli,
|
||||
|
@ -130,11 +129,8 @@ func newClientSet(ctx context.Context) (*clientSet, error) {
|
|||
}
|
||||
|
||||
func setup(ctx context.Context) error {
|
||||
deploymentMode = deployment.NewMode()
|
||||
log.Infof("running in %s mode", deploymentMode)
|
||||
|
||||
var err error
|
||||
im, err = instancemetadata.NewDev()
|
||||
_env, err = env.NewCoreForCI(ctx, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -150,7 +146,7 @@ func setup(ctx context.Context) error {
|
|||
clusterName = os.Getenv("CLUSTER")
|
||||
|
||||
if os.Getenv("CI") != "" { // always create cluster in CI
|
||||
cluster, err := cluster.New(log, deploymentMode, im, os.Getenv("CI") != "")
|
||||
cluster, err := cluster.New(log, _env, os.Getenv("CI") != "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -172,7 +168,7 @@ func setup(ctx context.Context) error {
|
|||
func done(ctx context.Context) error {
|
||||
// terminate early if delete flag is set to false
|
||||
if os.Getenv("CI") != "" && os.Getenv("E2E_DELETE_CLUSTER") != "false" {
|
||||
cluster, err := cluster.New(log, deploymentMode, im, os.Getenv("CI") != "")
|
||||
cluster, err := cluster.New(log, _env, os.Getenv("CI") != "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ var _ = Describe("Update clusters", func() {
|
|||
ctx := context.Background()
|
||||
value := strconv.Itoa(rand.Int())
|
||||
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, im.ResourceGroup(), clusterName)
|
||||
oc, err := clients.OpenshiftClusters.Get(ctx, _env.ResourceGroup(), clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(oc.Tags).NotTo(HaveKeyWithValue("key", &value))
|
||||
|
||||
|
@ -28,10 +28,10 @@ var _ = Describe("Update clusters", func() {
|
|||
}
|
||||
oc.Tags["key"] = &value
|
||||
|
||||
err = clients.OpenshiftClusters.CreateOrUpdateAndWait(ctx, im.ResourceGroup(), clusterName, oc)
|
||||
err = clients.OpenshiftClusters.CreateOrUpdateAndWait(ctx, _env.ResourceGroup(), clusterName, oc)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
oc, err = clients.OpenshiftClusters.Get(ctx, im.ResourceGroup(), clusterName)
|
||||
oc, err = clients.OpenshiftClusters.Get(ctx, _env.ResourceGroup(), clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(oc.Tags).To(HaveKeyWithValue("key", &value))
|
||||
})
|
||||
|
|
|
@ -15,17 +15,17 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
v1 "k8s.io/client-go/tools/clientcmd/api/v1"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift"
|
||||
"github.com/Azure/ARO-RP/pkg/util/instancemetadata"
|
||||
)
|
||||
|
||||
func Get(ctx context.Context, log *logrus.Entry, im instancemetadata.InstanceMetadata, authorizer autorest.Authorizer, resourceID string) (*v1.Config, error) {
|
||||
func Get(ctx context.Context, log *logrus.Entry, env env.Core, authorizer autorest.Authorizer, resourceID string) (*v1.Config, error) {
|
||||
res, err := azure.ParseResourceID(resourceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
openshiftclusters := redhatopenshift.NewOpenShiftClustersClient(im.Environment(), res.SubscriptionID, authorizer)
|
||||
openshiftclusters := redhatopenshift.NewOpenShiftClustersClient(env.Environment(), res.SubscriptionID, authorizer)
|
||||
|
||||
oc, err := openshiftclusters.Get(ctx, res.ResourceGroup, res.ResourceName)
|
||||
if err != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче