Skip to content

Commit

Permalink
Add support for specifying node pool pod cidr range (kubernetes-sigs#94)
Browse files Browse the repository at this point in the history
* Add support for node pool pod cidr range

* fix

* fix yaml
  • Loading branch information
richardchen-db committed May 16, 2024
1 parent a8d9471 commit 850d952
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cloud/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
AutoUpgrade: nodePool.Spec.Management.AutoUpgrade,
}
}
if nodePool.Spec.NetworkConfig != nil {
sdkNodePool.NetworkConfig = &containerpb.NodeNetworkConfig{
CreatePodRange: nodePool.Spec.NetworkConfig.CreatePodRange,
PodRange: nodePool.Spec.NetworkConfig.PodRange,
PodIpv4CidrBlock: nodePool.Spec.NetworkConfig.PodIpv4CidrBlock,
}
}
if nodePool.Spec.MaxPodsConstraint != nil {
sdkNodePool.MaxPodsConstraint = &containerpb.MaxPodsConstraint{
MaxPodsPerNode: *nodePool.Spec.MaxPodsConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ spec:
the default machine type is `e2-medium`.
type: string
management:
description: NodePoolManagement specifies auto-upgrade and auto-repair
options.
description: NodeManagement configuration for this NodePool.
properties:
autoRepair:
description: AutoRepair specifies whether the node auto-repair
Expand All @@ -132,6 +131,39 @@ spec:
can be run simultaneously on a node in the node pool.
format: int64
type: integer
networkConfig:
description: Networking configuration for this NodePool. If specified,
it overrides the cluster-level defaults.
properties:
createPodRange:
description: "Whether to create a new range for pod IPs in this
node pool. Defaults are provided for `pod_range` and `pod_ipv4_cidr_block`
if they are not specified. \n If neither `create_pod_range`
or `pod_range` are specified, the cluster-level default (`ip_allocation_policy.cluster_ipv4_cidr_block`)
is used. \n Only applicable if `ip_allocation_policy.use_ip_aliases`
is true. \n This field cannot be changed after the node pool
has been created."
type: boolean
podIpv4CidrBlock:
description: "The IP address range for pod IPs in this node pool.
\n Only applicable if `create_pod_range` is true. \n Set to
blank to have a range chosen with the default size. \n Set to
/netmask (e.g. `/14`) to have a range chosen with a specific
netmask. \n Set to a [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
notation (e.g. `10.96.0.0/14`) to pick a specific range to use.
\n Only applicable if `ip_allocation_policy.use_ip_aliases`
is true. \n This field cannot be changed after the node pool
has been created."
type: string
podRange:
description: "The ID of the secondary range for pod IPs. If `create_pod_range`
is true, this ID is used for the new range. If `create_pod_range`
is false, uses an existing secondary range with this ID. \n
Only applicable if `ip_allocation_policy.use_ip_aliases` is
true. \n This field cannot be changed after the node pool has
been created."
type: string
type: object
networkTags:
description: The list of instance tags applied to all nodes. Tags
are used to identify valid sources or targets for network firewalls
Expand Down
50 changes: 50 additions & 0 deletions exp/api/v1beta1/gcpmanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ type GCPManagedMachinePoolSpec struct {
// ones added by default.
// +optional
AdditionalLabels infrav1.Labels `json:"additionalLabels,omitempty"`
// NodeManagement configuration for this NodePool.
// +optional
Management *NodePoolManagement `json:"management,omitempty"`
// Networking configuration for this NodePool. If specified, it overrides the
// cluster-level defaults.
// +optional
NetworkConfig *NodeNetworkConfig `json:"networkConfig,omitempty"`
// MaxPodsConstraint is the maximum number of pods that can be run
// simultaneously on a node in the node pool.
// +optional
Expand Down Expand Up @@ -157,6 +163,50 @@ type NodePoolManagement struct {
AutoRepair bool `json:"autoRepair,omitempty"`
}

// NodeNetworkConfig specifies networking options for node pool.
type NodeNetworkConfig struct {
// Whether to create a new range for pod IPs in this node pool.
// Defaults are provided for `pod_range` and `pod_ipv4_cidr_block` if they
// are not specified.
//
// If neither `create_pod_range` or `pod_range` are specified, the
// cluster-level default (`ip_allocation_policy.cluster_ipv4_cidr_block`) is
// used.
//
// Only applicable if `ip_allocation_policy.use_ip_aliases` is true.
//
// This field cannot be changed after the node pool has been created.
CreatePodRange bool `json:"createPodRange,omitempty"`

// The ID of the secondary range for pod IPs.
// If `create_pod_range` is true, this ID is used for the new range.
// If `create_pod_range` is false, uses an existing secondary range with this
// ID.
//
// Only applicable if `ip_allocation_policy.use_ip_aliases` is true.
//
// This field cannot be changed after the node pool has been created.
PodRange string `json:"podRange,omitempty"`

// The IP address range for pod IPs in this node pool.
//
// Only applicable if `create_pod_range` is true.
//
// Set to blank to have a range chosen with the default size.
//
// Set to /netmask (e.g. `/14`) to have a range chosen with a specific
// netmask.
//
// Set to a
// [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
// notation (e.g. `10.96.0.0/14`) to pick a specific range to use.
//
// Only applicable if `ip_allocation_policy.use_ip_aliases` is true.
//
// This field cannot be changed after the node pool has been created.
PodIpv4CidrBlock string `json:"podIpv4CidrBlock,omitempty"`
}

// ManagedNodePoolLocationPolicy specifies the location policy of the node pool when autoscaling is enabled.
type ManagedNodePoolLocationPolicy string

Expand Down
25 changes: 25 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 850d952

Please sign in to comment.