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

Use private key fixtures for kubeadm unit tests #98664

Merged
merged 1 commit into from Feb 1, 2021
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
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/cmd/BUILD
Expand Up @@ -77,6 +77,7 @@ go_test(
"config_test.go",
"init_test.go",
"join_test.go",
"main_test.go",
"token_test.go",
"version_test.go",
],
Expand All @@ -95,6 +96,7 @@ go_test(
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
"//cmd/kubeadm/app/util/output:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/app/util/runtime:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//cmd/kubeadm/test/cmd:go_default_library",
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/cmd/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 cmd

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/cmd/phases/init/BUILD
Expand Up @@ -63,6 +63,7 @@ go_test(
srcs = [
"certs_test.go",
"data_test.go",
"main_test.go",
],
embed = [":go_default_library"],
deps = [
Expand All @@ -71,6 +72,7 @@ go_test(
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/util/certs:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/cmd/phases/init/certs_test.go
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
certstestutil "k8s.io/kubernetes/cmd/kubeadm/app/util/certs"
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
)

Expand Down Expand Up @@ -85,6 +86,8 @@ func TestCertsWithCSRs(t *testing.T) {
func TestCreateSparseCerts(t *testing.T) {
for _, test := range certstestutil.GetSparseCertTestCases(t) {
t.Run(test.Name, func(t *testing.T) {
pkiutiltesting.Reset()

tmpdir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpdir)

Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/cmd/phases/init/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 phases

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/phases/certs/BUILD
Expand Up @@ -11,13 +11,15 @@ go_test(
srcs = [
"certlist_test.go",
"certs_test.go",
"main_test.go",
],
embed = [":go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/util/certs:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
"//staging/src/k8s.io/client-go/util/keyutil:go_default_library",
Expand Down
7 changes: 7 additions & 0 deletions cmd/kubeadm/app/phases/certs/certs_test.go
Expand Up @@ -37,6 +37,7 @@ import (
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
certstestutil "k8s.io/kubernetes/cmd/kubeadm/app/util/certs"
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
)

Expand Down Expand Up @@ -486,6 +487,8 @@ func TestSharedCertificateExists(t *testing.T) {
func TestCreatePKIAssetsWithSparseCerts(t *testing.T) {
for _, test := range certstestutil.GetSparseCertTestCases(t) {
t.Run(test.Name, func(t *testing.T) {
pkiutiltesting.Reset()

tmpdir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpdir)

Expand Down Expand Up @@ -587,6 +590,8 @@ func TestUsingExternalCA(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
pkiutiltesting.Reset()

dir := testutil.SetupTempDir(t)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -776,6 +781,8 @@ func TestCreateCertificateFilesMethods(t *testing.T) {
}

for _, test := range tests {
pkiutiltesting.Reset()

// Create temp folder for the test case
tmpdir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpdir)
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/phases/certs/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 certs

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/phases/certs/renewal/BUILD
Expand Up @@ -28,6 +28,7 @@ go_test(
srcs = [
"expiration_test.go",
"filerenewer_test.go",
"main_test.go",
"manager_test.go",
"readwriter_test.go",
],
Expand All @@ -38,6 +39,7 @@ go_test(
"//cmd/kubeadm/app/util/certs:go_default_library",
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/phases/certs/renewal/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 renewal

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/phases/controlplane/BUILD
Expand Up @@ -9,6 +9,7 @@ load(
go_test(
name = "go_default_test",
srcs = [
"main_test.go",
"manifests_test.go",
"volumes_test.go",
],
Expand All @@ -18,6 +19,7 @@ go_test(
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/features:go_default_library",
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/app/util/staticpod:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/phases/controlplane/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 controlplane

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/phases/controlplane/manifests_test.go
Expand Up @@ -33,6 +33,7 @@ import (
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/features"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
staticpodutil "k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod"
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
)
Expand Down Expand Up @@ -920,6 +921,8 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
pkiutiltesting.Reset()

// Create temp folder for the test case
tmpdir := testutil.SetupTempDir(t)
defer os.RemoveAll(tmpdir)
Expand Down
6 changes: 5 additions & 1 deletion cmd/kubeadm/app/phases/copycerts/BUILD
Expand Up @@ -41,13 +41,17 @@ filegroup(

go_test(
name = "go_default_test",
srcs = ["copycerts_test.go"],
srcs = [
"copycerts_test.go",
"main_test.go",
],
embed = [":go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/util/crypto:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/phases/copycerts/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 copycerts

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
6 changes: 5 additions & 1 deletion cmd/kubeadm/app/phases/kubeconfig/BUILD
Expand Up @@ -44,14 +44,18 @@ filegroup(

go_test(
name = "go_default_test",
srcs = ["kubeconfig_test.go"],
srcs = [
"kubeconfig_test.go",
"main_test.go",
],
embed = [":go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//cmd/kubeadm/app/util/certs:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//cmd/kubeadm/test/kubeconfig:go_default_library",
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
Expand Down
26 changes: 26 additions & 0 deletions cmd/kubeadm/app/phases/kubeconfig/main_test.go
@@ -0,0 +1,26 @@
/*
Copyright 2021 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 kubeconfig

import (
pkiutiltesting "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil/testing"
"testing"
)

func TestMain(m *testing.M) {
pkiutiltesting.RunWithPrivateKeyFixtureDirectory(m)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/phases/upgrade/BUILD
Expand Up @@ -72,6 +72,7 @@ go_test(
name = "go_default_test",
srcs = [
"compute_test.go",
"main_test.go",
"policy_test.go",
"postupgrade_test.go",
"staticpods_test.go",
Expand All @@ -90,6 +91,7 @@ go_test(
"//cmd/kubeadm/app/util/config:go_default_library",
"//cmd/kubeadm/app/util/etcd:go_default_library",
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
"//cmd/kubeadm/app/util/pkiutil/testing:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down