Browse Source

Merge pull request #1435 from xh4n3/features/add-setNodeNetworkUnavailable

add flag setNodeNetworkUnavailable
Luther Monson 3 years ago
parent
commit
0760961a37
2 changed files with 48 additions and 39 deletions
  1. 30 28
      main.go
  2. 18 11
      subnet/kube/kube.go

+ 30 - 28
main.go

@@ -71,33 +71,34 @@ func (t *flagSlice) Set(val string) error {
 }
 
 type CmdLineOpts struct {
-	etcdEndpoints          string
-	etcdPrefix             string
-	etcdKeyfile            string
-	etcdCertfile           string
-	etcdCAFile             string
-	etcdUsername           string
-	etcdPassword           string
-	help                   bool
-	version                bool
-	kubeSubnetMgr          bool
-	kubeApiUrl             string
-	kubeAnnotationPrefix   string
-	kubeConfigFile         string
-	iface                  flagSlice
-	ifaceRegex             flagSlice
-	ipMasq                 bool
-	subnetFile             string
-	subnetDir              string
-	publicIP               string
-	subnetLeaseRenewMargin int
-	healthzIP              string
-	healthzPort            int
-	charonExecutablePath   string
-	charonViciUri          string
-	iptablesResyncSeconds  int
-	iptablesForwardRules   bool
-	netConfPath            string
+	etcdEndpoints             string
+	etcdPrefix                string
+	etcdKeyfile               string
+	etcdCertfile              string
+	etcdCAFile                string
+	etcdUsername              string
+	etcdPassword              string
+	help                      bool
+	version                   bool
+	kubeSubnetMgr             bool
+	kubeApiUrl                string
+	kubeAnnotationPrefix      string
+	kubeConfigFile            string
+	iface                     flagSlice
+	ifaceRegex                flagSlice
+	ipMasq                    bool
+	subnetFile                string
+	subnetDir                 string
+	publicIP                  string
+	subnetLeaseRenewMargin    int
+	healthzIP                 string
+	healthzPort               int
+	charonExecutablePath      string
+	charonViciUri             string
+	iptablesResyncSeconds     int
+	iptablesForwardRules      bool
+	netConfPath               string
+	setNodeNetworkUnavailable bool
 }
 
 var (
@@ -131,6 +132,7 @@ func init() {
 	flannelFlags.IntVar(&opts.iptablesResyncSeconds, "iptables-resync", 5, "resync period for iptables rules, in seconds")
 	flannelFlags.BoolVar(&opts.iptablesForwardRules, "iptables-forward-rules", true, "add default accept rules to FORWARD chain in iptables")
 	flannelFlags.StringVar(&opts.netConfPath, "net-config-path", "/etc/kube-flannel/net-conf.json", "path to the network configuration file")
+	flannelFlags.BoolVar(&opts.setNodeNetworkUnavailable, "set-node-network-unavailable", true, "set NodeNetworkUnavailable after ready")
 
 	log.InitFlags(nil)
 
@@ -162,7 +164,7 @@ func usage() {
 
 func newSubnetManager(ctx context.Context) (subnet.Manager, error) {
 	if opts.kubeSubnetMgr {
-		return kube.NewSubnetManager(ctx, opts.kubeApiUrl, opts.kubeConfigFile, opts.kubeAnnotationPrefix, opts.netConfPath)
+		return kube.NewSubnetManager(ctx, opts.kubeApiUrl, opts.kubeConfigFile, opts.kubeAnnotationPrefix, opts.netConfPath, opts.setNodeNetworkUnavailable)
 	}
 
 	cfg := &etcdv2.EtcdConfig{

+ 18 - 11
subnet/kube/kube.go

@@ -51,16 +51,17 @@ const (
 )
 
 type kubeSubnetManager struct {
-	annotations    annotations
-	client         clientset.Interface
-	nodeName       string
-	nodeStore      listers.NodeLister
-	nodeController cache.Controller
-	subnetConf     *subnet.Config
-	events         chan subnet.Event
+	annotations               annotations
+	client                    clientset.Interface
+	nodeName                  string
+	nodeStore                 listers.NodeLister
+	nodeController            cache.Controller
+	subnetConf                *subnet.Config
+	events                    chan subnet.Event
+	setNodeNetworkUnavailable bool
 }
 
-func NewSubnetManager(ctx context.Context, apiUrl, kubeconfig, prefix, netConfPath string) (subnet.Manager, error) {
+func NewSubnetManager(ctx context.Context, apiUrl, kubeconfig, prefix, netConfPath string, setNodeNetworkUnavailable bool) (subnet.Manager, error) {
 	var cfg *rest.Config
 	var err error
 	// Try to build kubernetes config from a master url or a kubeconfig filepath. If neither masterUrl
@@ -111,6 +112,7 @@ func NewSubnetManager(ctx context.Context, apiUrl, kubeconfig, prefix, netConfPa
 	if err != nil {
 		return nil, fmt.Errorf("error creating network manager: %s", err)
 	}
+	sm.setNodeNetworkUnavailable = setNodeNetworkUnavailable
 	go sm.Run(context.Background())
 
 	log.Infof("Waiting %s for node controller to sync", nodeControllerSyncTimeout)
@@ -273,9 +275,14 @@ func (ksm *kubeSubnetManager) AcquireLease(ctx context.Context, attrs *subnet.Le
 			return nil, err
 		}
 	}
-	err = ksm.setNodeNetworkUnavailableFalse(ctx)
-	if err != nil {
-		log.Errorf("Unable to set NetworkUnavailable to False for %q: %v", ksm.nodeName, err)
+	if ksm.setNodeNetworkUnavailable {
+		log.Infoln("Setting NodeNetworkUnavailable")
+		err = ksm.setNodeNetworkUnavailableFalse(ctx)
+		if err != nil {
+			log.Errorf("Unable to set NodeNetworkUnavailable to False for %q: %v", ksm.nodeName, err)
+		}
+	} else {
+		log.Infoln("Skip setting NodeNetworkUnavailable")
 	}
 	return &subnet.Lease{
 		Subnet:     ip.FromIPNet(cidr),