2021-03-08 03:34:58 +03:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
|
2021-06-23 23:58:35 +03:00
|
|
|
mgmtdocumentdb "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
|
2021-03-08 03:34:58 +03:00
|
|
|
mgmtdns "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns"
|
2021-09-01 23:54:35 +03:00
|
|
|
mgmtfeatures "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features"
|
2021-03-08 03:34:58 +03:00
|
|
|
"github.com/Azure/go-autorest/autorest/to"
|
|
|
|
|
|
|
|
"github.com/Azure/ARO-RP/pkg/deploy/generator"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/util/arm"
|
|
|
|
)
|
|
|
|
|
2021-03-08 03:36:03 +03:00
|
|
|
func (d *deployer) DeployRP(ctx context.Context) error {
|
2021-03-08 03:51:21 +03:00
|
|
|
rpMSI, err := d.userassignedidentities.Get(ctx, d.config.RPResourceGroupName, "aro-rp-"+d.config.Location)
|
2021-03-08 03:34:58 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-08 20:01:12 +03:00
|
|
|
gwMSI, err := d.userassignedidentities.Get(ctx, d.config.GatewayResourceGroupName, "aro-gateway-"+d.config.Location)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-08 03:34:58 +03:00
|
|
|
deploymentName := "rp-production-" + d.version
|
|
|
|
|
|
|
|
b, err := Asset(generator.FileRPProduction)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var template map[string]interface{}
|
|
|
|
err = json.Unmarshal(b, &template)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
parameters := d.getParameters(template["parameters"].(map[string]interface{}))
|
|
|
|
parameters.Parameters["adminApiCaBundle"] = &arm.ParametersParameter{
|
|
|
|
Value: base64.StdEncoding.EncodeToString([]byte(*d.config.Configuration.AdminAPICABundle)),
|
|
|
|
}
|
2021-03-10 21:39:01 +03:00
|
|
|
if d.config.Configuration.ARMAPICABundle != nil {
|
|
|
|
parameters.Parameters["armApiCaBundle"] = &arm.ParametersParameter{
|
|
|
|
Value: base64.StdEncoding.EncodeToString([]byte(*d.config.Configuration.ARMAPICABundle)),
|
|
|
|
}
|
|
|
|
}
|
2021-06-23 23:58:35 +03:00
|
|
|
ipRules := d.convertToIPAddressOrRange(d.config.Configuration.ExtraCosmosDBIPs)
|
|
|
|
parameters.Parameters["ipRules"] = &arm.ParametersParameter{
|
|
|
|
Value: ipRules,
|
2021-03-08 03:34:58 +03:00
|
|
|
}
|
2021-03-08 20:01:12 +03:00
|
|
|
parameters.Parameters["gatewayResourceGroupName"] = &arm.ParametersParameter{
|
|
|
|
Value: d.config.GatewayResourceGroupName,
|
|
|
|
}
|
|
|
|
parameters.Parameters["gatewayServicePrincipalId"] = &arm.ParametersParameter{
|
|
|
|
Value: gwMSI.PrincipalID.String(),
|
|
|
|
}
|
2021-03-08 03:34:58 +03:00
|
|
|
parameters.Parameters["rpImage"] = &arm.ParametersParameter{
|
|
|
|
Value: *d.config.Configuration.RPImagePrefix + ":" + d.version,
|
|
|
|
}
|
|
|
|
parameters.Parameters["rpServicePrincipalId"] = &arm.ParametersParameter{
|
|
|
|
Value: rpMSI.PrincipalID.String(),
|
|
|
|
}
|
|
|
|
parameters.Parameters["vmssName"] = &arm.ParametersParameter{
|
|
|
|
Value: d.version,
|
|
|
|
}
|
2021-05-25 23:49:35 +03:00
|
|
|
parameters.Parameters["keyvaultDNSSuffix"] = &arm.ParametersParameter{
|
|
|
|
Value: d.env.Environment().KeyVaultDNSSuffix,
|
|
|
|
}
|
2021-06-02 20:36:39 +03:00
|
|
|
parameters.Parameters["azureCloudName"] = &arm.ParametersParameter{
|
2021-06-23 23:10:06 +03:00
|
|
|
Value: d.env.Environment().ActualCloudName,
|
2021-06-02 20:36:39 +03:00
|
|
|
}
|
2021-07-19 16:36:42 +03:00
|
|
|
parameters.Parameters["fluentbitImage"] = &arm.ParametersParameter{
|
|
|
|
Value: *d.config.Configuration.FluentbitImage,
|
|
|
|
}
|
2021-03-08 03:34:58 +03:00
|
|
|
|
2021-09-01 23:54:35 +03:00
|
|
|
err = d.deploy(ctx, d.config.RPResourceGroupName, deploymentName, rpVMSSPrefix+d.version,
|
|
|
|
mgmtfeatures.Deployment{
|
|
|
|
Properties: &mgmtfeatures.DeploymentProperties{
|
|
|
|
Template: template,
|
|
|
|
Mode: mgmtfeatures.Incremental,
|
|
|
|
Parameters: parameters.Parameters,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2021-08-20 19:58:47 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-03-08 03:34:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return d.configureDNS(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *deployer) configureDNS(ctx context.Context) error {
|
2021-08-18 21:54:40 +03:00
|
|
|
rpPIP, err := d.publicipaddresses.Get(ctx, d.config.RPResourceGroupName, "rp-pip", "")
|
2021-03-08 03:34:58 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-18 21:54:40 +03:00
|
|
|
portalPIP, err := d.publicipaddresses.Get(ctx, d.config.RPResourceGroupName, "portal-pip", "")
|
2021-03-08 03:34:58 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-30 19:53:33 +03:00
|
|
|
lb, err := d.loadbalancers.Get(ctx, d.config.RPResourceGroupName, "rp-lb-internal", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-18 21:54:40 +03:00
|
|
|
dbtokenIP := *((*lb.FrontendIPConfigurations)[0].PrivateIPAddress)
|
2021-03-30 19:53:33 +03:00
|
|
|
|
2021-03-08 03:51:21 +03:00
|
|
|
zone, err := d.zones.Get(ctx, d.config.RPResourceGroupName, d.config.Location+"."+*d.config.Configuration.ClusterParentDomainName)
|
2021-03-08 03:34:58 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.globalrecordsets.CreateOrUpdate(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.RPParentDomainName, "rp."+d.config.Location, mgmtdns.A, mgmtdns.RecordSet{
|
|
|
|
RecordSetProperties: &mgmtdns.RecordSetProperties{
|
|
|
|
TTL: to.Int64Ptr(3600),
|
|
|
|
ARecords: &[]mgmtdns.ARecord{
|
|
|
|
{
|
2021-08-18 21:54:40 +03:00
|
|
|
Ipv4Address: rpPIP.IPAddress,
|
2021-03-08 03:34:58 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, "", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.globalrecordsets.CreateOrUpdate(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.RPParentDomainName, d.config.Location+".admin", mgmtdns.A, mgmtdns.RecordSet{
|
|
|
|
RecordSetProperties: &mgmtdns.RecordSetProperties{
|
|
|
|
TTL: to.Int64Ptr(3600),
|
|
|
|
ARecords: &[]mgmtdns.ARecord{
|
|
|
|
{
|
2021-08-18 21:54:40 +03:00
|
|
|
Ipv4Address: portalPIP.IPAddress,
|
2021-03-08 03:34:58 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, "", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-30 19:53:33 +03:00
|
|
|
_, err = d.globalrecordsets.CreateOrUpdate(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.RPParentDomainName, "dbtoken."+d.config.Location, mgmtdns.A, mgmtdns.RecordSet{
|
|
|
|
RecordSetProperties: &mgmtdns.RecordSetProperties{
|
|
|
|
TTL: to.Int64Ptr(3600),
|
|
|
|
ARecords: &[]mgmtdns.ARecord{
|
|
|
|
{
|
2021-08-18 21:54:40 +03:00
|
|
|
Ipv4Address: &dbtokenIP,
|
2021-03-30 19:53:33 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, "", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-08 03:34:58 +03:00
|
|
|
nsRecords := make([]mgmtdns.NsRecord, 0, len(*zone.NameServers))
|
|
|
|
for i := range *zone.NameServers {
|
|
|
|
nsRecords = append(nsRecords, mgmtdns.NsRecord{
|
|
|
|
Nsdname: &(*zone.NameServers)[i],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.globalrecordsets.CreateOrUpdate(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.ClusterParentDomainName, d.config.Location, mgmtdns.NS, mgmtdns.RecordSet{
|
|
|
|
RecordSetProperties: &mgmtdns.RecordSetProperties{
|
|
|
|
TTL: to.Int64Ptr(3600),
|
|
|
|
NsRecords: &nsRecords,
|
|
|
|
},
|
|
|
|
}, "", "")
|
|
|
|
return err
|
|
|
|
}
|
2021-06-23 23:58:35 +03:00
|
|
|
|
|
|
|
func (d *deployer) convertToIPAddressOrRange(ipSlice []string) []mgmtdocumentdb.IPAddressOrRange {
|
2021-08-09 16:28:43 +03:00
|
|
|
ips := []mgmtdocumentdb.IPAddressOrRange{}
|
2021-06-23 23:58:35 +03:00
|
|
|
for _, v := range ipSlice {
|
|
|
|
ips = append(ips, mgmtdocumentdb.IPAddressOrRange{IPAddressOrRange: to.StringPtr(v)})
|
|
|
|
}
|
|
|
|
return ips
|
|
|
|
}
|