| 91 | } |
| 92 | |
| 93 | func (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 | |
| 130 | func (i *istiocrdExecutor) delete(varr []istiomodel.Config, task *Task) (errs error) { |
| 131 | for _, config := range varr { |