Skip to content

Commit

Permalink
add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
loozhengyuan committed May 4, 2021
1 parent af9001c commit b953e59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
12 changes: 1 addition & 11 deletions staging/src/k8s.io/kubectl/pkg/cmd/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,11 @@ func (m *Masker) run() error {

// From returns the masked version of the 'from' object.
func (m *Masker) From() runtime.Object {
if m.from == nil {
return nil
}
return m.from
}

// To returns the masked version of the 'to' object.
func (m *Masker) To() runtime.Object {
if m.to == nil {
return nil
}
return m.to
}

Expand Down Expand Up @@ -569,11 +563,7 @@ func (d *Differ) Diff(obj Object, printer Printer) error {
}

// Mask secret values if object is V1Secret
o, err := obj.Merged()
if err != nil {
return err
}
if gvk := o.GetObjectKind().GroupVersionKind(); gvk.Version == "v1" && gvk.Kind == "Secret" {
if gvk := to.GetObjectKind().GroupVersionKind(); gvk.Version == "v1" && gvk.Kind == "Secret" {
m, err := NewMasker(from, to)
if err != nil {
return err
Expand Down
12 changes: 8 additions & 4 deletions staging/src/k8s.io/kubectl/pkg/cmd/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,15 @@ func TestMasker(t *testing.T) {
t.Fatal(err)
}
from, to := m.From(), m.To()
if diff := cmp.Diff(from, tc.want.from); diff != "" {
t.Errorf("from: (-want +got):\n%s", diff)
if from != nil && tc.want.from != nil {
if diff := cmp.Diff(from, tc.want.from); diff != "" {
t.Errorf("from: (-want +got):\n%s", diff)
}
}
if diff := cmp.Diff(to, tc.want.to); diff != "" {
t.Errorf("to: (-want +got):\n%s", diff)
if to != nil && tc.want.to != nil {
if diff := cmp.Diff(to, tc.want.to); diff != "" {
t.Errorf("to: (-want +got):\n%s", diff)
}
}
})
}
Expand Down

0 comments on commit b953e59

Please sign in to comment.