Skip to content

Commit 43de211

Browse files
authored
Enable creating IPV6 clusters with pod identities in addition to IRSA (#8322)
1 parent e082823 commit 43de211

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ logs/*
4747

4848
# Ignore social cards cache
4949
userdocs/.cache/*
50+
51+
# Visual Studio Code
52+
.vscode/

pkg/apis/eksctl.io/v1alpha5/addon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (a Addon) Validate() error {
115115

116116
if a.HasPodIDsSet() {
117117
if a.CanonicalName() == PodIdentityAgentAddon {
118-
return invalidAddonConfigErr(fmt.Sprintf("cannot set pod identity associtations for %q addon", PodIdentityAgentAddon))
118+
return invalidAddonConfigErr(fmt.Sprintf("cannot set pod identity associations for %q addon", PodIdentityAgentAddon))
119119
}
120120

121121
for i, pia := range *a.PodIdentityAssociations {

pkg/apis/eksctl.io/v1alpha5/addon_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var _ = Describe("Addon", func() {
107107
Name: api.PodIdentityAgentAddon,
108108
PodIdentityAssociations: &[]api.PodIdentityAssociation{{}},
109109
},
110-
expectedErr: "cannot set pod identity associtations for \"eks-pod-identity-agent\" addon",
110+
expectedErr: "cannot set pod identity associations for \"eks-pod-identity-agent\" addon",
111111
}),
112112
Entry("namespace is not set", addonWithPodIDEntry{
113113
addon: api.Addon{

pkg/apis/eksctl.io/v1alpha5/validation.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,15 @@ func (c *ClusterConfig) addonContainsManagedAddons(addons []string) []string {
535535
return missing
536536
}
537537

538+
func (c *ClusterConfig) getAddon(name string) *Addon {
539+
for _, addon := range c.Addons {
540+
if addon.Name == name {
541+
return addon
542+
}
543+
}
544+
return nil
545+
}
546+
538547
// ValidateClusterEndpointConfig checks the endpoint configuration for potential issues
539548
func (c *ClusterConfig) ValidateClusterEndpointConfig() error {
540549
if c.VPC.ClusterEndpoints != nil {
@@ -607,8 +616,26 @@ func (c *ClusterConfig) validateKubernetesNetworkConfig() error {
607616
if missing := c.addonContainsManagedAddons([]string{VPCCNIAddon, CoreDNSAddon, KubeProxyAddon}); len(missing) != 0 {
608617
return fmt.Errorf("the default core addons must be defined for IPv6; missing addon(s): %s; either define them or use EKS Auto Mode", strings.Join(missing, ", "))
609618
}
610-
if c.IAM == nil || c.IAM != nil && IsDisabled(c.IAM.WithOIDC) {
611-
return fmt.Errorf("oidc needs to be enabled if IPv6 is set; either set it or use EKS Auto Mode")
619+
620+
// Check if at least one credential provider (Pod identity or IRSA) is configured
621+
if len(c.addonContainsManagedAddons([]string{PodIdentityAgentAddon})) != 0 && (c.IAM == nil || c.IAM != nil && IsDisabled(c.IAM.WithOIDC)) {
622+
return errors.New("either pod identity or oidc needs to be enabled if IPv6 is set; set either one or use EKS Auto Mode")
623+
}
624+
625+
// If the pod identity addon is present, verify it is correctly configured for use by the VPC CNI addon
626+
// Assuming user intends to use pod identities if the pod identity agent addon is added.
627+
if len(c.addonContainsManagedAddons([]string{PodIdentityAgentAddon})) == 0 && !c.AddonsConfig.AutoApplyPodIdentityAssociations {
628+
vpcCNIAddonEntry := c.getAddon(VPCCNIAddon)
629+
630+
if vpcCNIAddonEntry == nil {
631+
// should be unreachable
632+
return errors.New("the vpc-cni addon must be defined for IPv6; either define it or use EKS Auto Mode")
633+
}
634+
635+
if !vpcCNIAddonEntry.UseDefaultPodIdentityAssociations &&
636+
(vpcCNIAddonEntry.PodIdentityAssociations == nil || len(*vpcCNIAddonEntry.PodIdentityAssociations) == 0) {
637+
return fmt.Errorf("Set one of: addonsConfig.autoApplyPodIdentityAssociations, useDefaultPodIdentityAssociations on the vpc-cni addon, apply a custom pod identity on the vpc-cni addon")
638+
}
612639
}
613640
}
614641

pkg/apis/eksctl.io/v1alpha5/validation_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,71 @@ var _ = Describe("ClusterConfig validation", func() {
11811181
})
11821182
})
11831183

1184+
When("ipFamily is set to IPV6, OIDC is disabled", func() {
1185+
JustBeforeEach(func() {
1186+
cfg.VPC.NAT = nil
1187+
cfg.IAM = &api.ClusterIAM{
1188+
WithOIDC: api.Disabled(),
1189+
}
1190+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.KubeProxyAddon}, &api.Addon{Name: api.CoreDNSAddon})
1191+
})
1192+
When("Pod identity addon is missing", func() {
1193+
It("returns an error", func() {
1194+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.VPCCNIAddon})
1195+
err = api.ValidateClusterConfig(cfg)
1196+
Expect(err).To(MatchError(ContainSubstring("either pod identity or oidc needs to be enabled if IPv6 is set; set either one or use EKS Auto Mode")))
1197+
})
1198+
})
1199+
1200+
When("Pod identity addon is present", func() {
1201+
JustBeforeEach(func() {
1202+
cfg.Addons = append(cfg.Addons,
1203+
&api.Addon{Name: api.PodIdentityAgentAddon})
1204+
})
1205+
1206+
When("Use default pod identity associations is set", func() {
1207+
It("accepts the setting", func() {
1208+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.VPCCNIAddon})
1209+
cfg.AddonsConfig.AutoApplyPodIdentityAssociations = true
1210+
1211+
err = api.ValidateClusterConfig(cfg)
1212+
Expect(err).ToNot(HaveOccurred())
1213+
})
1214+
})
1215+
1216+
When("Use default pod identity association is set on the vpc-cni addon", func() {
1217+
It("accepts the setting", func() {
1218+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.VPCCNIAddon, UseDefaultPodIdentityAssociations: true})
1219+
1220+
err = api.ValidateClusterConfig(cfg)
1221+
Expect(err).ToNot(HaveOccurred())
1222+
})
1223+
})
1224+
1225+
When("The vpc-cni addon has a pod identity association configured", func() {
1226+
It("accepts the setting", func() {
1227+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.VPCCNIAddon,
1228+
PodIdentityAssociations: &[]api.PodIdentityAssociation{{
1229+
Namespace: "test-namespace",
1230+
ServiceAccountName: "fakeserviceaccount",
1231+
RoleARN: "fakerolearn",
1232+
}}})
1233+
1234+
err = api.ValidateClusterConfig(cfg)
1235+
Expect(err).ToNot(HaveOccurred())
1236+
})
1237+
})
1238+
1239+
When("The vpc-cni addon is missing a pod identity configuration", func() {
1240+
It("returns an error", func() {
1241+
cfg.Addons = append(cfg.Addons, &api.Addon{Name: api.VPCCNIAddon})
1242+
err = api.ValidateClusterConfig(cfg)
1243+
Expect(err).To(MatchError(ContainSubstring("Set one of: addonsConfig.autoApplyPodIdentityAssociations, useDefaultPodIdentityAssociations on the vpc-cni addon, apply a custom pod identity on the vpc-cni addon")))
1244+
})
1245+
})
1246+
})
1247+
})
1248+
11841249
When("ipFamily is set to IPv6, no managed addons are provided, but auto-mode is used", func() {
11851250
It("accepts the setting", func() {
11861251
cfg.VPC.NAT = nil

0 commit comments

Comments
 (0)