From 4a6601638967b4f3a3c156ddc54e51fa1658fb76 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Mon, 25 Jun 2018 17:16:06 +0100 Subject: [PATCH] Check client_ca configmap needs update --- pkg/master/client_ca_hook.go | 7 +++++-- pkg/master/client_ca_hook_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/master/client_ca_hook.go b/pkg/master/client_ca_hook.go index 0a01a408627..4e5d4ff5198 100644 --- a/pkg/master/client_ca_hook.go +++ b/pkg/master/client_ca_hook.go @@ -19,6 +19,7 @@ package master import ( "encoding/json" "fmt" + "reflect" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -131,7 +132,9 @@ func writeConfigMap(client coreclient.ConfigMapsGetter, name string, data map[st return err } - existing.Data = data - _, err = client.ConfigMaps(metav1.NamespaceSystem).Update(existing) + if !reflect.DeepEqual(existing.Data, data) { + existing.Data = data + _, err = client.ConfigMaps(metav1.NamespaceSystem).Update(existing) + } return err } diff --git a/pkg/master/client_ca_hook_test.go b/pkg/master/client_ca_hook_test.go index 011078bddb9..fecfc685606 100644 --- a/pkg/master/client_ca_hook_test.go +++ b/pkg/master/client_ca_hook_test.go @@ -186,6 +186,30 @@ func TestWriteClientCAs(t *testing.T) { }, }, }, + { + name: "skip on no change", + hook: ClientCARegistrationHook{ + RequestHeaderUsernameHeaders: []string{}, + RequestHeaderGroupHeaders: []string{}, + RequestHeaderExtraHeaderPrefixes: []string{}, + RequestHeaderCA: []byte("bar"), + RequestHeaderAllowedNames: []string{}, + }, + preexistingObjs: []runtime.Object{ + &api.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceSystem, Name: "extension-apiserver-authentication"}, + Data: map[string]string{ + "requestheader-username-headers": `[]`, + "requestheader-group-headers": `[]`, + "requestheader-extra-headers-prefix": `[]`, + "requestheader-client-ca-file": "bar", + "requestheader-allowed-names": `[]`, + }, + }, + }, + expectedConfigMaps: map[string]*api.ConfigMap{}, + expectUpdate: false, + }, } for _, test := range tests {