-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ability to disable nodePort Support #4727
base: master
Are you sure you want to change the base?
Changes from all commits
fa449c7
725909b
1c7ec86
dd6e45a
224f85a
7ba31e5
d2441f8
25ccad8
7ec6439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,23 +39,28 @@ type podSource struct { | |
} | ||
|
||
// NewPodSource creates a new podSource with the given config. | ||
func NewPodSource(ctx context.Context, kubeClient kubernetes.Interface, namespace string, compatibility string) (Source, error) { | ||
func NewPodSource(ctx context.Context, kubeClient kubernetes.Interface, namespace string, compatibility string, disableNodeInformer bool) (Source, error) { | ||
informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 0, kubeinformers.WithNamespace(namespace)) | ||
podInformer := informerFactory.Core().V1().Pods() | ||
nodeInformer := informerFactory.Core().V1().Nodes() | ||
var nodeInformer coreinformers.NodeInformer | ||
|
||
podInformer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
}, | ||
}, | ||
) | ||
nodeInformer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
if disableNodeInformer { | ||
log.Infoln("host information (host IP/hostname) for pods is disabled as the node informer is disabled") | ||
} else { | ||
nodeInformer = informerFactory.Core().V1().Nodes() | ||
nodeInformer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
}, | ||
}, | ||
}, | ||
) | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we warn here in Same applies to service There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, I've dropped the log level in servive/pod to a debug level and then added warnings here. |
||
|
||
informerFactory.Start(ctx.Done()) | ||
|
||
|
@@ -108,6 +113,10 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error | |
domainList := splitHostnameAnnotation(domainAnnotation) | ||
for _, domain := range domainList { | ||
if len(targets) == 0 { | ||
if ps.nodeInformer == nil { | ||
log.Debugf("Unable to determine node's ip address for pod %s/%s as node informer is disabled", pod.Namespace, pod.Name) | ||
continue | ||
} | ||
node, _ := ps.nodeInformer.Lister().Get(pod.Spec.NodeName) | ||
for _, address := range node.Status.Addresses { | ||
recordType := suitableType(address.Address) | ||
|
@@ -133,14 +142,18 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error | |
} | ||
|
||
if domainAnnotation, ok := pod.Annotations[kopsDNSControllerHostnameAnnotationKey]; ok { | ||
domainList := splitHostnameAnnotation(domainAnnotation) | ||
for _, domain := range domainList { | ||
node, _ := ps.nodeInformer.Lister().Get(pod.Spec.NodeName) | ||
for _, address := range node.Status.Addresses { | ||
recordType := suitableType(address.Address) | ||
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well. | ||
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) { | ||
addToEndpointMap(endpointMap, domain, recordType, address.Address) | ||
if ps.nodeInformer == nil { | ||
log.Debugf("Unable to determine node's hostname for pod %s/%s as node informer is disabled", pod.Namespace, pod.Name) | ||
} else { | ||
domainList := splitHostnameAnnotation(domainAnnotation) | ||
for _, domain := range domainList { | ||
node, _ := ps.nodeInformer.Lister().Get(pod.Spec.NodeName) | ||
for _, address := range node.Status.Addresses { | ||
recordType := suitableType(address.Address) | ||
// IPv6 addresses are labeled as NodeInternalIP despite being usable externally as well. | ||
if address.Type == corev1.NodeExternalIP || (address.Type == corev1.NodeInternalIP && recordType == endpoint.RecordTypeAAAA) { | ||
addToEndpointMap(endpointMap, domain, recordType, address.Address) | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the user explicitly disabled nodePort support then Info seems more appropriate than Warn.
I've suggested Info level here (and elsewhere Warn is used) but I see other places in the PR where Debug is used.