Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: stoneshi-yunify <[email protected]>
  • Loading branch information
stoneshi-yunify committed Sep 14, 2024
1 parent d307b06 commit 518c2f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 145 deletions.
13 changes: 4 additions & 9 deletions config/samples/mongo-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: mongodb-test
annotations:
volume.storage.kubesphere.io/uid: "0"
volume.storage.kubesphere.io/gid: "0"
ttt.volume.storage.kubesphere.io/uid: mongodb
labels:
app: mongodb-test
spec:
Expand All @@ -15,12 +11,14 @@ spec:
app: mongodb-test
template:
metadata:
creationTimestamp: null
labels:
app: mongodb-test
volume.storage.kubesphere.io/uid: "0"
volume.storage.kubesphere.io/gid: "0"
ttt.volume.storage.kubesphere.io/uid: mongodb
spec:
containers:
- name: container-tle280
- name: mongodb
image: 'bitnami/mongodb:4.2.4-debian-10-r0'
ports:
- name: http-27017
Expand All @@ -45,15 +43,13 @@ spec:
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
schedulerName: default-scheduler
volumeClaimTemplates:
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ttt
creationTimestamp: null
spec:
accessModes:
- ReadWriteOnce
Expand All @@ -66,7 +62,6 @@ spec:
apiVersion: v1
metadata:
name: mongodb
creationTimestamp: null
spec:
accessModes:
- ReadWriteOnce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
- name: busybox-chown
image: busybox:latest
- name: mongo-chown
securityContext:
runAsGroup: 0
runAsUser: 0
image: bitnami/mongodb:4.2.4-debian-10-r0
command:
- sh
- '-c'
Expand Down Expand Up @@ -85,6 +88,6 @@ spec:
- pvcMatcherName: local-1
initContainerName: busybox-chmod
- pvcMatcherName: local-2
initContainerName: busybox-chown
initContainerName: mongo-chown
mountPathRoot: "/pvc"
status: {}
121 changes: 0 additions & 121 deletions deploy/webhook-deployment.yaml

This file was deleted.

24 changes: 12 additions & 12 deletions pkg/webhook/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (a *Admitter) Decide(ctx context.Context, reqInfo *ReqInfo) *admissionv1.Ad
}
container.Env = append(container.Env, envVarMountPath)

uid, gid := a.getVolumeUIDGIDFromPodAnnotations(volume.Name, reqInfo.Pod)
uid, gid := a.getVolumeUIDGIDFromPodLabels(volume.Name, reqInfo.Pod)
if uid != "" {
envVarUID := corev1.EnvVar{
Name: EnvVarPVC1UID,
Expand Down Expand Up @@ -219,24 +219,24 @@ const (
podsInitContainerPatch string = `[
{"op":"add","path":"/spec/initContainers","value":%s}
]`
AnnoVolumeUID = "volume.storage.kubesphere.io/uid"
AnnoVolumeGID = "volume.storage.kubesphere.io/gid"
AnnoSpecificVolumeUID = "%s.volume.storage.kubesphere.io/uid"
AnnoSpecificVolumeGID = "%s.volume.storage.kubesphere.io/gid"
LabelVolumeUID = "volume.storage.kubesphere.io/uid"
LabelVolumeGID = "volume.storage.kubesphere.io/gid"
LabelSpecificVolumeUID = "%s.volume.storage.kubesphere.io/uid"
LabelSpecificVolumeGID = "%s.volume.storage.kubesphere.io/gid"
)

func (a *Admitter) getVolumeUIDGIDFromPodAnnotations(volumeName string, pod *corev1.Pod) (uid, gid string) {
for k, v := range pod.Annotations {
func (a *Admitter) getVolumeUIDGIDFromPodLabels(volumeName string, pod *corev1.Pod) (uid, gid string) {
for k, v := range pod.Labels {
switch k {
case AnnoVolumeUID:
case LabelVolumeUID:
uid = v
case AnnoVolumeGID:
case LabelVolumeGID:
gid = v
}
}
for k, v := range pod.Annotations {
annoUID := fmt.Sprintf(AnnoSpecificVolumeUID, volumeName)
annoGID := fmt.Sprintf(AnnoSpecificVolumeGID, volumeName)
for k, v := range pod.Labels {
annoUID := fmt.Sprintf(LabelSpecificVolumeUID, volumeName)
annoGID := fmt.Sprintf(LabelSpecificVolumeGID, volumeName)
switch k {
case annoUID:
uid = v
Expand Down

0 comments on commit 518c2f6

Please sign in to comment.