Skip to content
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

Add tests for KubeletConfig #86034

Merged
merged 1 commit into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/kubelet/apis/config/BUILD
Expand Up @@ -45,10 +45,16 @@ filegroup(

go_test(
name = "go_default_test",
srcs = ["helpers_test.go"],
srcs = [
"helpers_test.go",
"register_test.go",
],
embed = [":go_default_library"],
deps = [
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/component-base/config/testing:go_default_library",
],
)
44 changes: 44 additions & 0 deletions pkg/kubelet/apis/config/register_test.go
@@ -0,0 +1,44 @@
/*
Copyright 2020 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 config

import (
"reflect"
"testing"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
componentconfigtesting "k8s.io/component-base/config/testing"
)

func TestComponentConfigSetup(t *testing.T) {
pkginfo := &componentconfigtesting.ComponentConfigPackage{
ComponentName: "kubelet",
GroupName: GroupName,
SchemeGroupVersion: SchemeGroupVersion,
AddToScheme: AddToScheme,
AllowedTags: map[reflect.Type]bool{
reflect.TypeOf(metav1.TypeMeta{}): true,
reflect.TypeOf(metav1.Duration{}): true,
reflect.TypeOf(v1.NodeConfigSource{}): true,
},
}

if err := componentconfigtesting.VerifyInternalTypePackage(pkginfo); err != nil {
t.Fatal(err)
}
}
2 changes: 2 additions & 0 deletions pkg/kubelet/apis/config/scheme/BUILD
Expand Up @@ -30,9 +30,11 @@ filegroup(
go_test(
name = "go_default_test",
srcs = ["scheme_test.go"],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//pkg/kubelet/apis/config/fuzzer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip:go_default_library",
"//staging/src/k8s.io/component-base/config/testing:go_default_library",
],
)
19 changes: 18 additions & 1 deletion pkg/kubelet/apis/config/scheme/scheme_test.go
Expand Up @@ -20,13 +20,30 @@ import (
"testing"

"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
componentconfigtesting "k8s.io/component-base/config/testing"
"k8s.io/kubernetes/pkg/kubelet/apis/config/fuzzer"
)

func TestRoundTripTypes(t *testing.T) {
func TestRoundTripFuzzing(t *testing.T) {
scheme, _, err := NewSchemeAndCodecs()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
roundtrip.RoundTripTestForScheme(t, scheme, fuzzer.Funcs)
}

func TestRoundTripYAML(t *testing.T) {
scheme, codec, err := NewSchemeAndCodecs()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
componentconfigtesting.RoundTripTest(t, scheme, *codec)
}

func TestDefaultsYAML(t *testing.T) {
scheme, codec, err := NewSchemeAndCodecs()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
componentconfigtesting.DefaultingTest(t, scheme, *codec)
}
@@ -0,0 +1,69 @@
address: 0.0.0.0
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
anonymous:
enabled: false
webhook:
cacheTTL: 2m0s
enabled: true
x509: {}
authorization:
mode: Webhook
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
cgroupDriver: cgroupfs
cgroupsPerQOS: true
configMapAndSecretChangeDetectionStrategy: Watch
containerLogMaxFiles: 5
containerLogMaxSize: 10Mi
contentType: application/vnd.kubernetes.protobuf
cpuCFSQuota: true
cpuCFSQuotaPeriod: 100ms
cpuManagerPolicy: none
cpuManagerReconcilePeriod: 10s
enableControllerAttachDetach: true
enableDebuggingHandlers: true
enforceNodeAllocatable:
- pods
eventBurst: 10
eventRecordQPS: 5
evictionHard:
imagefs.available: 15%
memory.available: 100Mi
nodefs.available: 10%
nodefs.inodesFree: 5%
evictionPressureTransitionPeriod: 5m0s
failSwapOn: true
fileCheckFrequency: 20s
hairpinMode: promiscuous-bridge
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 20s
imageGCHighThresholdPercent: 85
imageGCLowThresholdPercent: 80
imageMinimumGCAge: 2m0s
iptablesDropBit: 15
iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
nodeLeaseDurationSeconds: 40
nodeStatusReportFrequency: 5m0s
nodeStatusUpdateFrequency: 10s
oomScoreAdj: -999
podPidsLimit: -1
port: 10250
registryBurst: 10
registryPullQPS: 5
resolvConf: /etc/resolv.conf
runtimeRequestTimeout: 2m0s
serializeImagePulls: true
streamingConnectionIdleTimeout: 4h0m0s
syncFrequency: 1m0s
topologyManagerPolicy: none
volumePluginDir: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
volumeStatsAggPeriod: 1m0s
@@ -0,0 +1,2 @@
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
@@ -0,0 +1,69 @@
address: 0.0.0.0
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
anonymous:
enabled: false
webhook:
cacheTTL: 2m0s
enabled: true
x509: {}
authorization:
mode: Webhook
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
cgroupDriver: cgroupfs
cgroupsPerQOS: true
configMapAndSecretChangeDetectionStrategy: Watch
containerLogMaxFiles: 5
containerLogMaxSize: 10Mi
contentType: application/vnd.kubernetes.protobuf
cpuCFSQuota: true
cpuCFSQuotaPeriod: 100ms
cpuManagerPolicy: none
cpuManagerReconcilePeriod: 10s
enableControllerAttachDetach: true
enableDebuggingHandlers: true
enforceNodeAllocatable:
- pods
eventBurst: 10
eventRecordQPS: 5
evictionHard:
imagefs.available: 15%
memory.available: 100Mi
nodefs.available: 10%
nodefs.inodesFree: 5%
evictionPressureTransitionPeriod: 5m0s
failSwapOn: true
fileCheckFrequency: 20s
hairpinMode: promiscuous-bridge
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 20s
imageGCHighThresholdPercent: 85
imageGCLowThresholdPercent: 80
imageMinimumGCAge: 2m0s
iptablesDropBit: 15
iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
nodeLeaseDurationSeconds: 40
nodeStatusReportFrequency: 5m0s
nodeStatusUpdateFrequency: 10s
oomScoreAdj: -999
podPidsLimit: -1
port: 10250
registryBurst: 10
registryPullQPS: 5
resolvConf: /etc/resolv.conf
runtimeRequestTimeout: 2m0s
serializeImagePulls: true
streamingConnectionIdleTimeout: 4h0m0s
syncFrequency: 1m0s
topologyManagerPolicy: none
volumePluginDir: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
volumeStatsAggPeriod: 1m0s
@@ -0,0 +1,3 @@
apiVersion: kubelet.config.k8s.io/v1beta1
kind: SerializedNodeConfigSource
source: {}
@@ -0,0 +1,2 @@
apiVersion: kubelet.config.k8s.io/v1beta1
kind: SerializedNodeConfigSource
@@ -0,0 +1,3 @@
apiVersion: kubelet.config.k8s.io/v1beta1
kind: SerializedNodeConfigSource
source: {}
1 change: 1 addition & 0 deletions staging/publishing/import-restrictions.yaml
Expand Up @@ -206,6 +206,7 @@
- k8s.io/api
- k8s.io/apimachinery
- k8s.io/klog
- k8s.io/component-base

- baseImportPath: "./vendor/k8s.io/cluster-bootstrap/"
allowedImports:
Expand Down
4 changes: 4 additions & 0 deletions staging/publishing/rules.yaml
Expand Up @@ -966,6 +966,10 @@ rules:
branch: master
- repository: api
branch: master
- repository: client-go
liggitt marked this conversation as resolved.
Show resolved Hide resolved
branch: master
- repository: component-base
branch: master
- source:
branch: release-1.15
dir: staging/src/k8s.io/kubelet
Expand Down
Expand Up @@ -48,7 +48,7 @@ func GetDefaultingTestCases(t *testing.T, scheme *runtime.Scheme, codecs seriali
}

cases = append(cases, TestCase{
name: fmt.Sprintf("default_%s", gvk.Version),
name: fmt.Sprintf("%s default_%s", gvk.Kind, gvk.Version),
in: filepath.Join(beforeDir, filename),
out: filepath.Join(afterDir, filename),
codec: codec,
Expand Down
4 changes: 4 additions & 0 deletions staging/src/k8s.io/component-base/config/testing/helpers.go
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -93,6 +94,9 @@ func matchOutputFile(t *testing.T, actual []byte, expectedFilePath string) {
}
if needsUpdate {
if os.Getenv(updateEnvVar) == "true" {
if err := os.MkdirAll(filepath.Dir(expectedFilePath), 0755); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(expectedFilePath, actual, 0644); err != nil {
t.Fatal(err)
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ func GetRoundtripTestCases(t *testing.T, scheme *runtime.Scheme, codecs serializ

testname := dir.Name()
cases = append(cases, TestCase{
name: fmt.Sprintf("%sTo%s_%s", vin, vout, testname),
name: fmt.Sprintf("%s_%sTo%s_%s", gk.Kind, vin, vout, testname),
in: filepath.Join(testdir, testname, vin+".yaml"),
out: filepath.Join(testdir, testname, vout+".yaml"),
codec: codec,
Expand Down
9 changes: 8 additions & 1 deletion staging/src/k8s.io/kubelet/config/v1beta1/BUILD
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
Expand Down Expand Up @@ -32,3 +32,10 @@ filegroup(
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = ["register_test.go"],
embed = [":go_default_library"],
deps = ["//staging/src/k8s.io/component-base/config/testing:go_default_library"],
)
36 changes: 36 additions & 0 deletions staging/src/k8s.io/kubelet/config/v1beta1/register_test.go
@@ -0,0 +1,36 @@
/*
Copyright 2020 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 v1beta1

import (
"testing"

componentconfigtesting "k8s.io/component-base/config/testing"
)

func TestComponentConfigSetup(t *testing.T) {
pkginfo := &componentconfigtesting.ComponentConfigPackage{
ComponentName: "kubelet",
GroupName: GroupName,
SchemeGroupVersion: SchemeGroupVersion,
AddToScheme: AddToScheme,
}

if err := componentconfigtesting.VerifyExternalTypePackage(pkginfo); err != nil {
t.Fatal(err)
}
}
3 changes: 3 additions & 0 deletions staging/src/k8s.io/kubelet/go.mod
Expand Up @@ -11,12 +11,15 @@ require (
google.golang.org/grpc v1.26.0
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/component-base v0.0.0
)

replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => ../api
k8s.io/apimachinery => ../apimachinery
k8s.io/client-go => ../client-go
k8s.io/component-base => ../component-base
k8s.io/kubelet => ../kubelet
)