in pkg/api/defaults.go [958:1087]
func (cs *ContainerService) SetDefaultCerts(params DefaultCertParams) (bool, []net.IP, error) {
p := cs.Properties
if p.MasterProfile == nil {
return false, nil, nil
}
provided := certsAlreadyPresent(p.CertificateProfile, p.MasterProfile.Count)
if areAllTrue(provided) {
return false, nil, nil
}
var azureProdFQDNs []string
for _, location := range cs.GetLocations() {
azureProdFQDNs = append(azureProdFQDNs, FormatProdFQDNByLocation(p.MasterProfile.DNSPrefix, location, p.GetCustomCloudName()))
}
masterExtraFQDNs := append(azureProdFQDNs, p.MasterProfile.SubjectAltNames...)
masterExtraFQDNs = append(masterExtraFQDNs, "localhost")
firstMasterIP := net.ParseIP(p.MasterProfile.FirstConsecutiveStaticIP).To4()
localhostIP := net.ParseIP("127.0.0.1").To4()
if firstMasterIP == nil {
return false, nil, errors.Errorf("MasterProfile.FirstConsecutiveStaticIP '%s' is an invalid IP address", p.MasterProfile.FirstConsecutiveStaticIP)
}
ips := []net.IP{firstMasterIP, localhostIP}
// Include the Internal load balancer as well
if p.MasterProfile.IsVirtualMachineScaleSets() {
ips = append(ips, net.IP{firstMasterIP[0], firstMasterIP[1], byte(255), byte(DefaultInternalLbStaticIPOffset)})
} else {
// Add the Internal Loadbalancer IP which is always at p known offset from the firstMasterIP
ips = append(ips, net.IP{firstMasterIP[0], firstMasterIP[1], firstMasterIP[2], firstMasterIP[3] + byte(DefaultInternalLbStaticIPOffset)})
}
var offsetMultiplier int
if p.MasterProfile.IsVirtualMachineScaleSets() {
offsetMultiplier = p.MasterProfile.IPAddressCount
} else {
offsetMultiplier = 1
}
addr := binary.BigEndian.Uint32(firstMasterIP)
for i := 1; i < p.MasterProfile.Count; i++ {
newAddr := getNewAddr(addr, i, offsetMultiplier)
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, newAddr)
ips = append(ips, ip)
}
if p.CertificateProfile == nil {
p.CertificateProfile = &CertificateProfile{}
}
// use the specified Certificate Authority pair, or generate p new pair
var caPair *helpers.PkiKeyCertPair
if provided["ca"] {
caPair = &helpers.PkiKeyCertPair{CertificatePem: p.CertificateProfile.CaCertificate, PrivateKeyPem: p.CertificateProfile.CaPrivateKey}
} else {
var err error
pkiKeyCertPairParams := helpers.PkiKeyCertPairParams{
CommonName: "ca",
PkiKeySize: params.PkiKeySize,
}
caPair, err = helpers.CreatePkiKeyCertPair(pkiKeyCertPairParams)
if err != nil {
return false, ips, err
}
p.CertificateProfile.CaCertificate = caPair.CertificatePem
p.CertificateProfile.CaPrivateKey = caPair.PrivateKeyPem
}
serviceCIDR := p.OrchestratorProfile.KubernetesConfig.ServiceCIDR
// all validation for dual stack done with primary service cidr as that is considered
// the default ip family for cluster.
if cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6DualStack") {
// split service cidrs
serviceCIDRs := strings.Split(serviceCIDR, ",")
serviceCIDR = serviceCIDRs[0]
}
cidrFirstIP, err := common.CidrStringFirstIP(serviceCIDR)
if err != nil {
return false, ips, err
}
ips = append(ips, cidrFirstIP)
pkiParams := helpers.PkiParams{}
pkiParams.CaPair = caPair
pkiParams.ClusterDomain = DefaultKubernetesClusterDomain
pkiParams.ExtraFQDNs = masterExtraFQDNs
pkiParams.ExtraIPs = ips
pkiParams.MasterCount = p.MasterProfile.Count
pkiParams.PkiKeySize = params.PkiKeySize
apiServerPair, clientPair, kubeConfigPair, etcdServerPair, etcdClientPair, etcdPeerPairs, err :=
helpers.CreatePki(pkiParams)
if err != nil {
return false, ips, err
}
// If no Certificate Authority pair or no cert/key pair was provided, use generated cert/key pairs signed by provided Certificate Authority pair
if !provided["apiserver"] || !provided["ca"] {
p.CertificateProfile.APIServerCertificate = apiServerPair.CertificatePem
p.CertificateProfile.APIServerPrivateKey = apiServerPair.PrivateKeyPem
}
if !provided["client"] || !provided["ca"] {
p.CertificateProfile.ClientCertificate = clientPair.CertificatePem
p.CertificateProfile.ClientPrivateKey = clientPair.PrivateKeyPem
}
if !provided["kubeconfig"] || !provided["ca"] {
p.CertificateProfile.KubeConfigCertificate = kubeConfigPair.CertificatePem
p.CertificateProfile.KubeConfigPrivateKey = kubeConfigPair.PrivateKeyPem
}
if !provided["etcd"] || !provided["ca"] {
p.CertificateProfile.EtcdServerCertificate = etcdServerPair.CertificatePem
p.CertificateProfile.EtcdServerPrivateKey = etcdServerPair.PrivateKeyPem
p.CertificateProfile.EtcdClientCertificate = etcdClientPair.CertificatePem
p.CertificateProfile.EtcdClientPrivateKey = etcdClientPair.PrivateKeyPem
p.CertificateProfile.EtcdPeerCertificates = make([]string, p.MasterProfile.Count)
p.CertificateProfile.EtcdPeerPrivateKeys = make([]string, p.MasterProfile.Count)
for i, v := range etcdPeerPairs {
p.CertificateProfile.EtcdPeerCertificates[i] = v.CertificatePem
p.CertificateProfile.EtcdPeerPrivateKeys[i] = v.PrivateKeyPem
}
}
return true, ips, nil
}