Skip to content

Commit 493e016

Browse files
committed
feat: enhance local storage deployment and command configuration
- Update the backup command to use formatted arguments for executing the snapshot script - Introduce a variable for the local storage path in the local command - Modify logging to reference the correct local storage path - Add storage-related IP and path flags to the Cluster struct - Change how the cluster installs local storage to better utilize command arguments - Introduce new shell scripts and templates for local storage deployment Signed-off-by: ysicing <i@ysicing.me>
1 parent 20bc9f7 commit 493e016

7 files changed

Lines changed: 227 additions & 12 deletions

File tree

cmd/backup/cluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package backup
88

99
import (
10+
"fmt"
11+
1012
"github.com/cockroachdb/errors"
1113
"github.com/spf13/cobra"
1214

@@ -32,7 +34,7 @@ func NewCmdBackupCluster(f factory.Factory) *cobra.Command {
3234
return errors.Errorf("not support datastore %s", cfg.DB)
3335
}
3436
log.Info("start backup cluster datastore etcd")
35-
return exec.CommandRun("bash", "-c", common.GetCustomFile("hack/manifests/scripts/etcd-snapshot.sh"), cfg.DataDir, common.GetDefaultLogDir())
37+
return exec.CommandRun("bash", "-c", fmt.Sprintf("%s %s %s", common.GetCustomFile("hack/manifests/scripts/etcd-snapshot.sh"), cfg.DataDir, common.GetDefaultLogDir()))
3638
},
3739
}
3840
return bc

cmd/storage/storage.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package storage
88

99
import (
1010
"context"
11+
"fmt"
1112
"os"
1213

1314
"github.com/cockroachdb/errors"
@@ -71,21 +72,32 @@ func longhorn(f factory.Factory) *cobra.Command {
7172
}
7273

7374
func local(f factory.Factory) *cobra.Command {
75+
var path string
7476
logpkg := f.GetLog()
7577
cmd := &cobra.Command{
7678
Use: "local",
7779
Short: "deploy local pv storage",
7880
RunE: func(cmd *cobra.Command, args []string) error {
79-
kubeargs := []string{"experimental", "kubectl", "apply", "-f", common.GetCustomFile("hack/manifests/storage/local.yaml")}
81+
yamlfile := common.GetCustomFile("hack/manifests/storage/local.yaml")
82+
if len(path) != 0 {
83+
if err := qcexec.CommandRun("bash", "-c", fmt.Sprintf("%s %s", common.GetCustomFile("hack/manifests/storage/local.sh"), path)); err != nil {
84+
return errors.Errorf("precheck local storage failed, reason: %v", err)
85+
}
86+
yamlfile = common.GetCustomFile("hack/manifests/storage/local.deploy.yaml")
87+
} else {
88+
path = "/opt/quickon/storage/local"
89+
}
90+
kubeargs := []string{"experimental", "kubectl", "apply", "-f", yamlfile}
8091
output, err := qcexec.Command(os.Args[0], kubeargs...).CombinedOutput()
8192
if err != nil {
8293
logpkg.Errorf("upgrade install local storage failed: %s", string(output))
8394
return err
8495
}
85-
logpkg.Infof("install local storage class %s (%s) success", color.SGreen("q-local"), color.SGreen("/opt/quickon/storage/local"))
96+
logpkg.Infof("install local storage class %s (%s) success", color.SGreen("q-local"), color.SGreen(path))
8697
return nil
8798
},
8899
}
100+
cmd.Flags().StringVar(&path, "path", os.Getenv("LOCAL_PATH"), "local path")
89101
return cmd
90102
}
91103

@@ -141,8 +153,8 @@ func nfs(f factory.Factory) *cobra.Command {
141153
return nil
142154
},
143155
}
144-
cmd.Flags().StringVar(&ip, "ip", "", "cloud cfs/nas ip")
145-
cmd.Flags().StringVar(&path, "path", "", "cloud cfs/nas path")
156+
cmd.Flags().StringVar(&ip, "ip", os.Getenv("NFS_SERVER"), "cloud cfs/nas ip")
157+
cmd.Flags().StringVar(&path, "path", os.Getenv("NFS_PATH"), "cloud cfs/nas path")
146158
cmd.Flags().StringVar(&name, "name", "q-nfs", "storage class name")
147159
return cmd
148160
}

hack/manifests/storage/local.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
localPath=${1:-/opt/quickon/storage/local}
4+
sourcePath=$(dirname "$0")/local.yaml.tpl
5+
targetPath=$(dirname "$0")/local.deploy.yaml
6+
7+
mkdir -p "${localPath}"
8+
9+
cp -a "${sourcePath}" "${targetPath}"
10+
11+
sed -i "s|__LOCAL_PATH__|${localPath}|g" "${targetPath}"
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: q-local-provisioner-service-account
5+
namespace: kube-system
6+
---
7+
apiVersion: rbac.authorization.k8s.io/v1
8+
kind: ClusterRole
9+
metadata:
10+
name: q-local-provisioner-role
11+
rules:
12+
- apiGroups: [""]
13+
resources: ["nodes", "persistentvolumeclaims", "configmaps", "pods/log"]
14+
verbs: ["get", "list", "watch"]
15+
- apiGroups: [""]
16+
resources: ["endpoints", "persistentvolumes", "pods"]
17+
verbs: ["*"]
18+
- apiGroups: [""]
19+
resources: ["events"]
20+
verbs: ["create", "patch"]
21+
- apiGroups: ["storage.k8s.io"]
22+
resources: ["storageclasses"]
23+
verbs: ["get", "list", "watch"]
24+
---
25+
apiVersion: rbac.authorization.k8s.io/v1
26+
kind: ClusterRoleBinding
27+
metadata:
28+
name: q-local-provisioner-bind
29+
roleRef:
30+
apiGroup: rbac.authorization.k8s.io
31+
kind: ClusterRole
32+
name: q-local-provisioner-role
33+
subjects:
34+
- kind: ServiceAccount
35+
name: q-local-provisioner-service-account
36+
namespace: kube-system
37+
---
38+
apiVersion: apps/v1
39+
kind: Deployment
40+
metadata:
41+
name: q-local-provisioner
42+
namespace: kube-system
43+
spec:
44+
revisionHistoryLimit: 0
45+
strategy:
46+
type: RollingUpdate
47+
rollingUpdate:
48+
maxUnavailable: 1
49+
selector:
50+
matchLabels:
51+
app: q-local-provisioner
52+
template:
53+
metadata:
54+
labels:
55+
app: q-local-provisioner
56+
spec:
57+
priorityClassName: "system-node-critical"
58+
serviceAccountName: q-local-provisioner-service-account
59+
tolerations:
60+
- key: "CriticalAddonsOnly"
61+
operator: "Exists"
62+
- key: "node-role.kubernetes.io/control-plane"
63+
operator: "Exists"
64+
effect: "NoSchedule"
65+
- key: "node-role.kubernetes.io/master"
66+
operator: "Exists"
67+
effect: "NoSchedule"
68+
containers:
69+
- name: q-local-provisioner
70+
image: "hub.zentao.net/rancher/local-path-provisioner:v0.0.28"
71+
imagePullPolicy: IfNotPresent
72+
command:
73+
- local-path-provisioner
74+
- start
75+
- --config
76+
- /etc/config/config.json
77+
- --configmap-name
78+
- q-local-config
79+
- --service-account-name
80+
- q-local-provisioner-service-account
81+
volumeMounts:
82+
- name: config-volume
83+
mountPath: /etc/config/
84+
env:
85+
- name: POD_NAMESPACE
86+
valueFrom:
87+
fieldRef:
88+
fieldPath: metadata.namespace
89+
volumes:
90+
- name: config-volume
91+
configMap:
92+
name: q-local-config
93+
---
94+
apiVersion: storage.k8s.io/v1
95+
kind: StorageClass
96+
metadata:
97+
name: q-local
98+
annotations:
99+
defaultVolumeType: "local"
100+
storageclass.kubernetes.io/is-default-class: "true"
101+
provisioner: rancher.io/local-path
102+
volumeBindingMode: WaitForFirstConsumer
103+
reclaimPolicy: Delete
104+
---
105+
kind: ConfigMap
106+
apiVersion: v1
107+
metadata:
108+
name: q-local-config
109+
namespace: kube-system
110+
data:
111+
config.json: |-
112+
{
113+
"nodePathMap":[
114+
{
115+
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
116+
"paths":["__LOCAL_PATH__"]
117+
}
118+
]
119+
}
120+
setup: |-
121+
#!/bin/sh
122+
set -eu
123+
mkdir -m 0777 -p "${VOL_DIR}"
124+
chmod 700 "${VOL_DIR}/.."
125+
teardown: |-
126+
#!/bin/sh
127+
set -eu
128+
rm -rf "${VOL_DIR}"
129+
helperPod.yaml: |-
130+
apiVersion: v1
131+
kind: Pod
132+
metadata:
133+
name: helper-pod
134+
spec:
135+
containers:
136+
- name: helper-pod
137+
image: "hub.zentao.net/rancher/mirrored-library-busybox:1.36.1"
138+
imagePullPolicy: IfNotPresent

hack/scripts/devops/devops.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# Source code is available at https://github.com/easysoft/quickon_cli
99

10-
# SCRIPT_COMMIT_SHA="e9b38bb8a5e792f575692b9c0c179670663ddd0b"
11-
# SCRIPT_DATA="Mon Apr 14 10:18:36 CST 2025"
10+
# SCRIPT_COMMIT_SHA="20bc9f740b48cc21da0c6e49d0a081ca05a9ce27"
11+
# SCRIPT_DATA="Tue Apr 15 11:20:55 CST 2025"
1212

1313
# Usage:
1414
# curl ... | ENV_VAR=... sh -
@@ -30,6 +30,12 @@
3030
# - STORAGE_TYPE
3131
# Storage Type when install Zentao DevOPS default use local as storage provider.
3232
# Defaults to '', support 'local', 'nfs'
33+
# - STORAGE_IP
34+
# Storage NFS IP when install Zentao DevOPS default use local as storage provider.
35+
# Defaults to ''
36+
# - STORAGE_PATH
37+
# Storage NFS or Local Path when install Zentao DevOPS default use local as storage provider.
38+
# Defaults to ''
3339
# - EX_DB_HOST
3440
# External Database Host when install Zentao DevOPS.
3541
# Defaults to ''
@@ -222,6 +228,13 @@ install_zentao_devops() {
222228
fi
223229
if [ "${STORAGE_TYPE}" = "nfs" ]; then
224230
INSTALL_COMMAND="${INSTALL_COMMAND} --storage nfs"
231+
if [ -n "${STORAGE_IP}" ] && [ -n "${STORAGE_PATH}" ]; then
232+
INSTALL_COMMAND="${INSTALL_COMMAND} --storage-ip ${STORAGE_IP} --storage-path ${STORAGE_PATH}"
233+
fi
234+
else
235+
if [ -n "${STORAGE_PATH}" ]; then
236+
INSTALL_COMMAND="${INSTALL_COMMAND} --storage-path ${STORAGE_PATH}"
237+
fi
225238
fi
226239
if [ -n "${EX_DB_HOST}" ] && [ -n "${EX_DB_PASSWORD}" ]; then
227240
INSTALL_COMMAND="${INSTALL_COMMAND} --ext-db-host ${EX_DB_HOST} --ext-db-password ${EX_DB_PASSWORD}"

hack/scripts/devops/install.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# Source code is available at https://github.com/easysoft/quickon_cli
99

10-
# SCRIPT_COMMIT_SHA="e9b38bb8a5e792f575692b9c0c179670663ddd0b"
11-
# SCRIPT_DATA="Mon Apr 14 10:18:36 CST 2025"
10+
# SCRIPT_COMMIT_SHA="20bc9f740b48cc21da0c6e49d0a081ca05a9ce27"
11+
# SCRIPT_DATA="Tue Apr 15 11:20:55 CST 2025"
1212

1313
# Usage:
1414
# curl ... | ENV_VAR=... sh -
@@ -30,6 +30,12 @@
3030
# - STORAGE_TYPE
3131
# Storage Type when install Zentao DevOPS default use local as storage provider.
3232
# Defaults to '', support 'local', 'nfs'
33+
# - STORAGE_IP
34+
# Storage NFS IP when install Zentao DevOPS default use local as storage provider.
35+
# Defaults to ''
36+
# - STORAGE_PATH
37+
# Storage NFS or Local Path when install Zentao DevOPS default use local as storage provider.
38+
# Defaults to ''
3339
# - EX_DB_HOST
3440
# External Database Host when install Zentao DevOPS.
3541
# Defaults to ''
@@ -222,6 +228,13 @@ install_zentao_devops() {
222228
fi
223229
if [ "${STORAGE_TYPE}" = "nfs" ]; then
224230
INSTALL_COMMAND="${INSTALL_COMMAND} --storage nfs"
231+
if [ -n "${STORAGE_IP}" ] && [ -n "${STORAGE_PATH}" ]; then
232+
INSTALL_COMMAND="${INSTALL_COMMAND} --storage-ip ${STORAGE_IP} --storage-path ${STORAGE_PATH}"
233+
fi
234+
else
235+
if [ -n "${STORAGE_PATH}" ]; then
236+
INSTALL_COMMAND="${INSTALL_COMMAND} --storage-path ${STORAGE_PATH}"
237+
fi
225238
fi
226239
if [ -n "${EX_DB_HOST}" ] && [ -n "${EX_DB_PASSWORD}" ]; then
227240
INSTALL_COMMAND="${INSTALL_COMMAND} --ext-db-host ${EX_DB_HOST} --ext-db-password ${EX_DB_PASSWORD}"

pkg/cluster/cluster.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/ergoapi/util/expass"
2222
"github.com/ergoapi/util/exstr"
2323
"github.com/ergoapi/util/file"
24+
"github.com/sirupsen/logrus"
2425
"k8s.io/apimachinery/pkg/util/wait"
2526

2627
"github.com/easysoft/qcadmin/common"
@@ -56,6 +57,8 @@ type Cluster struct {
5657
OffLine bool
5758
Registry string
5859
Storage string
60+
StorageIP string
61+
StoragePath string
5962
DataStore string
6063
IgnorePreflightErrors bool
6164
}
@@ -100,6 +103,18 @@ func (c *Cluster) getInitFlags() []types.Flag {
100103
EnvVar: common.DefaultStorageType,
101104
Usage: `storage, e.g: nfs,local,none`,
102105
},
106+
{
107+
Name: "storage-ip",
108+
P: &c.StorageIP,
109+
V: c.StorageIP,
110+
Usage: `storage ip, nfs server ip`,
111+
},
112+
{
113+
Name: "storage-path",
114+
P: &c.StoragePath,
115+
V: c.StoragePath,
116+
Usage: `storage path, nfs or local path`,
117+
},
103118
{
104119
Name: "datastore",
105120
P: &c.DataStore,
@@ -281,11 +296,22 @@ func (c *Cluster) initMaster0(cfg *config.Config, sshClient ssh.Interface) error
281296
}
282297
c.log.Infof("install %s as default storage", c.Storage)
283298
if c.Storage == "nfs" {
284-
if err := qcexec.CommandRun("bash", "-c", common.GetCustomFile("hack/manifests/storage/nfs-server.sh")); err != nil {
285-
return errors.Errorf("%s run install nfs script failed, reason: %v", cfg.Cluster.InitNode, err)
299+
if len(c.StorageIP) > 0 && len(c.StoragePath) > 0 {
300+
kubeargs := []string{"cluster", "storage", "nfs", "--ip", c.StorageIP, "--path", c.StoragePath, fmt.Sprintf("--debug=%v", c.log.GetLevel() == logrus.DebugLevel)}
301+
if err := qcexec.CommandRun(os.Args[0], kubeargs...); err != nil {
302+
return errors.Errorf("%s run install nfs storage failed, reason: %v", cfg.Cluster.InitNode, err)
303+
}
304+
} else {
305+
if err := qcexec.CommandRun("bash", "-c", common.GetCustomFile("hack/manifests/storage/nfs-server.sh")); err != nil {
306+
return errors.Errorf("%s run install nfs script failed, reason: %v", cfg.Cluster.InitNode, err)
307+
}
286308
}
287309
} else if c.Storage == "local" {
288-
kubeargs := []string{"experimental", "kubectl", "apply", "-f", common.GetCustomFile("hack/manifests/storage/local.yaml")}
310+
kubeargs := []string{"cluster", "storage", "local"}
311+
if len(c.StoragePath) > 0 {
312+
kubeargs = append(kubeargs, "--path", c.StoragePath)
313+
}
314+
kubeargs = append(kubeargs, fmt.Sprintf("--debug=%v", c.log.GetLevel() == logrus.DebugLevel))
289315
if err := qcexec.CommandRun(os.Args[0], kubeargs...); err != nil {
290316
return errors.Errorf("%s run install local storage failed, reason: %v", cfg.Cluster.InitNode, err)
291317
}

0 commit comments

Comments
 (0)