Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSI Driver version label to Mountpoint pods #358

Merged
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: 4 additions & 2 deletions cmd/aws-s3-csi-controller/main.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/awslabs/aws-s3-csi-driver/cmd/aws-s3-csi-controller/csicontroller"
"github.com/awslabs/aws-s3-csi-driver/pkg/driver/version"
"github.com/awslabs/aws-s3-csi-driver/pkg/podmounter/mppod"
)

@@ -41,13 +42,14 @@ func main() {
}

err = csicontroller.NewReconciler(mgr.GetClient(), mppod.Config{
Namespace: *mountpointNamespace,
Version: *mountpointVersion,
Namespace: *mountpointNamespace,
MountpointVersion: *mountpointVersion,
Container: mppod.ContainerConfig{
Command: *mountpointContainerCommand,
Image: *mountpointImage,
ImagePullPolicy: corev1.PullPolicy(*mountpointImagePullPolicy),
},
CSIDriverVersion: version.GetVersion().DriverVersion,
}).SetupWithManager(mgr)
if err != nil {
log.Error(err, "Failed to create controller")
21 changes: 12 additions & 9 deletions pkg/podmounter/mppod/creator.go
Original file line number Diff line number Diff line change
@@ -10,9 +10,10 @@ import (

// Labels populated on spawned Mountpoint Pods.
const (
LabelVersion = "s3.csi.aws.com/mountpoint-version"
LabelPodUID = "s3.csi.aws.com/pod-uid"
LabelVolumeName = "s3.csi.aws.com/volume-name"
LabelMountpointVersion = "s3.csi.aws.com/mountpoint-version"
LabelPodUID = "s3.csi.aws.com/pod-uid"
LabelVolumeName = "s3.csi.aws.com/volume-name"
LabelCSIDriverVersion = "s3.csi.aws.com/mounted-by-csi-driver-version"
)

// A ContainerConfig represents configuration for containers in the spawned Mountpoint Pods.
@@ -24,9 +25,10 @@ type ContainerConfig struct {

// A Config represents configuration for spawned Mountpoint Pods.
type Config struct {
Namespace string
Version string
Container ContainerConfig
Namespace string
MountpointVersion string
Container ContainerConfig
CSIDriverVersion string
}

// A Creator allows creating specification for Mountpoint Pods to schedule.
@@ -52,9 +54,10 @@ func (c *Creator) Create(pod *corev1.Pod, pvc *corev1.PersistentVolumeClaim) *co
Name: name,
Namespace: c.config.Namespace,
Labels: map[string]string{
LabelVersion: c.config.Version,
LabelPodUID: string(pod.UID),
LabelVolumeName: pvc.Spec.VolumeName,
LabelMountpointVersion: c.config.MountpointVersion,
LabelPodUID: string(pod.UID),
LabelVolumeName: pvc.Spec.VolumeName,
LabelCSIDriverVersion: c.config.CSIDriverVersion,
},
},
Spec: corev1.PodSpec{
16 changes: 10 additions & 6 deletions pkg/podmounter/mppod/creator_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
func TestCreatingMountpointPods(t *testing.T) {
// Mountpoint Pod values
namespace := "mount-s3"
version := "1.10.0"
mountpointVersion := "1.10.0"
image := "mp-image:latest"
imagePullPolicy := corev1.PullAlways
command := "/bin/aws-s3-csi-mounter"
@@ -24,14 +24,17 @@ func TestCreatingMountpointPods(t *testing.T) {
testPodUID := "test-pod-uid"
testVolName := "test-vol"

csiDriverVersion := "1.12.0"

creator := mppod.NewCreator(mppod.Config{
Namespace: namespace,
Version: version,
Namespace: namespace,
MountpointVersion: mountpointVersion,
Container: mppod.ContainerConfig{
Image: image,
ImagePullPolicy: imagePullPolicy,
Command: command,
},
CSIDriverVersion: csiDriverVersion,
})

mpPod := creator.Create(&corev1.Pod{
@@ -51,9 +54,10 @@ func TestCreatingMountpointPods(t *testing.T) {
assert.Equals(t, "mp-8ef7856a0c7f1d5706bd6af93fdc4bc90b33cf2ceb6769b4afd62586", mpPod.Name)
assert.Equals(t, namespace, mpPod.Namespace)
assert.Equals(t, map[string]string{
mppod.LabelVersion: version,
mppod.LabelPodUID: testPodUID,
mppod.LabelVolumeName: testVolName,
mppod.LabelMountpointVersion: mountpointVersion,
mppod.LabelPodUID: testPodUID,
mppod.LabelVolumeName: testVolName,
mppod.LabelCSIDriverVersion: csiDriverVersion,
}, mpPod.Labels)

assert.Equals(t, corev1.RestartPolicyOnFailure, mpPod.Spec.RestartPolicy)
4 changes: 3 additions & 1 deletion tests/controller/controller_test.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import (
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/awslabs/aws-s3-csi-driver/pkg/driver/version"
"github.com/awslabs/aws-s3-csi-driver/pkg/podmounter/mppod"
)

@@ -685,9 +686,10 @@ func waitAndVerifyMountpointPodFor(pod *testPod, vol *testVolume) {

// verifyMountpointPodFor verifies given `mountpointPod` for given `pod` and `vol`.
func verifyMountpointPodFor(pod *testPod, vol *testVolume, mountpointPod *testPod) {
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelVersion, mountpointVersion))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelMountpointVersion, mountpointVersion))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelPodUID, string(pod.UID)))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelVolumeName, vol.pvc.Spec.VolumeName))
Expect(mountpointPod.ObjectMeta.Labels).To(HaveKeyWithValue(mppod.LabelCSIDriverVersion, version.GetVersion().DriverVersion))

Expect(mountpointPod.Spec.RestartPolicy).To(Equal(corev1.RestartPolicyOnFailure))

6 changes: 4 additions & 2 deletions tests/controller/suite_test.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/awslabs/aws-s3-csi-driver/cmd/aws-s3-csi-controller/csicontroller"
"github.com/awslabs/aws-s3-csi-driver/pkg/driver/version"
"github.com/awslabs/aws-s3-csi-driver/pkg/podmounter/mppod"
)

@@ -77,13 +78,14 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())

err = csicontroller.NewReconciler(k8sManager.GetClient(), mppod.Config{
Namespace: mountpointNamespace,
Version: mountpointVersion,
Namespace: mountpointNamespace,
MountpointVersion: mountpointVersion,
Container: mppod.ContainerConfig{
Command: mountpointContainerCommand,
Image: mountpointImage,
ImagePullPolicy: mountpointImagePullPolicy,
},
CSIDriverVersion: version.GetVersion().DriverVersion,
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())