diff --git a/pkg/edit/edit.go b/pkg/edit/edit.go index 5271c1ed27..74ac6a1d03 100644 --- a/pkg/edit/edit.go +++ b/pkg/edit/edit.go @@ -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 } diff --git a/pkg/edit/edit_test.go b/pkg/edit/edit_test.go index 7eb5deb4ac..a7b9403b11 100644 --- a/pkg/edit/edit_test.go +++ b/pkg/edit/edit_test.go @@ -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 {