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

add configmap based config #928

Closed
wants to merge 3 commits into from
Closed

add configmap based config #928

wants to merge 3 commits into from

Conversation

cadmuxe
Copy link
Member

@cadmuxe cadmuxe commented Nov 5, 2019

No description provided.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 5, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @cadmuxe. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 5, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cadmuxe
To complete the pull request process, please assign freehan
You can assign the PR to them by writing /assign @freehan in a comment when ready.

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

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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 5, 2019
@k8s-ci-robot k8s-ci-robot requested review from bowei and thockin November 5, 2019 21:26
cmd/glbc/main.go Outdated
time.Sleep(30 * time.Second)
return
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we add IsStopped functions to all the controllers and do a check in here?

@cadmuxe
Copy link
Member Author

cadmuxe commented Nov 5, 2019

/cc @freehan

@k8s-ci-robot k8s-ci-robot requested a review from freehan November 5, 2019 21:28
Copy link
Contributor

@freehan freehan left a comment

Choose a reason for hiding this comment

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

just some, will continue

// Config holds configmap based configurations.
type Config struct {
EnableASM bool
ASMServiceNEGSkipNamespaces string // should be common seperated namespaces.
Copy link
Contributor

Choose a reason for hiding this comment

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

Use list of strings?

cmd/glbc/main.go Outdated
stopCh := make(chan struct{})
cmConfig := cmConifgController.GetConfig()
if cmConifgController.IsConfigMapConfigModeOn() {
Copy link
Contributor

Choose a reason for hiding this comment

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

need to flag gate this behavior. Let me think about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added the flag gate to the controller. if it's enabled, it will try to load the configmap and watch it.
if disabled, it will just return the default config structure.
The idea is, even this feature is disabled, we want to get the default config. and I don't want to put the get default config out from the controller.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 6, 2019
@cadmuxe cadmuxe marked this pull request as ready for review November 7, 2019 01:06
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 7, 2019
@freehan
Copy link
Contributor

freehan commented Nov 7, 2019

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 7, 2019
cmd/glbc/main.go Outdated
lbc := controller.NewLoadBalancerController(ctx, stopCh)

fwc := firewalls.NewFirewallController(ctx, flags.F.NodePortRanges.Values())

if ctx.EnableASMConfigMapConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to below ctx.Init()

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved it to the below of lbc := controller.NewLoadBalancerController(ctx, stopCh)
Because the RegisterInformer need to call lbc.Stop.

if cmConfig.EnableASM {
dynamicClient, err := dynamic.NewForConfig(ctx.KubeConfig)
if err != nil {
klog.Fatalf("Failed to create kubernetes dynamic client: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

throw an event to the Config Map

}

// GetConfig returns the internal Config
func (c *ConfigMapConfigController) GetConfig() Config {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend this return (Config, boolean)

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 the controller was created with NewConfigMapConfigController, the c.currentConfig would never be null. Which means, if it's null, we probably want the program fail directly.

Imaging we change this to (Config, boolean), and in the case that it return (config, false).
What should the caller to doe?

  1. fail the program [ same as now]
  2. make a new Config which use the default value. [ I want to put the make default logic in the NewConfigMapConfigController function but not anywhere else. ]

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

@freehan freehan self-assigned this Nov 8, 2019
cmd/glbc/main.go Outdated
go app.RunHTTPServer(ctx.HealthCheck)

if !flags.F.LeaderElection.LeaderElect {
runControllers(ctx)
return
}

leaderElectionCtx, leaderElectionCancel := context.WithCancel(context.Background())
electionConfig, err := makeLeaderElectionConfig(leaderElectKubeClient, ctx.Recorder(flags.F.LeaderElection.LockObjectNamespace), func() {
runControllers(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

@bowei suggested exiting the program directly. after runController exits. That is more reliable.

https://gobyexample.com/exit

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, agree.

}

// LoadValue loads configs from a map, it will ignore any unknow/unvalid field.
func (c *Config) LoadValue(m map[string]string, recordWarning func(msg string)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function may be too complex.

Check out this one, it is very simple and straightforward.
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/legacy-cloud-providers/gce/gce_clusterid.go#L234

Copy link
Member Author

Choose a reason for hiding this comment

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

agree, the initial idea was keeping this generic.
Updated.

}

// GetConfig returns the internal Config
func (c *ConfigMapConfigController) GetConfig() Config {
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

@cadmuxe cadmuxe closed this Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants