Exemplo n.º 1
0
        //public async Task<bool> CheckNameAvailabilityAsync(
        //    string aksClusterName,
        //    CancellationToken cancellationToken = default
        //) {
        //    throw new NotImplementedException();
        //}

        public ManagedClusterInner GetClusterDefinition(
            IResourceGroup resourceGroup,
            Application aksApplication,
            string aksApplicationRbacSecret,
            string aksClusterName,
            X509Certificate2 sshCertificate,
            SubnetInner virtualNetworkSubnet,
            Workspace operationalInsightsWorkspace,
            IDictionary <string, string> tags = null
            )
        {
            tags ??= new Dictionary <string, string>();

            var aksDnsPrefix = aksClusterName + "-dns";
            var aksClusterX509CertificateOpenSshPublicKey = X509CertificateHelper.GetOpenSSHPublicKey(sshCertificate);

            var managedClusterDefinition = new ManagedClusterInner(
                //nodeResourceGroup: aksResourceGroupName // This is not propagated yet.
                )
            {
                Location = resourceGroup.RegionName,
                Tags     = tags,

                //ProvisioningState = null,
                KubernetesVersion = KUBERNETES_VERSION,
                DnsPrefix         = aksDnsPrefix,
                //Fqdn = null,
                AgentPoolProfiles = new List <ManagedClusterAgentPoolProfile> {
                    new ManagedClusterAgentPoolProfile {
                        Name         = "agentpool",
                        Count        = 2,
                        VmSize       = ContainerServiceVMSizeTypes.StandardDS2V2,
                        OsDiskSizeGB = 100,
                        OsType       = OSType.Linux,
                        VnetSubnetID = virtualNetworkSubnet.Id
                    }
                },
                LinuxProfile = new ContainerServiceLinuxProfile {
                    AdminUsername = "******",
                    Ssh           = new ContainerServiceSshConfiguration {
                        PublicKeys = new List <ContainerServiceSshPublicKey> {
                            new ContainerServiceSshPublicKey {
                                KeyData = aksClusterX509CertificateOpenSshPublicKey
                            }
                        }
                    }
                },
                ServicePrincipalProfile = new ManagedClusterServicePrincipalProfile {
                    ClientId = aksApplication.AppId,
                    Secret   = aksApplicationRbacSecret
                },
                AddonProfiles = new Dictionary <string, ManagedClusterAddonProfile> {
                    { "omsagent", new ManagedClusterAddonProfile {
                          Enabled = true,
                          Config  = new Dictionary <string, string> {
                              { "logAnalyticsWorkspaceResourceID", operationalInsightsWorkspace.Id }
                          }
                      } },
                    { "httpApplicationRouting", new ManagedClusterAddonProfile {
                          Enabled = false
                      } }
                },
                //NodeResourceGroup = aksResourceGroupName, // This is not propagated yet.
                EnableRBAC     = true,
                NetworkProfile = new ContainerServiceNetworkProfile {
                    NetworkPlugin = NetworkPlugin.Azure,
                    //PodCidr = "10.244.0.0/16",
                    ServiceCidr      = NETWORK_PROFILE_SERVICE_CIDR,
                    DnsServiceIP     = NETWORK_PROFILE_DNS_SERVICE_IP,
                    DockerBridgeCidr = NETWORK_PROFILE_DOCKER_BRIDGE_CIDR
                }
            };

            managedClusterDefinition.Validate();

            return(managedClusterDefinition);
        }