mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-16 17:19:53 +00:00
first commit
This commit is contained in:
commit
fe33d14dc4
8 changed files with 173 additions and 0 deletions
30
pkg/resource/main.go
Normal file
30
pkg/resource/main.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package resource
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Resource struct {
|
||||
Kind, Version, Namespace string
|
||||
}
|
||||
|
||||
// TODO: Support multi-resources yaml files
|
||||
func Read(r io.Reader) (Resource, error) {
|
||||
s, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return Resource{}, err
|
||||
}
|
||||
|
||||
resource := struct {
|
||||
APIVersion string `yaml:"apiVersion"`
|
||||
Kind string `yaml:"kind"`
|
||||
Metadata struct {
|
||||
Namespace string `yaml:"Namespace"`
|
||||
} `yaml:"Metadata"`
|
||||
}{}
|
||||
err = yaml.Unmarshal(s, &resource)
|
||||
|
||||
return Resource{Kind: resource.Kind, Version: resource.APIVersion, Namespace: resource.Metadata.Namespace}, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue