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
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1"
|
manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1"
|
||||||
|
|
@ -52,7 +55,7 @@ func New(loader loader.Loader) (Application, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var m manifest.Manifest
|
var m manifest.Manifest
|
||||||
err = yaml.Unmarshal(manifestBytes, &m)
|
err = unmarshal(manifestBytes, &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -221,3 +224,14 @@ func reindexResourceCollection(rc resource.ResourceCollection) resource.Resource
|
||||||
}
|
}
|
||||||
return result
|
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
|
kind: Manifest
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-app
|
name: nginx-app
|
||||||
description: nginx app
|
|
||||||
namePrefix: foo-
|
namePrefix: foo-
|
||||||
objectLabels:
|
objectLabels:
|
||||||
app: nginx
|
app: nginx
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
||||||
kind: Manifest
|
kind: Manifest
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-app
|
name: nginx-app
|
||||||
description: nginx app for team foo
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
objectLabels:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
||||||
kind: Manifest
|
kind: Manifest
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-app
|
name: nginx-app
|
||||||
description: an overlay for staging env
|
|
||||||
namePrefix: staging-
|
namePrefix: staging-
|
||||||
objectLabels:
|
objectLabels:
|
||||||
env: staging
|
env: staging
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
||||||
kind: Manifest
|
kind: Manifest
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-app
|
name: nginx-app
|
||||||
description: nginx app for team foo
|
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
objectLabels:
|
objectLabels:
|
||||||
app: mynginx
|
app: mynginx
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ apiVersion: manifest.k8s.io/v1alpha1
|
||||||
kind: Manifest
|
kind: Manifest
|
||||||
metadata:
|
metadata:
|
||||||
name: test-infra-mungebot
|
name: test-infra-mungebot
|
||||||
description: Mungebot config for test-infra repo
|
|
||||||
namePrefix: test-infra-
|
namePrefix: test-infra-
|
||||||
# Labels to add to all objects and selectors.
|
# Labels to add to all objects and selectors.
|
||||||
# These labels would also be used to form the selector for apply --prune
|
# 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.crt: "cat secret/tls.cert"
|
||||||
tls.key: "cat secret/tls.key"
|
tls.key: "cat secret/tls.key"
|
||||||
type: "kubernetes.io/tls"
|
type: "kubernetes.io/tls"
|
||||||
recursive: false
|
|
||||||
prune: true # I’d make this the default
|
prune: true # I’d make this the default
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,3 @@ objectAnnotations:
|
||||||
resources:
|
resources:
|
||||||
- deployment/deployment.yaml
|
- deployment/deployment.yaml
|
||||||
- service/service.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