Skip to content

Commit

Permalink
KubeletConfig: Verify EvictionSoftGracePeriod is set when EvictionSof…
Browse files Browse the repository at this point in the history
…t is set.

Signed-off-by: Harshal Patil <harpatil@redhat.com>
  • Loading branch information
harche authored and openshift-cherrypick-robot committed Jul 1, 2020
1 parent 9712a7c commit 2067ac9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/controller/kubelet-config/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func validateUserKubeletConfig(cfg *mcfgv1.KubeletConfig) error {
return fmt.Errorf("KubeletConfiguration: staticPodPath is not allowed to be set, but contains: %s", kcDecoded.StaticPodPath)
}

if kcDecoded.EvictionSoft != nil && len(kcDecoded.EvictionSoft) > 0 {
if kcDecoded.EvictionSoftGracePeriod == nil || len(kcDecoded.EvictionSoftGracePeriod) == 0 {
return fmt.Errorf("KubeletConfiguration: EvictionSoftGracePeriod must be set when evictionSoft is defined, evictionSoft: %v", kcDecoded.EvictionSoft)
}

for k := range kcDecoded.EvictionSoft {
if _, ok := kcDecoded.EvictionSoftGracePeriod[k]; !ok {
return fmt.Errorf("KubeletConfiguration: evictionSoft[%s] is defined but EvictionSoftGracePeriod[%s] is not set", k, k)
}
}
}

return nil
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/kubelet-config/kubelet_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,25 @@ func TestKubeletConfigBlacklistedOptions(t *testing.T) {
},
},
},
{
name: "evictionSoft cannot be supplied without evictionSoftGracePeriod",
config: &kubeletconfigv1beta1.KubeletConfiguration{
EvictionSoft: map[string]string{
"memory.available": "90%",
},
},
},
{
name: "evictionSoft cannot be supplied without corresponding evictionSoftGracePeriod",
config: &kubeletconfigv1beta1.KubeletConfiguration{
EvictionSoft: map[string]string{
"memory.available": "90%",
},
EvictionSoftGracePeriod: map[string]string{
"nodefs.inodesFree": "1h",
},
},
},
}

successTests := []struct {
Expand Down

0 comments on commit 2067ac9

Please sign in to comment.