MCPcopy
hub / github.com/redspread/spread / update

Method update

pkg/deploy/cluster.go:143–182  ·  view source on GitHub ↗

update replaces the currently deployed version with a new one. If the objects already match then nothing is done.

(obj KubeObject, create bool, mapping *meta.RESTMapping)

Source from the content-addressed store, hash-verified

141
142// update replaces the currently deployed version with a new one. If the objects already match then nothing is done.
143func (c *KubeCluster) update(obj KubeObject, create bool, mapping *meta.RESTMapping) (KubeObject, error) {
144 meta := obj.GetObjectMeta()
145
146 deployed, err := c.get(meta.GetNamespace(), meta.GetName(), true, mapping)
147 if doesNotExist(err) && create {
148 return c.create(obj, mapping)
149 } else if err != nil {
150 return nil, err
151 }
152
153 // TODO: need a better way to handle resource versioning
154 // set resource version on local to same as remote
155 deployedVersion := deployed.GetObjectMeta().GetResourceVersion()
156 meta.SetResourceVersion(deployedVersion)
157
158 copyImmutables(deployed, obj)
159
160 // if local matches deployed, do nothing
161 if kube.Semantic.DeepEqual(obj, deployed) {
162 return deployed, nil
163 }
164
165 patch, err := diff(deployed, obj)
166 if err != nil {
167 return nil, fmt.Errorf("could not create diff: %v", err)
168 }
169
170 req := c.Client.RESTClient.Patch(kube.StrategicMergePatchType).
171 Name(meta.GetName()).
172 Body(patch)
173
174 setRequestObjectInfo(req, meta.GetNamespace(), mapping)
175
176 runtimeObj, err := req.Do().Get()
177 if err != nil {
178 return nil, resourceError("update", meta.GetNamespace(), meta.GetName(), mapping, err)
179 }
180
181 return AsKubeObject(runtimeObj)
182}
183
184// Get retrieves an objects from a cluster using it's namespace name and API version.
185func (c *KubeCluster) Get(kind, namespace, name string, export bool) (KubeObject, error) {

Callers 1

deployMethod · 0.95

Calls 10

getMethod · 0.95
createMethod · 0.95
doesNotExistFunction · 0.85
copyImmutablesFunction · 0.85
diffFunction · 0.85
setRequestObjectInfoFunction · 0.85
resourceErrorFunction · 0.85
AsKubeObjectFunction · 0.85
NameMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected