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
4cfcf051
Commit
4cfcf051
authored
Feb 26, 2019
by
Peter McAlpine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lint warnings in pkg/controller/bootstrap
parent
aa5fda22
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
35 deletions
+33
-35
bootstrap.go
cmd/kube-controller-manager/app/bootstrap.go
+2
-2
.golint_failures
hack/.golint_failures
+0
-1
bootstrapsigner.go
pkg/controller/bootstrap/bootstrapsigner.go
+18
-19
bootstrapsigner_test.go
pkg/controller/bootstrap/bootstrapsigner_test.go
+13
-13
No files found.
cmd/kube-controller-manager/app/bootstrap.go
View file @
4cfcf051
...
@@ -25,11 +25,11 @@ import (
...
@@ -25,11 +25,11 @@ import (
)
)
func
startBootstrapSignerController
(
ctx
ControllerContext
)
(
http
.
Handler
,
bool
,
error
)
{
func
startBootstrapSignerController
(
ctx
ControllerContext
)
(
http
.
Handler
,
bool
,
error
)
{
bsc
,
err
:=
bootstrap
.
New
Bootstrap
Signer
(
bsc
,
err
:=
bootstrap
.
NewSigner
(
ctx
.
ClientBuilder
.
ClientOrDie
(
"bootstrap-signer"
),
ctx
.
ClientBuilder
.
ClientOrDie
(
"bootstrap-signer"
),
ctx
.
InformerFactory
.
Core
()
.
V1
()
.
Secrets
(),
ctx
.
InformerFactory
.
Core
()
.
V1
()
.
Secrets
(),
ctx
.
InformerFactory
.
Core
()
.
V1
()
.
ConfigMaps
(),
ctx
.
InformerFactory
.
Core
()
.
V1
()
.
ConfigMaps
(),
bootstrap
.
Default
Bootstrap
SignerOptions
(),
bootstrap
.
DefaultSignerOptions
(),
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
true
,
fmt
.
Errorf
(
"error creating BootstrapSigner controller: %v"
,
err
)
return
nil
,
true
,
fmt
.
Errorf
(
"error creating BootstrapSigner controller: %v"
,
err
)
...
...
hack/.golint_failures
View file @
4cfcf051
...
@@ -74,7 +74,6 @@ pkg/cloudprovider/providers/photon
...
@@ -74,7 +74,6 @@ pkg/cloudprovider/providers/photon
pkg/cloudprovider/providers/vsphere
pkg/cloudprovider/providers/vsphere
pkg/controller
pkg/controller
pkg/controller/apis/config/v1alpha1
pkg/controller/apis/config/v1alpha1
pkg/controller/bootstrap
pkg/controller/certificates
pkg/controller/certificates
pkg/controller/certificates/approver
pkg/controller/certificates/approver
pkg/controller/certificates/signer
pkg/controller/certificates/signer
...
...
pkg/controller/bootstrap/bootstrapsigner.go
View file @
4cfcf051
...
@@ -39,8 +39,8 @@ import (
...
@@ -39,8 +39,8 @@ import (
"k8s.io/kubernetes/pkg/util/metrics"
"k8s.io/kubernetes/pkg/util/metrics"
)
)
//
BootstrapSignerOptions contains options for the Bootstrap
Signer
//
SignerOptions contains options for the
Signer
type
Bootstrap
SignerOptions
struct
{
type
SignerOptions
struct
{
// ConfigMapNamespace is the namespace of the ConfigMap
// ConfigMapNamespace is the namespace of the ConfigMap
ConfigMapNamespace
string
ConfigMapNamespace
string
...
@@ -59,18 +59,17 @@ type BootstrapSignerOptions struct {
...
@@ -59,18 +59,17 @@ type BootstrapSignerOptions struct {
SecretResync
time
.
Duration
SecretResync
time
.
Duration
}
}
// DefaultBootstrapSignerOptions returns a set of default options for creating a
// DefaultSignerOptions returns a set of default options for creating a Signer.
// BootstrapSigner
func
DefaultSignerOptions
()
SignerOptions
{
func
DefaultBootstrapSignerOptions
()
BootstrapSignerOptions
{
return
SignerOptions
{
return
BootstrapSignerOptions
{
ConfigMapNamespace
:
api
.
NamespacePublic
,
ConfigMapNamespace
:
api
.
NamespacePublic
,
ConfigMapName
:
bootstrapapi
.
ConfigMapClusterInfo
,
ConfigMapName
:
bootstrapapi
.
ConfigMapClusterInfo
,
TokenSecretNamespace
:
api
.
NamespaceSystem
,
TokenSecretNamespace
:
api
.
NamespaceSystem
,
}
}
}
}
//
Bootstrap
Signer is a controller that signs a ConfigMap with a set of tokens.
// Signer is a controller that signs a ConfigMap with a set of tokens.
type
Bootstrap
Signer
struct
{
type
Signer
struct
{
client
clientset
.
Interface
client
clientset
.
Interface
configMapKey
string
configMapKey
string
configMapName
string
configMapName
string
...
@@ -90,9 +89,9 @@ type BootstrapSigner struct {
...
@@ -90,9 +89,9 @@ type BootstrapSigner struct {
configMapSynced
cache
.
InformerSynced
configMapSynced
cache
.
InformerSynced
}
}
// New
BootstrapSigner returns a new *Bootstrap
Signer.
// New
Signer returns a new *
Signer.
func
New
BootstrapSigner
(
cl
clientset
.
Interface
,
secrets
informers
.
SecretInformer
,
configMaps
informers
.
ConfigMapInformer
,
options
BootstrapSignerOptions
)
(
*
Bootstrap
Signer
,
error
)
{
func
New
Signer
(
cl
clientset
.
Interface
,
secrets
informers
.
SecretInformer
,
configMaps
informers
.
ConfigMapInformer
,
options
SignerOptions
)
(
*
Signer
,
error
)
{
e
:=
&
Bootstrap
Signer
{
e
:=
&
Signer
{
client
:
cl
,
client
:
cl
,
configMapKey
:
options
.
ConfigMapNamespace
+
"/"
+
options
.
ConfigMapName
,
configMapKey
:
options
.
ConfigMapNamespace
+
"/"
+
options
.
ConfigMapName
,
configMapName
:
options
.
ConfigMapName
,
configMapName
:
options
.
ConfigMapName
,
...
@@ -153,7 +152,7 @@ func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer
...
@@ -153,7 +152,7 @@ func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer
}
}
// Run runs controller loops and returns when they are done
// Run runs controller loops and returns when they are done
func
(
e
*
Bootstrap
Signer
)
Run
(
stopCh
<-
chan
struct
{})
{
func
(
e
*
Signer
)
Run
(
stopCh
<-
chan
struct
{})
{
// Shut down queues
// Shut down queues
defer
utilruntime
.
HandleCrash
()
defer
utilruntime
.
HandleCrash
()
defer
e
.
syncQueue
.
ShutDown
()
defer
e
.
syncQueue
.
ShutDown
()
...
@@ -168,11 +167,11 @@ func (e *BootstrapSigner) Run(stopCh <-chan struct{}) {
...
@@ -168,11 +167,11 @@ func (e *BootstrapSigner) Run(stopCh <-chan struct{}) {
klog
.
V
(
1
)
.
Infof
(
"Shutting down"
)
klog
.
V
(
1
)
.
Infof
(
"Shutting down"
)
}
}
func
(
e
*
Bootstrap
Signer
)
pokeConfigMapSync
()
{
func
(
e
*
Signer
)
pokeConfigMapSync
()
{
e
.
syncQueue
.
Add
(
e
.
configMapKey
)
e
.
syncQueue
.
Add
(
e
.
configMapKey
)
}
}
func
(
e
*
Bootstrap
Signer
)
serviceConfigMapQueue
()
{
func
(
e
*
Signer
)
serviceConfigMapQueue
()
{
key
,
quit
:=
e
.
syncQueue
.
Get
()
key
,
quit
:=
e
.
syncQueue
.
Get
()
if
quit
{
if
quit
{
return
return
...
@@ -184,7 +183,7 @@ func (e *BootstrapSigner) serviceConfigMapQueue() {
...
@@ -184,7 +183,7 @@ func (e *BootstrapSigner) serviceConfigMapQueue() {
// signConfigMap computes the signatures on our latest cached objects and writes
// signConfigMap computes the signatures on our latest cached objects and writes
// back if necessary.
// back if necessary.
func
(
e
*
Bootstrap
Signer
)
signConfigMap
()
{
func
(
e
*
Signer
)
signConfigMap
()
{
origCM
:=
e
.
getConfigMap
()
origCM
:=
e
.
getConfigMap
()
if
origCM
==
nil
{
if
origCM
==
nil
{
...
@@ -241,7 +240,7 @@ func (e *BootstrapSigner) signConfigMap() {
...
@@ -241,7 +240,7 @@ func (e *BootstrapSigner) signConfigMap() {
}
}
}
}
func
(
e
*
Bootstrap
Signer
)
updateConfigMap
(
cm
*
v1
.
ConfigMap
)
{
func
(
e
*
Signer
)
updateConfigMap
(
cm
*
v1
.
ConfigMap
)
{
_
,
err
:=
e
.
client
.
CoreV1
()
.
ConfigMaps
(
cm
.
Namespace
)
.
Update
(
cm
)
_
,
err
:=
e
.
client
.
CoreV1
()
.
ConfigMaps
(
cm
.
Namespace
)
.
Update
(
cm
)
if
err
!=
nil
&&
!
apierrors
.
IsConflict
(
err
)
&&
!
apierrors
.
IsNotFound
(
err
)
{
if
err
!=
nil
&&
!
apierrors
.
IsConflict
(
err
)
&&
!
apierrors
.
IsNotFound
(
err
)
{
klog
.
V
(
3
)
.
Infof
(
"Error updating ConfigMap: %v"
,
err
)
klog
.
V
(
3
)
.
Infof
(
"Error updating ConfigMap: %v"
,
err
)
...
@@ -249,7 +248,7 @@ func (e *BootstrapSigner) updateConfigMap(cm *v1.ConfigMap) {
...
@@ -249,7 +248,7 @@ func (e *BootstrapSigner) updateConfigMap(cm *v1.ConfigMap) {
}
}
// getConfigMap gets the ConfigMap we are interested in
// getConfigMap gets the ConfigMap we are interested in
func
(
e
*
Bootstrap
Signer
)
getConfigMap
()
*
v1
.
ConfigMap
{
func
(
e
*
Signer
)
getConfigMap
()
*
v1
.
ConfigMap
{
configMap
,
err
:=
e
.
configMapLister
.
ConfigMaps
(
e
.
configMapNamespace
)
.
Get
(
e
.
configMapName
)
configMap
,
err
:=
e
.
configMapLister
.
ConfigMaps
(
e
.
configMapNamespace
)
.
Get
(
e
.
configMapName
)
// If we can't get the configmap just return nil. The resync will eventually
// If we can't get the configmap just return nil. The resync will eventually
...
@@ -264,7 +263,7 @@ func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap {
...
@@ -264,7 +263,7 @@ func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap {
return
configMap
return
configMap
}
}
func
(
e
*
Bootstrap
Signer
)
listSecrets
()
[]
*
v1
.
Secret
{
func
(
e
*
Signer
)
listSecrets
()
[]
*
v1
.
Secret
{
secrets
,
err
:=
e
.
secretLister
.
Secrets
(
e
.
secretNamespace
)
.
List
(
labels
.
Everything
())
secrets
,
err
:=
e
.
secretLister
.
Secrets
(
e
.
secretNamespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
utilruntime
.
HandleError
(
err
)
utilruntime
.
HandleError
(
err
)
...
@@ -282,7 +281,7 @@ func (e *BootstrapSigner) listSecrets() []*v1.Secret {
...
@@ -282,7 +281,7 @@ func (e *BootstrapSigner) listSecrets() []*v1.Secret {
// getTokens returns a map of tokenID->tokenSecret. It ensures the token is
// getTokens returns a map of tokenID->tokenSecret. It ensures the token is
// valid for signing.
// valid for signing.
func
(
e
*
Bootstrap
Signer
)
getTokens
()
map
[
string
]
string
{
func
(
e
*
Signer
)
getTokens
()
map
[
string
]
string
{
ret
:=
map
[
string
]
string
{}
ret
:=
map
[
string
]
string
{}
secretObjs
:=
e
.
listSecrets
()
secretObjs
:=
e
.
listSecrets
()
for
_
,
secret
:=
range
secretObjs
{
for
_
,
secret
:=
range
secretObjs
{
...
...
pkg/controller/bootstrap/bootstrapsigner_test.go
View file @
4cfcf051
...
@@ -39,13 +39,13 @@ func init() {
...
@@ -39,13 +39,13 @@ func init() {
const
testTokenID
=
"abc123"
const
testTokenID
=
"abc123"
func
new
BootstrapSigner
()
(
*
Bootstrap
Signer
,
*
fake
.
Clientset
,
coreinformers
.
SecretInformer
,
coreinformers
.
ConfigMapInformer
,
error
)
{
func
new
Signer
()
(
*
Signer
,
*
fake
.
Clientset
,
coreinformers
.
SecretInformer
,
coreinformers
.
ConfigMapInformer
,
error
)
{
options
:=
Default
Bootstrap
SignerOptions
()
options
:=
DefaultSignerOptions
()
cl
:=
fake
.
NewSimpleClientset
()
cl
:=
fake
.
NewSimpleClientset
()
informers
:=
informers
.
NewSharedInformerFactory
(
fake
.
NewSimpleClientset
(),
controller
.
NoResyncPeriodFunc
())
informers
:=
informers
.
NewSharedInformerFactory
(
fake
.
NewSimpleClientset
(),
controller
.
NoResyncPeriodFunc
())
secrets
:=
informers
.
Core
()
.
V1
()
.
Secrets
()
secrets
:=
informers
.
Core
()
.
V1
()
.
Secrets
()
configMaps
:=
informers
.
Core
()
.
V1
()
.
ConfigMaps
()
configMaps
:=
informers
.
Core
()
.
V1
()
.
ConfigMaps
()
bsc
,
err
:=
New
Bootstrap
Signer
(
cl
,
secrets
,
configMaps
,
options
)
bsc
,
err
:=
NewSigner
(
cl
,
secrets
,
configMaps
,
options
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
nil
,
err
return
nil
,
nil
,
nil
,
nil
,
err
}
}
...
@@ -70,18 +70,18 @@ func newConfigMap(tokenID, signature string) *v1.ConfigMap {
...
@@ -70,18 +70,18 @@ func newConfigMap(tokenID, signature string) *v1.ConfigMap {
}
}
func
TestNoConfigMap
(
t
*
testing
.
T
)
{
func
TestNoConfigMap
(
t
*
testing
.
T
)
{
signer
,
cl
,
_
,
_
,
err
:=
new
Bootstrap
Signer
()
signer
,
cl
,
_
,
_
,
err
:=
newSigner
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error creating
Bootstrap
Signer: %v"
,
err
)
t
.
Fatalf
(
"error creating Signer: %v"
,
err
)
}
}
signer
.
signConfigMap
()
signer
.
signConfigMap
()
verifyActions
(
t
,
[]
core
.
Action
{},
cl
.
Actions
())
verifyActions
(
t
,
[]
core
.
Action
{},
cl
.
Actions
())
}
}
func
TestSimpleSign
(
t
*
testing
.
T
)
{
func
TestSimpleSign
(
t
*
testing
.
T
)
{
signer
,
cl
,
secrets
,
configMaps
,
err
:=
new
Bootstrap
Signer
()
signer
,
cl
,
secrets
,
configMaps
,
err
:=
newSigner
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error creating
Bootstrap
Signer: %v"
,
err
)
t
.
Fatalf
(
"error creating Signer: %v"
,
err
)
}
}
cm
:=
newConfigMap
(
""
,
""
)
cm
:=
newConfigMap
(
""
,
""
)
...
@@ -103,9 +103,9 @@ func TestSimpleSign(t *testing.T) {
...
@@ -103,9 +103,9 @@ func TestSimpleSign(t *testing.T) {
}
}
func
TestNoSignNeeded
(
t
*
testing
.
T
)
{
func
TestNoSignNeeded
(
t
*
testing
.
T
)
{
signer
,
cl
,
secrets
,
configMaps
,
err
:=
new
Bootstrap
Signer
()
signer
,
cl
,
secrets
,
configMaps
,
err
:=
newSigner
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error creating
Bootstrap
Signer: %v"
,
err
)
t
.
Fatalf
(
"error creating Signer: %v"
,
err
)
}
}
cm
:=
newConfigMap
(
testTokenID
,
"eyJhbGciOiJIUzI1NiIsImtpZCI6ImFiYzEyMyJ9..QSxpUG7Q542CirTI2ECPSZjvBOJURUW5a7XqFpNI958"
)
cm
:=
newConfigMap
(
testTokenID
,
"eyJhbGciOiJIUzI1NiIsImtpZCI6ImFiYzEyMyJ9..QSxpUG7Q542CirTI2ECPSZjvBOJURUW5a7XqFpNI958"
)
...
@@ -121,9 +121,9 @@ func TestNoSignNeeded(t *testing.T) {
...
@@ -121,9 +121,9 @@ func TestNoSignNeeded(t *testing.T) {
}
}
func
TestUpdateSignature
(
t
*
testing
.
T
)
{
func
TestUpdateSignature
(
t
*
testing
.
T
)
{
signer
,
cl
,
secrets
,
configMaps
,
err
:=
new
Bootstrap
Signer
()
signer
,
cl
,
secrets
,
configMaps
,
err
:=
newSigner
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error creating
Bootstrap
Signer: %v"
,
err
)
t
.
Fatalf
(
"error creating Signer: %v"
,
err
)
}
}
cm
:=
newConfigMap
(
testTokenID
,
"old signature"
)
cm
:=
newConfigMap
(
testTokenID
,
"old signature"
)
...
@@ -145,9 +145,9 @@ func TestUpdateSignature(t *testing.T) {
...
@@ -145,9 +145,9 @@ func TestUpdateSignature(t *testing.T) {
}
}
func
TestRemoveSignature
(
t
*
testing
.
T
)
{
func
TestRemoveSignature
(
t
*
testing
.
T
)
{
signer
,
cl
,
_
,
configMaps
,
err
:=
new
Bootstrap
Signer
()
signer
,
cl
,
_
,
configMaps
,
err
:=
newSigner
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error creating
Bootstrap
Signer: %v"
,
err
)
t
.
Fatalf
(
"error creating Signer: %v"
,
err
)
}
}
cm
:=
newConfigMap
(
testTokenID
,
"old signature"
)
cm
:=
newConfigMap
(
testTokenID
,
"old signature"
)
...
...
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