Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
meixingdb committed Sep 20, 2021
1 parent 75ff0f4 commit d54dd10
Show file tree
Hide file tree
Showing 9 changed files with 844 additions and 2 deletions.
26 changes: 26 additions & 0 deletions api/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,32 @@ type AzureBastion struct {
PublicIP PublicIPSpec `json:"publicIP,omitempty"`
}

// KubeletConfig kubelet configurations of agent nodes.
type KubeletConfig struct {
// CPUManagerPolicy - CPU Manager policy to use.
CPUManagerPolicy *string `json:"cpuManagerPolicy,omitempty"`
// CPUCfsQuota - Enable CPU CFS quota enforcement for containers that specify CPU limits.
CPUCfsQuota *bool `json:"cpuCfsQuota,omitempty"`
// CPUCfsQuotaPeriod - Sets CPU CFS quota period value.
CPUCfsQuotaPeriod *string `json:"cpuCfsQuotaPeriod,omitempty"`
// ImageGcHighThreshold - The percent of disk usage after which image garbage collection is always run.
ImageGcHighThreshold *int32 `json:"imageGcHighThreshold,omitempty"`
// ImageGcLowThreshold - The percent of disk usage before which image garbage collection is never run.
ImageGcLowThreshold *int32 `json:"imageGcLowThreshold,omitempty"`
// TopologyManagerPolicy - Topology Manager policy to use.
TopologyManagerPolicy *string `json:"topologyManagerPolicy,omitempty"`
// AllowedUnsafeSysctls - Allowlist of unsafe sysctls or unsafe sysctl patterns (ending in `*`).
AllowedUnsafeSysctls *[]string `json:"allowedUnsafeSysctls,omitempty"`
// FailSwapOn - If set to true it will make the Kubelet fail to start if swap is enabled on the node.
FailSwapOn *bool `json:"failSwapOn,omitempty"`
// ContainerLogMaxSizeMB - The maximum size (e.g. 10Mi) of container log file before it is rotated.
ContainerLogMaxSizeMB *int32 `json:"containerLogMaxSizeMB,omitempty"`
// ContainerLogMaxFiles - The maximum number of container log files that can be present for a container. The number must be ≥ 2.
ContainerLogMaxFiles *int32 `json:"containerLogMaxFiles,omitempty"`
// PodMaxPids - The maximum number of processes per pod.
PodMaxPids *int32 `json:"podMaxPids,omitempty"`
}

// IsTerminalProvisioningState returns true if the ProvisioningState is a terminal state for an Azure resource.
func IsTerminalProvisioningState(state ProvisioningState) bool {
return state == Failed || state == Succeeded
Expand Down
100 changes: 100 additions & 0 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,54 @@ func (s *ManagedControlPlaneScope) GetSystemAgentPoolSpecs(ctx context.Context)
ammp.Replicas = *ownerPool.Spec.Replicas
}

if pool.Spec.MaxCount != nil {
ammp.MaxCount = pool.Spec.MaxCount
}

if pool.Spec.MinCount != nil {
ammp.MinCount = pool.Spec.MinCount
}

if pool.Spec.EnableAutoScaling != nil {
ammp.EnableAutoScaling = pool.Spec.EnableAutoScaling
}

if pool.Spec.EnableFIPS != nil {
ammp.EnableFIPS = pool.Spec.EnableFIPS
}

if pool.Spec.EnableNodePublicIP != nil {
ammp.EnableNodePublicIP = pool.Spec.EnableNodePublicIP
}

if pool.Spec.NodeLabels != nil {
ammp.NodeLabels = pool.Spec.NodeLabels
}

if pool.Spec.NodeTaints != nil {
ammp.NodeTaints = pool.Spec.NodeTaints
}

if pool.Spec.OsDiskType != nil {
ammp.OsDiskType = pool.Spec.OsDiskType
}

if pool.Spec.AvailabilityZones != nil {
ammp.AvailabilityZones = pool.Spec.AvailabilityZones
}

if pool.Spec.VnetSubnetID != nil {
ammp.VnetSubnetID = *pool.Spec.VnetSubnetID
}

if pool.Spec.MaxPods != nil {
ammp.MaxPods = pool.Spec.MaxPods
}

if pool.Spec.KubeletConfig != nil {
ammp.KubeletConfig = (*infrav1.KubeletConfig)(pool.Spec.KubeletConfig)
}

ammps = append(ammps, ammp)
}

Expand Down Expand Up @@ -506,6 +554,58 @@ func (s *ManagedControlPlaneScope) AgentPoolSpec() azure.AgentPoolSpec {
agentPoolSpec.OSDiskSizeGB = *s.InfraMachinePool.Spec.OSDiskSizeGB
}

if s.InfraMachinePool.Spec.MaxCount != nil {
agentPoolSpec.MaxCount = s.InfraMachinePool.Spec.MaxCount
}

if s.InfraMachinePool.Spec.MinCount != nil {
agentPoolSpec.MinCount = s.InfraMachinePool.Spec.MinCount
}

if s.InfraMachinePool.Spec.EnableAutoScaling != nil {
agentPoolSpec.EnableAutoScaling = s.InfraMachinePool.Spec.EnableAutoScaling
}

if s.InfraMachinePool.Spec.EnableFIPS != nil {
agentPoolSpec.EnableFIPS = s.InfraMachinePool.Spec.EnableFIPS
}

if s.InfraMachinePool.Spec.EnableNodePublicIP != nil {
agentPoolSpec.EnableNodePublicIP = s.InfraMachinePool.Spec.EnableNodePublicIP
}

if s.InfraMachinePool.Spec.NodeLabels != nil {
agentPoolSpec.NodeLabels = s.InfraMachinePool.Spec.NodeLabels
}

if s.InfraMachinePool.Spec.NodeTaints != nil {
agentPoolSpec.NodeTaints = s.InfraMachinePool.Spec.NodeTaints
}

if s.InfraMachinePool.Spec.OsDiskType != nil {
agentPoolSpec.OsDiskType = s.InfraMachinePool.Spec.OsDiskType
}

if s.InfraMachinePool.Spec.VnetSubnetID != nil {
agentPoolSpec.VnetSubnetID = *s.InfraMachinePool.Spec.VnetSubnetID
}

if s.InfraMachinePool.Spec.AvailabilityZones != nil {
agentPoolSpec.AvailabilityZones = s.InfraMachinePool.Spec.AvailabilityZones
}

if s.InfraMachinePool.Spec.ScaleSetPriority != nil {
agentPoolSpec.ScaleSetPriority = s.InfraMachinePool.Spec.ScaleSetPriority
}

if s.InfraMachinePool.Spec.MaxPods != nil {
agentPoolSpec.MaxPods = s.InfraMachinePool.Spec.MaxPods
}

if s.InfraMachinePool.Spec.KubeletConfig != nil {
agentPoolSpec.KubeletConfig = (*infrav1.KubeletConfig)(s.InfraMachinePool.Spec.KubeletConfig)
}

return agentPoolSpec
}

Expand Down
56 changes: 56 additions & 0 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,54 @@ func (s *Service) Reconcile(ctx context.Context) error {
},
}

if agentPoolSpec.MaxCount != nil {
profile.MaxCount = agentPoolSpec.MaxCount
}

if agentPoolSpec.MinCount != nil {
profile.MinCount = agentPoolSpec.MinCount
}

if agentPoolSpec.EnableAutoScaling != nil {
profile.EnableAutoScaling = agentPoolSpec.EnableAutoScaling
}

if agentPoolSpec.EnableFIPS != nil {
profile.EnableFIPS = agentPoolSpec.EnableFIPS
}

if agentPoolSpec.EnableNodePublicIP != nil {
profile.EnableNodePublicIP = agentPoolSpec.EnableNodePublicIP
}

if agentPoolSpec.NodeLabels != nil {
profile.NodeLabels = agentPoolSpec.NodeLabels
}

if agentPoolSpec.NodeTaints != nil {
profile.NodeTaints = &agentPoolSpec.NodeTaints
}

if agentPoolSpec.OsDiskType != nil {
profile.OsDiskType = containerservice.OSDiskType(*agentPoolSpec.OsDiskType)
}

if agentPoolSpec.AvailabilityZones != nil {
profile.AvailabilityZones = &agentPoolSpec.AvailabilityZones
}

if agentPoolSpec.ScaleSetPriority != nil {
profile.ScaleSetPriority = containerservice.ScaleSetPriority(*agentPoolSpec.ScaleSetPriority)
}

if agentPoolSpec.MaxPods != nil {
profile.MaxPods = agentPoolSpec.MaxPods
}

if agentPoolSpec.KubeletConfig != nil {
profile.KubeletConfig = (*containerservice.KubeletConfig)(agentPoolSpec.KubeletConfig)
}

existingPool, err := s.Client.Get(ctx, agentPoolSpec.ResourceGroup, agentPoolSpec.Cluster, agentPoolSpec.Name)
if err != nil && !azure.ResourceNotFound(err) {
return errors.Wrap(err, "failed to get existing agent pool")
Expand Down Expand Up @@ -106,6 +154,10 @@ func (s *Service) Reconcile(ctx context.Context) error {
Count: existingPool.Count,
OrchestratorVersion: existingPool.OrchestratorVersion,
Mode: existingPool.Mode,
MaxCount: existingPool.MaxCount,
MinCount: existingPool.MinCount,
EnableAutoScaling: existingPool.EnableAutoScaling,
NodeLabels: existingPool.NodeLabels,
},
}

Expand All @@ -114,6 +166,10 @@ func (s *Service) Reconcile(ctx context.Context) error {
Count: profile.Count,
OrchestratorVersion: profile.OrchestratorVersion,
Mode: profile.Mode,
MaxCount: profile.MaxCount,
MinCount: profile.MinCount,
EnableAutoScaling: profile.EnableAutoScaling,
NodeLabels: profile.NodeLabels,
},
}

Expand Down
57 changes: 56 additions & 1 deletion azure/services/managedclusters/managedclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func New(scope ManagedClusterScope) *Service {
}

// Reconcile idempotently creates or updates a managed cluster, if possible.
//gocyclo:ignore
func (s *Service) Reconcile(ctx context.Context) error {
ctx, span := tele.Tracer().Start(ctx, "managedclusters.Service.Reconcile")
defer span.End()
Expand Down Expand Up @@ -160,9 +161,63 @@ func (s *Service) Reconcile(ctx context.Context) error {
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
VnetSubnetID: &managedClusterSpec.VnetSubnetID,
Mode: containerservice.AgentPoolModeSystem,
}

if pool.VnetSubnetID != "" {
profile.VnetSubnetID = &pool.VnetSubnetID
} else {
profile.VnetSubnetID = &managedClusterSpec.VnetSubnetID
}

if pool.MaxCount != nil {
profile.MaxCount = pool.MaxCount
}

if pool.MinCount != nil {
profile.MinCount = pool.MinCount
}

if pool.EnableAutoScaling != nil {
profile.EnableAutoScaling = pool.EnableAutoScaling
}

if pool.EnableFIPS != nil {
profile.EnableFIPS = pool.EnableFIPS
}

if pool.EnableNodePublicIP != nil {
profile.EnableNodePublicIP = pool.EnableNodePublicIP
}

if pool.NodeLabels != nil {
profile.NodeLabels = pool.NodeLabels
}

if pool.NodeTaints != nil {
profile.NodeTaints = &pool.NodeTaints
}

if pool.OsDiskType != nil {
profile.OsDiskType = containerservice.OSDiskType(*pool.OsDiskType)
}

if pool.AvailabilityZones != nil {
profile.AvailabilityZones = &pool.AvailabilityZones
}

if pool.ScaleSetPriority != nil {
profile.ScaleSetPriority = containerservice.ScaleSetPriority(*pool.ScaleSetPriority)
}

if pool.MaxPods != nil {
profile.MaxPods = pool.MaxPods
}

if pool.KubeletConfig != nil {
profile.KubeletConfig = (*containerservice.KubeletConfig)(pool.KubeletConfig)
}

*managedCluster.AgentPoolProfiles = append(*managedCluster.AgentPoolProfiles, profile)
}

Expand Down
39 changes: 39 additions & 0 deletions azure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,43 @@ type AgentPoolSpec struct {

// Mode represents mode of an agent pool. Possible values include: 'System', 'User'.
Mode string

// Max count for auto scaling
MaxCount *int32 `json:"maxCount,omitempty"`

// Min count for auto scaling
MinCount *int32 `json:"minCount,omitempty"`

// Enable auto scaling
EnableAutoScaling *bool `json:"EnableAutoScaling,omitempty"`

// Enable FIPS node image
EnableFIPS *bool `json:"EnableFIPS,omitempty"`

// Enable node public IP
EnableNodePublicIP *bool `json:"EnableNodePublicIP,omitempty"`

// Node labels
NodeLabels map[string]*string `json:"NodeLabels,omitempty"`

// Node taints
NodeTaints []string `json:"NodeTaints,omitempty"`

// Node OS disk type
OsDiskType *string `json:"OsDiskType,omitempty"`

// AvailabilityZones - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType.
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// ScaleSetPriority - ScaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Spot', 'Regular'
// +optional
ScaleSetPriority *string `json:"scaleSetPriority,omitempty"`

// MaxPods - Maximum number of pods that can run on a node.
// +optional
MaxPods *int32 `json:"maxPods,omitempty"`

// KubeletConfig - KubeletConfig specifies the configuration of kubelet on agent nodes.
// +optional
KubeletConfig *infrav1.KubeletConfig `json:"kubeletConfig,omitempty"`
}
Loading

0 comments on commit d54dd10

Please sign in to comment.