Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1108 from kahun/feature/add_linuxn…
Browse files Browse the repository at this point in the history
…odeconfig

Add linuxNodeConfig field to GCPManagedMachinePool
  • Loading branch information
k8s-ci-robot authored Jan 4, 2024
2 parents 3a197fc + e698070 commit 5aed75b
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cloud/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
if nodePool.Spec.Scaling != nil {
sdkNodePool.Autoscaling = infrav1exp.ConvertToSdkAutoscaling(nodePool.Spec.Scaling)
}
if nodePool.Spec.LinuxNodeConfig != nil {
sdkNodePool.Config.LinuxNodeConfig = infrav1exp.ConvertToSdkLinuxNodeConfig(nodePool.Spec.LinuxNodeConfig)
}
if nodePool.Spec.Management != nil {
sdkNodePool.Management = &containerpb.NodeManagement{
AutoRepair: nodePool.Spec.Management.AutoRepair,
Expand Down
9 changes: 8 additions & 1 deletion cloud/services/container/nodepools/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"cloud.google.com/go/container/apiv1/containerpb"
"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/googleapis/gax-go/v2/apierror"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
Expand Down Expand Up @@ -148,7 +149,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) {
log.Info("Node pool config update required", "request", nodePoolUpdateConfigRequest)
err = s.updateNodePoolConfig(ctx, nodePoolUpdateConfigRequest)
if err != nil {
return ctrl.Result{}, fmt.Errorf("node pool config update (either version/labels/taints/locations/image type/network tag or all) failed: %s", err)
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)
}
log.Info("Node pool config updating in progress")
s.scope.GCPManagedMachinePool.Status.Ready = true
Expand Down Expand Up @@ -399,6 +400,12 @@ func (s *Service) checkDiffAndPrepareUpdateConfig(existingNodePool *containerpb.
Tags: desiredNetworkTags,
}
}
// LinuxNodeConfig
desiredLinuxNodeConfig := infrav1exp.ConvertToSdkLinuxNodeConfig(s.scope.GCPManagedMachinePool.Spec.LinuxNodeConfig)
if !cmp.Equal(desiredLinuxNodeConfig, existingNodePool.Config.LinuxNodeConfig, cmpopts.IgnoreUnexported(containerpb.LinuxNodeConfig{})) {
needUpdate = true
updateNodePoolRequest.LinuxNodeConfig = desiredLinuxNodeConfig
}

return needUpdate, &updateNodePoolRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ spec:
- value
type: object
type: array
linuxNodeConfig:
description: LinuxNodeConfig specifies the settings for Linux agent
nodes.
properties:
cgroupMode:
description: CgroupMode specifies the cgroup mode for this node
pool.
format: int32
type: integer
sysctls:
description: Sysctls specifies the sysctl settings for this node
pool.
items:
description: SysctlConfig specifies the sysctl settings for
Linux nodes.
properties:
parameter:
description: Parameter specifies sysctl parameter name.
type: string
value:
description: Value specifies sysctl parameter value.
type: string
type: object
type: array
type: object
localSsdCount:
description: LocalSsdCount is the number of local SSD disks to be
attached to the node.
Expand Down
26 changes: 26 additions & 0 deletions exp/api/v1beta1/gcpmanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type GCPManagedMachinePoolSpec struct {
// Management specifies the node pool management options.
// +optional
Management *NodePoolManagement `json:"management,omitempty"`
// LinuxNodeConfig specifies the settings for Linux agent nodes.
// +optional
LinuxNodeConfig *LinuxNodeConfig `json:"linuxNodeConfig,omitempty"`
// ProviderIDList are the provider IDs of instances in the
// managed instance group corresponding to the nodegroup represented by this
// machine pool
Expand Down Expand Up @@ -234,6 +237,29 @@ type NodePoolManagement struct {
// ManagedNodePoolLocationPolicy specifies the location policy of the node pool when autoscaling is enabled.
type ManagedNodePoolLocationPolicy string

// LinuxNodeConfig specifies the settings for Linux agent nodes.
type LinuxNodeConfig struct {
// Sysctls specifies the sysctl settings for this node pool.
// +optional
Sysctls []SysctlConfig `json:"sysctls,omitempty"`
// CgroupMode specifies the cgroup mode for this node pool.
// +optional
CgroupMode *ManagedNodePoolCgroupMode `json:"cgroupMode,omitempty"`
}

// SysctlConfig specifies the sysctl settings for Linux nodes.
type SysctlConfig struct {
// Parameter specifies sysctl parameter name.
// +optional
Parameter string `json:"parameter,omitempty"`
// Value specifies sysctl parameter value.
// +optional
Value string `json:"value,omitempty"`
}

// ManagedNodePoolCgroupMode specifies the cgroup mode of the node pool when autoscaling is enabled.
type ManagedNodePoolCgroupMode int32

const (
// ManagedNodePoolLocationPolicyBalanced aims to balance the sizes of different zones.
ManagedNodePoolLocationPolicyBalanced ManagedNodePoolLocationPolicy = "balanced"
Expand Down
29 changes: 29 additions & 0 deletions exp/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,32 @@ func ConvertFromSdkNodeVersion(sdkNodeVersion string) string {
// 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
return strings.Split(sdkNodeVersion, "-")[0]
}

// ConvertToSdkCgroupMode converts GCP SDK node version to k8s version.
func ConvertToSdkCgroupMode(cgroupMode ManagedNodePoolCgroupMode) containerpb.LinuxNodeConfig_CgroupMode {
switch cgroupMode {
case 1:
return containerpb.LinuxNodeConfig_CGROUP_MODE_V1
case 2:
return containerpb.LinuxNodeConfig_CGROUP_MODE_V2
}
return containerpb.LinuxNodeConfig_CGROUP_MODE_UNSPECIFIED
}

// ConvertToSdkLinuxNodeConfig converts GCP SDK node version to k8s version.
func ConvertToSdkLinuxNodeConfig(linuxNodeConfig *LinuxNodeConfig) *containerpb.LinuxNodeConfig {
sdkLinuxNodeConfig := containerpb.LinuxNodeConfig{}
if linuxNodeConfig != nil {
if linuxNodeConfig.Sysctls != nil {
sdkSysctl := make(map[string]string)
for _, sysctl := range linuxNodeConfig.Sysctls {
sdkSysctl[sysctl.Parameter] = sysctl.Value
}
sdkLinuxNodeConfig.Sysctls = sdkSysctl
}
if linuxNodeConfig.CgroupMode != nil {
sdkLinuxNodeConfig.CgroupMode = ConvertToSdkCgroupMode(*linuxNodeConfig.CgroupMode)
}
}
return &sdkLinuxNodeConfig
}
45 changes: 45 additions & 0 deletions exp/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5aed75b

Please sign in to comment.