-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1465 from DualSpark/k-c-m-attachedetachflag
Updates for new k-c-m flag
- Loading branch information
Showing
9 changed files
with
259 additions
and
2 deletions.
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 kubernetes controller manager to the model. | ||
type KubeControllerManagerOptionsBuilder struct { | ||
Context *OptionsContext | ||
} | ||
|
||
var _ loader.OptionsBuilder = &KubeControllerManagerOptionsBuilder{} | ||
|
||
// BuildOptions generates the configurations used to create kubernetes controller manager manifest | ||
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" { | ||
|
||
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