MCPcopy
hub / github.com/kubernetes/kubectl / Diff

Method Diff

pkg/cmd/diff/diff.go:568–599  ·  view source on GitHub ↗

Diff diffs to versions of a specific object, and print both versions to directories.

(obj Object, printer Printer, showManagedFields, showSecrets bool)

Source from the content-addressed store, hash-verified

566
567// Diff diffs to versions of a specific object, and print both versions to directories.
568func (d *Differ) Diff(obj Object, printer Printer, showManagedFields, showSecrets bool) error {
569 from, err := d.From.getObject(obj)
570 if err != nil {
571 return err
572 }
573 to, err := d.To.getObject(obj)
574 if err != nil {
575 return err
576 }
577
578 if !showManagedFields {
579 from = omitManagedFields(from)
580 to = omitManagedFields(to)
581 }
582
583 // Mask secret values if object is V1Secret
584 if gvk := to.GetObjectKind().GroupVersionKind(); !showSecrets && gvk.Version == "v1" && gvk.Kind == "Secret" {
585 m, err := NewMasker(from, to)
586 if err != nil {
587 return err
588 }
589 from, to = m.From(), m.To()
590 }
591
592 if err := d.From.Print(obj.Name(), from, printer); err != nil {
593 return err
594 }
595 if err := d.To.Print(obj.Name(), to, printer); err != nil {
596 return err
597 }
598 return nil
599}
600
601func omitManagedFields(o runtime.Object) runtime.Object {
602 a, err := meta.Accessor(o)

Callers 15

RunMethod · 0.95
TestDifferFunction · 0.95
TestShowManagedFieldsFunction · 0.95
TestShowSecretsFunction · 0.95
TestLogsForObjectFunction · 0.80
TestSortingPrinterFunction · 0.80
TestLabelFuncFunction · 0.80
TestMaskerFunction · 0.80

Calls 9

FromMethod · 0.95
ToMethod · 0.95
omitManagedFieldsFunction · 0.85
NewMaskerFunction · 0.85
getObjectMethod · 0.80
NameMethod · 0.65
GroupVersionKindMethod · 0.45
GetObjectKindMethod · 0.45
PrintMethod · 0.45

Tested by 15

TestDifferFunction · 0.76
TestShowManagedFieldsFunction · 0.76
TestShowSecretsFunction · 0.76
TestLogsForObjectFunction · 0.64
TestSortingPrinterFunction · 0.64
TestLabelFuncFunction · 0.64
TestMaskerFunction · 0.64
TestGenerateNodeDebugPodFunction · 0.64