2020-08-24 13:37:22 +03:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-11 00:50:05 +03:00
|
|
|
"time"
|
2020-08-24 13:37:22 +03:00
|
|
|
|
2024-06-07 10:36:15 +03:00
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
|
2022-09-23 19:49:36 +03:00
|
|
|
"github.com/Azure/go-autorest/autorest"
|
2020-08-24 13:37:22 +03:00
|
|
|
"github.com/Azure/go-autorest/autorest/azure"
|
|
|
|
configclient "github.com/openshift/client-go/config/clientset/versioned"
|
2021-09-06 17:42:15 +03:00
|
|
|
imageregistryclient "github.com/openshift/client-go/imageregistry/clientset/versioned"
|
2022-04-19 14:10:09 +03:00
|
|
|
machineclient "github.com/openshift/client-go/machine/clientset/versioned"
|
2020-08-24 13:37:22 +03:00
|
|
|
operatorclient "github.com/openshift/client-go/operator/clientset/versioned"
|
|
|
|
samplesclient "github.com/openshift/client-go/samples/clientset/versioned"
|
|
|
|
securityclient "github.com/openshift/client-go/security/clientset/versioned"
|
2021-02-19 19:28:48 +03:00
|
|
|
mcoclient "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned"
|
2020-08-24 13:37:22 +03:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
extensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
2023-11-28 18:45:00 +03:00
|
|
|
"k8s.io/client-go/dynamic"
|
2020-08-24 13:37:22 +03:00
|
|
|
"k8s.io/client-go/kubernetes"
|
2024-02-19 17:26:52 +03:00
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
2020-08-24 13:37:22 +03:00
|
|
|
|
|
|
|
"github.com/Azure/ARO-RP/pkg/api"
|
2021-02-20 03:44:31 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/cluster/graph"
|
2020-08-24 13:37:22 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/database"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/env"
|
2022-05-31 15:09:11 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/hive"
|
2022-06-28 01:45:55 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/metrics"
|
2021-01-04 18:18:16 +03:00
|
|
|
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
2022-03-16 17:07:09 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/operator/deploy"
|
2024-05-07 18:51:07 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/azblob"
|
2024-05-16 09:15:57 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork"
|
2024-06-07 10:36:15 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/common"
|
2021-02-24 15:33:52 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/authorization"
|
2020-08-24 13:37:22 +03:00
|
|
|
"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"
|
2020-11-12 00:07:14 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/privatedns"
|
2020-08-24 13:37:22 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/billing"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/util/dns"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/util/encryption"
|
2023-08-25 05:22:08 +03:00
|
|
|
utilgraph "github.com/Azure/ARO-RP/pkg/util/graph"
|
2023-05-04 20:38:24 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/refreshable"
|
2021-02-20 03:14:29 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/storage"
|
2020-08-24 13:37:22 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/subnet"
|
|
|
|
)
|
|
|
|
|
2020-08-24 13:40:49 +03:00
|
|
|
type Interface interface {
|
2020-11-09 08:44:48 +03:00
|
|
|
Install(ctx context.Context) error
|
2020-10-19 09:20:06 +03:00
|
|
|
Delete(ctx context.Context) error
|
2020-11-09 08:44:48 +03:00
|
|
|
Update(ctx context.Context) error
|
|
|
|
AdminUpdate(ctx context.Context) error
|
2020-08-24 13:40:49 +03:00
|
|
|
}
|
|
|
|
|
2020-08-24 13:37:22 +03:00
|
|
|
// manager contains information needed to install and maintain an ARO cluster
|
|
|
|
type manager struct {
|
2022-09-01 15:55:46 +03:00
|
|
|
log *logrus.Entry
|
|
|
|
env env.Interface
|
|
|
|
db database.OpenShiftClusters
|
|
|
|
dbGateway database.Gateway
|
|
|
|
dbOpenShiftVersions database.OpenShiftVersions
|
|
|
|
|
2020-10-19 09:20:06 +03:00
|
|
|
billing billing.Manager
|
|
|
|
doc *api.OpenShiftClusterDocument
|
|
|
|
subscriptionDoc *api.SubscriptionDocument
|
2023-05-04 20:38:24 +03:00
|
|
|
fpAuthorizer refreshable.Authorizer
|
2022-09-23 19:49:36 +03:00
|
|
|
localFpAuthorizer autorest.Authorizer
|
2022-06-29 23:49:51 +03:00
|
|
|
metricsEmitter metrics.Emitter
|
2020-08-24 13:37:22 +03:00
|
|
|
|
2023-08-25 05:22:08 +03:00
|
|
|
spGraphClient *utilgraph.GraphServiceClient
|
2021-03-08 20:01:12 +03:00
|
|
|
disks compute.DisksClient
|
|
|
|
virtualMachines compute.VirtualMachinesClient
|
2024-05-16 09:15:57 +03:00
|
|
|
interfaces network.InterfacesClient // TODO: use armInterfaces instead.
|
|
|
|
armInterfaces armnetwork.InterfacesClient
|
2024-06-07 10:36:15 +03:00
|
|
|
publicIPAddresses network.PublicIPAddressesClient // TODO: use armPublicIPAddresses instead.
|
|
|
|
armPublicIPAddresses armnetwork.PublicIPAddressesClient
|
2024-05-16 09:15:57 +03:00
|
|
|
loadBalancers network.LoadBalancersClient // TODO: use armLoadBalancers instead.
|
|
|
|
armLoadBalancers armnetwork.LoadBalancersClient
|
2021-03-08 20:01:12 +03:00
|
|
|
privateEndpoints network.PrivateEndpointsClient
|
|
|
|
securityGroups network.SecurityGroupsClient
|
|
|
|
deployments features.DeploymentsClient
|
|
|
|
resourceGroups features.ResourceGroupsClient
|
|
|
|
resources features.ResourcesClient
|
|
|
|
privateZones privatedns.PrivateZonesClient
|
|
|
|
virtualNetworkLinks privatedns.VirtualNetworkLinksClient
|
|
|
|
roleAssignments authorization.RoleAssignmentsClient
|
|
|
|
roleDefinitions authorization.RoleDefinitionsClient
|
|
|
|
denyAssignments authorization.DenyAssignmentClient
|
|
|
|
fpPrivateEndpoints network.PrivateEndpointsClient
|
|
|
|
rpPrivateLinkServices network.PrivateLinkServicesClient
|
2020-08-24 13:37:22 +03:00
|
|
|
|
2021-03-07 16:55:45 +03:00
|
|
|
dns dns.Manager
|
|
|
|
storage storage.Manager
|
|
|
|
subnet subnet.Manager
|
|
|
|
graph graph.Manager
|
2024-05-07 18:51:07 +03:00
|
|
|
rpBlob azblob.Manager
|
2020-08-24 13:37:22 +03:00
|
|
|
|
2024-02-19 17:26:52 +03:00
|
|
|
client client.Client
|
2022-02-16 17:16:48 +03:00
|
|
|
kubernetescli kubernetes.Interface
|
2023-11-28 18:45:00 +03:00
|
|
|
dynamiccli dynamic.Interface
|
2022-02-16 17:16:48 +03:00
|
|
|
extensionscli extensionsclient.Interface
|
2022-04-19 14:10:09 +03:00
|
|
|
maocli machineclient.Interface
|
2022-02-16 17:16:48 +03:00
|
|
|
mcocli mcoclient.Interface
|
|
|
|
operatorcli operatorclient.Interface
|
|
|
|
configcli configclient.Interface
|
|
|
|
samplescli samplesclient.Interface
|
|
|
|
securitycli securityclient.Interface
|
|
|
|
arocli aroclient.Interface
|
|
|
|
imageregistrycli imageregistryclient.Interface
|
2022-03-16 17:07:09 +03:00
|
|
|
|
2022-07-28 06:18:38 +03:00
|
|
|
installViaHive bool
|
2022-09-05 06:24:14 +03:00
|
|
|
adoptViaHive bool
|
2022-05-31 15:09:11 +03:00
|
|
|
hiveClusterManager hive.ClusterManager
|
|
|
|
|
2022-03-16 17:07:09 +03:00
|
|
|
aroOperatorDeployer deploy.Operator
|
2022-08-11 00:50:05 +03:00
|
|
|
|
|
|
|
now func() time.Time
|
2023-01-26 13:47:36 +03:00
|
|
|
|
|
|
|
openShiftClusterDocumentVersioner openShiftClusterDocumentVersioner
|
2020-08-24 13:37:22 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 08:44:48 +03:00
|
|
|
// New returns a cluster manager
|
2022-09-01 15:55:46 +03:00
|
|
|
func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database.OpenShiftClusters, dbGateway database.Gateway, dbOpenShiftVersions database.OpenShiftVersions, aead encryption.AEAD,
|
2023-04-17 17:52:22 +03:00
|
|
|
billing billing.Manager, doc *api.OpenShiftClusterDocument, subscriptionDoc *api.SubscriptionDocument, hiveClusterManager hive.ClusterManager, metricsEmitter metrics.Emitter,
|
|
|
|
) (Interface, error) {
|
2020-08-24 13:37:22 +03:00
|
|
|
r, err := azure.ParseResourceID(doc.OpenShiftCluster.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-04-03 17:28:23 +03:00
|
|
|
localFPAuthorizer, err := _env.FPAuthorizer(_env.TenantID(), _env.Environment().ResourceManagerScope)
|
2020-08-24 13:37:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:15:57 +03:00
|
|
|
// TODO: Delete once the replace to track2 is done
|
2023-05-04 20:38:24 +03:00
|
|
|
fpAuthorizer, err := refreshable.NewAuthorizer(_env, subscriptionDoc.Subscription.Properties.TenantID)
|
2020-08-24 13:37:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-06-28 18:41:20 +03:00
|
|
|
fpCredClusterTenant, err := _env.FPNewClientCertificateCredential(subscriptionDoc.Subscription.Properties.TenantID)
|
2024-05-16 09:15:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-07 18:51:07 +03:00
|
|
|
msiCredential, err := _env.NewMSITokenCredential()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-17 07:17:14 +03:00
|
|
|
msiAuthorizer, err := _env.NewMSIAuthorizer(_env.Environment().ResourceManagerScope)
|
2021-03-08 20:01:12 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
storage := storage.NewManager(_env, r.SubscriptionID, fpAuthorizer)
|
2021-02-20 03:44:31 +03:00
|
|
|
|
2022-07-28 06:18:38 +03:00
|
|
|
installViaHive, err := _env.LiveConfig().InstallViaHive(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-09-05 06:24:14 +03:00
|
|
|
adoptByHive, err := _env.LiveConfig().AdoptByHive(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-05-31 15:09:11 +03:00
|
|
|
}
|
|
|
|
|
2024-06-07 10:36:15 +03:00
|
|
|
clientOptions := arm.ClientOptions{
|
|
|
|
ClientOptions: azcore.ClientOptions{
|
|
|
|
Cloud: _env.Environment().Cloud,
|
|
|
|
Retry: common.RetryOptions,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-06-28 18:41:20 +03:00
|
|
|
armLoadBalancersClient, err := armnetwork.NewLoadBalancersClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
|
2024-06-07 10:36:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-06-28 18:41:20 +03:00
|
|
|
armInterfacesClient, err := armnetwork.NewInterfacesClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
|
2024-05-16 09:15:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-06-28 18:41:20 +03:00
|
|
|
armPublicIPAddressesClient, err := armnetwork.NewPublicIPAddressesClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
|
2024-05-16 09:15:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-06-07 01:16:12 +03:00
|
|
|
rpBlob, err := azblob.NewManager(_env.Environment(), _env.SubscriptionID(), msiCredential)
|
2024-05-07 18:51:07 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-08-24 13:37:22 +03:00
|
|
|
return &manager{
|
2022-06-29 23:49:51 +03:00
|
|
|
log: log,
|
|
|
|
env: _env,
|
|
|
|
db: db,
|
|
|
|
dbGateway: dbGateway,
|
2022-09-01 15:55:46 +03:00
|
|
|
dbOpenShiftVersions: dbOpenShiftVersions,
|
2022-06-29 23:49:51 +03:00
|
|
|
billing: billing,
|
|
|
|
doc: doc,
|
|
|
|
subscriptionDoc: subscriptionDoc,
|
|
|
|
fpAuthorizer: fpAuthorizer,
|
|
|
|
localFpAuthorizer: localFPAuthorizer,
|
|
|
|
metricsEmitter: metricsEmitter,
|
2021-03-08 20:01:12 +03:00
|
|
|
disks: compute.NewDisksClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
virtualMachines: compute.NewVirtualMachinesClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
interfaces: network.NewInterfacesClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
2024-05-16 09:15:57 +03:00
|
|
|
armInterfaces: armInterfacesClient,
|
2021-03-08 20:01:12 +03:00
|
|
|
publicIPAddresses: network.NewPublicIPAddressesClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
2024-06-07 10:36:15 +03:00
|
|
|
armPublicIPAddresses: armPublicIPAddressesClient,
|
2021-03-08 20:01:12 +03:00
|
|
|
loadBalancers: network.NewLoadBalancersClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
2024-05-16 09:15:57 +03:00
|
|
|
armLoadBalancers: armLoadBalancersClient,
|
2021-03-08 20:01:12 +03:00
|
|
|
privateEndpoints: network.NewPrivateEndpointsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
securityGroups: network.NewSecurityGroupsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
deployments: features.NewDeploymentsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
resourceGroups: features.NewResourceGroupsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
resources: features.NewResourcesClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
privateZones: privatedns.NewPrivateZonesClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
virtualNetworkLinks: privatedns.NewVirtualNetworkLinksClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
roleAssignments: authorization.NewRoleAssignmentsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
roleDefinitions: authorization.NewRoleDefinitionsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
denyAssignments: authorization.NewDenyAssignmentsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
|
|
|
fpPrivateEndpoints: network.NewPrivateEndpointsClient(_env.Environment(), _env.SubscriptionID(), localFPAuthorizer),
|
|
|
|
rpPrivateLinkServices: network.NewPrivateLinkServicesClient(_env.Environment(), _env.SubscriptionID(), msiAuthorizer),
|
|
|
|
|
|
|
|
dns: dns.NewManager(_env, localFPAuthorizer),
|
2021-03-07 16:55:45 +03:00
|
|
|
storage: storage,
|
2021-08-17 12:15:03 +03:00
|
|
|
subnet: subnet.NewManager(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
2024-03-13 07:15:34 +03:00
|
|
|
graph: graph.NewManager(_env, log, aead, storage),
|
2024-05-07 18:51:07 +03:00
|
|
|
rpBlob: rpBlob,
|
2022-05-31 15:09:11 +03:00
|
|
|
|
2023-01-26 13:47:36 +03:00
|
|
|
installViaHive: installViaHive,
|
|
|
|
adoptViaHive: adoptByHive,
|
|
|
|
hiveClusterManager: hiveClusterManager,
|
|
|
|
now: func() time.Time { return time.Now() },
|
|
|
|
openShiftClusterDocumentVersioner: new(openShiftClusterDocumentVersionerService),
|
2020-08-24 13:37:22 +03:00
|
|
|
}, nil
|
|
|
|
}
|