-
Notifications
You must be signed in to change notification settings - Fork 38.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
merge duplicated linux/windows kube-proxy setup code #118017
Changes from 1 commit
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ import ( | |
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"k8s.io/apimachinery/pkg/selection" | ||
"k8s.io/apimachinery/pkg/types" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/apiserver/pkg/server/healthz" | ||
|
@@ -57,11 +58,13 @@ import ( | |
"k8s.io/component-base/configz" | ||
"k8s.io/component-base/logs" | ||
logsapi "k8s.io/component-base/logs/api/v1" | ||
"k8s.io/component-base/metrics" | ||
metricsfeatures "k8s.io/component-base/metrics/features" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
"k8s.io/component-base/metrics/prometheus/slis" | ||
"k8s.io/component-base/version" | ||
"k8s.io/component-base/version/verflag" | ||
nodeutil "k8s.io/component-helpers/node/util" | ||
"k8s.io/klog/v2" | ||
"k8s.io/kube-proxy/config/v1alpha1" | ||
api "k8s.io/kubernetes/pkg/apis/core" | ||
|
@@ -319,7 +322,7 @@ func (o *Options) Run() error { | |
return cleanupAndExit() | ||
} | ||
|
||
proxyServer, err := NewProxyServer(o) | ||
proxyServer, err := newProxyServer(o.config, o.master) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -516,10 +519,61 @@ type ProxyServer struct { | |
Recorder events.EventRecorder | ||
NodeRef *v1.ObjectReference | ||
HealthzServer healthcheck.ProxierHealthUpdater | ||
Hostname string | ||
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. this could be internal variables 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. you mean 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. yep yep |
||
NodeIP net.IP | ||
|
||
Proxier proxy.Provider | ||
} | ||
|
||
// newProxyServer creates a ProxyServer based on the given config | ||
func newProxyServer(config *kubeproxyconfig.KubeProxyConfiguration, master string) (*ProxyServer, error) { | ||
s := &ProxyServer{Config: config} | ||
|
||
cz, err := configz.New(kubeproxyconfig.GroupName) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to register configz: %s", err) | ||
} | ||
cz.Set(config) | ||
|
||
if len(config.ShowHiddenMetricsForVersion) > 0 { | ||
metrics.SetShowHidden() | ||
} | ||
|
||
s.Hostname, err = nodeutil.GetHostname(config.HostnameOverride) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
s.Client, err = createClient(config.ClientConnection, master) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
s.NodeIP = detectNodeIP(s.Client, s.Hostname, config.BindAddress) | ||
klog.InfoS("Detected node IP", "address", s.NodeIP.String()) | ||
|
||
s.Broadcaster = events.NewBroadcaster(&events.EventSinkImpl{Interface: s.Client.EventsV1()}) | ||
s.Recorder = s.Broadcaster.NewRecorder(proxyconfigscheme.Scheme, "kube-proxy") | ||
|
||
s.NodeRef = &v1.ObjectReference{ | ||
Kind: "Node", | ||
Name: s.Hostname, | ||
UID: types.UID(s.Hostname), | ||
Namespace: "", | ||
} | ||
|
||
if len(config.HealthzBindAddress) > 0 { | ||
s.HealthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, s.Recorder, s.NodeRef) | ||
} | ||
|
||
s.Proxier, err = s.createProxier(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
// createClient creates a kube client from the given config and masterOverride. | ||
// TODO remove masterOverride when CLI flags are removed. | ||
func createClient(config componentbaseconfig.ClientConnectionConfiguration, masterOverride string) (clientset.Interface, error) { | ||
|
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.
I hope nobody is importing this