Skip to content

Conversation

@stevesloka
Copy link
Contributor

What this PR does / why we need it:

Currentlykube-proxy loads configuration from a config file. There are cases where the hostname needs to be overridden (See: kubernetes/kubeadm#857).

There is a flag that allows the hostname to be overridden (hostname-override), but when the config file is loaded, if this arg is set, it's overridden by whatever the config file contains making the argument ignored if it was set.

This PR checks for this argument and uses it if it is passed to kube-proxy.

Which issue(s) this PR fixes:
Fixes #57518
Fixes kubernetes/kubeadm#857

Special notes for your reviewer:

Release note:

kube-proxy argument `hostname-override` can be used to override hostname defined in the configuration file

// @timothysc

Signed-off-by: Steve Sloka [email protected]

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 2, 2018
@stevesloka stevesloka force-pushed the fixHostNameOverride branch from d1c4741 to 3f87bd7 Compare October 2, 2018 19:17
)

var (
hostNameOverride string
Copy link
Member

Choose a reason for hiding this comment

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

If we decide to proceed with this one-off approach for hostnameOverride, let's make this an unexported field in Options.

Copy link
Member

Choose a reason for hiding this comment

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

if err := opts.Complete(); err != nil {
glog.Fatalf("failed complete: %v", err)
}
if err := opts.ProcessArgs(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a new top-level function to the complete/validate/run flow, I'd recommend renaming ProcessArgs() to processHostnameOverrideFlag() and calling it from within Complete()


// TestProcessArgs tests processing args
func TestProcessArgs(t *testing.T) {

Copy link
Member

Choose a reason for hiding this comment

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

Please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been renamed to match the code it is testing.

Copy link
Member

Choose a reason for hiding this comment

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

... the blank line

testCases := []struct {
name string
hostnameArg string
expHostname string
Copy link
Member

Choose a reason for hiding this comment

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

exp->expected

Copy link
Member

Choose a reason for hiding this comment

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

gofmt

Copy link
Member

Choose a reason for hiding this comment

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

also: if err := ...; err != nil {

Copy link
Member

Choose a reason for hiding this comment

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

Revert?

@stevesloka stevesloka force-pushed the fixHostNameOverride branch 2 times, most recently from 5102ffa to 7b9e797 Compare October 2, 2018 19:32
@stevesloka
Copy link
Contributor Author

@ncdc I addressed your comments, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I would call this hostnameOverride

Copy link
Member

Choose a reason for hiding this comment

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

How about something like

hostnameOverride, if set from the command line flag, takes precedence over the `HostnameOverride` value from the config file

Copy link
Member

Choose a reason for hiding this comment

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

argument -> flag

Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no not needed, removing

Copy link
Member

Choose a reason for hiding this comment

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

hostnameArg -> hostnameOverrideFlag

Copy link
Member

Choose a reason for hiding this comment

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

argument -> flag

Copy link
Member

Choose a reason for hiding this comment

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

Use a go subtest:

t.Run(tc.name, func(t *testing.T) {
  // body of test case
}

Copy link
Member

Choose a reason for hiding this comment

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

When you switch to using a subtest, you can remove the initial %s for tc.name

Copy link
Member

Choose a reason for hiding this comment

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

When you switch to using a subtest, you can remove the initial %s for tc.name

@timothysc
Copy link
Contributor

/ok-to-test
/sig networking
/sig clusterlifecycle

/cc @kubernetes/sig-network-pr-reviews

@k8s-ci-robot k8s-ci-robot added sig/network Categorizes an issue or PR as relevant to SIG Network. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 2, 2018
@stevesloka stevesloka force-pushed the fixHostNameOverride branch from 7b9e797 to 5834f94 Compare October 2, 2018 20:09
@stevesloka
Copy link
Contributor Author

/retest

@timothysc timothysc added the kind/bug Categorizes issue or PR as related to a bug. label Oct 11, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Oct 11, 2018
@timothysc
Copy link
Contributor

@kubernetes/sig-network-pr-reviews - re-ping!
/assign @thockin


// processHostnameOverrideFlag processes hostname-override flag
func (o *Options) processHostnameOverrideFlag() error {
// Check if hostname-override flag is set and use value since configFile always overrides
Copy link
Member

Choose a reason for hiding this comment

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

I thought the flag would always override - the flag reads into the config struct..

@mtaufen

Copy link
Member

Choose a reason for hiding this comment

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

@thockin I did kube-proxy first, as a POC, and it got merged well before all the docs/discussions on the proper way to do things going forward. I didn't realize that there would be a need for per-instance configuration settings as well as those that are shared across all instances. The way kube-proxy specifically works, today, is that it's completely either-or. Either you use a config file, or you use flags. Flags do not override the config file.

Copy link
Member

Choose a reason for hiding this comment

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

blech

@thockin
Copy link
Member

thockin commented Oct 16, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 16, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: stevesloka, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 16, 2018
@mtaufen
Copy link
Contributor

mtaufen commented Oct 16, 2018

You may find that this becomes a general problem.
In the Kubelet we did a general thing to make flags take precedence over config files.
I'm not saying you should exactly emulate the way the Kubelet does the general thing, because there are likely cleaner bootstrap approaches that enable flags to take precedence, but if you notice this kind of thing keeps happening, you may want to consider a more general approach.

@stevesloka
Copy link
Contributor Author

@mtaufen yes this came up with discussions with @ncdc and others. I am going to look to better implement these flags in a future PR, but might need some further discussion.

@anguslees
Copy link
Member

(fwiw, the --{bind-address,metrics-bind-address,healthz-bind-address} flags are further examples that are probably going to be given node-specific values via flags rather than configured in the cluster-wide config)

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

7 participants