Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv6 version check #4300

Merged
merged 4 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/29-vpc-with-ip-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kind: ClusterConfig
metadata:
name: cluster-2
region: eu-north-1
version: "1.21"

vpc:
ipFamily: IPv6
Expand Down
17 changes: 12 additions & 5 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

corev1 "k8s.io/api/core/v1"

"github.com/weaveworks/eksctl/pkg/utils"
"github.com/weaveworks/eksctl/pkg/utils/taints"

"k8s.io/apimachinery/pkg/util/validation"
Expand Down Expand Up @@ -138,11 +139,6 @@ func ValidateClusterConfig(cfg *ClusterConfig) error {
return errors.New("field secretsEncryption.keyARN is required for enabling secrets encryption")
}

// manageSharedNodeSecurityGroupRules cannot be disabled if using eksctl managed security groups
if cfg.VPC != nil && cfg.VPC.SharedNodeSecurityGroup == "" && IsDisabled(cfg.VPC.ManageSharedNodeSecurityGroupRules) {
return errors.New("vpc.manageSharedNodeSecurityGroupRules must be enabled when using ekstcl-managed security groups")
}

return nil
}

Expand Down Expand Up @@ -177,8 +173,19 @@ func (c *ClusterConfig) ValidateVPCConfig() error {
if c.IAM == nil || c.IAM != nil && IsDisabled(c.IAM.WithOIDC) {
return fmt.Errorf("oidc needs to be enabled if IPv6 is set")
}

if version, err := utils.CompareVersions(c.Metadata.Version, Version1_21); err != nil {
return fmt.Errorf("failed to convert %s cluster version to semver: %w", c.Metadata.Version, err)
} else if err == nil && version == -1 {
return fmt.Errorf("cluster version must be >= %s", Version1_21)
}
}
}

// manageSharedNodeSecurityGroupRules cannot be disabled if using eksctl managed security groups
if c.VPC.SharedNodeSecurityGroup == "" && IsDisabled(c.VPC.ManageSharedNodeSecurityGroupRules) {
return errors.New("vpc.manageSharedNodeSecurityGroupRules must be enabled when using ekstcl-managed security groups")
}
return nil
}

Expand Down
26 changes: 25 additions & 1 deletion pkg/apis/eksctl.io/v1alpha5/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ var _ = Describe("ClusterConfig validation", func() {
Expect(err).ToNot(HaveOccurred())
Expect(*cfg.VPC.IPFamily).To(Equal(string(api.IPV4Family)))
})
When("ipFamily is set ot IPv6", func() {
When("ipFamily is set to IPv6", func() {
It("accepts that setting", func() {
ipv6 := string(api.IPV6Family)
cfg.VPC.IPFamily = &ipv6
Expand All @@ -554,8 +554,32 @@ var _ = Describe("ClusterConfig validation", func() {
cfg.IAM = &api.ClusterIAM{
WithOIDC: api.Enabled(),
}
cfg.Metadata.Version = api.Version1_21
err = cfg.ValidateVPCConfig()
Expect(err).ToNot(HaveOccurred())
cfg.Metadata.Version = "1.31"
err = cfg.ValidateVPCConfig()
Expect(err).ToNot(HaveOccurred())
})
})
When("ipFamily is set ot IPv6 but version is not or too low", func() {
It("returns an error", func() {
ipv6 := string(api.IPV6Family)
cfg.VPC.IPFamily = &ipv6
cfg.Addons = append(cfg.Addons,
&api.Addon{Name: api.KubeProxyAddon},
&api.Addon{Name: api.CoreDNSAddon},
&api.Addon{Name: api.VPCCNIAddon},
)
cfg.IAM = &api.ClusterIAM{
WithOIDC: api.Enabled(),
}
cfg.Metadata.Version = ""
err = cfg.ValidateVPCConfig()
Expect(err).To(MatchError(ContainSubstring("failed to convert cluster version to semver: unable to parse first version")))
cfg.Metadata.Version = api.Version1_12
err = cfg.ValidateVPCConfig()
Expect(err).To(MatchError(ContainSubstring("cluster version must be >= 1.21")))
})
})
When("ipFamily is set ot IPv6 but no managed addons are provided", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/cmdutils/configfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ var _ = Describe("cmdutils configfile", func() {
}

err := NewMetadataLoader(cmd).Load()
Expect(err).ToNot(HaveOccurred())

cfg := cmd.ClusterConfig
Expect(err).ToNot(HaveOccurred())
Expect(cfg.Metadata.Name).ToNot(BeEmpty())
Expect(cfg.Metadata.Region).ToNot(BeEmpty())
Expect(cfg.Metadata.Region).To(Equal(cmd.ProviderConfig.Region))
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func IsMinVersion(minimumVersion, version string) (bool, error) {
// CompareVersions compares two version strings with the usual conventions:
// returns 0 if a == b
// returns 1 if a > b
// returns -1 if b < a
// returns -1 if a < b
func CompareVersions(a, b string) (int, error) {
aVersion, err := semver.ParseTolerant(a)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion userdocs/src/usage/vpc-networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ kind: ClusterConfig
metadata:
name: my-test
region: us-west-2
version: "1.21"

vpc:
ipFamily: IPv6 # or IPv4
Expand All @@ -50,7 +51,12 @@ iam:
withOIDC: true
```

This is an in config file setting only. Managed addons need to be defined when IPv6 is set along with OIDC.
This is an in config file setting only. When IPv6 is set, the following restriction must be followed:

- OIDC is enabled
- managed addons are defined as shows above
- version must be => 1.21

The default value is `IPv4`.

## Change VPC CIDR
Expand Down