Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f9a3a22e
Unverified
Commit
f9a3a22e
authored
Apr 22, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76769 from rojkov/kubeadm-drop-NewCACertAndKey
kubeadm: drop duplicate function NewCACertAndKey
parents
75d45bdf
580513ed
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
16 additions
and
49 deletions
+16
-49
certlist.go
cmd/kubeadm/app/phases/certs/certlist.go
+2
-2
certs.go
cmd/kubeadm/app/phases/certs/certs.go
+1
-12
certs_test.go
cmd/kubeadm/app/phases/certs/certs_test.go
+0
-10
BUILD
cmd/kubeadm/app/phases/certs/renewal/BUILD
+0
-1
filerenewal_test.go
cmd/kubeadm/app/phases/certs/renewal/filerenewal_test.go
+2
-2
renewal_test.go
cmd/kubeadm/app/phases/certs/renewal/renewal_test.go
+2
-3
util.go
cmd/kubeadm/app/util/certs/util.go
+0
-7
pki_helpers.go
cmd/kubeadm/app/util/pkiutil/pki_helpers.go
+2
-2
pki_helpers_test.go
cmd/kubeadm/app/util/pkiutil/pki_helpers_test.go
+7
-10
No files found.
cmd/kubeadm/app/phases/certs/certlist.go
View file @
f9a3a22e
...
@@ -85,7 +85,7 @@ func (k *KubeadmCert) CreateAsCA(ic *kubeadmapi.InitConfiguration) (*x509.Certif
...
@@ -85,7 +85,7 @@ func (k *KubeadmCert) CreateAsCA(ic *kubeadmapi.InitConfiguration) (*x509.Certif
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"couldn't get configuration for %q CA certificate"
,
k
.
Name
)
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"couldn't get configuration for %q CA certificate"
,
k
.
Name
)
}
}
caCert
,
caKey
,
err
:=
NewCACertAndKe
y
(
cfg
)
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthorit
y
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"couldn't generate %q CA certificate"
,
k
.
Name
)
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"couldn't generate %q CA certificate"
,
k
.
Name
)
}
}
...
@@ -141,7 +141,7 @@ func (t CertificateTree) CreateTree(ic *kubeadmapi.InitConfiguration) error {
...
@@ -141,7 +141,7 @@ func (t CertificateTree) CreateTree(ic *kubeadmapi.InitConfiguration) error {
// CA key exists; just use that to create new certificates.
// CA key exists; just use that to create new certificates.
}
else
{
}
else
{
// CACert doesn't already exist, create a new cert and key.
// CACert doesn't already exist, create a new cert and key.
caCert
,
caKey
,
err
=
NewCACertAndKe
y
(
cfg
)
caCert
,
caKey
,
err
=
pkiutil
.
NewCertificateAuthorit
y
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
cmd/kubeadm/app/phases/certs/certs.go
View file @
f9a3a22e
...
@@ -90,17 +90,6 @@ func NewServiceAccountSigningKey() (*rsa.PrivateKey, error) {
...
@@ -90,17 +90,6 @@ func NewServiceAccountSigningKey() (*rsa.PrivateKey, error) {
return
saSigningKey
,
nil
return
saSigningKey
,
nil
}
}
// NewCACertAndKey will generate a self signed CA.
func
NewCACertAndKey
(
certSpec
*
certutil
.
Config
)
(
*
x509
.
Certificate
,
*
rsa
.
PrivateKey
,
error
)
{
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthority
(
certSpec
)
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"failure while generating CA certificate and key"
)
}
return
caCert
,
caKey
,
nil
}
// CreateCACertAndKeyFiles generates and writes out a given certificate authority.
// CreateCACertAndKeyFiles generates and writes out a given certificate authority.
// The certSpec should be one of the variables from this package.
// The certSpec should be one of the variables from this package.
func
CreateCACertAndKeyFiles
(
certSpec
*
KubeadmCert
,
cfg
*
kubeadmapi
.
InitConfiguration
)
error
{
func
CreateCACertAndKeyFiles
(
certSpec
*
KubeadmCert
,
cfg
*
kubeadmapi
.
InitConfiguration
)
error
{
...
@@ -114,7 +103,7 @@ func CreateCACertAndKeyFiles(certSpec *KubeadmCert, cfg *kubeadmapi.InitConfigur
...
@@ -114,7 +103,7 @@ func CreateCACertAndKeyFiles(certSpec *KubeadmCert, cfg *kubeadmapi.InitConfigur
return
err
return
err
}
}
caCert
,
caKey
,
err
:=
NewCACertAndKe
y
(
certConfig
)
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthorit
y
(
certConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
cmd/kubeadm/app/phases/certs/certs_test.go
View file @
f9a3a22e
...
@@ -370,16 +370,6 @@ func TestWriteKeyFilesIfNotExist(t *testing.T) {
...
@@ -370,16 +370,6 @@ func TestWriteKeyFilesIfNotExist(t *testing.T) {
}
}
}
}
func
TestNewCACertAndKey
(
t
*
testing
.
T
)
{
certCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCert
,
_
,
err
:=
NewCACertAndKey
(
certCfg
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed call NewCACertAndKey: %v"
,
err
)
}
certstestutil
.
AssertCertificateIsCa
(
t
,
caCert
)
}
func
TestSharedCertificateExists
(
t
*
testing
.
T
)
{
func
TestSharedCertificateExists
(
t
*
testing
.
T
)
{
caCert
,
caKey
:=
certstestutil
.
CreateCACert
(
t
)
caCert
,
caKey
:=
certstestutil
.
CreateCACert
(
t
)
_
,
key
,
_
:=
certstestutil
.
CreateTestCert
(
t
,
caCert
,
caKey
,
certutil
.
AltNames
{})
_
,
key
,
_
:=
certstestutil
.
CreateTestCert
(
t
,
caCert
,
caKey
,
certutil
.
AltNames
{})
...
...
cmd/kubeadm/app/phases/certs/renewal/BUILD
View file @
f9a3a22e
...
@@ -30,7 +30,6 @@ go_test(
...
@@ -30,7 +30,6 @@ go_test(
],
],
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/util/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:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//cmd/kubeadm/test:go_default_library",
...
...
cmd/kubeadm/app/phases/certs/renewal/filerenewal_test.go
View file @
f9a3a22e
...
@@ -21,12 +21,12 @@ import (
...
@@ -21,12 +21,12 @@ import (
"testing"
"testing"
certutil
"k8s.io/client-go/util/cert"
certutil
"k8s.io/client-go/util/cert"
"k8s.io/kubernetes/cmd/kubeadm/app/
phases/certs
"
"k8s.io/kubernetes/cmd/kubeadm/app/
util/pkiutil
"
)
)
func
TestFileRenew
(
t
*
testing
.
T
)
{
func
TestFileRenew
(
t
*
testing
.
T
)
{
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCert
,
caKey
,
err
:=
certs
.
NewCACertAndKe
y
(
caCertCfg
)
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthorit
y
(
caCertCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
}
}
...
...
cmd/kubeadm/app/phases/certs/renewal/renewal_test.go
View file @
f9a3a22e
...
@@ -32,7 +32,6 @@ import (
...
@@ -32,7 +32,6 @@ import (
fakecerts
"k8s.io/client-go/kubernetes/typed/certificates/v1beta1/fake"
fakecerts
"k8s.io/client-go/kubernetes/typed/certificates/v1beta1/fake"
k8stesting
"k8s.io/client-go/testing"
k8stesting
"k8s.io/client-go/testing"
certutil
"k8s.io/client-go/util/cert"
certutil
"k8s.io/client-go/util/cert"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
certtestutil
"k8s.io/kubernetes/cmd/kubeadm/app/util/certs"
certtestutil
"k8s.io/kubernetes/cmd/kubeadm/app/util/certs"
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
testutil
"k8s.io/kubernetes/cmd/kubeadm/test"
testutil
"k8s.io/kubernetes/cmd/kubeadm/test"
...
@@ -40,7 +39,7 @@ import (
...
@@ -40,7 +39,7 @@ import (
func
TestRenewImplementations
(
t
*
testing
.
T
)
{
func
TestRenewImplementations
(
t
*
testing
.
T
)
{
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCert
,
caKey
,
err
:=
certs
.
NewCACertAndKe
y
(
caCertCfg
)
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthorit
y
(
caCertCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
}
}
...
@@ -198,7 +197,7 @@ func TestRenewExistingCert(t *testing.T) {
...
@@ -198,7 +197,7 @@ func TestRenewExistingCert(t *testing.T) {
}
}
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCertCfg
:=
&
certutil
.
Config
{
CommonName
:
"kubernetes"
}
caCert
,
caKey
,
err
:=
certs
.
NewCACertAndKe
y
(
caCertCfg
)
caCert
,
caKey
,
err
:=
pkiutil
.
NewCertificateAuthorit
y
(
caCertCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
t
.
Fatalf
(
"couldn't create CA: %v"
,
err
)
}
}
...
...
cmd/kubeadm/app/util/certs/util.go
View file @
f9a3a22e
...
@@ -39,13 +39,6 @@ func SetupCertificateAuthorithy(t *testing.T) (*x509.Certificate, *rsa.PrivateKe
...
@@ -39,13 +39,6 @@ func SetupCertificateAuthorithy(t *testing.T) (*x509.Certificate, *rsa.PrivateKe
return
caCert
,
caKey
return
caCert
,
caKey
}
}
// AssertCertificateIsCa is a utility function for kubeadm testing that asserts if a given certificate is a CA
func
AssertCertificateIsCa
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
)
{
if
!
cert
.
IsCA
{
t
.
Error
(
"cert is not a valida CA"
)
}
}
// AssertCertificateIsSignedByCa is a utility function for kubeadm testing that asserts if a given certificate is signed
// AssertCertificateIsSignedByCa is a utility function for kubeadm testing that asserts if a given certificate is signed
// by the expected CA
// by the expected CA
func
AssertCertificateIsSignedByCa
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
,
signingCa
*
x509
.
Certificate
)
{
func
AssertCertificateIsSignedByCa
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
,
signingCa
*
x509
.
Certificate
)
{
...
...
cmd/kubeadm/app/util/pkiutil/pki_helpers.go
View file @
f9a3a22e
...
@@ -61,12 +61,12 @@ const (
...
@@ -61,12 +61,12 @@ const (
func
NewCertificateAuthority
(
config
*
certutil
.
Config
)
(
*
x509
.
Certificate
,
*
rsa
.
PrivateKey
,
error
)
{
func
NewCertificateAuthority
(
config
*
certutil
.
Config
)
(
*
x509
.
Certificate
,
*
rsa
.
PrivateKey
,
error
)
{
key
,
err
:=
NewPrivateKey
()
key
,
err
:=
NewPrivateKey
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"unable to create private key"
)
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"unable to create private key
while generating CA certificate
"
)
}
}
cert
,
err
:=
certutil
.
NewSelfSignedCACert
(
*
config
,
key
)
cert
,
err
:=
certutil
.
NewSelfSignedCACert
(
*
config
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"unable to create self-signed certificate"
)
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"unable to create self-signed
CA
certificate"
)
}
}
return
cert
,
key
,
nil
return
cert
,
key
,
nil
...
...
cmd/kubeadm/app/util/pkiutil/pki_helpers_test.go
View file @
f9a3a22e
...
@@ -33,20 +33,17 @@ func TestNewCertificateAuthority(t *testing.T) {
...
@@ -33,20 +33,17 @@ func TestNewCertificateAuthority(t *testing.T) {
cert
,
key
,
err
:=
NewCertificateAuthority
(
&
certutil
.
Config
{
CommonName
:
"kubernetes"
})
cert
,
key
,
err
:=
NewCertificateAuthority
(
&
certutil
.
Config
{
CommonName
:
"kubernetes"
})
if
cert
==
nil
{
if
cert
==
nil
{
t
.
Error
f
(
t
.
Error
(
"failed NewCertificateAuthority, cert == nil"
)
"failed NewCertificateAuthority, cert == nil"
,
}
else
if
!
cert
.
IsCA
{
)
t
.
Error
(
"cert is not a valida CA"
)
}
}
if
key
==
nil
{
if
key
==
nil
{
t
.
Errorf
(
t
.
Error
(
"failed NewCertificateAuthority, key == nil"
)
"failed NewCertificateAuthority, key == nil"
,
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
t
.
Errorf
(
"failed NewCertificateAuthority with an error: %+v"
,
err
)
"failed NewCertificateAuthority with an error: %v"
,
err
,
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment