Skip to content

Commit 440f973

Browse files
committed
Consolidate multiple commits into one: Add PVC manager functionality and related fixes
1 parent c4e02da commit 440f973

30 files changed

+2776
-29
lines changed

Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ endif
6262

6363
# Specify the name for the binaries
6464
PROVISIONER_LOCALPV=provisioner-localpv
65+
PVC_MANAGER=pvc-manager
6566

6667
# Specify the name of the image
6768
PROVISIONER_LOCALPV_IMAGE?=provisioner-localpv
69+
PVC_MANAGER_IMAGE?=pvc-manager
6870

6971
# Final variable with image org, name and tag
7072
PROVISIONER_LOCALPV_IMAGE_TAG=${IMAGE_ORG}/${PROVISIONER_LOCALPV_IMAGE}:${TAG}
73+
PVC_MANAGER_IMAGE_TAG=${IMAGE_ORG}/${PVC_MANAGER_IMAGE}:${TAG}
7174

7275
# Specify the date of build
7376
DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
@@ -97,7 +100,7 @@ EXTERNAL_TOOLS=\
97100
export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL} --build-arg BRANCH=${BRANCH} --build-arg RELEASE_TAG=${RELEASE_TAG}
98101

99102
.PHONY: all
100-
all: test provisioner-localpv-image
103+
all: test provisioner-localpv-image pvc-manager-image
101104

102105
.PHONY: deps
103106
deps:
@@ -126,8 +129,10 @@ clean:
126129
rm -rf bin
127130
./ci/ci-test.sh clean
128131
chmod -R u+w ${GOPATH}/bin/${PROVISIONER_LOCALPV} 2>/dev/null || true
132+
chmod -R u+w ${GOPATH}/bin/${PVC_MANAGER} 2>/dev/null || true
129133
chmod -R u+w ${GOPATH}/pkg/* 2>/dev/null || true
130134
rm -rf ${GOPATH}/bin/${PROVISIONER_LOCALPV}
135+
rm -rf ${GOPATH}/bin/${PVC_MANAGER}
131136
rm -rf ${GOPATH}/pkg/*
132137

133138
.PHONY: test
@@ -173,6 +178,14 @@ provisioner-localpv:
173178
@echo "----------------------------"
174179
@PNAME=${PROVISIONER_LOCALPV} CTLNAME=${PROVISIONER_LOCALPV} sh -c "'./buildscripts/build.sh'"
175180

181+
#Use this to build pvc-manager
182+
.PHONY: pvc-manager
183+
pvc-manager:
184+
@echo "----------------------------"
185+
@echo "--> pvc-manager "
186+
@echo "----------------------------"
187+
@PNAME=${PVC_MANAGER} CTLNAME=${PVC_MANAGER} sh -c "'./buildscripts/build.sh'"
188+
176189
.PHONY: provisioner-localpv-image
177190
provisioner-localpv-image: provisioner-localpv
178191
@echo "-------------------------------"
@@ -182,6 +195,15 @@ provisioner-localpv-image: provisioner-localpv
182195
@cd buildscripts/provisioner-localpv && docker build -t ${PROVISIONER_LOCALPV_IMAGE_TAG} ${DBUILD_ARGS} . --no-cache
183196
@rm buildscripts/provisioner-localpv/${PROVISIONER_LOCALPV}
184197

198+
.PHONY: pvc-manager-image
199+
pvc-manager-image: pvc-manager
200+
@echo "-------------------------------"
201+
@echo "--> pvc-manager image "
202+
@echo "-------------------------------"
203+
@cp bin/pvc-manager/${PVC_MANAGER} buildscripts/pvc-manager/
204+
@cd buildscripts/pvc-manager && docker build -t ${PVC_MANAGER_IMAGE_TAG} ${DBUILD_ARGS} . --no-cache
205+
@rm buildscripts/pvc-manager/${PVC_MANAGER}
206+
185207
.PHONY: image-tag
186208
image-tag:
187209
@echo ${TAG}
@@ -197,6 +219,7 @@ image-ref:
197219
.PHONY: push
198220
push:
199221
DIMAGE=${IMAGE_ORG}/${PROVISIONER_LOCALPV_IMAGE} ./buildscripts/push.sh
222+
DIMAGE=${IMAGE_ORG}/${PVC_MANAGER_IMAGE} ./buildscripts/push.sh
200223

201224
# include the buildx recipes
202225
include Makefile.buildx.mk

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ OpenEBS Dynamic LocalPV Provisioner is an open‐source Kubernetes component tha
2323

2424
## Architecture
2525

26+
### Traditional Architecture (Helper Pods)
27+
2628
```mermaid
2729
2830
graph TD
@@ -66,6 +68,51 @@ graph TD
6668
6769
```
6870

71+
### New Architecture (PVC Manager DaemonSet)
72+
73+
```mermaid
74+
75+
graph TD
76+
%% Define Styles with Black Text
77+
style kubelet fill:#ffcc00,stroke:#d4a017,stroke-width:2px,color:#000
78+
style Provisioner fill:#66ccff,stroke:#3388cc,stroke-width:2px,color:#000
79+
style PVCManager fill:#99ff99,stroke:#44aa44,stroke-width:2px,color:#000
80+
style App fill:#ff9999,stroke:#cc6666,stroke-width:2px,color:#000
81+
style Hostpath fill:#ffdd99,stroke:#d4a017,stroke-width:2px,color:#000
82+
style PVC fill:#ffdd99,stroke:#d4a017,stroke-width:2px,color:#000
83+
style PV fill:#d9b3ff,stroke:#9955cc,stroke-width:2px,color:#000
84+
85+
subgraph "Kubernetes Cluster"
86+
subgraph "Kubelet"
87+
kubelet["Kubelet"]
88+
end
89+
subgraph "OpenEBS LocalPV"
90+
Provisioner["LocalPV Provisioner"]
91+
end
92+
subgraph "Worker Node (Every Node)"
93+
PVCManager["PVC Manager (DaemonSet)"]
94+
App["Application Pod"]
95+
PVC["Persistent Volume Claim"]
96+
PV["Persistent Volume"]
97+
Hostpath["[User-defined path on host]"]
98+
end
99+
end
100+
101+
%% Storage Flow
102+
App -->|Requests Storage| PVC
103+
PVC -->|Binds to| PV
104+
PV -->|Mounted on| Hostpath
105+
kubelet -->|Mounts Path| Hostpath
106+
107+
%% Provisioning Flow (New)
108+
Provisioner -->|HTTP Request| PVCManager
109+
Provisioner -->|Watches PVC Requests| Provisioner
110+
Provisioner -->|Creates PV| PV
111+
PVCManager -->|Creates/Deletes Directory| Hostpath
112+
PV -->|Bound to| PVC
113+
114+
```
115+
69116
Please check [here](./design/hostpath_localpv_provisioner.md) for complete design and architecture.
70117

71118
## Kubernetes Compatibility Matrix
@@ -90,6 +137,9 @@ Please check [here](./design/hostpath_localpv_provisioner.md) for complete desig
90137

91138
## Features
92139

140+
- [x] **Two Architecture Modes**:
141+
- [x] **Helper Pod Mode** (Traditional): Creates ephemeral pods for volume operations
142+
- [x] **PVC Manager Mode** (New): Uses DaemonSet with HTTP API for faster operations
93143
- [x] Access Modes
94144
- [x] ReadWriteOnce
95145
- ~~ReadOnlyMany~~
@@ -99,6 +149,25 @@ Please check [here](./design/hostpath_localpv_provisioner.md) for complete desig
99149
- [ ] `Block` mode
100150
- [x] [Volume Resize(Via Quotas)](./docs/tutorials/hostpath/xfs_quota/)
101151

152+
### PVC Manager Architecture Benefits
153+
154+
The new PVC Manager architecture provides:
155+
156+
- **Better Performance**: Eliminates pod creation overhead for volume operations
157+
- **Reduced API Server Load**: Fewer ephemeral pod objects created/destroyed
158+
- **Improved Reliability**: Persistent service always available for volume operations
159+
- **Enhanced Observability**: HTTP API with health checks and metrics
160+
- **Backward Compatibility**: Can be disabled to use traditional helper pod mode
161+
162+
To enable PVC Manager mode, set the environment variable:
163+
```yaml
164+
env:
165+
- name: OPENEBS_IO_ENABLE_PVC_MANAGER
166+
value: "true"
167+
```
168+
169+
[Learn more about PVC Manager architecture](./docs/pvc-manager-architecture.md)
170+
102171
## Inspiration/Credit
103172
104173
OpenEBS Local PV has been inspired by the prior work done by the following the Kubernetes projects:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM alpine:3.20.1
2+
3+
RUN apk add --no-cache \
4+
iproute2 \
5+
bash \
6+
util-linux \
7+
e2fsprogs \
8+
xfsprogs \
9+
xfsprogs-extra \
10+
blkid \
11+
findmnt \
12+
ca-certificates \
13+
quota-tools
14+
15+
COPY pvc-manager /usr/local/bin/
16+
17+
ARG DBUILD_DATE
18+
ARG DBUILD_REPO_URL
19+
ARG DBUILD_SITE_URL
20+
LABEL org.label-schema.name="pvc-manager"
21+
LABEL org.label-schema.description="OpenEBS LocalPV PVC Manager"
22+
LABEL org.label-schema.url="$DBUILD_SITE_URL"
23+
LABEL org.label-schema.vcs-url="$DBUILD_REPO_URL"
24+
LABEL org.label-schema.schema-version="1.0"
25+
LABEL org.label-schema.build-date="$DBUILD_DATE"
26+
27+
ENTRYPOINT ["/usr/local/bin/pvc-manager"]
28+
CMD ["--help"]

cmd/provisioner-localpv/app/env.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ const (
3131
// ProvisionerImagePullSecrets is the environment variable that provides the
3232
// init pod to use as authentication when pulling helper image, it is used in the scene where authentication is required
3333
ProvisionerImagePullSecrets menv.ENVKey = "OPENEBS_IO_IMAGE_PULL_SECRETS"
34+
35+
// ProvisionerEnablePVCManager enables the PVC Manager mode instead of helper pods
36+
ProvisionerEnablePVCManager string = "OPENEBS_IO_ENABLE_PVC_MANAGER"
37+
38+
// ProvisionerPVCManagerPort is the port where PVC Manager service listens
39+
ProvisionerPVCManagerPort string = "OPENEBS_IO_PVC_MANAGER_PORT"
3440
)
3541

3642
var (
37-
defaultHelperImage = "openebs/linux-utils:latest"
38-
defaultBasePath = "/var/openebs/local"
43+
defaultHelperImage = "openebs/linux-utils:latest"
44+
defaultBasePath = "/var/openebs/local"
45+
defaultPVCManagerPort = "8080"
3946
)
4047

4148
func getOpenEBSNamespace() string {
@@ -59,3 +66,19 @@ func getOpenEBSServiceAccountName() string {
5966
func getOpenEBSImagePullSecrets() string {
6067
return menv.Get(ProvisionerImagePullSecrets)
6168
}
69+
70+
// GetEnv gets an environment variable value
71+
func GetEnv(key string) string {
72+
return menv.Get(menv.ENVKey(key))
73+
}
74+
75+
// getPVCManagerEnabled returns whether PVC Manager mode is enabled
76+
func getPVCManagerEnabled() bool {
77+
val, _ := k8sEnv.GetBool(ProvisionerEnablePVCManager, true) // Default to true for new architecture
78+
return val
79+
}
80+
81+
// getPVCManagerPort returns the port for PVC Manager service
82+
func getPVCManagerPort() string {
83+
return k8sEnv.GetString(ProvisionerPVCManagerPort, defaultPVCManagerPort)
84+
}

cmd/provisioner-localpv/app/helper_hostpath.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/container"
13+
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/pod"
14+
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/volume"
1215
hostpath "github.com/openebs/maya/pkg/hostpath/v1alpha1"
1316
errors "github.com/pkg/errors"
1417
corev1 "k8s.io/api/core/v1"
1518
k8serror "k8s.io/apimachinery/pkg/api/errors"
1619
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1720
"k8s.io/klog/v2"
18-
19-
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/container"
20-
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/pod"
21-
"github.com/openebs/dynamic-localpv-provisioner/pkg/kubernetes/api/core/v1/volume"
21+
"sigs.k8s.io/yaml"
2222
)
2323

2424
type podConfig struct {
@@ -213,7 +213,21 @@ func (p *Provisioner) createCleanupPod(ctx context.Context, pOpts *HelperPodOpti
213213

214214
config.taints = pOpts.selectedNodeTaints
215215

216-
config.pOpts.cmdsForPath = append(config.pOpts.cmdsForPath, filepath.Join("/data/", config.volumeDir))
216+
path := filepath.Join("/data/", config.volumeDir)
217+
218+
scripts := "" +
219+
"FS=`stat -f -c %T " + path + "` ; " +
220+
"if [[ \"$FS\" == \"xfs\" ]]; then " +
221+
"id=`xfs_io -c stat " + path + " 2>/dev/null | grep projid | head -1 | awk -F '=' '{print $2}' | tr -d ' '` ; " +
222+
"echo \"projid=$id\" ; " +
223+
"if [[ -n \"$id\" && \"$id\" != \"0\" ]]; then " +
224+
"xfs_io -c 'chproj -R 0' " + path + " 2>/dev/null || true ; " +
225+
"xfs_quota -x -c \"limit -p bsoft=0 bhard=0 $id\" /data 2>/dev/null || true ; " +
226+
"fi ; " +
227+
"fi ; " +
228+
"rm -rf " + path
229+
230+
config.pOpts.cmdsForPath = []string{"sh", "-c", scripts}
217231

218232
_, err := p.launchPod(ctx, config)
219233
if err != nil && !k8serror.IsAlreadyExists(err) {
@@ -349,6 +363,13 @@ func (p *Provisioner) launchPod(ctx context.Context, config podConfig) (*corev1.
349363
return nil, err
350364
}
351365

366+
helperPodYAML, err := yaml.Marshal(helperPod)
367+
if err != nil {
368+
klog.Errorf("failed to marshal helper pod to YAML: %v", err)
369+
} else {
370+
klog.Infof("launching helper pod: %s", string(helperPodYAML))
371+
}
372+
352373
var hPod *corev1.Pod
353374

354375
//Launch the helper pod.

0 commit comments

Comments
 (0)