Allow providers to skip downward API resolving
This commit is contained in:
@@ -254,6 +254,11 @@ type NodeConfig struct {
|
||||
// Set the error handler for node status update failures
|
||||
NodeStatusUpdateErrorHandler node.ErrorHandler
|
||||
|
||||
// SkipDownwardAPIResolution can be used to skip any attempts at resolving downward API references
|
||||
// in pods before calling CreatePod on the provider.
|
||||
// Providers need this if they need to do their own custom resolving
|
||||
SkipDownwardAPIResolution bool
|
||||
|
||||
routeAttacher func(Provider, NodeConfig, corev1listers.PodLister)
|
||||
}
|
||||
|
||||
@@ -393,13 +398,14 @@ func NewNode(name string, newProvider NewProviderFunc, opts ...NodeOpt) (*Node,
|
||||
}
|
||||
|
||||
pc, err := node.NewPodController(node.PodControllerConfig{
|
||||
PodClient: cfg.Client.CoreV1(),
|
||||
EventRecorder: cfg.EventRecorder,
|
||||
Provider: p,
|
||||
PodInformer: podInformer,
|
||||
SecretInformer: secretInformer,
|
||||
ConfigMapInformer: configMapInformer,
|
||||
ServiceInformer: serviceInformer,
|
||||
PodClient: cfg.Client.CoreV1(),
|
||||
EventRecorder: cfg.EventRecorder,
|
||||
Provider: p,
|
||||
PodInformer: podInformer,
|
||||
SecretInformer: secretInformer,
|
||||
ConfigMapInformer: configMapInformer,
|
||||
ServiceInformer: serviceInformer,
|
||||
SkipDownwardAPIResolution: cfg.SkipDownwardAPIResolution,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error creating pod controller")
|
||||
|
||||
12
node/pod.go
12
node/pod.go
@@ -69,11 +69,13 @@ func (pc *PodController) createOrUpdatePod(ctx context.Context, pod *corev1.Pod)
|
||||
"namespace": pod.GetNamespace(),
|
||||
})
|
||||
|
||||
// We do this so we don't mutate the pod from the informer cache
|
||||
pod = pod.DeepCopy()
|
||||
if err := podutils.PopulateEnvironmentVariables(ctx, pod, pc.resourceManager, pc.recorder); err != nil {
|
||||
span.SetStatus(err)
|
||||
return err
|
||||
if !pc.skipDownwardAPIResolution {
|
||||
// We do this so we don't mutate the pod from the informer cache
|
||||
pod = pod.DeepCopy()
|
||||
if err := podutils.PopulateEnvironmentVariables(ctx, pod, pc.resourceManager, pc.recorder); err != nil {
|
||||
span.SetStatus(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// We have to use a different pod that we pass to the provider than the one that gets used in handleProviderError
|
||||
|
||||
@@ -140,6 +140,11 @@ type PodController struct {
|
||||
// This is used since `pc.Run()` is typically called in a goroutine and managing
|
||||
// this can be non-trivial for callers.
|
||||
err error
|
||||
|
||||
// skipDownwardAPIResolution can be used to skip any attempts at resolving downward API references
|
||||
// in pods before calling CreatePod on the provider.
|
||||
// Providers need this if they need to do their own custom resolving
|
||||
skipDownwardAPIResolution bool
|
||||
}
|
||||
|
||||
type knownPod struct {
|
||||
@@ -196,6 +201,11 @@ type PodControllerConfig struct {
|
||||
// For example, if the pod informer is not filtering based on pod.Spec.NodeName, you should
|
||||
// set that filter here so the pod controller does not handle events for pods assigned to other nodes.
|
||||
PodEventFilterFunc PodEventFilterFunc
|
||||
|
||||
// SkipDownwardAPIResolution can be used to skip any attempts at resolving downward API references
|
||||
// in pods before calling CreatePod on the provider.
|
||||
// Providers need this if they need to do their own custom resolving
|
||||
SkipDownwardAPIResolution bool
|
||||
}
|
||||
|
||||
// NewPodController creates a new pod controller with the provided config.
|
||||
@@ -236,15 +246,16 @@ func NewPodController(cfg PodControllerConfig) (*PodController, error) {
|
||||
}
|
||||
|
||||
pc := &PodController{
|
||||
client: cfg.PodClient,
|
||||
podsInformer: cfg.PodInformer,
|
||||
podsLister: cfg.PodInformer.Lister(),
|
||||
provider: cfg.Provider,
|
||||
resourceManager: rm,
|
||||
ready: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
recorder: cfg.EventRecorder,
|
||||
podEventFilterFunc: cfg.PodEventFilterFunc,
|
||||
client: cfg.PodClient,
|
||||
podsInformer: cfg.PodInformer,
|
||||
podsLister: cfg.PodInformer.Lister(),
|
||||
provider: cfg.Provider,
|
||||
resourceManager: rm,
|
||||
ready: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
recorder: cfg.EventRecorder,
|
||||
podEventFilterFunc: cfg.PodEventFilterFunc,
|
||||
skipDownwardAPIResolution: cfg.SkipDownwardAPIResolution,
|
||||
}
|
||||
|
||||
pc.syncPodsFromKubernetes = queue.New(cfg.SyncPodsFromKubernetesRateLimiter, "syncPodsFromKubernetes", pc.syncPodFromKubernetesHandler, cfg.SyncPodsFromKubernetesShouldRetryFunc)
|
||||
|
||||
Reference in New Issue
Block a user