Skip to content

Commit

Permalink
Add ipFamily validation
Browse files Browse the repository at this point in the history
Setting ipFamily to invalid value didn't return any error and kind just
created an ipv4 cluster silently. It could be a bit confusing when it is
set to some plausible but invalid values like IPv4, IPv6, Dual, ds.

Signed-off-by: Quan Tian <[email protected]>
  • Loading branch information
tnqn committed Jan 18, 2024
1 parent 40c81f1 commit 1b631bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/internal/apis/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (c *Cluster) Validate() error {
}
}

// ipFamily should be ipv4, ipv6, or dual
if c.Networking.IPFamily != IPv4Family && c.Networking.IPFamily != IPv6Family && c.Networking.IPFamily != DualStackFamily {
errs = append(errs, errors.Errorf("invalid ipFamily: %s", c.Networking.IPFamily))
}

// podSubnet should be a valid CIDR
if err := validateSubnets(c.Networking.PodSubnet, c.Networking.IPFamily); err != nil {
errs = append(errs, errors.Errorf("invalid pod subnet %v", err))
Expand Down
10 changes: 10 additions & 0 deletions pkg/internal/apis/config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ func TestClusterValidate(t *testing.T) {
}(),
ExpectErrors: 1,
},
{
Name: "bogus ipFamily",
Cluster: func() Cluster {
c := Cluster{}
SetDefaultsCluster(&c)
c.Networking.IPFamily = "ds"
return c
}(),
ExpectErrors: 1,
},
{
Name: "bogus serviceSubnet",
Cluster: func() Cluster {
Expand Down

0 comments on commit 1b631bd

Please sign in to comment.