Exclude invalid resources from status

This commit is contained in:
Phani Teja Marupaka
2020-01-15 16:58:45 -08:00
parent 32c959cde0
commit 2bcf82c6a4
2 changed files with 54 additions and 8 deletions

View File

@@ -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() != ""
}

View 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)
})
}
}