Skip to content
Open
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
6 changes: 6 additions & 0 deletions assets/overlays/aws-ebs/base/csidriver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ spec:
seLinuxMount: true
volumeLifecycleModes:
- Persistent
# We set the field even though the field is not available by default.
# The API server will clear the field if the field is not enabled.
# It would be complicated to add the field conditionally in the operator
# by our usual ${xxx} replacement, because yaml fields cannot start with '$'.
# And StaticResourceController does not allow any programmatic hooks.
nodeAllocatableUpdatePeriodSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ metadata:
spec:
attachRequired: true
fsGroupPolicy: File
nodeAllocatableUpdatePeriodSeconds: 600
podInfoOnMount: false
requiresRepublish: false
seLinuxMount: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ metadata:
spec:
attachRequired: true
fsGroupPolicy: File
nodeAllocatableUpdatePeriodSeconds: 600
podInfoOnMount: false
requiresRepublish: false
seLinuxMount: true
Expand Down
28 changes: 28 additions & 0 deletions pkg/driver/aws-ebs/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func GetAWSEBSOperatorControllerConfig(ctx context.Context, flavour generator.Cl
if featureGates.Enabled(configv1.FeatureGateName("VolumeAttributesClass")) {
cfg.AddDeploymentHookBuilders(c, withVolumeAttributesClassHook)
}
if featureGates.Enabled(configv1.FeatureGateName("MutableCSINodeAllocatableCount")) {
cfg.AddDeploymentHookBuilders(c, withMutableCSINodeAllocatableCount)
}

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

cfg.ExtraReplacementsFunc = func() []string {
if featureGates.Enabled(configv1.FeatureGateName("MutableCSINodeAllocatableCount")) {
return nil
}
// CLEAR the field when the feature gate is disabled
return []string{"nodeAllocatableUpdatePeriodSeconds: 600", ""}
}

if flavour == generator.FlavourHyperShift {
volumeTagController := NewEBSVolumeTagsController(cfg.GetControllerName("EBSVolumeTagsController"), c, c.EventRecorder)
cfg.ExtraControlPlaneControllers = append(cfg.ExtraControlPlaneControllers, volumeTagController)
Expand Down Expand Up @@ -500,3 +511,20 @@ func withVolumeAttributesClassHook(c *clients.Clients) (dc.DeploymentHookFunc, [
}
return hook, nil
}

// withMutableCSINodeAllocatableCount enables the MutableCSINodeAllocatableCount feature gate in the external attacher
// TODO: remove when MutableCSINodeAllocatableCount is GA
func withMutableCSINodeAllocatableCount(c *clients.Clients) (dc.DeploymentHookFunc, []factory.Informer) {
hook := func(spec *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
fgArgument := "--feature-gates=MutableCSINodeAllocatableCount=true"
for i := range deployment.Spec.Template.Spec.Containers {
container := &deployment.Spec.Template.Spec.Containers[i]
if container.Name != "csi-attacher" {
continue
}
container.Args = append(container.Args, fgArgument)
}
return nil
}
return hook, nil
}
37 changes: 37 additions & 0 deletions pkg/driver/aws-ebs/aws_ebs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,40 @@ func Test_WithKMSKeyHook(t *testing.T) {
})
}
}

func Test_WithMutableCSINodeAllocatableCount(t *testing.T) {
cr := clients.GetFakeOperatorCR()
c := clients.NewFakeClients("clusters-test", cr)

hook, _ := withMutableCSINodeAllocatableCount(c)
deployment := getTestDeployment()
// Arrange - inject custom infrastructure

// Act
err := hook(&cr.Spec.OperatorSpec, deployment)
if err != nil {
t.Fatalf("unexpected hook error: %v", err)
}

// Assert
found := false
expectedFeatureGatesArg := "--feature-gates=MutableCSINodeAllocatableCount=true"
for _, container := range deployment.Spec.Template.Spec.Containers {
if container.Name == "csi-attacher" {
found = true
// Collect env vars from struct EnvVar to map[string]string
featureGatesArg := ""
for _, arg := range container.Args {
if strings.HasPrefix(arg, "--feature-gates") {
featureGatesArg = arg
}
}
if featureGatesArg != expectedFeatureGatesArg {
t.Errorf("expected csi-driver feature gates argument %s, got %s", expectedFeatureGatesArg, featureGatesArg)
}
}
}
if !found {
t.Errorf("container csi-attacher not found")
}
}