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
e75aafd0
Commit
e75aafd0
authored
Feb 01, 2017
by
Kubernetes Submit Queue
Committed by
GitHub
Feb 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #40612 from jcbsmpsn/share-certificate-loading-function
Automatic merge from submit-queue Move certificate loading function where it can be shared.
parents
0bb31560
f15e6aac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
21 deletions
+22
-21
bootstrap.go
cmd/kubelet/app/bootstrap.go
+1
-21
io.go
staging/src/k8s.io/client-go/util/cert/io.go
+21
-0
No files found.
cmd/kubelet/app/bootstrap.go
View file @
e75aafd0
...
...
@@ -18,7 +18,6 @@ package app
import
(
"fmt"
"io/ioutil"
_
"net/http/pprof"
"os"
"path/filepath"
...
...
@@ -74,7 +73,7 @@ func bootstrapClientCert(kubeconfigPath string, bootstrapPath string, certDir st
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to build bootstrap key path: %v"
,
err
)
}
keyData
,
generatedKeyFile
,
err
:=
l
oadOrGenerateKeyFile
(
keyPath
)
keyData
,
generatedKeyFile
,
err
:=
certutil
.
L
oadOrGenerateKeyFile
(
keyPath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -161,22 +160,3 @@ func loadRESTClientConfig(kubeconfig string) (*restclient.Config, error) {
loader
,
)
.
ClientConfig
()
}
func
loadOrGenerateKeyFile
(
keyPath
string
)
(
data
[]
byte
,
wasGenerated
bool
,
err
error
)
{
loadedData
,
err
:=
ioutil
.
ReadFile
(
keyPath
)
if
err
==
nil
{
return
loadedData
,
false
,
err
}
if
!
os
.
IsNotExist
(
err
)
{
return
nil
,
false
,
fmt
.
Errorf
(
"error loading key from %s: %v"
,
keyPath
,
err
)
}
generatedData
,
err
:=
certutil
.
MakeEllipticPrivateKeyPEM
()
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"error generating key: %v"
,
err
)
}
if
err
:=
certutil
.
WriteKey
(
keyPath
,
generatedData
);
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"error writing key to %s: %v"
,
keyPath
,
err
)
}
return
generatedData
,
true
,
nil
}
staging/src/k8s.io/client-go/util/cert/io.go
View file @
e75aafd0
...
...
@@ -86,6 +86,27 @@ func WriteKey(keyPath string, data []byte) error {
return
nil
}
// LoadOrGenerateKeyFile looks for a key in the file at the given path. If it
// can't find one, it will generate a new key and store it there.
func
LoadOrGenerateKeyFile
(
keyPath
string
)
(
data
[]
byte
,
wasGenerated
bool
,
err
error
)
{
loadedData
,
err
:=
ioutil
.
ReadFile
(
keyPath
)
if
err
==
nil
{
return
loadedData
,
false
,
err
}
if
!
os
.
IsNotExist
(
err
)
{
return
nil
,
false
,
fmt
.
Errorf
(
"error loading key from %s: %v"
,
keyPath
,
err
)
}
generatedData
,
err
:=
MakeEllipticPrivateKeyPEM
()
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"error generating key: %v"
,
err
)
}
if
err
:=
WriteKey
(
keyPath
,
generatedData
);
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"error writing key to %s: %v"
,
keyPath
,
err
)
}
return
generatedData
,
true
,
nil
}
// NewPool returns an x509.CertPool containing the certificates in the given PEM-encoded file.
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
func
NewPool
(
filename
string
)
(
*
x509
.
CertPool
,
error
)
{
...
...
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