Skip to content

Commit

Permalink
fix: trigger reload cm after update (#1109)
Browse files Browse the repository at this point in the history
* fix: trigger reload cm after update

Signed-off-by: zwwhdls <[email protected]>

* use crypto/rand.Read, and remove math/rand.Seed. for go lint error in go1.20

Signed-off-by: zwwhdls <[email protected]>

* fix yaml parse

Signed-off-by: Xuhui zhang <[email protected]>

---------

Signed-off-by: zwwhdls <[email protected]>
Signed-off-by: Xuhui zhang <[email protected]>
Co-authored-by: Xuhui zhang <[email protected]>
  • Loading branch information
zwwhdls and zxh326 authored Sep 4, 2024
1 parent 140f16f commit 30540c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
13 changes: 6 additions & 7 deletions dashboard-ui-v2/src/components/config-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { memo, ReactNode, useEffect, useState } from 'react'
import Editor from '@monaco-editor/react'
import { Button, Modal, Space } from 'antd'
import { FormattedMessage } from 'react-intl'
import YAML from 'yaml'
import YAML, { YAMLParseError } from 'yaml'

import { useConfig, useUpdateConfig } from '@/hooks/cm-api'

Expand All @@ -44,12 +44,11 @@ const ConfigModal: React.FC<{
const [config, setConfig] = useState('')
useEffect(() => {
if (data?.data) {
setConfig(
YAML.stringify(data?.data?.['config.yaml'])
.split('\n')
.slice(1)
.join('\n'),
)
try {
setConfig(YAML.stringify(YAML.parse(data?.data?.['config.yaml'])))
} catch (e) {
setConfig((e as YAMLParseError).message)
}
}
}, [data])

Expand Down
23 changes: 23 additions & 0 deletions pkg/dashboard/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ func (api *API) putCSIConfig() gin.HandlerFunc {
c.JSON(500, gin.H{"error": err.Error()})
return
}
s, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": "juicefs-csi-driver",
"app": "juicefs-csi-node",
},
})
if err != nil {
c.String(500, "parse label selector error %v", err)
return
}
csiNodeList, err := api.client.CoreV1().Pods(api.sysNamespace).List(c, metav1.ListOptions{LabelSelector: s.String()})
if err != nil {
c.String(500, "list csi node error %v", err)
return
}
for _, pod := range csiNodeList.Items {
pod.Annotations["juicefs/update-time"] = metav1.Now().Format("2006-01-02T15:04:05Z")
_, err = api.client.CoreV1().Pods(api.sysNamespace).Update(c, &pod, metav1.UpdateOptions{})
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
}
c.JSON(200, cm)
}
}
7 changes: 2 additions & 5 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ var (
utilLog = klog.NewKlogr().WithName("util")
)

func init() {
rand.Seed(time.Now().UnixNano())
}

type mountInfo struct {
// Unique ID for the mount (maybe reused after umount).
id int
Expand Down Expand Up @@ -305,8 +301,9 @@ var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")

func RandStringRunes(n int) string {
b := make([]rune, n)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
b[i] = letterRunes[r.Intn(len(letterRunes))]
}
return string(b)
}
Expand Down

0 comments on commit 30540c6

Please sign in to comment.