apiserver/options: avoid segfault by handling unset core k8s client
Fixes: https://github.com/kubernetes/apiserver/issues/108 Signed-off-by: Andrew DeMaria <ademaria@cloudflare.com>
This commit is contained in:
		@@ -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,10 +120,19 @@ 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
 | 
				
			||||||
 | 
						var dynamicClient *dynamic.DynamicClient
 | 
				
			||||||
 | 
						if config.ClientConfig != nil {
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							kubeClient, err = kubernetes.NewForConfig(config.ClientConfig)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user