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 4, 2024
1 parent 5a35bf3 commit e40af2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deploy/webhook-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: ["tenant.kubesphere.io"]
Expand Down
13 changes: 13 additions & 0 deletions pkg/webhook/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"path"
"slices"

"github.com/kubesphere/volume-initializer/pkg/apis/storage/v1alpha1"
admissionv1 "k8s.io/api/admission/v1"
Expand Down Expand Up @@ -111,6 +112,11 @@ func (a *Admitter) Decide(ctx context.Context, reqInfo *ReqInfo) *admissionv1.Ad
return toV1AdmissionResponseWithPatch(nil)
}

var containerNames []string
for _, c := range reqInfo.Pod.Spec.Containers {
containerNames = append(containerNames, c.Name)
}

initializerList := &v1alpha1.InitializerList{}
err = a.client.List(ctx, initializerList)
if err != nil {
Expand Down Expand Up @@ -143,6 +149,13 @@ func (a *Admitter) Decide(ctx context.Context, reqInfo *ReqInfo) *admissionv1.Ad
pvcInitContainer.MountPathRoot = "/"
}
container := pvcInitContainer.Container
container.Name = fmt.Sprintf("%s-vol-%s", container.Name, volume.Name)

// check if the container already exists
if slices.Contains(containerNames, container.Name) {
continue
}

mountPath := path.Join(pvcInitContainer.MountPathRoot, volume.Name)
volumeMount := corev1.VolumeMount{
Name: volume.Name,
Expand Down

0 comments on commit e40af2c

Please sign in to comment.