ARO-RP/pkg/deploy/deploy_rp.go

185 строки
5.7 KiB
Go
Исходник Обычный вид История

package deploy
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"encoding/base64"
"encoding/json"
mgmtdocumentdb "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
mgmtdns "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns"
mgmtfeatures "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/ARO-RP/pkg/deploy/generator"
"github.com/Azure/ARO-RP/pkg/util/arm"
)
func (d *deployer) DeployRP(ctx context.Context) error {
rpMSI, err := d.userassignedidentities.Get(ctx, d.config.RPResourceGroupName, "aro-rp-"+d.config.Location)
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
}
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)),
}
if d.config.Configuration.ARMAPICABundle != nil {
parameters.Parameters["armApiCaBundle"] = &arm.ParametersParameter{
Value: base64.StdEncoding.EncodeToString([]byte(*d.config.Configuration.ARMAPICABundle)),
}
}
ipRules := d.convertToIPAddressOrRange(d.config.Configuration.ExtraCosmosDBIPs)
parameters.Parameters["ipRules"] = &arm.ParametersParameter{
Value: ipRules,
}
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(),
}
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,
}
parameters.Parameters["azureCloudName"] = &arm.ParametersParameter{
Value: d.env.Environment().ActualCloudName,
}
2021-07-19 16:36:42 +03:00
parameters.Parameters["fluentbitImage"] = &arm.ParametersParameter{
Value: *d.config.Configuration.FluentbitImage,
}
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
}
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", "")
if err != nil {
return err
}
2021-08-18 21:54:40 +03:00
portalPIP, err := d.publicipaddresses.Get(ctx, d.config.RPResourceGroupName, "portal-pip", "")
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
zone, err := d.zones.Get(ctx, d.config.RPResourceGroupName, d.config.Location+"."+*d.config.Configuration.ClusterParentDomainName)
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,
},
},
},
}, "", "")
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,
},
},
},
}, "", "")
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
}
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
}
func (d *deployer) convertToIPAddressOrRange(ipSlice []string) []mgmtdocumentdb.IPAddressOrRange {
ips := []mgmtdocumentdb.IPAddressOrRange{}
for _, v := range ipSlice {
ips = append(ips, mgmtdocumentdb.IPAddressOrRange{IPAddressOrRange: to.StringPtr(v)})
}
return ips
}