mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +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 {
|
||||
return nil, err
|
||||
}
|
||||
f.Identifiers = append(f.Identifiers, wait.ResourceIdentifier{
|
||||
Name: id.Name,
|
||||
Namespace: id.Namespace,
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: gv.Group,
|
||||
Kind: id.Kind,
|
||||
},
|
||||
})
|
||||
if IsValidKubernetesResource(id) {
|
||||
f.Identifiers = append(f.Identifiers, wait.ResourceIdentifier{
|
||||
Name: id.Name,
|
||||
Namespace: id.Namespace,
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: gv.Group,
|
||||
Kind: id.Kind,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
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