Skip to content

Commit

Permalink
Merge pull request kubernetes#57594 from m1093782566/hairpin
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix incorrect hairpin-mode value and validate it

**What this PR does / why we need it**:

* Fix incorrect hairpin-mode value 

* Add validation

**Which issue(s) this PR fixes**:
Fixes kubernetes#57609

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored Dec 26, 2017
2 parents 025886a + 120a23a commit 18758f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/kubeadm/app/apis/kubeadm/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
ReadOnlyPort: utilpointer.Int32Ptr(0),
RegistryBurst: 10,
RegistryPullQPS: utilpointer.Int32Ptr(5),
HairpinMode: "promiscuous-bridge",
},
}
if allErrors := ValidateKubeletConfiguration(successCase, nil); len(allErrors) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/apis/kubeletconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ type KubeletConfiguration struct {
// "promiscuous-bridge": make the container bridge promiscuous.
// "hairpin-veth": set the hairpin flag on container veth interfaces.
// "none": do nothing.
// Generally, one must set --hairpin-mode=veth-flag to achieve hairpin NAT,
// Generally, one must set --hairpin-mode=hairpin-veth to achieve hairpin NAT,
// because promiscous-bridge assumes the existence of a container bridge named cbr0.
HairpinMode string
// maxPods is the number of pods that can run on this Kubelet.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/apis/kubeletconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ type KubeletConfiguration struct {
// "promiscuous-bridge": make the container bridge promiscuous.
// "hairpin-veth": set the hairpin flag on container veth interfaces.
// "none": do nothing.
// Generally, one must set --hairpin-mode=veth-flag to achieve hairpin NAT,
// Generally, one must set --hairpin-mode=hairpin-veth to achieve hairpin NAT,
// because promiscous-bridge assumes the existence of a container bridge named cbr0.
HairpinMode string `json:"hairpinMode"`
// maxPods is the number of pods that can run on this Kubelet.
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubelet/apis/kubeletconfig/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,13 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error
val, kubetypes.NodeAllocatableEnforcementKey, kubetypes.SystemReservedEnforcementKey, kubetypes.KubeReservedEnforcementKey))
}
}
switch kc.HairpinMode {
case kubeletconfig.HairpinNone:
case kubeletconfig.HairpinVeth:
case kubeletconfig.PromiscuousBridge:
default:
allErrors = append(allErrors, fmt.Errorf("Invalid option %q specified for HairpinMode (--hairpin-mode) setting. Valid options are %q, %q or %q",
kc.HairpinMode, kubeletconfig.HairpinNone, kubeletconfig.HairpinVeth, kubeletconfig.PromiscuousBridge))
}
return utilerrors.NewAggregate(allErrors)
}
6 changes: 4 additions & 2 deletions pkg/kubelet/apis/kubeletconfig/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
ReadOnlyPort: 0,
RegistryBurst: 10,
RegistryPullQPS: 5,
HairpinMode: kubeletconfig.PromiscuousBridge,
}
if allErrors := ValidateKubeletConfiguration(successCase); allErrors != nil {
t.Errorf("expect no errors got %v", allErrors)
Expand Down Expand Up @@ -75,8 +76,9 @@ func TestValidateKubeletConfiguration(t *testing.T) {
ReadOnlyPort: -10,
RegistryBurst: -10,
RegistryPullQPS: -10,
HairpinMode: "foo",
}
if allErrors := ValidateKubeletConfiguration(errorCase); len(allErrors.(utilerrors.Aggregate).Errors()) != 21 {
t.Errorf("expect 21 errors got %v", len(allErrors.(utilerrors.Aggregate).Errors()))
if allErrors := ValidateKubeletConfiguration(errorCase); len(allErrors.(utilerrors.Aggregate).Errors()) != 22 {
t.Errorf("expect 22 errors got %v", len(allErrors.(utilerrors.Aggregate).Errors()))
}
}

0 comments on commit 18758f5

Please sign in to comment.