Skip to content
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

Refactor kube-proxy configuration #34727

Merged
merged 1 commit into from
May 2, 2017

Conversation

ncdc
Copy link
Member

@ncdc ncdc commented Oct 13, 2016

This is a proof of concept refactoring of the configuration and startup of kube-proxy. Most flags have been removed and replaced by a single config file, specified by --config. This is in regards to the component configuration improvement suggestions listed in #32215.

Also during this effort, I discovered that Hyperkube is roughly reimplementing portions of cobra, and that the current cobra command definitions are solely used to generated docs and man pages. I would like to move the individual commands as well as Hyperkube to using cobra, but that is a separate issue and discussion.

cc @mikedanese @liggitt @deads2k @eparis @sttts @smarterclayton @dgoodwin @timothysc


This change is Reviewable

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note-label-needed labels Oct 13, 2016
@ncdc ncdc force-pushed the kube-proxy-config branch from 6f5b2a6 to 375ba9e Compare October 13, 2016 15:43
@ncdc ncdc assigned mikedanese and unassigned dchen1107 Oct 13, 2016
@k8s-ci-robot
Copy link
Contributor

Bootstrap GCE e2e failed for commit 375ba9e. Full PR test history.

The magic incantation to run this job again is @k8s-bot bootstrap gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@mikedanese
Copy link
Member

@thockin can you sign to someone on networking for review?

@ncdc
Copy link
Member Author

ncdc commented Oct 14, 2016

@mikedanese @thockin ideally the iptables/proxier bits would be refactored so that they have distinct New() (no side effects) vs Start() (side effects) behavior. I didn't make that effort here as my focus is on showing what the config changes could look like.

I also think I need to add a validation check to ProxyServer.Run to make sure all fields are set appropriately before continuing.

@eparis
Copy link
Contributor

eparis commented Oct 14, 2016

@marun would you have time to take a look. I know you won't be able to do an adequate review of the whole idea, but you can at least review the code here I think...

@timothysc
Copy link
Member

Most flags have been removed and replaced by a single config file, specified by --config

Don't we have to go through at least 1 release where we mark as deprecated? Not that I'm opposed to what you're doing, as flags have gone feral. Just trying to ensure customer expectations are congruent with policy.

@timothysc timothysc added area/kube-proxy release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed release-note-label-needed labels Oct 17, 2016
@ncdc
Copy link
Member Author

ncdc commented Oct 17, 2016

@timothysc this is currently just a proof of concept of what the end state could look like. I will do whatever we all agree upon re a deprecation period and behavior.

assert.NotNil(t, proxyserver.IptInterface)
}

func TestGetConntrackMax(t *testing.T) {
ncores := runtime.NumCPU()
testCases := []struct {
config componentconfig.KubeProxyConfiguration
config componentconfig.KubeProxyConntrackConfiguration
Copy link
Contributor

@marun marun Oct 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but whenever I see tests written like this I want to simplify as follows:

testCases := []struct {
  max        int32
  maxPerCore int32
  expected   int
  err        string
}{
  {
    expected: 0,
  },
  ...
}

for i, tc:= range testCases {
  config := componentConfig.KubeProxyConntrackConfiguration{
    Max: tc.max,
    MaxPerCore: tc.maxPerCore,
  }
  ...
}

Or is it preferable to define objects in test tables?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the particular test, its cases, and how much flexibility you need.

@marun
Copy link
Contributor

marun commented Oct 18, 2016

I like the separation of concerns this POC promotes. It makes the code easier to reason about and should allow for cleaner testing. An open question is how much work it will be to remove side-effects at configuration time (and the potential for breakage that represents), but I think it should be worth it.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 19, 2016
Conntracker: conntracker,
ProxyMode: proxyMode,
}, nil
type KubeProxyOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in the kube-proxy package here. Any need for the KubeProxy prefix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, though "Options" is as meaningless as "Config".

flags := cmd.Flags()
BindKubeProxyOptions(&opts, flags)

cmd.MarkFlagFilename("config", "yaml", "yml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No json? Then I would expect a hint for yaml in the flags description.

glog.Errorf("unable to register configz: %s", err)
}

glog.V(4).Infof("using configuration: %#v", config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: capital first letter in logs.

Recorder record.EventRecorder
ConntrackConfiguration componentconfig.KubeProxyConntrackConfiguration
Conntracker Conntracker // if nil, ignored
ProxyMode string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional to duplicate all the config values here? Feels like a lot of bloat instead of just leaving the config reference in here (we have that at many places in other component as well, unfortunately).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree - the more places this is replicated the harder it becomes to keep correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I feel lik the definition of the struct should be in the callee - it is the Server package's job to define what args it needs, and the main package's job to provide those args..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. There is 1 struct for configuration (componentconfig.KubeProxyConfiguration) and 1 struct for runtime (ProxyServer). The runtime struct is used to run the component, and the config struct is the source of the configuration that is used to generate the runtime struct. We do not want to include the config struct inside the runtime struct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's not required that you go from config struct to runtime struct. You could create only a runtime struct and use that to run the component. That is the contract for running. The config struct is a helper to go from a human-editable config file to runtime.

"os"

"github.com/spf13/pflag"

goflag "flag"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move up

--hostname-override="${HOSTNAME_OVERRIDE}" \
--feature-gates="${FEATURE_GATES}" \
--master="http://${API_HOST}:${API_PORT}" >"${PROXY_LOG}" 2>&1 &
--config /tmp/kube-proxy.yaml \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to lose feature-gates, which is a flag defined in a different lib, and pretty important :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 45077, 45180, 34727, 45079, 45177)

@k8s-github-robot k8s-github-robot merged commit 5ffbd37 into kubernetes:master May 2, 2017
@wojtek-t
Copy link
Member

wojtek-t commented May 2, 2017

This PR kind-of broke hollow-proxy (i.e. it didn't break tests, but with this PR, hollow-proxy isn't doing anything useful). I will try to send out PR fixing this soon.
@gmarek @shyamjvs

@wojtek-t
Copy link
Member

wojtek-t commented May 2, 2017

#45227 is out for review

k8s-github-robot pushed a commit that referenced this pull request May 2, 2017
Automatic merge from submit-queue

Fix hollow proxy to watch services and endpoints

Ref #34727
@shyamjvs shyamjvs mentioned this pull request May 8, 2017
k8s-github-robot pushed a commit that referenced this pull request May 20, 2017
Automatic merge from submit-queue (batch tested with PRs 46033, 46122, 46053, 46018, 45981)

Restore kube-proxy --version

Accidentally removed by #34727.

Fixes #46026
@bboreham
Copy link
Contributor

Where are the docs for this change, please?

@ncdc
Copy link
Member Author

ncdc commented Jun 13, 2017 via email

@bboreham
Copy link
Contributor

@ncdc
Copy link
Member Author

ncdc commented Jun 28, 2017

@bboreham I believe that file is autogenerated (it basically comes from kube-proxy --help). I posted a question in slack asking the best way to document this (https://kubernetes.slack.com/archives/C1J0BPD2M/p1498659434352871).

@djsly
Copy link
Contributor

djsly commented Sep 7, 2017

Where can we find the procedure for using the new --config approach?

The official addon seems to be creating an empty configmap

@ncdc
Copy link
Member Author

ncdc commented Sep 7, 2017 via email

ironcladlou added a commit to ironcladlou/kubernetes that referenced this pull request Nov 7, 2017
Refactor the kube-scheduler configuration API, command setup, and server
setup according to the guidelines established in kubernetes#32215 and using the
kube-proxy refactor (kubernetes#34727) as a model of a well factored component
adhering to said guidelines.

* Config API: clarify meaning and use of algorithm source by replacing
modality derived from bools and string emptiness checks with an explicit
AlgorithmSource type hierarchy.
* Config API: consolidate client connection config with common structs.
* Config API: split and simplify healthz/metrics server configuration.
* Config API: clarify leader election configuration.
* Config API: improve defaulting.
* CLI: deprecate all flags except `--config`.
* CLI: port all flags to new config API.
* CLI: refactor to match kube-proxy Cobra command style.
* Server: refactor away configurator.go to clarify application wiring.
* Server: refactor to more clearly separate wiring/setup from running.

Fixes kubernetes#52428.
k8s-github-robot pushed a commit that referenced this pull request Nov 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53592, 52562, 55175, 55213). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Refactor kube-scheduler config API, command, and server setup

Refactor the kube-scheduler configuration API, command setup, and server setup according to the guidelines established in #32215 and using the kube-proxy refactor (#34727) as a model of a well factored component adhering to said guidelines.

* Config API: clarify meaning and use of algorithm source by replacing modality derived from bools and string emptiness checks with an explicit AlgorithmSource type hierarchy.
* Config API: consolidate client connection config with common structs.
* Config API: split and simplify healthz/metrics server configuration.
* Config API: clarify leader election configuration.
* Config API: improve defaulting.
* CLI: deprecate all flags except `--config`.
* CLI: port all flags to new config API.
* CLI: refactor to match kube-proxy Cobra command style.
* Server: refactor away configurator.go to clarify application wiring.
* Server: refactor to more clearly separate wiring/setup from running.

Fixes #52428.

@kubernetes/api-reviewers 
@kubernetes/sig-cluster-lifecycle-pr-reviews 
@kubernetes/sig-scheduling-pr-reviews 

/cc @ncdc @timothysc @bsalamat

```release-note
The kube-scheduler command now supports a `--config` flag which is the location of a file containing a serialized scheduler configuration. Most other kube-scheduler flags are now deprecated.
```
adnavare pushed a commit to adnavare/kubernetes that referenced this pull request Nov 13, 2017
Refactor the kube-scheduler configuration API, command setup, and server
setup according to the guidelines established in kubernetes#32215 and using the
kube-proxy refactor (kubernetes#34727) as a model of a well factored component
adhering to said guidelines.

* Config API: clarify meaning and use of algorithm source by replacing
modality derived from bools and string emptiness checks with an explicit
AlgorithmSource type hierarchy.
* Config API: consolidate client connection config with common structs.
* Config API: split and simplify healthz/metrics server configuration.
* Config API: clarify leader election configuration.
* Config API: improve defaulting.
* CLI: deprecate all flags except `--config`.
* CLI: port all flags to new config API.
* CLI: refactor to match kube-proxy Cobra command style.
* Server: refactor away configurator.go to clarify application wiring.
* Server: refactor to more clearly separate wiring/setup from running.

Fixes kubernetes#52428.
@ncdc ncdc deleted the kube-proxy-config branch October 22, 2018 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kube-proxy cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.