mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 18:30:15 +00:00
Exclude invalid resources from status
This commit is contained in:
@@ -64,14 +64,20 @@ func (f *CaptureIdentifiersFilter) Filter(slice []*yaml.RNode) ([]*yaml.RNode, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.Identifiers = append(f.Identifiers, wait.ResourceIdentifier{
|
if IsValidKubernetesResource(id) {
|
||||||
Name: id.Name,
|
f.Identifiers = append(f.Identifiers, wait.ResourceIdentifier{
|
||||||
Namespace: id.Namespace,
|
Name: id.Name,
|
||||||
GroupKind: schema.GroupKind{
|
Namespace: id.Namespace,
|
||||||
Group: gv.Group,
|
GroupKind: schema.GroupKind{
|
||||||
Kind: id.Kind,
|
Group: gv.Group,
|
||||||
},
|
Kind: id.Kind,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return slice, nil
|
return slice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsValidKubernetesResource(id yaml.ResourceIdentifier) bool {
|
||||||
|
return id.GetKind() != "" && id.GetAPIVersion() != "" && id.GetName() != ""
|
||||||
|
}
|
||||||
|
|||||||
40
cmd/resource/status/cmd/util_test.go
Normal file
40
cmd/resource/status/cmd/util_test.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsValidKubernetesResource(t *testing.T) {
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
data yaml.ResourceIdentifier
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
"invalid resource": {
|
||||||
|
data: yaml.ResourceIdentifier {
|
||||||
|
Name : "",
|
||||||
|
APIVersion : "",
|
||||||
|
Kind : "",
|
||||||
|
Namespace : "",
|
||||||
|
},
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
"valid resource": {
|
||||||
|
data: yaml.ResourceIdentifier {
|
||||||
|
Name : "SomeName",
|
||||||
|
APIVersion : "SomeVersion",
|
||||||
|
Kind : "SomeKind",
|
||||||
|
Namespace : "",
|
||||||
|
},
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
assert.Equal(t, IsValidKubernetesResource(tc.data), tc.expected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user