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) {
|
func HasExtraFields(yamlString string, object runtime.Object) (string, error) {
|
||||||
switch object.(type) {
|
switch object.(type) {
|
||||||
case *kops.Cluster:
|
case *kops.Cluster:
|
||||||
editedClusterObj := kops.Cluster{}
|
editedObj := kops.Cluster{}
|
||||||
err := yaml.UnmarshalStrict([]byte(yamlString), &editedClusterObj)
|
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 {
|
if err == nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTimestamp = metav1.Time{Time: time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)}
|
testTimestamp = metav1.Time{Time: time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)}
|
||||||
testObj = kops.Cluster{
|
testClusterObj = kops.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
CreationTimestamp: testTimestamp,
|
CreationTimestamp: testTimestamp,
|
||||||
Name: "hello",
|
Name: "hello",
|
||||||
|
@ -38,6 +38,15 @@ var (
|
||||||
KubernetesVersion: "1.2.3",
|
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) {
|
func TestHasExtraFields(t *testing.T) {
|
||||||
|
@ -47,7 +56,7 @@ func TestHasExtraFields(t *testing.T) {
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
obj: &testObj,
|
obj: &testClusterObj,
|
||||||
yaml: heredoc.Doc(`
|
yaml: heredoc.Doc(`
|
||||||
apiVersion: kops.k8s.io/v1alpha2
|
apiVersion: kops.k8s.io/v1alpha2
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
|
@ -61,7 +70,7 @@ func TestHasExtraFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
obj: &testObj,
|
obj: &testClusterObj,
|
||||||
yaml: heredoc.Doc(`
|
yaml: heredoc.Doc(`
|
||||||
apiVersion: kops.k8s.io/v1alpha2
|
apiVersion: kops.k8s.io/v1alpha2
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
|
@ -81,7 +90,7 @@ func TestHasExtraFields(t *testing.T) {
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
obj: &testObj,
|
obj: &testClusterObj,
|
||||||
yaml: heredoc.Doc(`
|
yaml: heredoc.Doc(`
|
||||||
apiVersion: kops.k8s.io/v1alpha2
|
apiVersion: kops.k8s.io/v1alpha2
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
|
@ -100,7 +109,7 @@ func TestHasExtraFields(t *testing.T) {
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
obj: &testObj,
|
obj: &testClusterObj,
|
||||||
yaml: heredoc.Doc(`
|
yaml: heredoc.Doc(`
|
||||||
apiVersion: kops.k8s.io/v1alpha2
|
apiVersion: kops.k8s.io/v1alpha2
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
|
@ -113,6 +122,19 @@ func TestHasExtraFields(t *testing.T) {
|
||||||
`),
|
`),
|
||||||
expected: "",
|
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 {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue