Skip to content

Commit 5aed75b

Browse files
authored
Merge pull request kubernetes-sigs#1108 from kahun/feature/add_linuxnodeconfig
Add linuxNodeConfig field to GCPManagedMachinePool
2 parents 3a197fc + e698070 commit 5aed75b

File tree

6 files changed

+136
-1
lines changed

6 files changed

+136
-1
lines changed

cloud/scope/managedmachinepool.go

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
213213
if nodePool.Spec.Scaling != nil {
214214
sdkNodePool.Autoscaling = infrav1exp.ConvertToSdkAutoscaling(nodePool.Spec.Scaling)
215215
}
216+
if nodePool.Spec.LinuxNodeConfig != nil {
217+
sdkNodePool.Config.LinuxNodeConfig = infrav1exp.ConvertToSdkLinuxNodeConfig(nodePool.Spec.LinuxNodeConfig)
218+
}
216219
if nodePool.Spec.Management != nil {
217220
sdkNodePool.Management = &containerpb.NodeManagement{
218221
AutoRepair: nodePool.Spec.Management.AutoRepair,

cloud/services/container/nodepools/reconcile.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"cloud.google.com/go/container/apiv1/containerpb"
3131
"github.com/go-logr/logr"
3232
"github.com/google/go-cmp/cmp"
33+
"github.com/google/go-cmp/cmp/cmpopts"
3334
"github.com/googleapis/gax-go/v2/apierror"
3435
"github.com/pkg/errors"
3536
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
@@ -148,7 +149,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) {
148149
log.Info("Node pool config update required", "request", nodePoolUpdateConfigRequest)
149150
err = s.updateNodePoolConfig(ctx, nodePoolUpdateConfigRequest)
150151
if err != nil {
151-
return ctrl.Result{}, fmt.Errorf("node pool config update (either version/labels/taints/locations/image type/network tag or all) failed: %s", err)
152+
return ctrl.Result{}, fmt.Errorf("node pool config update (either version/labels/taints/locations/image type/network tag/linux node config or all) failed: %s", err)
152153
}
153154
log.Info("Node pool config updating in progress")
154155
s.scope.GCPManagedMachinePool.Status.Ready = true
@@ -399,6 +400,12 @@ func (s *Service) checkDiffAndPrepareUpdateConfig(existingNodePool *containerpb.
399400
Tags: desiredNetworkTags,
400401
}
401402
}
403+
// LinuxNodeConfig
404+
desiredLinuxNodeConfig := infrav1exp.ConvertToSdkLinuxNodeConfig(s.scope.GCPManagedMachinePool.Spec.LinuxNodeConfig)
405+
if !cmp.Equal(desiredLinuxNodeConfig, existingNodePool.Config.LinuxNodeConfig, cmpopts.IgnoreUnexported(containerpb.LinuxNodeConfig{})) {
406+
needUpdate = true
407+
updateNodePoolRequest.LinuxNodeConfig = desiredLinuxNodeConfig
408+
}
402409

403410
return needUpdate, &updateNodePoolRequest
404411
}

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedmachinepools.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,31 @@ spec:
109109
- value
110110
type: object
111111
type: array
112+
linuxNodeConfig:
113+
description: LinuxNodeConfig specifies the settings for Linux agent
114+
nodes.
115+
properties:
116+
cgroupMode:
117+
description: CgroupMode specifies the cgroup mode for this node
118+
pool.
119+
format: int32
120+
type: integer
121+
sysctls:
122+
description: Sysctls specifies the sysctl settings for this node
123+
pool.
124+
items:
125+
description: SysctlConfig specifies the sysctl settings for
126+
Linux nodes.
127+
properties:
128+
parameter:
129+
description: Parameter specifies sysctl parameter name.
130+
type: string
131+
value:
132+
description: Value specifies sysctl parameter value.
133+
type: string
134+
type: object
135+
type: array
136+
type: object
112137
localSsdCount:
113138
description: LocalSsdCount is the number of local SSD disks to be
114139
attached to the node.

exp/api/v1beta1/gcpmanagedmachinepool_types.go

+26
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ type GCPManagedMachinePoolSpec struct {
106106
// Management specifies the node pool management options.
107107
// +optional
108108
Management *NodePoolManagement `json:"management,omitempty"`
109+
// LinuxNodeConfig specifies the settings for Linux agent nodes.
110+
// +optional
111+
LinuxNodeConfig *LinuxNodeConfig `json:"linuxNodeConfig,omitempty"`
109112
// ProviderIDList are the provider IDs of instances in the
110113
// managed instance group corresponding to the nodegroup represented by this
111114
// machine pool
@@ -234,6 +237,29 @@ type NodePoolManagement struct {
234237
// ManagedNodePoolLocationPolicy specifies the location policy of the node pool when autoscaling is enabled.
235238
type ManagedNodePoolLocationPolicy string
236239

240+
// LinuxNodeConfig specifies the settings for Linux agent nodes.
241+
type LinuxNodeConfig struct {
242+
// Sysctls specifies the sysctl settings for this node pool.
243+
// +optional
244+
Sysctls []SysctlConfig `json:"sysctls,omitempty"`
245+
// CgroupMode specifies the cgroup mode for this node pool.
246+
// +optional
247+
CgroupMode *ManagedNodePoolCgroupMode `json:"cgroupMode,omitempty"`
248+
}
249+
250+
// SysctlConfig specifies the sysctl settings for Linux nodes.
251+
type SysctlConfig struct {
252+
// Parameter specifies sysctl parameter name.
253+
// +optional
254+
Parameter string `json:"parameter,omitempty"`
255+
// Value specifies sysctl parameter value.
256+
// +optional
257+
Value string `json:"value,omitempty"`
258+
}
259+
260+
// ManagedNodePoolCgroupMode specifies the cgroup mode of the node pool when autoscaling is enabled.
261+
type ManagedNodePoolCgroupMode int32
262+
237263
const (
238264
// ManagedNodePoolLocationPolicyBalanced aims to balance the sizes of different zones.
239265
ManagedNodePoolLocationPolicyBalanced ManagedNodePoolLocationPolicy = "balanced"

exp/api/v1beta1/types.go

+29
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,32 @@ func ConvertFromSdkNodeVersion(sdkNodeVersion string) string {
112112
// For example, the node version returned from GCP SDK can be 1.27.2-gke.2100, we want to convert it to 1.27.2
113113
return strings.Split(sdkNodeVersion, "-")[0]
114114
}
115+
116+
// ConvertToSdkCgroupMode converts GCP SDK node version to k8s version.
117+
func ConvertToSdkCgroupMode(cgroupMode ManagedNodePoolCgroupMode) containerpb.LinuxNodeConfig_CgroupMode {
118+
switch cgroupMode {
119+
case 1:
120+
return containerpb.LinuxNodeConfig_CGROUP_MODE_V1
121+
case 2:
122+
return containerpb.LinuxNodeConfig_CGROUP_MODE_V2
123+
}
124+
return containerpb.LinuxNodeConfig_CGROUP_MODE_UNSPECIFIED
125+
}
126+
127+
// ConvertToSdkLinuxNodeConfig converts GCP SDK node version to k8s version.
128+
func ConvertToSdkLinuxNodeConfig(linuxNodeConfig *LinuxNodeConfig) *containerpb.LinuxNodeConfig {
129+
sdkLinuxNodeConfig := containerpb.LinuxNodeConfig{}
130+
if linuxNodeConfig != nil {
131+
if linuxNodeConfig.Sysctls != nil {
132+
sdkSysctl := make(map[string]string)
133+
for _, sysctl := range linuxNodeConfig.Sysctls {
134+
sdkSysctl[sysctl.Parameter] = sysctl.Value
135+
}
136+
sdkLinuxNodeConfig.Sysctls = sdkSysctl
137+
}
138+
if linuxNodeConfig.CgroupMode != nil {
139+
sdkLinuxNodeConfig.CgroupMode = ConvertToSdkCgroupMode(*linuxNodeConfig.CgroupMode)
140+
}
141+
}
142+
return &sdkLinuxNodeConfig
143+
}

exp/api/v1beta1/zz_generated.deepcopy.go

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)