Skip to content

Commit 55859a6

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#67836 from sttts/sttts-non-fatal-missing-external-apiserver-authn-configmap
Automatic merge from submit-queue (batch tested with PRs 67764, 68034, 67836). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md. apiserver: make not-found external-apiserver-authn configmap non-fatal As client-ca and requestheader-client-ca is optional in the external-apiserver-authentication config file and components like kube-controller-manager and kube-scheduler won't need that anyway, we better make it non-fatal if the configmap is not found in the cluster. Consumer counter-part PR to kubernetes#67694. ```release-note Don't let aggregated apiservers fail to launch if the external-apiserver-authentication configmap is not found in the cluster. ```
2 parents 39ea20a + 5d56e79 commit 55859a6

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

staging/src/k8s.io/apiserver/pkg/server/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ go_library(
2323
visibility = ["//visibility:public"],
2424
deps = [
2525
"//staging/src/k8s.io/api/core/v1:go_default_library",
26+
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2627
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2728
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
2829
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",

staging/src/k8s.io/apiserver/pkg/server/options/authentication.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/spf13/pflag"
2727

2828
"k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/api/errors"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apiserver/pkg/authentication/authenticatorfactory"
3132
"k8s.io/apiserver/pkg/server"
@@ -238,34 +239,45 @@ func (s *DelegatingAuthenticationOptions) lookupMissingConfigInCluster(client ku
238239
}
239240

240241
authConfigMap, err := client.CoreV1().ConfigMaps(authenticationConfigMapNamespace).Get(authenticationConfigMapName, metav1.GetOptions{})
241-
if err != nil {
242+
switch {
243+
case errors.IsNotFound(err):
244+
// ignore, authConfigMap is nil now
245+
case errors.IsForbidden(err):
242246
glog.Warningf("Unable to get configmap/%s in %s. Usually fixed by "+
243247
"'kubectl create rolebinding -n %s ROLE_NAME --role=%s --serviceaccount=YOUR_NS:YOUR_SA'",
244248
authenticationConfigMapName, authenticationConfigMapNamespace, authenticationConfigMapNamespace, authenticationRoleName)
245249
return err
250+
case err != nil:
251+
return err
246252
}
247253

248254
if len(s.ClientCert.ClientCA) == 0 {
249-
opt, err := inClusterClientCA(authConfigMap)
250-
if err != nil {
251-
return err
255+
if authConfigMap != nil {
256+
opt, err := inClusterClientCA(authConfigMap)
257+
if err != nil {
258+
return err
259+
}
260+
if opt != nil {
261+
s.ClientCert = *opt
262+
}
252263
}
253-
if opt == nil {
264+
if len(s.ClientCert.ClientCA) == 0 {
254265
glog.Warningf("Cluster doesn't provide client-ca-file in configmap/%s in %s, so client certificate authentication to extension api-server won't work.", authenticationConfigMapName, authenticationConfigMapNamespace)
255-
} else {
256-
s.ClientCert = *opt
257266
}
258267
}
259268

260269
if len(s.RequestHeader.ClientCAFile) == 0 {
261-
opt, err := inClusterRequestHeader(authConfigMap)
262-
if err != nil {
263-
return err
270+
if authConfigMap != nil {
271+
opt, err := inClusterRequestHeader(authConfigMap)
272+
if err != nil {
273+
return err
274+
}
275+
if opt != nil {
276+
s.RequestHeader = *opt
277+
}
264278
}
265-
if opt == nil {
279+
if len(s.RequestHeader.ClientCAFile) == 0 {
266280
glog.Warningf("Cluster doesn't provide requestheader-client-ca-file in configmap/%s in %s, so request-header client certificate authentication to extension api-server won't work.", authenticationConfigMapName, authenticationConfigMapNamespace)
267-
} else {
268-
s.RequestHeader = *opt
269281
}
270282
}
271283

0 commit comments

Comments
 (0)