зеркало из https://github.com/Azure/ARO-RP.git
add vnet to geneva output
This commit is contained in:
Родитель
949d8d1da8
Коммит
87f87b350b
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/metrics/statsd/k8s"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
||||
"github.com/Azure/ARO-RP/pkg/util/encryption"
|
||||
)
|
||||
|
||||
|
@ -94,7 +95,8 @@ func rp(ctx context.Context, log *logrus.Entry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
f, err := frontend.NewFrontend(ctx, log.WithField("component", "frontend"), _env, db, api.APIs, m, feCipher, kubeactions.New, features.NewResourcesClient, compute.NewVirtualMachinesClient)
|
||||
// TODO(mj): We need to fix this argument chain
|
||||
f, err := frontend.NewFrontend(ctx, log.WithField("component", "frontend"), _env, db, api.APIs, m, feCipher, kubeactions.New, features.NewResourcesClient, compute.NewVirtualMachinesClient, network.NewVirtualNetworksClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ func TestAdminKubernetesObjectsGetAndDelete(t *testing.T) {
|
|||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, func(*logrus.Entry, env.Interface) kubeactions.Interface {
|
||||
return kactions
|
||||
}, nil, nil)
|
||||
}, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ func TestAdminPostKubernetesObjects(t *testing.T) {
|
|||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, func(*logrus.Entry, env.Interface) kubeactions.Interface {
|
||||
return kactions
|
||||
}, nil, nil)
|
||||
}, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ func TestAdminListOpenShiftCluster(t *testing.T) {
|
|||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, cipher, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, cipher, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ func TestAdminRedeployVM(t *testing.T) {
|
|||
Subscriptions: subscriptions,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, func(subscriptionID string, authorizer autorest.Authorizer) compute.VirtualMachinesClient {
|
||||
return vmClient
|
||||
})
|
||||
}, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/util/arm"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||
"github.com/Azure/ARO-RP/pkg/util/stringutils"
|
||||
"github.com/Azure/ARO-RP/pkg/util/subnet"
|
||||
)
|
||||
|
||||
func (f *frontend) listAdminOpenShiftClusterResources(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -67,6 +68,7 @@ func (f *frontend) _listAdminOpenShiftClusterResources(ctx context.Context, r *h
|
|||
|
||||
resourcesClient := f.resourcesClientFactory(subscriptionDoc.ID, fpAuthorizer)
|
||||
vmClient := f.computeClientFactory(subscriptionDoc.ID, fpAuthorizer)
|
||||
vnetClient := f.vnetClientFactory(subscriptionDoc.ID, fpAuthorizer)
|
||||
|
||||
clusterResourceGroup := stringutils.LastTokenByte(doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
resources, err := resourcesClient.List(ctx, fmt.Sprintf("resourceGroup eq '%s'", clusterResourceGroup), "", nil)
|
||||
|
@ -75,6 +77,26 @@ func (f *frontend) _listAdminOpenShiftClusterResources(ctx context.Context, r *h
|
|||
}
|
||||
|
||||
armResources := make([]arm.Resource, 0, len(resources))
|
||||
{ // get customer vnet and append it to the list
|
||||
vnetID, _, err := subnet.Split(doc.OpenShiftCluster.Properties.MasterProfile.SubnetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := azure.ParseResourceID(vnetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vnet, err := vnetClient.Get(ctx, r.ResourceGroup, r.ResourceName, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
armResources = append(armResources, arm.Resource{
|
||||
Resource: vnet,
|
||||
})
|
||||
}
|
||||
|
||||
for _, res := range resources {
|
||||
apiVersion, err := azureclient.APIVersionForType(*res.Type)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"testing"
|
||||
|
||||
mgmtcompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute"
|
||||
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-07-01/network"
|
||||
mgmtfeatures "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features"
|
||||
"github.com/Azure/go-autorest/autorest"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
|
@ -29,10 +30,12 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
||||
"github.com/Azure/ARO-RP/pkg/util/clientauthorizer"
|
||||
mockcompute "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/compute"
|
||||
mockfeatures "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/features"
|
||||
mock_database "github.com/Azure/ARO-RP/pkg/util/mocks/database"
|
||||
mocknetwork "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/network"
|
||||
mockdatabase "github.com/Azure/ARO-RP/pkg/util/mocks/database"
|
||||
utiltls "github.com/Azure/ARO-RP/pkg/util/tls"
|
||||
"github.com/Azure/ARO-RP/test/util/listener"
|
||||
)
|
||||
|
@ -72,7 +75,7 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
type test struct {
|
||||
name string
|
||||
resourceID string
|
||||
mocks func(*test, *mock_database.MockOpenShiftClusters, *mock_database.MockSubscriptions, *mockfeatures.MockResourcesClient, *mockcompute.MockVirtualMachinesClient)
|
||||
mocks func(*test, *mockdatabase.MockOpenShiftClusters, *mockdatabase.MockSubscriptions, *mockfeatures.MockResourcesClient, *mockcompute.MockVirtualMachinesClient, *mocknetwork.MockVirtualNetworksClient)
|
||||
wantStatusCode int
|
||||
wantResponse func() []byte
|
||||
wantError string
|
||||
|
@ -82,7 +85,7 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
{
|
||||
name: "basic coverage",
|
||||
resourceID: fmt.Sprintf("/subscriptions/%s/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName", mockSubID),
|
||||
mocks: func(tt *test, openshiftClusters *mock_database.MockOpenShiftClusters, subscriptions *mock_database.MockSubscriptions, resources *mockfeatures.MockResourcesClient, compute *mockcompute.MockVirtualMachinesClient) {
|
||||
mocks: func(tt *test, openshiftClusters *mockdatabase.MockOpenShiftClusters, subscriptions *mockdatabase.MockSubscriptions, resources *mockfeatures.MockResourcesClient, compute *mockcompute.MockVirtualMachinesClient, network *mocknetwork.MockVirtualNetworksClient) {
|
||||
clusterDoc := &api.OpenShiftClusterDocument{
|
||||
Key: tt.resourceID,
|
||||
OpenShiftCluster: &api.OpenShiftCluster{
|
||||
|
@ -90,6 +93,9 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
ClusterProfile: api.ClusterProfile{
|
||||
ResourceGroupID: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster", mockSubID),
|
||||
},
|
||||
MasterProfile: api.MasterProfile{
|
||||
SubnetID: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master", mockSubID),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -122,6 +128,16 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
},
|
||||
}, nil)
|
||||
|
||||
network.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(mgmtnetwork.VirtualNetwork{
|
||||
ID: to.StringPtr("/subscriptions/id"),
|
||||
Type: to.StringPtr("Microsoft.Network/virtualNetworks"),
|
||||
VirtualNetworkPropertiesFormat: &mgmtnetwork.VirtualNetworkPropertiesFormat{
|
||||
DhcpOptions: &mgmtnetwork.DhcpOptions{
|
||||
DNSServers: &[]string{},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
resources.EXPECT().GetByID(gomock.Any(), "/subscriptions/id", azureclient.APIVersions["Microsoft.Storage"]).Return(mgmtfeatures.GenericResource{
|
||||
Name: to.StringPtr("storage"),
|
||||
ID: to.StringPtr("/subscriptions/id"),
|
||||
|
@ -139,7 +155,7 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
},
|
||||
wantStatusCode: http.StatusOK,
|
||||
wantResponse: func() []byte {
|
||||
return []byte(`[{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]` + "\n")
|
||||
return []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]}},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]` + "\n")
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
@ -160,10 +176,11 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
defer controller.Finish()
|
||||
|
||||
resourcesClient := mockfeatures.NewMockResourcesClient(controller)
|
||||
openshiftClusters := mock_database.NewMockOpenShiftClusters(controller)
|
||||
subscriptions := mock_database.NewMockSubscriptions(controller)
|
||||
openshiftClusters := mockdatabase.NewMockOpenShiftClusters(controller)
|
||||
subscriptions := mockdatabase.NewMockSubscriptions(controller)
|
||||
computeClient := mockcompute.NewMockVirtualMachinesClient(controller)
|
||||
tt.mocks(tt, openshiftClusters, subscriptions, resourcesClient, computeClient)
|
||||
vnetClientFactory := mocknetwork.NewMockVirtualNetworksClient(controller)
|
||||
tt.mocks(tt, openshiftClusters, subscriptions, resourcesClient, computeClient, vnetClientFactory)
|
||||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
|
@ -175,6 +192,9 @@ func TestAdminListResourcesList(t *testing.T) {
|
|||
func(subscriptionID string, authorizer autorest.Authorizer) compute.VirtualMachinesClient {
|
||||
return computeClient
|
||||
},
|
||||
func(subscriptionID string, authorizer autorest.Authorizer) network.VirtualNetworksClient {
|
||||
return vnetClientFactory
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -194,7 +194,7 @@ func TestGetAsyncOperationResult(t *testing.T) {
|
|||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
AsyncOperations: asyncOperations,
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ func TestGetAsyncOperationsStatus(t *testing.T) {
|
|||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
AsyncOperations: asyncOperations,
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/metrics"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
||||
"github.com/Azure/ARO-RP/pkg/util/bucket"
|
||||
"github.com/Azure/ARO-RP/pkg/util/clusterdata"
|
||||
"github.com/Azure/ARO-RP/pkg/util/encryption"
|
||||
|
@ -45,6 +46,7 @@ func (err statusCodeError) Error() string {
|
|||
type kubeActionsFactory func(*logrus.Entry, env.Interface) kubeactions.Interface
|
||||
type resourcesClientFactory func(subscriptionID string, authorizer autorest.Authorizer) features.ResourcesClient
|
||||
type computeClientFactory func(subscriptionID string, authorizer autorest.Authorizer) compute.VirtualMachinesClient
|
||||
type vnetClientFactory func(subscriptionID string, authorizer autorest.Authorizer) network.VirtualNetworksClient
|
||||
|
||||
type frontend struct {
|
||||
baseLog *logrus.Entry
|
||||
|
@ -58,6 +60,7 @@ type frontend struct {
|
|||
kubeActionsFactory kubeActionsFactory
|
||||
resourcesClientFactory resourcesClientFactory
|
||||
computeClientFactory computeClientFactory
|
||||
vnetClientFactory vnetClientFactory
|
||||
|
||||
l net.Listener
|
||||
s *http.Server
|
||||
|
@ -74,7 +77,17 @@ type Runnable interface {
|
|||
}
|
||||
|
||||
// NewFrontend returns a new runnable frontend
|
||||
func NewFrontend(ctx context.Context, baseLog *logrus.Entry, _env env.Interface, db *database.Database, apis map[string]*api.Version, m metrics.Interface, cipher encryption.Cipher, kubeActionsFactory kubeActionsFactory, resourcesClientFactory resourcesClientFactory, computeClientFactory computeClientFactory) (Runnable, error) {
|
||||
func NewFrontend(ctx context.Context,
|
||||
baseLog *logrus.Entry,
|
||||
_env env.Interface,
|
||||
db *database.Database,
|
||||
apis map[string]*api.Version,
|
||||
m metrics.Interface,
|
||||
cipher encryption.Cipher,
|
||||
kubeActionsFactory kubeActionsFactory,
|
||||
resourcesClientFactory resourcesClientFactory,
|
||||
computeClientFactory computeClientFactory,
|
||||
vnetClientFactory vnetClientFactory) (Runnable, error) {
|
||||
f := &frontend{
|
||||
baseLog: baseLog,
|
||||
env: _env,
|
||||
|
@ -85,6 +98,7 @@ func NewFrontend(ctx context.Context, baseLog *logrus.Entry, _env env.Interface,
|
|||
kubeActionsFactory: kubeActionsFactory,
|
||||
resourcesClientFactory: resourcesClientFactory,
|
||||
computeClientFactory: computeClientFactory,
|
||||
vnetClientFactory: vnetClientFactory,
|
||||
|
||||
ocEnricher: clusterdata.NewBestEffortEnricher(baseLog, _env, m),
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ func TestDeleteOpenShiftCluster(t *testing.T) {
|
|||
AsyncOperations: asyncOperations,
|
||||
OpenShiftClusters: openShiftClusters,
|
||||
Subscriptions: subscriptions,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ func TestGetOpenShiftCluster(t *testing.T) {
|
|||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -304,7 +304,7 @@ func TestListOpenShiftCluster(t *testing.T) {
|
|||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, cipher, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, cipher, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -701,7 +701,7 @@ func TestPutOrPatchOpenShiftCluster(t *testing.T) {
|
|||
AsyncOperations: asyncOperations,
|
||||
OpenShiftClusters: openShiftClusters,
|
||||
Subscriptions: subscriptions,
|
||||
}, apis, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, apis, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ func TestPostOpenShiftClusterCredentials(t *testing.T) {
|
|||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
Subscriptions: subscriptions,
|
||||
}, apis, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, apis, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestSecurity(t *testing.T) {
|
|||
pool := x509.NewCertPool()
|
||||
pool.AddCert(env.TLSCerts[0])
|
||||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, nil, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, nil, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ func TestPutSubscription(t *testing.T) {
|
|||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), env, &database.Database{
|
||||
Subscriptions: subscriptions,
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil)
|
||||
}, api.APIs, &noop.Noop{}, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче