Skip to content

Commit ca7b756

Browse files
committed
Enable nodeAllocatableUpdatePeriodSeconds in AWS EBS in TP
AWS EBS CSI driver should support MutableCSINodeAllocatableCount feature. Set CSIDriver nodeAllocatableUpdatePeriodSeconds to 10 minutes when the feature gate is enabled. Kubelet will then call NodeGetDriverInfo every 10 minutes to update the attach limit of EBS volumes.
1 parent 845e3ff commit ca7b756

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

assets/overlays/aws-ebs/base/csidriver.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ spec:
1414
seLinuxMount: true
1515
volumeLifecycleModes:
1616
- Persistent
17+
# This will be cleared when the MutableCSINodeAllocatableCount feature gate is disabled.
18+
# Using this approach instead of adding the field using our common ${xxx} syntax, because $ is not allowed in a YAML field name
19+
nodeAllocatableUpdatePeriodSeconds: 600

assets/overlays/aws-ebs/generated/hypershift/csidriver.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
spec:
1414
attachRequired: true
1515
fsGroupPolicy: File
16+
nodeAllocatableUpdatePeriodSeconds: 600
1617
podInfoOnMount: false
1718
requiresRepublish: false
1819
seLinuxMount: true

assets/overlays/aws-ebs/generated/standalone/csidriver.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
spec:
1414
attachRequired: true
1515
fsGroupPolicy: File
16+
nodeAllocatableUpdatePeriodSeconds: 600
1617
podInfoOnMount: false
1718
requiresRepublish: false
1819
seLinuxMount: true

pkg/driver/aws-ebs/aws_ebs.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func GetAWSEBSOperatorControllerConfig(ctx context.Context, flavour generator.Cl
183183
if featureGates.Enabled(configv1.FeatureGateName("VolumeAttributesClass")) {
184184
cfg.AddDeploymentHookBuilders(c, withVolumeAttributesClassHook)
185185
}
186+
if featureGates.Enabled(configv1.FeatureGateName("MutableCSINodeAllocatableCount")) {
187+
cfg.AddDeploymentHookBuilders(c, withMutableCSINodeAllocatableCount)
188+
}
186189

187190
cfg.AddDaemonSetHookBuilders(c, withCABundleDaemonSetHook)
188191
cfg.AddStorageClassHookBuilders(c, withKMSKeyHook)
@@ -208,6 +211,14 @@ func GetAWSEBSOperatorControllerConfig(ctx context.Context, flavour generator.Cl
208211
cfg.ExtraControlPlaneControllers = append(cfg.ExtraControlPlaneControllers, ctrl)
209212
}
210213

214+
cfg.ExtraReplacementsFunc = func() []string {
215+
if featureGates.Enabled(configv1.FeatureGateName("MutableCSINodeAllocatableCount")) {
216+
return nil
217+
}
218+
// CLEAR the field when the feature gate is disabled
219+
return []string{"nodeAllocatableUpdatePeriodSeconds: 600", ""}
220+
}
221+
211222
if flavour == generator.FlavourHyperShift {
212223
volumeTagController := NewEBSVolumeTagsController(cfg.GetControllerName("EBSVolumeTagsController"), c, c.EventRecorder)
213224
cfg.ExtraControlPlaneControllers = append(cfg.ExtraControlPlaneControllers, volumeTagController)
@@ -500,3 +511,20 @@ func withVolumeAttributesClassHook(c *clients.Clients) (dc.DeploymentHookFunc, [
500511
}
501512
return hook, nil
502513
}
514+
515+
// withMutableCSINodeAllocatableCount enables the MutableCSINodeAllocatableCount feature gate in the external attacher
516+
// TODO: remove when MutableCSINodeAllocatableCount is GA
517+
func withMutableCSINodeAllocatableCount(c *clients.Clients) (dc.DeploymentHookFunc, []factory.Informer) {
518+
hook := func(spec *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
519+
fgArgument := "--feature-gates=MutableCSINodeAllocatableCount=true"
520+
for i := range deployment.Spec.Template.Spec.Containers {
521+
container := &deployment.Spec.Template.Spec.Containers[i]
522+
if container.Name != "csi-attacher" {
523+
continue
524+
}
525+
container.Args = append(container.Args, fgArgument)
526+
}
527+
return nil
528+
}
529+
return hook, nil
530+
}

pkg/driver/aws-ebs/aws_ebs_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,40 @@ func Test_WithKMSKeyHook(t *testing.T) {
363363
})
364364
}
365365
}
366+
367+
func Test_WithMutableCSINodeAllocatableCount(t *testing.T) {
368+
cr := clients.GetFakeOperatorCR()
369+
c := clients.NewFakeClients("clusters-test", cr)
370+
371+
hook, _ := withMutableCSINodeAllocatableCount(c)
372+
deployment := getTestDeployment()
373+
// Arrange - inject custom infrastructure
374+
375+
// Act
376+
err := hook(&cr.Spec.OperatorSpec, deployment)
377+
if err != nil {
378+
t.Fatalf("unexpected hook error: %v", err)
379+
}
380+
381+
// Assert
382+
found := false
383+
expectedFeatureGatesArg := "--feature-gates=MutableCSINodeAllocatableCount=true"
384+
for _, container := range deployment.Spec.Template.Spec.Containers {
385+
if container.Name == "csi-attacher" {
386+
found = true
387+
// Collect env vars from struct EnvVar to map[string]string
388+
featureGatesArg := ""
389+
for _, arg := range container.Args {
390+
if strings.HasPrefix(arg, "--feature-gates") {
391+
featureGatesArg = arg
392+
}
393+
}
394+
if featureGatesArg != expectedFeatureGatesArg {
395+
t.Errorf("expected csi-driver feature gates argument %s, got %s", expectedFeatureGatesArg, featureGatesArg)
396+
}
397+
}
398+
}
399+
if !found {
400+
t.Errorf("container csi-attacher not found")
401+
}
402+
}

0 commit comments

Comments
 (0)