mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 23:29:21 +00:00
Merge pull request #124450 from muff1nman/handle-nil-k8s-client
apiserver/options: avoid segfault by handling unset core k8s client
This commit is contained in:
commit
0d8f996aa9
@ -139,6 +139,9 @@ func (a *AdmissionOptions) ApplyTo(
|
|||||||
if informers == nil {
|
if informers == nil {
|
||||||
return fmt.Errorf("admission depends on a Kubernetes core API shared informer, it cannot be nil")
|
return fmt.Errorf("admission depends on a Kubernetes core API shared informer, it cannot be nil")
|
||||||
}
|
}
|
||||||
|
if kubeClient == nil || dynamicClient == nil {
|
||||||
|
return fmt.Errorf("admission depends on a Kubernetes core API client, it cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
pluginNames := a.enabledPluginNames()
|
pluginNames := a.enabledPluginNames()
|
||||||
|
|
||||||
|
@ -71,6 +71,9 @@ func (o *FeatureOptions) ApplyTo(c *server.Config, clientset kubernetes.Interfac
|
|||||||
c.EnableContentionProfiling = o.EnableContentionProfiling
|
c.EnableContentionProfiling = o.EnableContentionProfiling
|
||||||
|
|
||||||
if o.EnablePriorityAndFairness {
|
if o.EnablePriorityAndFairness {
|
||||||
|
if clientset == nil {
|
||||||
|
return fmt.Errorf("invalid configuration: priority and fairness requires a core Kubernetes client")
|
||||||
|
}
|
||||||
if c.MaxRequestsInFlight+c.MaxMutatingRequestsInFlight <= 0 {
|
if c.MaxRequestsInFlight+c.MaxMutatingRequestsInFlight <= 0 {
|
||||||
return fmt.Errorf("invalid configuration: MaxRequestsInFlight=%d and MaxMutatingRequestsInFlight=%d; they must add up to something positive", c.MaxRequestsInFlight, c.MaxMutatingRequestsInFlight)
|
return fmt.Errorf("invalid configuration: MaxRequestsInFlight=%d and MaxMutatingRequestsInFlight=%d; they must add up to something positive", c.MaxRequestsInFlight, c.MaxMutatingRequestsInFlight)
|
||||||
|
|
||||||
|
@ -120,9 +120,18 @@ func (o *RecommendedOptions) ApplyTo(config *server.RecommendedConfig) error {
|
|||||||
if err := o.CoreAPI.ApplyTo(config); err != nil {
|
if err := o.CoreAPI.ApplyTo(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
kubeClient, err := kubernetes.NewForConfig(config.ClientConfig)
|
var kubeClient *kubernetes.Clientset
|
||||||
if err != nil {
|
var dynamicClient *dynamic.DynamicClient
|
||||||
return err
|
if config.ClientConfig != nil {
|
||||||
|
var err error
|
||||||
|
kubeClient, err = kubernetes.NewForConfig(config.ClientConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dynamicClient, err = dynamic.NewForConfig(config.ClientConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := o.Features.ApplyTo(&config.Config, kubeClient, config.SharedInformerFactory); err != nil {
|
if err := o.Features.ApplyTo(&config.Config, kubeClient, config.SharedInformerFactory); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -131,10 +140,6 @@ func (o *RecommendedOptions) ApplyTo(config *server.RecommendedConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dynamicClient, err := dynamic.NewForConfig(config.ClientConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := o.Admission.ApplyTo(&config.Config, config.SharedInformerFactory, kubeClient, dynamicClient, o.FeatureGate,
|
if err := o.Admission.ApplyTo(&config.Config, config.SharedInformerFactory, kubeClient, dynamicClient, o.FeatureGate,
|
||||||
initializers...); err != nil {
|
initializers...); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user