Skip to content

Commit

Permalink
match all k8s list resources (#606)
Browse files Browse the repository at this point in the history
Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero authored May 9, 2024
1 parent c59f32f commit 5f3faf5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func parseContent(content string, defaultNamespace string, normalizeManifests bo
return nil, nil
}

if parsedMetadata.Kind == "List" {
if strings.HasSuffix(parsedMetadata.Kind, "List") {
type ListV1 struct {
Items []yaml.MapSlice `yaml:"items"`
}
Expand Down
26 changes: 26 additions & 0 deletions manifest/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ func TestList(t *testing.T) {
)
}

func TestConfigMapList(t *testing.T) {
spec, err := os.ReadFile("testdata/configmaplist_v1.yaml")
require.NoError(t, err)

require.Equal(t,
[]string{
"default, configmap-2-1, ConfigMap (v1)",
"default, configmap-2-2, ConfigMap (v1)",
},
foundObjects(Parse(string(spec), "default", false)),
)
}

func TestSecretList(t *testing.T) {
spec, err := os.ReadFile("testdata/secretlist_v1.yaml")
require.NoError(t, err)

require.Equal(t,
[]string{
"default, my-secret-1, Secret (v1)",
"default, my-secret-2, Secret (v1)",
},
foundObjects(Parse(string(spec), "default", false)),
)
}

func TestEmpty(t *testing.T) {
spec, err := os.ReadFile("testdata/empty.yaml")
require.NoError(t, err)
Expand Down
15 changes: 15 additions & 0 deletions manifest/testdata/configmaplist_v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMapList
items:
- apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-2-1
data:
key1: data1
- apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-2-2
data:
key2: data2
18 changes: 18 additions & 0 deletions manifest/testdata/secretlist_v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: SecretList
items:
- apiVersion: v1
kind: Secret
metadata:
name: my-secret-1
type: Opaque
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm
- apiVersion: v1
kind: Secret
metadata:
name: my-secret-2
type: Opaque
data:
token: ZXlKaGJHY2lPaUpTVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjFhV1FpT2pFc0luUnBiV1VpT2pFMU56RXlPRGd3TmpFeE1qQXdNVGN5TWpFeE1qQXdNVEE0TWpVMUxDSmhiR2NpT2lKSVV6STFOaUo5LmV5SjFhV1FpT2pFc0luUnBiV1VpT2pFMU56RXlPRGd3TmpFeE1qQXdNVGN5TWpFeE1qQXdNVEE0TWpVMUxDSmhiR2NpT2lKSVV6STFOaUo=

0 comments on commit 5f3faf5

Please sign in to comment.