detect unknown fields in Kube-manifest.yaml
This commit is contained in:
parent
315679d1c5
commit
b58c4b4066
|
|
@ -17,6 +17,9 @@ limitations under the License.
|
|||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1"
|
||||
|
|
@ -52,7 +55,7 @@ func New(loader loader.Loader) (Application, error) {
|
|||
}
|
||||
|
||||
var m manifest.Manifest
|
||||
err = yaml.Unmarshal(manifestBytes, &m)
|
||||
err = unmarshal(manifestBytes, &m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -221,3 +224,14 @@ func reindexResourceCollection(rc resource.ResourceCollection) resource.Resource
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func unmarshal(y []byte, o interface{}) error {
|
||||
j, err := yaml.YAMLToJSON(y)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(bytes.NewReader(j))
|
||||
dec.DisallowUnknownFields()
|
||||
return dec.Decode(o)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ func setupTest(t *testing.T) loader.Loader {
|
|||
kind: Manifest
|
||||
metadata:
|
||||
name: nginx-app
|
||||
description: nginx app
|
||||
namePrefix: foo-
|
||||
objectLabels:
|
||||
app: nginx
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
|||
kind: Manifest
|
||||
metadata:
|
||||
name: nginx-app
|
||||
description: nginx app for team foo
|
||||
namePrefix: team-foo-
|
||||
objectLabels:
|
||||
app: mynginx
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
|||
kind: Manifest
|
||||
metadata:
|
||||
name: nginx-app
|
||||
description: an overlay for staging env
|
||||
namePrefix: staging-
|
||||
objectLabels:
|
||||
env: staging
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
|||
kind: Manifest
|
||||
metadata:
|
||||
name: nginx-app
|
||||
description: nginx app for team foo
|
||||
namePrefix: team-foo-
|
||||
objectLabels:
|
||||
app: mynginx
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
|||
kind: Manifest
|
||||
metadata:
|
||||
name: test-infra-mungebot
|
||||
description: Mungebot config for test-infra repo
|
||||
namePrefix: test-infra-
|
||||
# Labels to add to all objects and selectors.
|
||||
# These labels would also be used to form the selector for apply --prune
|
||||
|
|
@ -34,5 +33,4 @@ secretGenerators:
|
|||
tls.crt: "cat secret/tls.cert"
|
||||
tls.key: "cat secret/tls.key"
|
||||
type: "kubernetes.io/tls"
|
||||
recursive: false
|
||||
prune: true # I’d make this the default
|
||||
|
|
|
|||
|
|
@ -17,7 +17,3 @@ objectAnnotations:
|
|||
resources:
|
||||
- deployment/deployment.yaml
|
||||
- service/service.yaml
|
||||
#Recursive would be similar to kubectl --recursive behavior, extended to look for Kube-manifest.yaml
|
||||
recursive: false
|
||||
#Whether PersistentVolumeClaims should be deleted with the other resources
|
||||
ownPersistentVolumeClaims: true
|
||||
|
|
|
|||
Loading…
Reference in New Issue