@@ -143,37 +143,18 @@ func New(c *OsdnNodeConfig) (network.NodeInterface, error) {
143
143
// Not an OpenShift plugin
144
144
return nil , nil
145
145
}
146
+ glog .Infof ("Initializing SDN node of type %q with configured hostname %q (IP %q), iptables sync period %q" , c .PluginName , c .Hostname , c .SelfIP , c .IPTablesSyncPeriod .String ())
147
+
148
+ if useConnTrack && c .ProxyMode != componentconfig .ProxyModeIPTables {
149
+ return nil , fmt .Errorf ("%q plugin is not compatible with proxy-mode %q" , c .PluginName , c .ProxyMode )
150
+ }
146
151
147
152
// If our CNI config file exists, remove it so that kubelet doesn't think
148
153
// we're ready yet
149
154
os .Remove (filepath .Join (cniDirPath , openshiftCNIFile ))
150
155
151
- glog .Infof ("Initializing SDN node of type %q with configured hostname %q (IP %q), iptables sync period %q" , c .PluginName , c .Hostname , c .SelfIP , c .IPTablesSyncPeriod .String ())
152
- if c .Hostname == "" {
153
- output , err := kexec .New ().Command ("uname" , "-n" ).CombinedOutput ()
154
- if err != nil {
155
- return nil , err
156
- }
157
- c .Hostname = strings .TrimSpace (string (output ))
158
- glog .Infof ("Resolved hostname to %q" , c .Hostname )
159
- }
160
- if c .SelfIP == "" {
161
- var err error
162
- c .SelfIP , err = netutils .GetNodeIP (c .Hostname )
163
- if err != nil {
164
- glog .V (5 ).Infof ("Failed to determine node address from hostname %s; using default interface (%v)" , c .Hostname , err )
165
- var defaultIP net.IP
166
- defaultIP , err = kubeutilnet .ChooseHostInterface ()
167
- if err != nil {
168
- return nil , err
169
- }
170
- c .SelfIP = defaultIP .String ()
171
- glog .Infof ("Resolved IP address to %q" , c .SelfIP )
172
- }
173
- }
174
-
175
- if useConnTrack && c .ProxyMode != componentconfig .ProxyModeIPTables {
176
- return nil , fmt .Errorf ("%q plugin is not compatible with proxy-mode %q" , c .PluginName , c .ProxyMode )
156
+ if err := c .setNodeIP (); err != nil {
157
+ return nil , err
177
158
}
178
159
179
160
ovsif , err := ovs .New (kexec .New (), Br0 , minOvsVersion )
@@ -215,6 +196,35 @@ func New(c *OsdnNodeConfig) (network.NodeInterface, error) {
215
196
return plugin , nil
216
197
}
217
198
199
+ // Set node IP if required
200
+ func (c * OsdnNodeConfig ) setNodeIP () error {
201
+ if len (c .Hostname ) == 0 {
202
+ output , err := kexec .New ().Command ("uname" , "-n" ).CombinedOutput ()
203
+ if err != nil {
204
+ return err
205
+ }
206
+ c .Hostname = strings .TrimSpace (string (output ))
207
+ glog .Infof ("Resolved hostname to %q" , c .Hostname )
208
+ }
209
+
210
+ if len (c .SelfIP ) == 0 {
211
+ var err error
212
+ c .SelfIP , err = netutils .GetNodeIP (c .Hostname )
213
+ if err != nil {
214
+ glog .V (5 ).Infof ("Failed to determine node address from hostname %s; using default interface (%v)" , c .Hostname , err )
215
+ var defaultIP net.IP
216
+ defaultIP , err = kubeutilnet .ChooseHostInterface ()
217
+ if err != nil {
218
+ return err
219
+ }
220
+ c .SelfIP = defaultIP .String ()
221
+ glog .Infof ("Resolved IP address to %q" , c .SelfIP )
222
+ }
223
+ }
224
+
225
+ return nil
226
+ }
227
+
218
228
// Detect whether we are upgrading from a pre-CNI openshift and clean up
219
229
// interfaces and iptables rules that are no longer required
220
230
func (node * OsdnNode ) dockerPreCNICleanup () error {
0 commit comments