Skip to content

Commit e9fa086

Browse files
committed
Only pass identity provider mountOption for managed sidecar version >= v1.12.2-gke.0
1 parent 3a7bfd8 commit e9fa086

File tree

11 files changed

+555
-8
lines changed

11 files changed

+555
-8
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/prometheus/client_golang v1.18.0
1818
github.com/prometheus/client_model v0.6.0
1919
github.com/prometheus/common v0.46.0
20+
golang.org/x/mod v0.19.0
2021
golang.org/x/net v0.37.0
2122
golang.org/x/oauth2 v0.22.0
2223
golang.org/x/time v0.6.0

pkg/cloud_provider/clientset/clientset.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"time"
2525

26+
"github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/webhook"
2627
authenticationv1 "k8s.io/api/authentication/v1"
2728
corev1 "k8s.io/api/core/v1"
2829
"k8s.io/apimachinery/pkg/api/meta"
@@ -105,6 +106,11 @@ func (c *Clientset) ConfigurePodLister(nodeName string) {
105106

106107
var newInitContainers []corev1.Container
107108
for _, cont := range podObj.Spec.InitContainers {
109+
if cont.Name == webhook.GcsFuseSidecarName {
110+
newInitContainers = append(newInitContainers, cont)
111+
112+
continue
113+
}
108114
container := corev1.Container{
109115
Name: cont.Name,
110116
SecurityContext: cont.SecurityContext,

pkg/csi_driver/node.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,25 @@ func (s *nodeServer) prepareStorageService(ctx context.Context, vc map[string]st
295295
}
296296

297297
func (s *nodeServer) shouldStartTokenServer(pod *corev1.Pod) bool {
298+
tokenVolumeInjected := false
298299
for _, vol := range pod.Spec.Volumes {
299300
if vol.Name == webhook.SidecarContainerSATokenVolumeName {
300-
klog.Infof("Service Account Token Injection feature is turned on.")
301+
klog.Infof("Service Account Token Injection feature is turned on from webhook.")
301302

302-
return true
303+
tokenVolumeInjected = true
304+
305+
break
306+
}
307+
}
308+
var sidecarVersionSupported bool
309+
310+
for _, container := range pod.Spec.InitContainers {
311+
if container.Name == webhook.GcsFuseSidecarName {
312+
sidecarVersionSupported = isSidecarVersionSupportedForTokenServer(container.Image)
313+
314+
break
303315
}
304316
}
305317

306-
return false
318+
return tokenVolumeInjected && sidecarVersionSupported
307319
}

pkg/csi_driver/utils.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import (
2222
"fmt"
2323
"os"
2424
"path/filepath"
25+
"regexp"
2526
"strconv"
2627
"strings"
2728

2829
csi "github.com/container-storage-interface/spec/lib/go/csi"
2930
"github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/util"
3031
"github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/webhook"
3132
pbSanitizer "github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
33+
"golang.org/x/mod/semver"
3234
"golang.org/x/net/context"
3335
"google.golang.org/grpc"
3436
"google.golang.org/grpc/codes"
@@ -63,6 +65,7 @@ const (
6365
VolumeContextKeyPodNamespace = "csi.storage.k8s.io/pod.namespace"
6466
VolumeContextKeyEphemeral = "csi.storage.k8s.io/ephemeral"
6567
VolumeContextKeyBucketName = "bucketName"
68+
tokenServerSidecarMinVersion = "v1.12.2-gke.0" // #nosec G101
6669
)
6770

6871
func NewVolumeCapabilityAccessMode(mode csi.VolumeCapability_AccessMode_Mode) *csi.VolumeCapability_AccessMode {
@@ -460,3 +463,24 @@ func getSidecarContainerStatus(isInitContainer bool, pod *corev1.Pod) (*corev1.C
460463

461464
return nil, errors.New("the sidecar container was not found")
462465
}
466+
467+
func isSidecarVersionSupportedForTokenServer(imageName string) bool {
468+
managedSidecarPattern := `.*/gke-release(-staging)?/gcs-fuse-csi-driver-sidecar-mounter:v\d+.\d+.\d+-gke\.\d+.*`
469+
re := regexp.MustCompile(managedSidecarPattern)
470+
isManagedSidecar := re.MatchString(imageName)
471+
472+
if !isManagedSidecar {
473+
klog.Infof("mountOptions should not be passed because this is a private sidecar image %q", imageName)
474+
475+
return false
476+
}
477+
imageVersion := strings.Split(strings.Split(imageName, ":")[1], "@")[0]
478+
klog.Infof("sidecar image version: %v", imageVersion)
479+
if semver.Compare(imageVersion, tokenServerSidecarMinVersion) >= 0 {
480+
klog.Infof("sidecar version is supported for token server")
481+
482+
return true
483+
}
484+
485+
return false
486+
}

pkg/csi_driver/utils_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ func TestJoinMountOptions(t *testing.T) {
6565
})
6666
}
6767

68+
func TestIsSidecarVersionSupportedForTokenServer(t *testing.T) {
69+
t.Parallel()
70+
t.Run("checking if sidecar version is supported for token server", func(t *testing.T) {
71+
t.Parallel()
72+
testCases := []struct {
73+
name string
74+
imageName string
75+
expectedSupported bool
76+
}{
77+
{
78+
name: "should return true for supported sidecar version",
79+
imageName: "us-central1-artifactregistry.gcr.io/gke-release/gke-release/gcs-fuse-csi-driver-sidecar-mounter:v1.12.3-gke.2@sha256:abcd",
80+
expectedSupported: true,
81+
},
82+
{
83+
name: "should return true for supported sidecar version in staging gcr",
84+
imageName: "gcr.io/gke-release-staging/gcs-fuse-csi-driver-sidecar-mounter:v1.12.2-gke.0@sha256:abcd",
85+
expectedSupported: true,
86+
},
87+
{
88+
name: "should return false for unsupported sidecar version",
89+
imageName: "us-central1-artifactregistry.gcr.io/gke-release/gke-release/gcs-fuse-csi-driver-sidecar-mounter:v1.8.7-gke.1@sha256:abcd",
90+
expectedSupported: false,
91+
},
92+
{
93+
name: "should return false for private sidecar",
94+
imageName: "customer.gcr.io/dir/gcs-fuse-csi-driver-sidecar-mounter:v1.12.2-gke.0@sha256:abcd",
95+
expectedSupported: false,
96+
},
97+
}
98+
99+
for _, tc := range testCases {
100+
t.Logf("test case: %s", tc.name)
101+
actual := isSidecarVersionSupportedForTokenServer(tc.imageName)
102+
if actual != tc.expectedSupported {
103+
t.Errorf("Got supported %v, but expected %v", actual, tc.expectedSupported)
104+
}
105+
}
106+
})
107+
}
108+
68109
func TestParseVolumeAttributes(t *testing.T) {
69110
t.Parallel()
70111
t.Run("parsing volume attributes into mount options", func(t *testing.T) {

test/e2e/specs/specs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const (
9090
GolangImage = "golang:1.22.7"
9191
UbuntuImage = "ubuntu:20.04"
9292

93-
LastPublishedSidecarContainerImage = "gcr.io/gke-release/gcs-fuse-csi-driver-sidecar-mounter@sha256:380bd2a716b936d9469d09e3a83baf22dddca1586a04a0060d7006ea78930cac"
93+
LastPublishedSidecarContainerImage = "gcr.io/gke-release/gcs-fuse-csi-driver-sidecar-mounter:v1.7.1-gke.3@sha256:380bd2a716b936d9469d09e3a83baf22dddca1586a04a0060d7006ea78930cac"
9494

9595
pollInterval = 1 * time.Second
9696
pollTimeout = 1 * time.Minute

test/e2e/testsuites/volumes.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ func (t *gcsFuseCSIVolumesTestSuite) DefineTests(driver storageframework.TestDri
321321
tPod.SetCustomSidecarContainerImage()
322322
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
323323

324+
if configPrefix == specs.EnableHostNetworkPrefix {
325+
ginkgo.By("Turn on hostnetwork setting")
326+
tPod.EnableHostNetwork()
327+
}
328+
324329
ginkgo.By("Deploying the pod")
325330
tPod.Create(ctx)
326331
defer tPod.Cleanup(ctx)
@@ -330,15 +335,20 @@ func (t *gcsFuseCSIVolumesTestSuite) DefineTests(driver storageframework.TestDri
330335

331336
ginkgo.By("Checking that the sidecar container is using the custom image")
332337
tPod.VerifyCustomSidecarContainerImage(supportsNativeSidecar, hasMetadataPrefetch)
333-
334-
ginkgo.By("Checking that the pod command exits with no error")
335-
tPod.VerifyExecInPodSucceed(f, specs.TesterContainerName, fmt.Sprintf("mount | grep %v | grep rw,", mountPath))
336-
tPod.VerifyExecInPodSucceed(f, specs.TesterContainerName, fmt.Sprintf("echo 'hello world' > %v/data && grep 'hello world' %v/data", mountPath, mountPath))
338+
// Do not check pod exec for hostnetwork, as we do not expect it to work until we support this feature for private sidecars.
339+
if configPrefix != specs.EnableHostNetworkPrefix {
340+
ginkgo.By("Checking that the pod command exits with no error")
341+
tPod.VerifyExecInPodSucceed(f, specs.TesterContainerName, fmt.Sprintf("mount | grep %v | grep rw,", mountPath))
342+
tPod.VerifyExecInPodSucceed(f, specs.TesterContainerName, fmt.Sprintf("echo 'hello world' > %v/data && grep 'hello world' %v/data", mountPath, mountPath))
343+
}
337344
}
338345

339346
ginkgo.It("should store data using custom sidecar container image", func() {
340347
testCaseStoreDataCustomContainerImage("")
341348
})
349+
ginkgo.It("should gcsfuse process succeed without missing flag error for hostnetwork pods using custom sidecar container image", func() {
350+
testCaseStoreDataCustomContainerImage(specs.EnableHostNetworkPrefix)
351+
})
342352
ginkgo.It("[csi-skip-bucket-access-check] should store data using custom sidecar container image", func() {
343353
testCaseStoreDataCustomContainerImage(specs.SkipCSIBucketAccessCheckPrefix)
344354
})

vendor/golang.org/x/mod/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/mod/PATENTS

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)