@@ -1523,6 +1523,7 @@ func TestCSIDriverValidation(t *testing.T) {
15231523 featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .SELinuxMountReadWriteOncePod , true )
15241524 // assume this feature is on for this test, detailed enabled/disabled tests in TestMutableCSINodeAllocatableCountEnabledDisabled
15251525 featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .MutableCSINodeAllocatableCount , true )
1526+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIServiceAccountTokenSecrets , true )
15261527
15271528 driverName := "test-driver"
15281529 longName := "my-a-b-c-d-c-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-ABCDEFGHIJKLMNOPQRSTUVWXYZ-driver"
@@ -1536,10 +1537,13 @@ func TestCSIDriverValidation(t *testing.T) {
15361537 notStorageCapacity := false
15371538 seLinuxMount := true
15381539 notSELinuxMount := false
1540+ serviceAccountTokenInSecrets := true
1541+ notServiceAccountTokenInSecrets := false
15391542 supportedFSGroupPolicy := storage .FileFSGroupPolicy
15401543 invalidFSGroupPolicy := storage .FSGroupPolicy ("invalid-mode" )
15411544 validNodeAllocatableUpdatePeriodSeconds := int64 (10 )
15421545 invalidNodeAllocatableUpdatePeriodSeconds := int64 (9 )
1546+ tokenRequests := []storage.TokenRequest {{Audience : "test-audience" }}
15431547 successCases := []storage.CSIDriver {{
15441548 ObjectMeta : metav1.ObjectMeta {Name : driverName },
15451549 Spec : storage.CSIDriverSpec {
@@ -1709,6 +1713,41 @@ func TestCSIDriverValidation(t *testing.T) {
17091713 SELinuxMount : & seLinuxMount ,
17101714 NodeAllocatableUpdatePeriodSeconds : & validNodeAllocatableUpdatePeriodSeconds ,
17111715 },
1716+ }, {
1717+ // With ServiceAccountTokenInSecrets set to true with TokenRequests
1718+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1719+ Spec : storage.CSIDriverSpec {
1720+ AttachRequired : & attachNotRequired ,
1721+ PodInfoOnMount : & notPodInfoOnMount ,
1722+ RequiresRepublish : & notRequiresRepublish ,
1723+ StorageCapacity : & storageCapacity ,
1724+ SELinuxMount : & seLinuxMount ,
1725+ ServiceAccountTokenInSecrets : & serviceAccountTokenInSecrets ,
1726+ TokenRequests : tokenRequests ,
1727+ },
1728+ }, {
1729+ // With ServiceAccountTokenInSecrets set to false with TokenRequests
1730+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1731+ Spec : storage.CSIDriverSpec {
1732+ AttachRequired : & attachNotRequired ,
1733+ PodInfoOnMount : & notPodInfoOnMount ,
1734+ RequiresRepublish : & notRequiresRepublish ,
1735+ StorageCapacity : & storageCapacity ,
1736+ SELinuxMount : & seLinuxMount ,
1737+ ServiceAccountTokenInSecrets : & notServiceAccountTokenInSecrets ,
1738+ TokenRequests : tokenRequests ,
1739+ },
1740+ }, {
1741+ // With ServiceAccountTokenInSecrets set to nil (not set)
1742+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1743+ Spec : storage.CSIDriverSpec {
1744+ AttachRequired : & attachNotRequired ,
1745+ PodInfoOnMount : & notPodInfoOnMount ,
1746+ RequiresRepublish : & notRequiresRepublish ,
1747+ StorageCapacity : & storageCapacity ,
1748+ SELinuxMount : & seLinuxMount ,
1749+ ServiceAccountTokenInSecrets : nil ,
1750+ },
17121751 }}
17131752
17141753 for _ , csiDriver := range successCases {
@@ -1799,6 +1838,16 @@ func TestCSIDriverValidation(t *testing.T) {
17991838 SELinuxMount : & seLinuxMount ,
18001839 NodeAllocatableUpdatePeriodSeconds : & invalidNodeAllocatableUpdatePeriodSeconds ,
18011840 },
1841+ }, {
1842+ // ServiceAccountTokenInSecrets set without TokenRequests (invalid)
1843+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1844+ Spec : storage.CSIDriverSpec {
1845+ AttachRequired : & attachNotRequired ,
1846+ PodInfoOnMount : & notPodInfoOnMount ,
1847+ StorageCapacity : & storageCapacity ,
1848+ SELinuxMount : & seLinuxMount ,
1849+ ServiceAccountTokenInSecrets : & serviceAccountTokenInSecrets ,
1850+ },
18021851 }}
18031852
18041853 for _ , csiDriver := range errorCases {
@@ -1813,6 +1862,7 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
18131862 featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .SELinuxMountReadWriteOncePod , true )
18141863 // assume this feature is on for this test, detailed enabled/disabled tests in TestMutableCSINodeAllocatableCountEnabledDisabled
18151864 featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .MutableCSINodeAllocatableCount , true )
1865+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIServiceAccountTokenSecrets , true )
18161866
18171867 driverName := "test-driver"
18181868 longName := "my-a-b-c-d-c-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-ABCDEFGHIJKLMNOPQRSTUVWXYZ-driver"
@@ -1828,8 +1878,11 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
18281878 notStorageCapacity := false
18291879 seLinuxMount := true
18301880 notSELinuxMount := false
1881+ serviceAccountTokenInSecrets := true
1882+ notServiceAccountTokenInSecrets := false
18311883 validNodeAllocatableUpdatePeriodSeconds := int64 (10 )
18321884 invalidNodeAllocatableUpdatePeriodSeconds := int64 (9 )
1885+ tokenRequests := []storage.TokenRequest {{Audience : "test-audience" }}
18331886
18341887 old := storage.CSIDriver {
18351888 ObjectMeta : metav1.ObjectMeta {Name : driverName , ResourceVersion : "1" },
@@ -1888,6 +1941,26 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
18881941 modify : func (new * storage.CSIDriver ) {
18891942 new .Spec .NodeAllocatableUpdatePeriodSeconds = & validNodeAllocatableUpdatePeriodSeconds
18901943 },
1944+ }, {
1945+ name : "change ServiceAccountTokenInSecrets from nil to true with TokenRequests" ,
1946+ modify : func (new * storage.CSIDriver ) {
1947+ new .Spec .ServiceAccountTokenInSecrets = & serviceAccountTokenInSecrets
1948+ new .Spec .TokenRequests = tokenRequests
1949+ },
1950+ }, {
1951+ name : "change ServiceAccountTokenInSecrets from nil to false with TokenRequests" ,
1952+ modify : func (new * storage.CSIDriver ) {
1953+ new .Spec .ServiceAccountTokenInSecrets = & notServiceAccountTokenInSecrets
1954+ new .Spec .TokenRequests = tokenRequests
1955+ },
1956+ }, {
1957+ name : "change ServiceAccountTokenInSecrets from true to false" ,
1958+ modify : func (new * storage.CSIDriver ) {
1959+ new .Spec .ServiceAccountTokenInSecrets = & serviceAccountTokenInSecrets
1960+ new .Spec .TokenRequests = tokenRequests
1961+ old := new .DeepCopy ()
1962+ old .Spec .ServiceAccountTokenInSecrets = & notServiceAccountTokenInSecrets
1963+ },
18911964 }}
18921965
18931966 for _ , test := range successCases {
@@ -1980,6 +2053,11 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
19802053 modify : func (new * storage.CSIDriver ) {
19812054 new .Spec .NodeAllocatableUpdatePeriodSeconds = & invalidNodeAllocatableUpdatePeriodSeconds
19822055 },
2056+ }, {
2057+ name : "ServiceAccountTokenInSecrets set without TokenRequests" ,
2058+ modify : func (new * storage.CSIDriver ) {
2059+ new .Spec .ServiceAccountTokenInSecrets = & serviceAccountTokenInSecrets
2060+ },
19832061 }}
19842062
19852063 for _ , test := range errorCases {
0 commit comments