MCPcopy
hub / github.com/XiaoMi/naftis / replace

Method replace

src/api/executor/istiocrd.go:93–128  ·  view source on GitHub ↗
(varr []istiomodel.Config, task *Task)

Source from the content-addressed store, hash-verified

91}
92
93func (i *istiocrdExecutor) replace(varr []istiomodel.Config, task *Task) (errs error) {
94 currentCfgs := make([]istiomodel.Config, 0)
95 defer func() {
96 task.PrevState = i.yamlOutput(currentCfgs)
97 }()
98
99 for _, config := range varr {
100 var err error
101 // overwrite config.Namespace with user specified namespace
102 if config.Namespace, err = handleNamespaces(task.Namespace); err != nil {
103 return err
104 }
105
106 // fill up revision
107 if config.ResourceVersion == "" {
108 current, exists := i.client.Get(config.Type, config.Name, config.Namespace)
109 if !exists {
110 log.Error("Task not exists", "type", config.Type, "name", config.Name, "namespace", task.Namespace)
111 return ErrTaskNotExists
112 }
113 config.ResourceVersion = current.ResourceVersion
114 // clear resourceVersion for rollback
115 current.ResourceVersion = ""
116 currentCfgs = append(currentCfgs, *current)
117 }
118 var newRev string
119 if newRev, err = i.client.Update(config); err != nil {
120 // if the config create fail, break loop and return error
121 log.Info("Replace config fail", "config", config.Key(), "error", err, "config", config)
122 return err
123 }
124 log.Info("Replace config success", "config", config.Key(), "revision", newRev, "config", config)
125 }
126
127 return nil
128}
129
130func (i *istiocrdExecutor) delete(varr []istiomodel.Config, task *Task) (errs error) {
131 for _, config := range varr {

Callers 7

crdExecMethod · 0.95
applyMethod · 0.95
eFunction · 0.80
rFunction · 0.80
UeFunction · 0.80
DuFunction · 0.80
index.jsFile · 0.80

Calls 4

yamlOutputMethod · 0.95
handleNamespacesFunction · 0.85
GetMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected