Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3796ef2
Rename labelMatchCount to matchCount
mneverov Oct 26, 2026
01f4e76
Compare IP addresses, not strings, in the IP tie-break
mneverov Oct 30, 2026
b9d2c4e
Break ClusterCIDR ties by IP address, then by name
mneverov Oct 30, 2026
d4da3ab
Occupy existing Pod CIDRs in terminating ClusterCIDRs
mneverov Oct 30, 2026
8dabf35
Order catch-all ClusterCIDRs by priority
mneverov Oct 30, 2026
7d4bda8
Match ClusterCIDR node selectors with the core v1 semantics
mneverov Oct 30, 2026
2ce0ad4
Document the node selector rules in the examples README
mneverov Oct 26, 2026
3c90c87
Check that a ClusterCIDR holds every Pod CIDR before occupying any
mneverov Oct 31, 2026
371be39
Release a node's Pod CIDRs from every ClusterCIDR it is associated with
mneverov Nov 1, 2026
48af180
Occupy a node's Pod CIDRs in the ClusterCIDR it is already associated…
mneverov Nov 6, 2026
02d555a
Occupy a node's Pod CIDRs in a ClusterCIDR that holds them even if it…
mneverov Nov 6, 2026
e6fbc27
Load a ClusterCIDR whose node selector is rejected as selecting no node
mneverov Nov 6, 2026
6262d6c
Register the ClusterCIDR types for events on ClusterCIDRs
mneverov Nov 6, 2026
ad92e00
Prefer a ClusterCIDR that holds a node's Pod CIDRs whole when occupyi…
mneverov Nov 7, 2026
aaad848
Mark a ClusterCIDR that is being deleted as terminating at bootstrap
mneverov Nov 7, 2026
9983818
Fix stale comments and test names and drop a duplicate CIDR set helper
mneverov Nov 10, 2026
f556827
Add bats e2e tests for Pod CIDR allocation, release and the upgrade f…
mneverov Nov 6, 2026
fc9dba4
Pin the bats version and authenticate its download in the bats workflow
mneverov Nov 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: bats

on:
push:
branches:
- main
pull_request:
branches:
- "**"

permissions: {}

jobs:
bats:
name: bats e2e
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# A pinned version and the token keep the action off the unauthenticated
# GitHub API, whose rate limit made the download fail. The tests use no
# bats libraries.
- name: Set up bats
uses: bats-core/bats-action@77d6fb60505b4d0d1d73e48bd035b55074bbfb43 # 4.0.0
with:
bats-version: 1.11.1
github-token: ${{ secrets.GITHUB_TOKEN }}
support-install: false
assert-install: false
detik-install: false
file-install: false

- name: Run bats tests
env:
TERM: xterm
run: bats -T -o _artifacts --print-output-on-failure tests/

- name: Upload logs
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: kind-logs-bats-${{ github.run_id }}
path: ./_artifacts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ hack/test/kind/node-ipam-controller-local-test-env.yaml

# Build output
_output/

# e2e test reports and logs
_artifacts/
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ spec:
nodeSelector:
description: |-
nodeSelector defines which nodes the config is applicable to.
An empty or nil nodeSelector selects all nodes.
A nil nodeSelector makes the config apply to any node, after the configs
that select the node. An empty nodeSelector selects no node.
This field is optional and immutable.
properties:
nodeSelectorTerms:
Expand Down
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ kubectl create -f clustercidr-dual.yaml
kubectl delete -f clustercidr-dual.yaml
```

The `nodeSelector` of a ClusterCIDR follows the same rules as a Pod's node
affinity: the terms under `nodeSelectorTerms` are ORed, and the requirements
within a term are ANDed. `matchExpressions` match node labels, and
`matchFields` match the node name (`metadata.name`). A ClusterCIDR without a
`nodeSelector` applies to every node, after the ClusterCIDRs that select the
node. When several ClusterCIDRs select a node, the one whose matching term has
the most requirements is used first.

Note that to delete a ClusterCIDR, the corresponding nodes need to be deleted first as they are still using the CIDR
range. This ensures that no network conflicts occur after the deletion.

Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/clustercidr/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (in *ClusterCIDR) Default() {}
// +kubebuilder:validation:XValidation:message="A CIDR must be specified for ipv4 or ipv6.",rule="self.ipv4 != \"\" || self.ipv6 != \"\""
type ClusterCIDRSpec struct {
// nodeSelector defines which nodes the config is applicable to.
// An empty or nil nodeSelector selects all nodes.
// A nil nodeSelector makes the config apply to any node, after the configs
// that select the node. An empty nodeSelector selects no node.
// This field is optional and immutable.
// +optional
// +kubebuilder:validation:XValidation:message="NodeSelector cannot be changed.",rule="oldSelf == self"
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/ipam/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"

v1 "sigs.k8s.io/node-ipam-controller/pkg/apis/clustercidr/v1"
"sigs.k8s.io/node-ipam-controller/pkg/controller/ipam/multicidrset"
)

// loadExampleCIDRMap maps the ClusterCIDRs of the given files in the examples
// directory, the way the controller does when it creates them.
func loadExampleCIDRMap(t *testing.T, files ...string) map[string][]*multicidrset.ClusterCIDR {
func loadExampleCIDRMap(t *testing.T, files ...string) map[string]*clusterCIDREntry {
t.Helper()

ra := &multiCIDRRangeAllocator{}
cidrMap := make(map[string][]*multicidrset.ClusterCIDR)
cidrMap := make(map[string]*clusterCIDREntry)
for _, file := range files {
f, err := os.Open(filepath.Join("..", "..", "..", "examples", file))
require.NoError(t, err)
Expand All @@ -52,11 +51,12 @@ func loadExampleCIDRMap(t *testing.T, files ...string) map[string][]*multicidrse
}
require.NoError(t, err, file)

key, err := ra.nodeSelectorKey(clusterCIDR)
selector, err := ra.clusterCIDRNodeSelector(clusterCIDR)
require.NoError(t, err, clusterCIDR.Name)
clusterCIDRSet, err := ra.createClusterCIDRSet(clusterCIDR, false)
require.NoError(t, err, clusterCIDR.Name)
require.NoError(t, ra.mapClusterCIDRSet(cidrMap, key, clusterCIDRSet))
require.NotContains(t, cidrMap, clusterCIDR.Name)
require.NoError(t, ra.mapClusterCIDRSet(cidrMap, selector, clusterCIDRSet))
}
}
return cidrMap
Expand Down
Loading
Loading