-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package components | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/upup/pkg/fi/loader" | ||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
defaultAttachDetachReconcileSyncPeriod = time.Minute | ||
) | ||
|
||
// KubeControllerManagerOptionsBuilder adds options for the k-c-m to the model | ||
type KubeControllerManagerOptionsBuilder struct { | ||
Context *OptionsContext | ||
} | ||
|
||
var _ loader.OptionsBuilder = &KubeControllerManagerOptionsBuilder{} | ||
|
||
// BuildOptions tests for options to be added to the model | ||
func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o interface{}) error { | ||
|
||
options := o.(*kops.ClusterSpec) | ||
|
||
if options.KubeControllerManager == nil { | ||
options.KubeControllerManager = &kops.KubeControllerManagerConfig{} | ||
} | ||
|
||
k8sv148, err := kops.ParseKubernetesVersion("v1.4.8") | ||
|
||
if err != nil { | ||
return fmt.Errorf("Unable to parse kubernetesVersion %s", err) | ||
} | ||
|
||
k8sv152, _ := kops.ParseKubernetesVersion("v1.5.2") | ||
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 need to assign err here 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. have in an update 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. Assuming this returns an
Shouldn't we grab it? 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. already did in an update ... will push 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 need to map the error here |
||
|
||
if err != nil { | ||
return fmt.Errorf("Unable to parse kubernetesVersion %s", err) | ||
} | ||
|
||
kubernetesVersion, err := b.Context.KubernetesVersion() | ||
if err != nil { | ||
return fmt.Errorf("Unable to parse kubernetesVersion %s", err) | ||
} | ||
|
||
// In 1.4.8+ and 1.5.2+ k8s added the capability to tune the duration upon which the volume attach detach | ||
// component is called. | ||
// See https://github.com/kubernetes/kubernetes/pull/39551 | ||
// TLDR; set this too low, and have a few EBS Volumes, and you will spam AWS api | ||
|
||
// if 1.4.8+ and 1.5.2+ | ||
if kubernetesVersion.GTE(*k8sv148) || kubernetesVersion.GTE(*k8sv152) { | ||
|
||
glog.V(4).Infof("Kubernetes version %q supports AttachDetachReconcileSyncPeriod; will configure", kubernetesVersion) | ||
// If not set ... or set to 0s ... which is stupid | ||
if options.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil || | ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String() == "0s" { | ||
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. I think you can do 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. That did not work when I tested it :( |
||
|
||
glog.V(8).Info("AttachDetachReconcileSyncPeriod is not set; will set to default %v", defaultAttachDetachReconcileSyncPeriod) | ||
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. 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 |
||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod = &metav1.Duration{Duration: defaultAttachDetachReconcileSyncPeriod} | ||
|
||
// If less than 1 min and greater than 1 sec ... you get a warning | ||
} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < defaultAttachDetachReconcileSyncPeriod && | ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration > time.Second { | ||
|
||
glog.Info("KubeControllerManager AttachDetachReconcileSyncPeriod is set lower than recommended") | ||
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.
|
||
|
||
// If less than 1sec you get an error. Controller no worky .. it goes boom. | ||
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. Is there a Github issue? 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. It is written in the code in k-c-m to not allow setting it less than 1s. 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. Is there a k8s issue? 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. Misworded .. let me reword |
||
} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < time.Second { | ||
return fmt.Errorf("Unable to set AttachDetachReconcileSyncPeriod than 1 second") | ||
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. Let's make it more obviously a validation error: "AttachDetachReconcileSyncPeriod cannot be set to less than 1 second" |
||
} | ||
} else { | ||
|
||
glog.Info("not setting AttachDetachReconcileSyncPeriod, k8s version is too low") | ||
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. V(2) or higher |
||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod = nil | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package components | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
api "k8s.io/kops/pkg/apis/kops" | ||
) | ||
|
||
type ClusterParams struct { | ||
CloudProvider string | ||
KubernetesVersion string | ||
UpdatePolicy string | ||
} | ||
|
||
func buildCluster() *api.Cluster { | ||
|
||
return &api.Cluster{ | ||
Spec: api.ClusterSpec{ | ||
CloudProvider: "aws", | ||
KubernetesVersion: "v1.4.0", | ||
}, | ||
} | ||
} | ||
|
||
func Test_Build_KCM_Builder_Lower_Version(t *testing.T) { | ||
c := buildCluster() | ||
|
||
kcm := &KubeControllerManagerOptionsBuilder{ | ||
Context: &OptionsContext{ | ||
Cluster: c, | ||
}, | ||
} | ||
|
||
spec := c.Spec | ||
err := kcm.BuildOptions(&spec) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error from BuildOptions: %v", err) | ||
} | ||
|
||
if spec.KubeControllerManager.AttachDetachReconcileSyncPeriod != nil { | ||
t.Fatalf("AttachDetachReconcileSyncPeriod should not be set for old kubernetes version %s", spec.KubernetesVersion) | ||
} | ||
|
||
} | ||
|
||
func Test_Build_KCM_Builder_High_Enough_Version(t *testing.T) { | ||
c := buildCluster() | ||
c.Spec.KubernetesVersion = "1.4.8" | ||
|
||
kcm := &KubeControllerManagerOptionsBuilder{ | ||
Context: &OptionsContext{ | ||
Cluster: c, | ||
}, | ||
} | ||
|
||
spec := c.Spec | ||
err := kcm.BuildOptions(&spec) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error from BuildOptions %s", err) | ||
} | ||
|
||
if spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration != time.Minute { | ||
t.Fatalf("k-c-m builder should be set to 1m - %s", spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.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. s/k-c-m- builder/AttachDetachReconcileSyncPeriod/g 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. AttachDetachReconcileSyncPeriod should be set... |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,3 +450,46 @@ func TestPopulateCluster_DockerVersion(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestPopulateCluster_KubeController_High_Enough_Version(t *testing.T) { | ||
c := buildMinimalCluster() | ||
c.Spec.KubernetesVersion = "v1.5.2" | ||
|
||
err := PerformAssignments(c) | ||
if err != nil { | ||
t.Fatalf("error from PerformAssignments: %v", err) | ||
} | ||
|
||
addEtcdClusters(c) | ||
|
||
full, err := PopulateClusterSpec(c) | ||
if err != nil { | ||
t.Fatalf("Unexpected error from PopulateCluster: %v", err) | ||
} | ||
|
||
if full.Spec.KubeControllerManager.AttachDetachReconcileSyncPeriod == nil { | ||
t.Fatalf("Attache Detach not set correctly") | ||
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. AttachDetachReconcileSyncPeriod |
||
} | ||
|
||
} | ||
|
||
func TestPopulateCluster_KubeController_Fail(t *testing.T) { | ||
c := buildMinimalCluster() | ||
c.Spec.KubernetesVersion = "1.4.7" | ||
|
||
err := PerformAssignments(c) | ||
if err != nil { | ||
t.Fatalf("error from PerformAssignments: %v", err) | ||
} | ||
|
||
addEtcdClusters(c) | ||
|
||
full, err := PopulateClusterSpec(c) | ||
if err != nil { | ||
t.Fatalf("Unexpected error from PopulateCluster: %v", err) | ||
} | ||
|
||
if full.Spec.KubeControllerManager.AttachDetachReconcileSyncPeriod != nil { | ||
t.Fatalf("Attach Detach is not supported in 1.4.7") | ||
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. AttachDetachReconcileSyncPeriod |
||
} | ||
} |
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.
Can you remove this blank line for clarity?
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.
Also, it might be easier to call
semver.Parse
orsemver.ParseTolerant
directlyThere 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.
@justinsb / @kris-nova Should we look at singleton patter for this data? http://blog.ralch.com/tutorial/design-patterns/golang-singleton/ - More code, but I think a lot of our code kinda follows this, and is not implemented.
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.
Simpler is better I think.