Beispiel #1
0
        private AgentPool GetAgentPool()
        {
            var agentPool = new AgentPool(
                name: Name,
                count: Count,
                vmSize: VmSize,
                osDiskSizeGB: OsDiskSize,
                type: VmSetType ?? "AvailabilitySet",
                vnetSubnetID: VnetSubnetID);

            if (this.IsParameterBound(c => c.KubernetesVersion))
            {
                agentPool.OrchestratorVersion = KubernetesVersion;
            }

            if (this.IsParameterBound(c => c.OsType))
            {
                agentPool.OsType = OsType;
            }
            if (this.IsParameterBound(c => c.MaxPodCount))
            {
                agentPool.MaxPods = MaxPodCount;
            }
            if (this.IsParameterBound(c => c.MinCount))
            {
                agentPool.MinCount = MinCount;
            }
            if (this.IsParameterBound(c => c.MaxCount))
            {
                agentPool.MaxCount = MaxCount;
            }
            if (EnableAutoScaling.IsPresent)
            {
                agentPool.EnableAutoScaling = EnableAutoScaling.ToBool();
            }
            if (EnableNodePublicIp.IsPresent)
            {
                agentPool.EnableNodePublicIP = EnableNodePublicIp.ToBool();
            }
            if (this.IsParameterBound(c => c.NodePublicIPPrefixID))
            {
                agentPool.NodePublicIPPrefixID = NodePublicIPPrefixID;
            }
            if (this.IsParameterBound(c => c.ScaleSetEvictionPolicy))
            {
                agentPool.ScaleSetEvictionPolicy = ScaleSetEvictionPolicy;
            }
            if (this.IsParameterBound(c => c.ScaleSetPriority))
            {
                agentPool.ScaleSetPriority = ScaleSetPriority;
            }
            if (this.IsParameterBound(c => c.AvailabilityZone))
            {
                agentPool.AvailabilityZones = AvailabilityZone;
            }

            return(agentPool);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            AgentPool          pool     = null;
            ResourceIdentifier resource = null;

            switch (ParameterSetName)
            {
            case Constants.IdParameterSet:
                resource          = new ResourceIdentifier(Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = Utilities.GetParentResourceName(resource.ParentResource, nameof(Id));
                Name = resource.ResourceName;
                break;

            case Constants.InputObjectParameterSet:
                WriteVerbose(Resources.UsingAgentPoolFromPipeline);
                pool              = PSMapper.Instance.Map <AgentPool>(InputObject);
                resource          = new ResourceIdentifier(pool.Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = Utilities.GetParentResourceName(resource.ParentResource, nameof(InputObject));
                Name              = resource.ResourceName;
                break;

            case Constants.ParentObjectParameterSet:
                resource          = new ResourceIdentifier(ClusterObject.Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = ClusterObject.Name;
                break;
            }

            var msg = $"{Name} for {ClusterName} in {ResourceGroupName}";

            if (ShouldProcess(msg, Resources.UpdateAgentPool))
            {
                RunCmdLet(() =>
                {
                    {
                        //Put agentPool in the block to avoid referencing it incorrectly.
                        var agentPool = GetAgentPoolObject();
                        if (agentPool == null)
                        {
                            WriteErrorWithTimestamp(Resources.AgentPoolDoesNotExist);
                            return;
                        }

                        if (pool == null)
                        {
                            pool = agentPool;
                        }
                    }

                    if (this.IsParameterBound(c => c.KubernetesVersion))
                    {
                        pool.OrchestratorVersion = KubernetesVersion;
                    }
                    if (this.IsParameterBound(c => c.MinCount))
                    {
                        pool.MinCount = MinCount;
                    }
                    if (this.IsParameterBound(c => c.MaxCount))
                    {
                        pool.MaxCount = MaxCount;
                    }
                    if (this.IsParameterBound(c => c.EnableAutoScaling))
                    {
                        pool.EnableAutoScaling = EnableAutoScaling.ToBool();
                    }
                    if (this.IsParameterBound(c => c.NodeCount))
                    {
                        pool.Count = NodeCount;
                    }

                    if (this.IsParameterBound(c => c.NodeImageOnly))
                    {
                        if (this.IsParameterBound(c => c.KubernetesVersion))
                        {
                            throw new AzPSArgumentException(Resources.UpdateKubernetesVersionAndNodeImageOnlyConflict, "KubernetesVersion");
                        }
                        if (!ShouldProcess(Resources.ConfirmOnlyUpgradeNodeVersion, ""))
                        {
                            return;
                        }

                        var upgradedPool = Client.AgentPools.UpgradeNodeImageVersion(ResourceGroupName, ClusterName, Name);
                        WriteObject(PSMapper.Instance.Map <PSNodePool>(upgradedPool));
                        return;
                    }

                    var updatedPool = Client.AgentPools.CreateOrUpdate(ResourceGroupName, ClusterName, Name, pool);
                    WriteObject(PSMapper.Instance.Map <PSNodePool>(updatedPool));
                });
            }
        }