Skip to content

Commit

Permalink
Add CSI Driver version label to Mountpoint pods
Browse files Browse the repository at this point in the history
Signed-off-by: Renan Magagnin <[email protected]>
  • Loading branch information
renanmagagnin committed Jan 27, 2025
1 parent 22d3773 commit 18d83da
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#See the License for the specific language governing permissions and
#limitations under the License.

ARG VERSION
ENV CSI_DRIVER_VERSION=${VERSION}

ARG MOUNTPOINT_VERSION=1.14.0

# Download the mountpoint tarball and produce an installable directory
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ all-push-skip-if-present:

.PHONY: build_image
build_image:
DOCKER_BUILDKIT=1 docker buildx build -f ${DOCKERFILE} -t=${IMAGE}:${TAG} --platform=${PLATFORM} .
DOCKER_BUILDKIT=1 docker buildx build -f ${DOCKERFILE} -t=${IMAGE}:${TAG} --platform=${PLATFORM} --build-arg VERSION=$(VERSION) .

.PHONY: push-manifest
push-manifest: create-manifest
Expand Down
2 changes: 2 additions & 0 deletions cmd/aws-s3-csi-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var mountpointVersion = flag.String("mountpoint-version", os.Getenv("MOUNTPOINT_
var mountpointImage = flag.String("mountpoint-image", os.Getenv("MOUNTPOINT_IMAGE"), "Image of Mountpoint to use in spawned Mountpoint Pods.")
var mountpointImagePullPolicy = flag.String("mountpoint-image-pull-policy", os.Getenv("MOUNTPOINT_IMAGE_PULL_POLICY"), "Pull policy of Mountpoint images.")
var mountpointContainerCommand = flag.String("mountpoint-container-command", "/bin/aws-s3-csi-mounter", "Entrypoint command of the Mountpoint Pods.")
var csiDriverVersion = flag.String("csi-driver-version", os.Getenv("CSI_DRIVER_VERSION"), "Version of Mountpoint CSI Driver.")

func main() {
flag.Parse()
Expand All @@ -48,6 +49,7 @@ func main() {
Image: *mountpointImage,
ImagePullPolicy: corev1.PullPolicy(*mountpointImagePullPolicy),
},
CSIDriverVersion: *csiDriverVersion,
}).SetupWithManager(mgr)
if err != nil {
log.Error(err, "Failed to create controller")
Expand Down
21 changes: 12 additions & 9 deletions pkg/podmounter/mppod/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
LabelVersion = "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/csi-driver-version"
)

// A ContainerConfig represents configuration for containers in the spawned Mountpoint Pods.
Expand All @@ -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
Version string
Container ContainerConfig
CSIDriverVersion string
}

// A Creator allows creating specification for Mountpoint Pods to schedule.
Expand All @@ -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,
LabelVersion: c.config.Version,
LabelPodUID: string(pod.UID),
LabelVolumeName: pvc.Spec.VolumeName,
LabelCSIDriverVersion: c.config.CSIDriverVersion,
},
},
Spec: corev1.PodSpec{
Expand Down
14 changes: 9 additions & 5 deletions pkg/podmounter/mppod/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Version: mountpointVersion,
Container: mppod.ContainerConfig{
Image: image,
ImagePullPolicy: imagePullPolicy,
Command: command,
},
CSIDriverVersion: csiDriverVersion,
})

mpPod := creator.Create(&corev1.Pod{
Expand All @@ -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.LabelVersion: mountpointVersion,
mppod.LabelPodUID: testPodUID,
mppod.LabelVolumeName: testVolName,
mppod.LabelCSIDriverVersion: csiDriverVersion,
}, mpPod.Labels)

assert.Equals(t, corev1.RestartPolicyOnFailure, mpPod.Spec.RestartPolicy)
Expand Down

0 comments on commit 18d83da

Please sign in to comment.