Returns the "merged" object, as it would look like if applied or created.
()
| 346 | // Returns the "merged" object, as it would look like if applied or |
| 347 | // created. |
| 348 | func (obj InfoObject) Merged() (runtime.Object, error) { |
| 349 | helper := resource.NewHelper(obj.Info.Client, obj.Info.Mapping). |
| 350 | DryRun(true). |
| 351 | WithFieldManager(obj.FieldManager) |
| 352 | if obj.ServerSideApply { |
| 353 | data, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj.LocalObj) |
| 354 | if err != nil { |
| 355 | return nil, err |
| 356 | } |
| 357 | options := metav1.PatchOptions{ |
| 358 | Force: &obj.ForceConflicts, |
| 359 | FieldManager: obj.FieldManager, |
| 360 | } |
| 361 | return helper.Patch( |
| 362 | obj.Info.Namespace, |
| 363 | obj.Info.Name, |
| 364 | types.ApplyPatchType, |
| 365 | data, |
| 366 | &options, |
| 367 | ) |
| 368 | } |
| 369 | |
| 370 | // Build the patcher, and then apply the patch with dry-run, unless the object doesn't exist, in which case we need to create it. |
| 371 | if obj.Live() == nil { |
| 372 | // Dry-run create if the object doesn't exist. |
| 373 | return helper.CreateWithOptions( |
| 374 | obj.Info.Namespace, |
| 375 | true, |
| 376 | obj.LocalObj, |
| 377 | &metav1.CreateOptions{}, |
| 378 | ) |
| 379 | } |
| 380 | |
| 381 | var resourceVersion *string |
| 382 | if !obj.Force { |
| 383 | accessor, err := meta.Accessor(obj.Info.Object) |
| 384 | if err != nil { |
| 385 | return nil, err |
| 386 | } |
| 387 | str := accessor.GetResourceVersion() |
| 388 | resourceVersion = &str |
| 389 | } |
| 390 | |
| 391 | modified, err := util.GetModifiedConfiguration(obj.LocalObj, false, unstructured.UnstructuredJSONScheme) |
| 392 | if err != nil { |
| 393 | return nil, err |
| 394 | } |
| 395 | |
| 396 | // This is using the patcher from apply, to keep the same behavior. |
| 397 | // We plan on replacing this with server-side apply when it becomes available. |
| 398 | patcher := &apply.Patcher{ |
| 399 | Mapping: obj.Info.Mapping, |
| 400 | Helper: helper, |
| 401 | Overwrite: true, |
| 402 | BackOff: clockwork.NewRealClock(), |
| 403 | OpenAPIGetter: obj.OpenAPIGetter, |
| 404 | OpenAPIV3Root: obj.OpenAPIV3Root, |
| 405 | ResourceVersion: resourceVersion, |
nothing calls this directly
no test coverage detected