mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Add event when failed to open local port.
This commit is contained in:
		@@ -219,7 +219,19 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err
 | 
			
		||||
			// IPTablesMasqueradeBit must be specified or defaulted.
 | 
			
		||||
			return nil, fmt.Errorf("Unable to read IPTablesMasqueradeBit from config")
 | 
			
		||||
		}
 | 
			
		||||
		proxierIPTables, err := iptables.NewProxier(iptInterface, utilsysctl.New(), execer, config.IPTablesSyncPeriod.Duration, config.IPTablesMinSyncPeriod.Duration, config.MasqueradeAll, int(*config.IPTablesMasqueradeBit), config.ClusterCIDR, hostname, getNodeIP(client, hostname))
 | 
			
		||||
		proxierIPTables, err := iptables.NewProxier(
 | 
			
		||||
			iptInterface,
 | 
			
		||||
			utilsysctl.New(),
 | 
			
		||||
			execer,
 | 
			
		||||
			config.IPTablesSyncPeriod.Duration,
 | 
			
		||||
			config.IPTablesMinSyncPeriod.Duration,
 | 
			
		||||
			config.MasqueradeAll,
 | 
			
		||||
			int(*config.IPTablesMasqueradeBit),
 | 
			
		||||
			config.ClusterCIDR,
 | 
			
		||||
			hostname,
 | 
			
		||||
			getNodeIP(client, hostname),
 | 
			
		||||
			recorder,
 | 
			
		||||
		)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			glog.Fatalf("Unable to create proxier: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,8 @@ go_library(
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//pkg/api:go_default_library",
 | 
			
		||||
        "//pkg/api/service:go_default_library",
 | 
			
		||||
        "//pkg/api/v1:go_default_library",
 | 
			
		||||
        "//pkg/client/record:go_default_library",
 | 
			
		||||
        "//pkg/proxy:go_default_library",
 | 
			
		||||
        "//pkg/proxy/healthcheck:go_default_library",
 | 
			
		||||
        "//pkg/types:go_default_library",
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,8 @@ import (
 | 
			
		||||
	"github.com/golang/glog"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	apiservice "k8s.io/kubernetes/pkg/api/service"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/v1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/record"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/proxy"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/proxy/healthcheck"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/types"
 | 
			
		||||
@@ -180,6 +182,7 @@ type Proxier struct {
 | 
			
		||||
	hostname       string
 | 
			
		||||
	nodeIP         net.IP
 | 
			
		||||
	portMapper     portOpener
 | 
			
		||||
	recorder       record.EventRecorder
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type localPort struct {
 | 
			
		||||
@@ -219,7 +222,18 @@ var _ proxy.ProxyProvider = &Proxier{}
 | 
			
		||||
// An error will be returned if iptables fails to update or acquire the initial lock.
 | 
			
		||||
// Once a proxier is created, it will keep iptables up to date in the background and
 | 
			
		||||
// will not terminate if a particular iptables call fails.
 | 
			
		||||
func NewProxier(ipt utiliptables.Interface, sysctl utilsysctl.Interface, exec utilexec.Interface, syncPeriod time.Duration, minSyncPeriod time.Duration, masqueradeAll bool, masqueradeBit int, clusterCIDR string, hostname string, nodeIP net.IP) (*Proxier, error) {
 | 
			
		||||
func NewProxier(ipt utiliptables.Interface,
 | 
			
		||||
	sysctl utilsysctl.Interface,
 | 
			
		||||
	exec utilexec.Interface,
 | 
			
		||||
	syncPeriod time.Duration,
 | 
			
		||||
	minSyncPeriod time.Duration,
 | 
			
		||||
	masqueradeAll bool,
 | 
			
		||||
	masqueradeBit int,
 | 
			
		||||
	clusterCIDR string,
 | 
			
		||||
	hostname string,
 | 
			
		||||
	nodeIP net.IP,
 | 
			
		||||
	recorder record.EventRecorder,
 | 
			
		||||
) (*Proxier, error) {
 | 
			
		||||
	// check valid user input
 | 
			
		||||
	if minSyncPeriod > syncPeriod {
 | 
			
		||||
		return nil, fmt.Errorf("min-sync (%v) must be < sync(%v)", minSyncPeriod, syncPeriod)
 | 
			
		||||
@@ -278,6 +292,7 @@ func NewProxier(ipt utiliptables.Interface, sysctl utilsysctl.Interface, exec ut
 | 
			
		||||
		hostname:       hostname,
 | 
			
		||||
		nodeIP:         nodeIP,
 | 
			
		||||
		portMapper:     &listenPortOpener{},
 | 
			
		||||
		recorder:       recorder,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -989,7 +1004,16 @@ func (proxier *Proxier) syncProxyRules() {
 | 
			
		||||
				} else {
 | 
			
		||||
					socket, err := proxier.portMapper.OpenLocalPort(&lp)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						glog.Errorf("can't open %s, skipping this externalIP: %v", lp.String(), err)
 | 
			
		||||
						msg := fmt.Sprintf("can't open %s, skipping this externalIP: %v", lp.String(), err)
 | 
			
		||||
 | 
			
		||||
						proxier.recorder.Eventf(
 | 
			
		||||
							&v1.ObjectReference{
 | 
			
		||||
								Kind:      "Node",
 | 
			
		||||
								Name:      proxier.hostname,
 | 
			
		||||
								UID:       types.UID(proxier.hostname),
 | 
			
		||||
								Namespace: "",
 | 
			
		||||
							}, api.EventTypeWarning, err.Error(), msg)
 | 
			
		||||
						glog.Error(msg)
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
					replacementPortsMap[lp] = socket
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user