sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/managedagentpool.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package converters
    18  
    19  import (
    20  	asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
    21  	asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
    22  	"k8s.io/utils/ptr"
    23  )
    24  
    25  // AgentPoolToManagedClusterAgentPoolProfile converts a AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolProfile used in managedcluster reconcile.
    26  func AgentPoolToManagedClusterAgentPoolProfile(pool *asocontainerservicev1.ManagedClustersAgentPool) asocontainerservicev1.ManagedClusterAgentPoolProfile {
    27  	properties := pool.Spec
    28  	agentPool := asocontainerservicev1.ManagedClusterAgentPoolProfile{
    29  		Name:                        ptr.To(pool.AzureName()),
    30  		VmSize:                      properties.VmSize,
    31  		OsType:                      properties.OsType,
    32  		OsDiskSizeGB:                properties.OsDiskSizeGB,
    33  		Count:                       properties.Count,
    34  		Type:                        properties.Type,
    35  		OrchestratorVersion:         properties.OrchestratorVersion,
    36  		VnetSubnetReference:         properties.VnetSubnetReference,
    37  		Mode:                        properties.Mode,
    38  		EnableAutoScaling:           properties.EnableAutoScaling,
    39  		MaxCount:                    properties.MaxCount,
    40  		MinCount:                    properties.MinCount,
    41  		NodeTaints:                  properties.NodeTaints,
    42  		AvailabilityZones:           properties.AvailabilityZones,
    43  		MaxPods:                     properties.MaxPods,
    44  		OsDiskType:                  properties.OsDiskType,
    45  		NodeLabels:                  properties.NodeLabels,
    46  		EnableUltraSSD:              properties.EnableUltraSSD,
    47  		EnableNodePublicIP:          properties.EnableNodePublicIP,
    48  		NodePublicIPPrefixReference: properties.NodePublicIPPrefixReference,
    49  		ScaleSetPriority:            properties.ScaleSetPriority,
    50  		ScaleDownMode:               properties.ScaleDownMode,
    51  		SpotMaxPrice:                properties.SpotMaxPrice,
    52  		Tags:                        properties.Tags,
    53  		KubeletDiskType:             properties.KubeletDiskType,
    54  		LinuxOSConfig:               properties.LinuxOSConfig,
    55  		EnableFIPS:                  properties.EnableFIPS,
    56  		EnableEncryptionAtHost:      properties.EnableEncryptionAtHost,
    57  	}
    58  	if properties.KubeletConfig != nil {
    59  		agentPool.KubeletConfig = properties.KubeletConfig
    60  	}
    61  	return agentPool
    62  }
    63  
    64  // AgentPoolToManagedClusterAgentPoolPreviewProfile converts an AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolPreviewProfile used in managedcluster reconcile.
    65  func AgentPoolToManagedClusterAgentPoolPreviewProfile(pool *asocontainerservicev1preview.ManagedClustersAgentPool) asocontainerservicev1preview.ManagedClusterAgentPoolProfile {
    66  	properties := pool.Spec
    67  
    68  	// Populate the same properties as the stable version since the patcher will handle the preview-only fields.
    69  	agentPool := asocontainerservicev1preview.ManagedClusterAgentPoolProfile{
    70  		Name:                        ptr.To(pool.AzureName()),
    71  		VmSize:                      properties.VmSize,
    72  		OsType:                      properties.OsType,
    73  		OsDiskSizeGB:                properties.OsDiskSizeGB,
    74  		Count:                       properties.Count,
    75  		Type:                        properties.Type,
    76  		OrchestratorVersion:         properties.OrchestratorVersion,
    77  		VnetSubnetReference:         properties.VnetSubnetReference,
    78  		Mode:                        properties.Mode,
    79  		EnableAutoScaling:           properties.EnableAutoScaling,
    80  		MaxCount:                    properties.MaxCount,
    81  		MinCount:                    properties.MinCount,
    82  		NodeTaints:                  properties.NodeTaints,
    83  		AvailabilityZones:           properties.AvailabilityZones,
    84  		MaxPods:                     properties.MaxPods,
    85  		OsDiskType:                  properties.OsDiskType,
    86  		NodeLabels:                  properties.NodeLabels,
    87  		EnableUltraSSD:              properties.EnableUltraSSD,
    88  		EnableNodePublicIP:          properties.EnableNodePublicIP,
    89  		NodePublicIPPrefixReference: properties.NodePublicIPPrefixReference,
    90  		ScaleSetPriority:            properties.ScaleSetPriority,
    91  		ScaleDownMode:               properties.ScaleDownMode,
    92  		SpotMaxPrice:                properties.SpotMaxPrice,
    93  		Tags:                        properties.Tags,
    94  		KubeletDiskType:             properties.KubeletDiskType,
    95  		LinuxOSConfig:               properties.LinuxOSConfig,
    96  		EnableFIPS:                  properties.EnableFIPS,
    97  		EnableEncryptionAtHost:      properties.EnableEncryptionAtHost,
    98  	}
    99  	if properties.KubeletConfig != nil {
   100  		agentPool.KubeletConfig = properties.KubeletConfig
   101  	}
   102  	return agentPool
   103  }