mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Pass pod metadata to flex plugin
This commit is contained in:
parent
dddc6b863e
commit
b22ff25638
@ -51,6 +51,12 @@ const (
|
|||||||
optionKeySecret = "kubernetes.io/secret"
|
optionKeySecret = "kubernetes.io/secret"
|
||||||
optionFSGroup = "kubernetes.io/fsGroup"
|
optionFSGroup = "kubernetes.io/fsGroup"
|
||||||
optionMountsDir = "kubernetes.io/mountsDir"
|
optionMountsDir = "kubernetes.io/mountsDir"
|
||||||
|
|
||||||
|
optionKeyPodName = "kubernetes.io/pod.name"
|
||||||
|
optionKeyPodNamespace = "kubernetes.io/pod.namespace"
|
||||||
|
optionKeyPodUID = "kubernetes.io/pod.uid"
|
||||||
|
|
||||||
|
optionKeyServiceAccountName = "kubernetes.io/serviceAccount.name"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -66,6 +66,13 @@ func (f *flexVolumeMounter) SetUpAt(dir string, fsGroup *types.UnixGroupID) erro
|
|||||||
|
|
||||||
extraOptions := make(map[string]string)
|
extraOptions := make(map[string]string)
|
||||||
|
|
||||||
|
// pod metadata
|
||||||
|
extraOptions[optionKeyPodName] = f.podName
|
||||||
|
extraOptions[optionKeyPodNamespace] = f.podNamespace
|
||||||
|
extraOptions[optionKeyPodUID] = string(f.podUID)
|
||||||
|
// service account metadata
|
||||||
|
extraOptions[optionKeyServiceAccountName] = f.podServiceAccountName
|
||||||
|
|
||||||
// Extract secret and pass it as options.
|
// Extract secret and pass it as options.
|
||||||
if err := addSecretsToOptions(extraOptions, f.spec, f.podNamespace, f.driverName, f.plugin.host); err != nil {
|
if err := addSecretsToOptions(extraOptions, f.spec, f.podNamespace, f.driverName, f.plugin.host); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -19,6 +19,7 @@ package flexvolume
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
@ -26,7 +27,16 @@ import (
|
|||||||
|
|
||||||
func TestSetUpAt(t *testing.T) {
|
func TestSetUpAt(t *testing.T) {
|
||||||
spec := fakeVolumeSpec()
|
spec := fakeVolumeSpec()
|
||||||
pod := &v1.Pod{}
|
pod := &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "my-pod",
|
||||||
|
Namespace: "my-ns",
|
||||||
|
UID: types.UID("my-uid"),
|
||||||
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
ServiceAccountName: "my-sa",
|
||||||
|
},
|
||||||
|
}
|
||||||
mounter := &mount.FakeMounter{}
|
mounter := &mount.FakeMounter{}
|
||||||
|
|
||||||
plugin, rootDir := testPlugin()
|
plugin, rootDir := testPlugin()
|
||||||
@ -34,12 +44,21 @@ func TestSetUpAt(t *testing.T) {
|
|||||||
plugin.runner = fakeRunner(
|
plugin.runner = fakeRunner(
|
||||||
// first call without fsGroup
|
// first call without fsGroup
|
||||||
assertDriverCall(t, successOutput(), mountCmd, rootDir+"/mount-dir",
|
assertDriverCall(t, successOutput(), mountCmd, rootDir+"/mount-dir",
|
||||||
specJson(plugin, spec, nil)),
|
specJson(plugin, spec, map[string]string{
|
||||||
|
optionKeyPodName: "my-pod",
|
||||||
|
optionKeyPodNamespace: "my-ns",
|
||||||
|
optionKeyPodUID: "my-uid",
|
||||||
|
optionKeyServiceAccountName: "my-sa",
|
||||||
|
})),
|
||||||
|
|
||||||
// second test has fsGroup
|
// second test has fsGroup
|
||||||
assertDriverCall(t, notSupportedOutput(), mountCmd, rootDir+"/mount-dir",
|
assertDriverCall(t, notSupportedOutput(), mountCmd, rootDir+"/mount-dir",
|
||||||
specJson(plugin, spec, map[string]string{
|
specJson(plugin, spec, map[string]string{
|
||||||
optionFSGroup: "42",
|
optionFSGroup: "42",
|
||||||
|
optionKeyPodName: "my-pod",
|
||||||
|
optionKeyPodNamespace: "my-ns",
|
||||||
|
optionKeyPodUID: "my-uid",
|
||||||
|
optionKeyServiceAccountName: "my-sa",
|
||||||
})),
|
})),
|
||||||
assertDriverCall(t, fakeVolumeNameOutput("sdx"), getVolumeNameCmd,
|
assertDriverCall(t, fakeVolumeNameOutput("sdx"), getVolumeNameCmd,
|
||||||
specJson(plugin, spec, nil)),
|
specJson(plugin, spec, nil)),
|
||||||
|
@ -112,8 +112,10 @@ func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.P
|
|||||||
execPath: plugin.getExecutable(),
|
execPath: plugin.getExecutable(),
|
||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
|
podName: pod.Name,
|
||||||
podUID: pod.UID,
|
podUID: pod.UID,
|
||||||
podNamespace: pod.Namespace,
|
podNamespace: pod.Namespace,
|
||||||
|
podServiceAccountName: pod.Spec.ServiceAccountName,
|
||||||
volName: spec.Name(),
|
volName: spec.Name(),
|
||||||
},
|
},
|
||||||
runner: runner,
|
runner: runner,
|
||||||
|
@ -30,10 +30,14 @@ type flexVolume struct {
|
|||||||
// mounter provides the interface that is used to mount the actual
|
// mounter provides the interface that is used to mount the actual
|
||||||
// block device.
|
// block device.
|
||||||
mounter mount.Interface
|
mounter mount.Interface
|
||||||
|
// podName is the name of the pod, if available.
|
||||||
|
podName string
|
||||||
// podUID is the UID of the pod.
|
// podUID is the UID of the pod.
|
||||||
podUID types.UID
|
podUID types.UID
|
||||||
// podNamespace is the namespace of the pod.
|
// podNamespace is the namespace of the pod, if available.
|
||||||
podNamespace string
|
podNamespace string
|
||||||
|
// podServiceAccountName is the service account name of the pod, if available.
|
||||||
|
podServiceAccountName string
|
||||||
// volName is the name of the pod's volume.
|
// volName is the name of the pod's volume.
|
||||||
volName string
|
volName string
|
||||||
// the underlying plugin
|
// the underlying plugin
|
||||||
|
Loading…
Reference in New Issue
Block a user