-
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
Merged
justinsb
merged 3 commits into
kubernetes:master
from
DualSpark:k-c-m-attachedetachflag
Jan 19, 2017
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
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, err := kops.ParseKubernetesVersion("v1.5.2") | ||
|
||
if err != nil { | ||
return fmt.Errorf("Unable to parse kubernetesVersion %s", err) | ||
} | ||
|
||
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).Infof("AttachDetachReconcileSyncPeriod is not set; will set to default %v", defaultAttachDetachReconcileSyncPeriod) | ||
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.Infof("KubeControllerManager AttachDetachReconcileSyncPeriod is set lower than recommended: %s", defaultAttachDetachReconcileSyncPeriod) | ||
|
||
// If less than 1sec you get an error. Controller is coded to not allow configuration | ||
// less than one second. | ||
} else if options.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration < time.Second { | ||
return fmt.Errorf("AttachDetachReconcileSyncPeriod cannot be set to less than 1 second") | ||
} | ||
} else { | ||
|
||
glog.V(4).Infof("not setting AttachDetachReconcileSyncPeriod, k8s version is too low") | ||
options.KubeControllerManager.AttachDetachReconcileSyncPeriod = nil | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("AttachDetachReconcileSyncPeriod should be set to 1m - %s", spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration.String()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.