mirror of https://github.com/kubernetes/kops.git
Strictly validate instance groups
This commit is contained in:
parent
6d1741968e
commit
5b69b51bed
|
@ -35,8 +35,14 @@ import (
|
|||
func HasExtraFields(yamlString string, object runtime.Object) (string, error) {
|
||||
switch object.(type) {
|
||||
case *kops.Cluster:
|
||||
editedClusterObj := kops.Cluster{}
|
||||
err := yaml.UnmarshalStrict([]byte(yamlString), &editedClusterObj)
|
||||
editedObj := kops.Cluster{}
|
||||
err := yaml.UnmarshalStrict([]byte(yamlString), &editedObj)
|
||||
if err == nil {
|
||||
return "", nil
|
||||
}
|
||||
case *kops.InstanceGroup:
|
||||
editedObj := kops.InstanceGroup{}
|
||||
err := yaml.UnmarshalStrict([]byte(yamlString), &editedObj)
|
||||
if err == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
testTimestamp = metav1.Time{Time: time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)}
|
||||
testObj = kops.Cluster{
|
||||
testTimestamp = metav1.Time{Time: time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)}
|
||||
testClusterObj = kops.Cluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
CreationTimestamp: testTimestamp,
|
||||
Name: "hello",
|
||||
|
@ -38,6 +38,15 @@ var (
|
|||
KubernetesVersion: "1.2.3",
|
||||
},
|
||||
}
|
||||
testIGObj = kops.InstanceGroup{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
CreationTimestamp: testTimestamp,
|
||||
Name: "hello",
|
||||
},
|
||||
Spec: kops.InstanceGroupSpec{
|
||||
Role: kops.InstanceGroupRoleNode,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func TestHasExtraFields(t *testing.T) {
|
||||
|
@ -47,7 +56,7 @@ func TestHasExtraFields(t *testing.T) {
|
|||
expected string
|
||||
}{
|
||||
{
|
||||
obj: &testObj,
|
||||
obj: &testClusterObj,
|
||||
yaml: heredoc.Doc(`
|
||||
apiVersion: kops.k8s.io/v1alpha2
|
||||
kind: Cluster
|
||||
|
@ -61,7 +70,7 @@ func TestHasExtraFields(t *testing.T) {
|
|||
},
|
||||
|
||||
{
|
||||
obj: &testObj,
|
||||
obj: &testClusterObj,
|
||||
yaml: heredoc.Doc(`
|
||||
apiVersion: kops.k8s.io/v1alpha2
|
||||
kind: Cluster
|
||||
|
@ -81,7 +90,7 @@ func TestHasExtraFields(t *testing.T) {
|
|||
`),
|
||||
},
|
||||
{
|
||||
obj: &testObj,
|
||||
obj: &testClusterObj,
|
||||
yaml: heredoc.Doc(`
|
||||
apiVersion: kops.k8s.io/v1alpha2
|
||||
kind: Cluster
|
||||
|
@ -100,7 +109,7 @@ func TestHasExtraFields(t *testing.T) {
|
|||
`),
|
||||
},
|
||||
{
|
||||
obj: &testObj,
|
||||
obj: &testClusterObj,
|
||||
yaml: heredoc.Doc(`
|
||||
apiVersion: kops.k8s.io/v1alpha2
|
||||
kind: Cluster
|
||||
|
@ -113,6 +122,19 @@ func TestHasExtraFields(t *testing.T) {
|
|||
`),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
obj: &testIGObj,
|
||||
yaml: heredoc.Doc(`
|
||||
apiVersion: kops.k8s.io/v1alpha2
|
||||
kind: InstanceGroup
|
||||
metadata:
|
||||
creationTimestamp: "2017-01-01T00:00:00Z"
|
||||
name: hello
|
||||
spec:
|
||||
role: Node
|
||||
`),
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue