mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #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 https://github.com/kubernetes/kubernetes/pull/67694. ```release-note Don't let aggregated apiservers fail to launch if the external-apiserver-authentication configmap is not found in the cluster. ```
This commit is contained in:
commit
55859a60fe
@ -23,6 +23,7 @@ go_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apiserver/pkg/authentication/authenticatorfactory"
|
"k8s.io/apiserver/pkg/authentication/authenticatorfactory"
|
||||||
"k8s.io/apiserver/pkg/server"
|
"k8s.io/apiserver/pkg/server"
|
||||||
@ -238,36 +239,47 @@ func (s *DelegatingAuthenticationOptions) lookupMissingConfigInCluster(client ku
|
|||||||
}
|
}
|
||||||
|
|
||||||
authConfigMap, err := client.CoreV1().ConfigMaps(authenticationConfigMapNamespace).Get(authenticationConfigMapName, metav1.GetOptions{})
|
authConfigMap, err := client.CoreV1().ConfigMaps(authenticationConfigMapNamespace).Get(authenticationConfigMapName, metav1.GetOptions{})
|
||||||
if err != nil {
|
switch {
|
||||||
|
case errors.IsNotFound(err):
|
||||||
|
// ignore, authConfigMap is nil now
|
||||||
|
case errors.IsForbidden(err):
|
||||||
glog.Warningf("Unable to get configmap/%s in %s. Usually fixed by "+
|
glog.Warningf("Unable to get configmap/%s in %s. Usually fixed by "+
|
||||||
"'kubectl create rolebinding -n %s ROLE_NAME --role=%s --serviceaccount=YOUR_NS:YOUR_SA'",
|
"'kubectl create rolebinding -n %s ROLE_NAME --role=%s --serviceaccount=YOUR_NS:YOUR_SA'",
|
||||||
authenticationConfigMapName, authenticationConfigMapNamespace, authenticationConfigMapNamespace, authenticationRoleName)
|
authenticationConfigMapName, authenticationConfigMapNamespace, authenticationConfigMapNamespace, authenticationRoleName)
|
||||||
return err
|
return err
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s.ClientCert.ClientCA) == 0 {
|
if len(s.ClientCert.ClientCA) == 0 {
|
||||||
|
if authConfigMap != nil {
|
||||||
opt, err := inClusterClientCA(authConfigMap)
|
opt, err := inClusterClientCA(authConfigMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if opt == nil {
|
if opt != nil {
|
||||||
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)
|
|
||||||
} else {
|
|
||||||
s.ClientCert = *opt
|
s.ClientCert = *opt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(s.ClientCert.ClientCA) == 0 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(s.RequestHeader.ClientCAFile) == 0 {
|
if len(s.RequestHeader.ClientCAFile) == 0 {
|
||||||
|
if authConfigMap != nil {
|
||||||
opt, err := inClusterRequestHeader(authConfigMap)
|
opt, err := inClusterRequestHeader(authConfigMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if opt == nil {
|
if opt != nil {
|
||||||
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)
|
|
||||||
} else {
|
|
||||||
s.RequestHeader = *opt
|
s.RequestHeader = *opt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(s.RequestHeader.ClientCAFile) == 0 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user