MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / UpdateConf

Method UpdateConf

agent/app/service/docker.go:139–243  ·  view source on GitHub ↗
(req dto.SettingUpdate, withRestart bool)

Source from the content-addressed store, hash-verified

137}
138
139func (u *DockerService) UpdateConf(req dto.SettingUpdate, withRestart bool) error {
140 err := createIfNotExistDaemonJsonFile()
141 if err != nil {
142 return err
143 }
144 file, err := os.ReadFile(constant.DaemonJsonPath)
145 if err != nil {
146 return err
147 }
148 daemonMap := make(map[string]interface{})
149 _ = json.Unmarshal(file, &daemonMap)
150 switch req.Key {
151 case "Registries":
152 req.Value = strings.TrimSuffix(req.Value, ",")
153 if len(req.Value) == 0 {
154 delete(daemonMap, "insecure-registries")
155 } else {
156 daemonMap["insecure-registries"] = strings.Split(req.Value, ",")
157 }
158 case "Mirrors":
159 req.Value = strings.TrimSuffix(req.Value, ",")
160 if len(req.Value) == 0 {
161 delete(daemonMap, "registry-mirrors")
162 } else {
163 daemonMap["registry-mirrors"] = strings.Split(req.Value, ",")
164 }
165 case "Ipv6":
166 if req.Value == "disable" {
167 delete(daemonMap, "ipv6")
168 delete(daemonMap, "fixed-cidr-v6")
169 delete(daemonMap, "ip6tables")
170 delete(daemonMap, "experimental")
171 }
172 case "LogOption":
173 if req.Value == "disable" {
174 delete(daemonMap, "log-opts")
175 }
176 case "LiveRestore":
177 if req.Value == "disable" {
178 delete(daemonMap, "live-restore")
179 } else {
180 daemonMap["live-restore"] = true
181 }
182 case "IPtables":
183 if req.Value == "enable" {
184 delete(daemonMap, "iptables")
185 } else {
186 daemonMap["iptables"] = false
187 }
188 case "Driver":
189 if opts, ok := daemonMap["exec-opts"]; ok {
190 if optsValue, isArray := opts.([]interface{}); isArray {
191 for i := 0; i < len(optsValue); i++ {
192 if opt, isStr := optsValue[i].(string); isStr {
193 if strings.HasPrefix(opt, "native.cgroupdriver=") {
194 optsValue[i] = "native.cgroupdriver=" + req.Value
195 break
196 }

Callers

nothing calls this directly

Calls 3

validateDockerConfigFunction · 0.85
WriteFileMethod · 0.80

Tested by

no test coverage detected