Skip to content

Commit a22ac11

Browse files
Merge pull request #314 from dfajmon/volumeattributesclass
STOR-2078: Enable VolumeAttributesClass on AWS EBS for resizer + provisioner
2 parents a615ba3 + 54f6633 commit a22ac11

9 files changed

+162
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: ${ASSET_SHORT_PREFIX}-csi-volumeattributesclass-reader-provisioner-binding
5+
subjects:
6+
- kind: ServiceAccount
7+
name: ${ASSET_PREFIX}-controller-sa
8+
namespace: ${NODE_NAMESPACE}
9+
roleRef:
10+
kind: ClusterRole
11+
name: openshift-csi-provisioner-volumeattributesclass-reader-role
12+
apiGroup: rbac.authorization.k8s.io
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: ${ASSET_SHORT_PREFIX}-csi-volumeattributesclass-reader-resizer-binding
5+
subjects:
6+
- kind: ServiceAccount
7+
name: ${ASSET_PREFIX}-controller-sa
8+
namespace: ${NODE_NAMESPACE}
9+
roleRef:
10+
kind: ClusterRole
11+
name: openshift-csi-resizer-volumeattributesclass-reader-role
12+
apiGroup: rbac.authorization.k8s.io

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ guestStaticAssetNames:
1919
- storageclass_gp2.yaml
2020
- storageclass_gp3.yaml
2121
- storageclass_reader_resizer_binding.yaml
22+
- volumeattributesclass_reader_provisioner_binding.yaml
23+
- volumeattributesclass_reader_resizer_binding.yaml
2224
- volumesnapshot_reader_provisioner_binding.yaml
2325
- volumesnapshotclass.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated file. Do not edit. Update using "make update".
2+
#
3+
# Loaded from base/rbac/volumeattributesclass_reader_provisioner_binding.yaml
4+
# because it's needed by controller sidecar common/sidecars/provisioner.yaml
5+
#
6+
#
7+
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: ebs-csi-volumeattributesclass-reader-provisioner-binding
12+
roleRef:
13+
apiGroup: rbac.authorization.k8s.io
14+
kind: ClusterRole
15+
name: openshift-csi-provisioner-volumeattributesclass-reader-role
16+
subjects:
17+
- kind: ServiceAccount
18+
name: aws-ebs-csi-driver-controller-sa
19+
namespace: ${NODE_NAMESPACE}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated file. Do not edit. Update using "make update".
2+
#
3+
# Loaded from base/rbac/volumeattributesclass_reader_resizer_binding.yaml
4+
# because it's needed by controller sidecar common/sidecars/resizer.yaml
5+
#
6+
#
7+
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: ebs-csi-volumeattributesclass-reader-resizer-binding
12+
roleRef:
13+
apiGroup: rbac.authorization.k8s.io
14+
kind: ClusterRole
15+
name: openshift-csi-resizer-volumeattributesclass-reader-role
16+
subjects:
17+
- kind: ServiceAccount
18+
name: aws-ebs-csi-driver-controller-sa
19+
namespace: ${NODE_NAMESPACE}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ guestStaticAssetNames:
2424
- storageclass_gp2.yaml
2525
- storageclass_gp3.yaml
2626
- storageclass_reader_resizer_binding.yaml
27+
- volumeattributesclass_reader_provisioner_binding.yaml
28+
- volumeattributesclass_reader_resizer_binding.yaml
2729
- volumesnapshot_reader_provisioner_binding.yaml
2830
- volumesnapshotclass.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated file. Do not edit. Update using "make update".
2+
#
3+
# Loaded from base/rbac/volumeattributesclass_reader_provisioner_binding.yaml
4+
# because it's needed by controller sidecar common/sidecars/provisioner.yaml
5+
#
6+
#
7+
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: ebs-csi-volumeattributesclass-reader-provisioner-binding
12+
roleRef:
13+
apiGroup: rbac.authorization.k8s.io
14+
kind: ClusterRole
15+
name: openshift-csi-provisioner-volumeattributesclass-reader-role
16+
subjects:
17+
- kind: ServiceAccount
18+
name: aws-ebs-csi-driver-controller-sa
19+
namespace: ${NODE_NAMESPACE}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated file. Do not edit. Update using "make update".
2+
#
3+
# Loaded from base/rbac/volumeattributesclass_reader_resizer_binding.yaml
4+
# because it's needed by controller sidecar common/sidecars/resizer.yaml
5+
#
6+
#
7+
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: ebs-csi-volumeattributesclass-reader-resizer-binding
12+
roleRef:
13+
apiGroup: rbac.authorization.k8s.io
14+
kind: ClusterRole
15+
name: openshift-csi-resizer-volumeattributesclass-reader-role
16+
subjects:
17+
- kind: ServiceAccount
18+
name: aws-ebs-csi-driver-controller-sa
19+
namespace: ${NODE_NAMESPACE}

pkg/driver/aws-ebs/aws_ebs.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package aws_ebs
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
8+
"time"
79

10+
configv1 "github.com/openshift/api/config/v1"
811
opv1 "github.com/openshift/api/operator/v1"
912
"github.com/openshift/csi-operator/assets"
1013
"github.com/openshift/csi-operator/pkg/clients"
@@ -13,6 +16,7 @@ import (
1316
"github.com/openshift/csi-operator/pkg/generator"
1417
"github.com/openshift/csi-operator/pkg/operator/config"
1518
"github.com/openshift/library-go/pkg/controller/factory"
19+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1620
"github.com/openshift/library-go/pkg/operator/csi/csidrivercontrollerservicecontroller"
1721
"github.com/openshift/library-go/pkg/operator/csi/csidrivernodeservicecontroller"
1822
"github.com/openshift/library-go/pkg/operator/csi/csistorageclasscontroller"
@@ -23,6 +27,7 @@ import (
2327
storagev1 "k8s.io/api/storage/v1"
2428
apierrors "k8s.io/apimachinery/pkg/api/errors"
2529
corev1listers "k8s.io/client-go/listers/core/v1"
30+
2631
"k8s.io/klog/v2"
2732
)
2833

@@ -36,6 +41,8 @@ const (
3641
trustedCAConfigMap = "aws-ebs-csi-driver-trusted-ca-bundle"
3742
kmsKeyID = "kmsKeyId"
3843

44+
operatorImageVersionEnvVarName = "OPERATOR_IMAGE_VERSION"
45+
3946
generatedAssetBase = "overlays/aws-ebs/generated"
4047
)
4148

@@ -69,6 +76,8 @@ func GetAWSEBSGeneratorConfig() *generator.CSIDriverGeneratorConfig {
6976
"--kube-api-qps=20",
7077
"--kube-api-burst=100",
7178
"--worker-threads=100",
79+
).WithAdditionalAssets(
80+
"base/rbac/volumeattributesclass_reader_provisioner_binding.yaml",
7281
),
7382
commongenerator.DefaultAttacher.WithExtraArguments(
7483
"--timeout=60s",
@@ -81,6 +90,8 @@ func GetAWSEBSGeneratorConfig() *generator.CSIDriverGeneratorConfig {
8190
"--kube-api-qps=20",
8291
"--kube-api-burst=100",
8392
"--workers=100",
93+
).WithAdditionalAssets(
94+
"base/rbac/volumeattributesclass_reader_resizer_binding.yaml",
8495
),
8596
commongenerator.DefaultSnapshotter.WithExtraArguments(
8697
"--extra-create-metadata",
@@ -136,12 +147,43 @@ func GetAWSEBSOperatorConfig() *config.OperatorConfig {
136147
func GetAWSEBSOperatorControllerConfig(ctx context.Context, flavour generator.ClusterFlavour, c *clients.Clients) (*config.OperatorControllerConfig, error) {
137148
cfg := operator.NewDefaultOperatorControllerConfig(flavour, c, "AWSEBS")
138149

150+
// We need featuregate accessor made available to the operator pods
151+
desiredVersion := os.Getenv(operatorImageVersionEnvVarName)
152+
missingVersion := "0.0.1-snapshot"
153+
154+
featureGateAccessor := featuregates.NewFeatureGateAccess(
155+
desiredVersion,
156+
missingVersion,
157+
c.ConfigInformers.Config().V1().ClusterVersions(),
158+
c.ConfigInformers.Config().V1().FeatureGates(),
159+
c.EventRecorder,
160+
)
161+
go featureGateAccessor.Run(ctx)
162+
go c.ConfigInformers.Start(ctx.Done())
163+
164+
var featureGates featuregates.FeatureGate
165+
166+
select {
167+
case <-featureGateAccessor.InitialFeatureGatesObserved():
168+
featureGates, _ = featureGateAccessor.CurrentFeatureGates()
169+
klog.Info("FeatureGates initialized", "knownFeatures", featureGates.KnownFeatures())
170+
case <-time.After(1 * time.Minute):
171+
klog.Error(nil, "timed out waiting for FeatureGate detection")
172+
return nil, fmt.Errorf("timed out waiting for FeatureGate detection")
173+
}
174+
139175
// Hooks to run on all clusters
140176
cfg.AddDeploymentHookBuilders(c,
141177
withAWSRegion,
142178
withCustomTags,
143179
withCustomEndPoint,
144-
withCABundleDeploymentHook)
180+
withCABundleDeploymentHook,
181+
)
182+
183+
if featureGates.Enabled(configv1.FeatureGateName("VolumeAttributesClass")) {
184+
cfg.AddDeploymentHookBuilders(c, withVolumeAttributesClassHook)
185+
}
186+
145187
cfg.AddDaemonSetHookBuilders(c, withCABundleDaemonSetHook)
146188
cfg.AddStorageClassHookBuilders(c, withKMSKeyHook)
147189

@@ -434,3 +476,18 @@ func withKMSKeyHook(c *clients.Clients) csistorageclasscontroller.StorageClassHo
434476
}
435477
return hook
436478
}
479+
480+
func withVolumeAttributesClassHook(c *clients.Clients) (dc.DeploymentHookFunc, []factory.Informer) {
481+
hook := func(_ *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
482+
newArg := "--feature-gates=VolumeAttributesClass=true"
483+
for i := range deployment.Spec.Template.Spec.Containers {
484+
container := &deployment.Spec.Template.Spec.Containers[i]
485+
if container.Name == "csi-provisioner" || container.Name == "csi-resizer" {
486+
container.Args = append(container.Args, newArg)
487+
}
488+
}
489+
490+
return nil
491+
}
492+
return hook, nil
493+
}

0 commit comments

Comments
 (0)