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

Updates for new k-c-m flag #1465

Merged
merged 3 commits into from
Jan 19, 2017

Conversation

chrislovecnm
Copy link
Contributor

@chrislovecnm chrislovecnm commented Jan 13, 2017

Closes #1417

New flag for kubernetes controller manager that reduces the number of API calls that k-c-m makes. In 1.4.7 and 1.5.x a new feature was added to k-c-m. That feature can now spam AWS APIs if not tuned correctly.


This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Jenkins Kubernetes AWS e2e failed for commit 34bc061. Full PR test history. cc @chrislovecnm

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

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. I understand the commands that are listed here.

@chrislovecnm
Copy link
Contributor Author

I am not able to get the yaml updating on the cluster spec of a running server:

kops get cluster --name my.cluster --full -o yaml

  kubeControllerManager:
    allocateNodeCIDRs: true
    attachDetachReconcileSyncPeriod: 1m0s
    cloudProvider: aws
    clusterCIDR: 100.96.0.0/11
    clusterName: liea-ginny.dev.datapipe.io
    configureCloudRoutes: false
    image: gcr.io/google_containers/kube-controller-manager:v1.5.2
    leaderElection:
      leaderElect: true
    logLevel: 2
    master: 127.0.0.1:8080
    master: 127.0.0.1:8080
    config: /etc/kubernetes/manifests
    enableDebuggingHandlers: true
    hostnameOverride: '@aws'
    logLevel: 2
    networkPluginMTU: null
    networkPluginName: cni
    nonMasqueradeCIDR: 100.64.0.0/10

Ideas?

return fmt.Errorf("Unable to parse kubernetesVersion v1.4.8")
}

k8sv152, _ := kops.ParseKubernetesVersion("v1.5.2")
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this returns an error

k8sv152, _

Shouldn't we grab it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already did in an update ... will push

Copy link
Member

@justinsb justinsb left a comment

Choose a reason for hiding this comment

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

A bunch of style nits. Will now look at why the flag isn't working...

}

if spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration != time.Minute {
t.Fatalf("k-c-m builder should be set to 1m - %s", spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String())
Copy link
Member

Choose a reason for hiding this comment

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

s/k-c-m- builder/AttachDetachReconcileSyncPeriod/g

err := kcm.BuildOptions(&spec)

if err != nil {
t.Fatalf("k-c-m builder errors: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

s/k-c-m builder errors/unexpected error from BuildOptions/g

}

if spec.KubeControllerManager.AttachDetachReconcileSyncPeriod != nil {
t.Fatalf("k-c-m builder cannot be set for k8s %s", spec.KubernetesVersion)
Copy link
Member

Choose a reason for hiding this comment

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

"AttachDetachReconcileSyncPeriod should not be set for old kubernetes version %s"

err := kcm.BuildOptions(&spec)

if err != nil {
t.Fatalf("k-c-m builder errors: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

"unexpected error from BuildOptions"

UpdatePolicy string
}

func buildCluster(clusterArgs interface{}) *api.Cluster {
Copy link
Member

Choose a reason for hiding this comment

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

Why interface{}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just code I grabbed from elsewhere, will clean-up the tests some

return fmt.Errorf("Unable to parse kubernetesVersion v1.4.8")
}

k8sv152, _ := kops.ParseKubernetesVersion("v1.5.2")
Copy link
Member

Choose a reason for hiding this comment

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

You need to assign err here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have in an update


kubernetesVersion, err := b.Context.KubernetesVersion()
if err != nil {
return fmt.Errorf("Unable to parse kubernetesVersion")
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to add to the error - the error that comes back from KubernetesVersion is already pretty good I think. But you shouldn't swallow the error i.e. do fmt.Errorf("additional info: %v", err)

glog.Info("k-c-m default-attach-detach-reconcile-sync-period correct version found")
// If not set ... or set to 0s ... which is stupid
if options.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String() == "0s" {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can do == 0 rather than calling .String() == "0s"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That did not work when I tested it :(

if options.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String() == "0s" {

glog.V(8).Info("k-c-m default-attach-detach-reconcile-sync-period flag is set to default")
Copy link
Member

Choose a reason for hiding this comment

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

"AttachDetachReconcileSyncPeriod is not set; will set to default %v", defaultAttachDetachReconcileSyncPeriod

} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < defaultAttachDetachReconcileSyncPeriod &&
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration > time.Second {

glog.Info("k-c-m default-attach-detach-reconcile-sync-period flag is set lower than recommended")
Copy link
Member

Choose a reason for hiding this comment

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

Either use the flag name attach-detach-reconcile-sync-period or the field AttachDetachReconcileSyncPeriod. And probably best to spell out kube-controller-manager, particularly as this is at level Info

@justinsb
Copy link
Member

You want a test like this also...


func TestBuildFlags(t *testing.T) {
	kcm := &api.KubeControllerManagerConfig{
		AttachDetachReconcileSyncPeriod: &metav1.Duration{ Duration: time.Minute },
	}
	actual, err := nodeup.BuildFlags(kcm)
	if err != nil {
		t.Fatalf("error from BuildFlags: %v", err)
	}
	expected := []string{ "--attach-detach-reconcile-sync-period=60s"}
	if !reflect.DeepEqual(actual, expected) {
		t.Fatalf("unexpected flags.  actual=%v expected=%v", actual, expected)
	}
}

Which will fail because BuildFlags of value type not handled: v1.Duration .AttachDetachReconcileSyncPeriod={1m0s}

@justinsb
Copy link
Member

And to fix that you need this in build_flags.go

		case metav1.Duration:
			vString := v.Duration.String()
			flag = fmt.Sprintf("--%s=%s", flagName, vString)

@justinsb
Copy link
Member

Also glog.Infof is really annoying after a kops edit cluster. I think we want at least v(2)

But then it works for me:

  kubeControllerManager:
    allocateNodeCIDRs: true
    attachDetachReconcileSyncPeriod: 1m0s

I haven't tested it all the way through, but I think that should be it....

@justinsb
Copy link
Member

Correct version of test. Note also the awkward v=0 arg, but that's a separate issue...


func TestBuildFlags(t *testing.T) {
	kcm := &api.KubeControllerManagerConfig{
		AttachDetachReconcileSyncPeriod: &metav1.Duration{Duration: time.Minute},
	}
	actual, err := nodeup.BuildFlags(kcm)
	if err != nil {
		t.Fatalf("error from BuildFlags: %v", err)
	}
	expected := "--attach-detach-reconcile-sync-period=1m0s --v=0"
	if actual != expected {
		t.Fatalf("unexpected flags.  actual=%q expected=%q", actual, expected)
	}
}

@chrislovecnm
Copy link
Contributor Author

@justinsb thanks for the catch ... was driving me nuts.

@chrislovecnm
Copy link
Contributor Author

@justinsb not sure where you want me to put the test, because you seemed to changed:

actual, err := nodeup.BuildFlags(kcm)

to

actual, err := nodeup.buildFlags(kcm)

You changed buildFlags to public.

@chrislovecnm chrislovecnm changed the title [WIP] Updates for new k-c-m flag Updates for new k-c-m flag Jan 18, 2017
@chrislovecnm
Copy link
Contributor Author

@justinsb / @kris-nova need another review. Will rebase after e2e

@chrislovecnm
Copy link
Contributor Author

#1528 filed this issue for documenting changes like this.

Copy link
Member

@justinsb justinsb left a comment

Choose a reason for hiding this comment

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

A few more tweaks needed I think

}

k8sv148, err := kops.ParseKubernetesVersion("v1.4.8")

Copy link
Member

Choose a reason for hiding this comment

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

Simpler is better I think.

return fmt.Errorf("Unable to parse kubernetesVersion %s", err)
}

k8sv152, _ := kops.ParseKubernetesVersion("v1.5.2")
Copy link
Member

Choose a reason for hiding this comment

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

You need to map the error here

if options.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String() == "0s" {

glog.V(8).Info("AttachDetachReconcileSyncPeriod is not set; will set to default %v", defaultAttachDetachReconcileSyncPeriod)
Copy link
Member

Choose a reason for hiding this comment

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

Infof. I prefer always to use Infof, because then you never make this mistake, though I think go vet or go lint doesn't like it


glog.Info("KubeControllerManager AttachDetachReconcileSyncPeriod is set lower than recommended")

// If less than 1sec you get an error. Controller no worky .. it goes boom.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a k8s issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Misworded .. let me reword

}
} else {

glog.Info("not setting AttachDetachReconcileSyncPeriod, k8s version is too low")
Copy link
Member

Choose a reason for hiding this comment

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

V(2) or higher

}

if spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration != time.Minute {
t.Fatalf("k-c-m builder should be set to 1m - %s", spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String())
Copy link
Member

Choose a reason for hiding this comment

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

AttachDetachReconcileSyncPeriod should be set...

}

if full.Spec.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil {
t.Fatalf("Attache Detach not set correctly")
Copy link
Member

Choose a reason for hiding this comment

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

AttachDetachReconcileSyncPeriod

}

if full.Spec.KubeControllerManager.AttachDetachReconcileSyncPeriod != nil {
t.Fatalf("Attach Detach is not supported in 1.4.7")
Copy link
Member

Choose a reason for hiding this comment

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

AttachDetachReconcileSyncPeriod


// If less than 1sec you get an error. Controller no worky .. it goes boom.
} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < time.Second {
return fmt.Errorf("Unable to set AttachDetachReconcileSyncPeriod than 1 second")
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it more obviously a validation error: "AttachDetachReconcileSyncPeriod cannot be set to less than 1 second"

} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < defaultAttachDetachReconcileSyncPeriod &&
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration > time.Second {

glog.Info("KubeControllerManager AttachDetachReconcileSyncPeriod is set lower than recommended")
Copy link
Member

Choose a reason for hiding this comment

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

Infof(...than recommend: %v", options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration)

@chrislovecnm
Copy link
Contributor Author

@justinsb

Simpler is better I think.

Huh??

Copy link
Member

@justinsb justinsb left a comment

Choose a reason for hiding this comment

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

LGTM

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. critical-path P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants