Skip to content

Commit

Permalink
*: support the x.x.x.x:/dbbackup nfs address. radondb#716
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Oct 24, 2022
1 parent 52b4ddd commit e7a7c52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
11 changes: 8 additions & 3 deletions api/v1alpha1/mysqlcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ func (r *MysqlCluster) ValidateDelete() error {
return nil
}

// TODO: Add NFSServerAddress webhook & backup schedule.
// Add NFSServerAddress webhook & backup schedule.
func (r *MysqlCluster) validateNFSServerAddress(oldCluster *MysqlCluster) error {
isIP := net.ParseIP(r.Spec.NFSServerAddress) != nil
//nfsaddress format is x.x.x.x:/yyy such as 10.233.55.172:/backup
ipStr := strings.Split(r.Spec.NFSServerAddress, ":")
if len(r.Spec.NFSServerAddress) != 0 && len(ipStr) == 0 {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP:/PATH or IP"))
}
isIP := net.ParseIP(ipStr[0]) != nil
if len(r.Spec.NFSServerAddress) != 0 && !isIP {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP"))
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("nfsServerAddress should be set as IP:/PATH or IP"))
}
if len(r.Spec.BackupSchedule) != 0 && len(r.Spec.BackupSecretName) == 0 && !isIP {
return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("backupSchedule is set without any backupSecretName or nfsServerAddress"))
Expand Down
6 changes: 4 additions & 2 deletions backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ func (s *jobSyncer) ensurePodSpec(in corev1.PodSpec) corev1.PodSpec {
in.Containers[0].Image = fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), s.backup.Spec.Image)
in.ServiceAccountName = s.backup.Spec.ClusterName
if len(s.backup.Spec.NFSServerAddress) != 0 {
//parse NFSServerAddress to IP:/Path
ip, path := utils.ParseIPAndPath(s.backup.Spec.NFSServerAddress)
// add volumn about pvc
in.Volumes = []corev1.Volume{
{
Name: utils.XtrabackupPV,
VolumeSource: corev1.VolumeSource{
NFS: &corev1.NFSVolumeSource{
Server: s.backup.Spec.NFSServerAddress,
Path: "/",
Server: ip,
Path: path,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/samples/nfs_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
containers:
- name: nfs-server
## TODO: radondb/volume-nfs:0.8
image: k8s.gcr.io/volume-nfs:0.8
image: gcr.azk8s.cn/google_containers/volume-nfs:0.8
ports:
- name: nfs
containerPort: 2049
Expand Down
5 changes: 3 additions & 2 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ func (c *MysqlCluster) EnsureVolumes() []corev1.Volume {
)
// add the nfs volumn mount
if len(c.Spec.NFSServerAddress) != 0 {
ip, path := utils.ParseIPAndPath(c.Spec.NFSServerAddress)
volumes = append(volumes, corev1.Volume{
Name: utils.XtrabackupPV,
VolumeSource: corev1.VolumeSource{
NFS: &corev1.NFSVolumeSource{
Server: c.Spec.NFSServerAddress,
Path: "/",
Server: ip,
Path: path,
},
},
})
Expand Down
9 changes: 9 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,12 @@ func ParseImageName(image string) (string, string, string, error) {
imageTag := imageNameArry[1]
return imagePrefix, imageName, imageTag, nil
}

func ParseIPAndPath(nfsaddr string) (string, string) {
res := strings.Split(nfsaddr, ":")
if len(res) == 2 {
return res[0], res[1]
} else {
return res[0], "/"
}
}

0 comments on commit e7a7c52

Please sign in to comment.