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
fea0c790
Commit
fea0c790
authored
Sep 14, 2016
by
d00369826
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix certificates controller hotloop on unexpected API server rejections
Change-Id: Ib7d2e18bcaa498bddfc785f3ff12958dfaaecbc3
parent
6b1565d2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
controller.go
pkg/controller/certificates/controller.go
+25
-16
No files found.
pkg/controller/certificates/controller.go
View file @
fea0c790
...
@@ -58,7 +58,7 @@ type CertificateController struct {
...
@@ -58,7 +58,7 @@ type CertificateController struct {
signer
*
local
.
Signer
signer
*
local
.
Signer
queue
*
workqueue
.
Typ
e
queue
workqueue
.
RateLimitingInterfac
e
}
}
func
NewCertificateController
(
kubeClient
clientset
.
Interface
,
syncPeriod
time
.
Duration
,
caCertFile
,
caKeyFile
string
,
approveAllKubeletCSRsForGroup
string
)
(
*
CertificateController
,
error
)
{
func
NewCertificateController
(
kubeClient
clientset
.
Interface
,
syncPeriod
time
.
Duration
,
caCertFile
,
caKeyFile
string
,
approveAllKubeletCSRsForGroup
string
)
(
*
CertificateController
,
error
)
{
...
@@ -79,7 +79,7 @@ func NewCertificateController(kubeClient clientset.Interface, syncPeriod time.Du
...
@@ -79,7 +79,7 @@ func NewCertificateController(kubeClient clientset.Interface, syncPeriod time.Du
cc
:=
&
CertificateController
{
cc
:=
&
CertificateController
{
kubeClient
:
kubeClient
,
kubeClient
:
kubeClient
,
queue
:
workqueue
.
NewNamed
(
"certificate"
),
queue
:
workqueue
.
NewNamed
RateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"certificate"
),
signer
:
ca
,
signer
:
ca
,
approveAllKubeletCSRsForGroup
:
approveAllKubeletCSRsForGroup
,
approveAllKubeletCSRsForGroup
:
approveAllKubeletCSRsForGroup
,
}
}
...
@@ -121,37 +121,47 @@ func NewCertificateController(kubeClient clientset.Interface, syncPeriod time.Du
...
@@ -121,37 +121,47 @@ func NewCertificateController(kubeClient clientset.Interface, syncPeriod time.Du
// Run the main goroutine responsible for watching and syncing jobs.
// Run the main goroutine responsible for watching and syncing jobs.
func
(
cc
*
CertificateController
)
Run
(
workers
int
,
stopCh
<-
chan
struct
{})
{
func
(
cc
*
CertificateController
)
Run
(
workers
int
,
stopCh
<-
chan
struct
{})
{
defer
utilruntime
.
HandleCrash
()
defer
utilruntime
.
HandleCrash
()
defer
cc
.
queue
.
ShutDown
()
go
cc
.
csrController
.
Run
(
stopCh
)
go
cc
.
csrController
.
Run
(
stopCh
)
glog
.
Infof
(
"Starting certificate controller manager"
)
glog
.
Infof
(
"Starting certificate controller manager"
)
for
i
:=
0
;
i
<
workers
;
i
++
{
for
i
:=
0
;
i
<
workers
;
i
++
{
go
wait
.
Until
(
cc
.
worker
,
time
.
Second
,
stopCh
)
go
wait
.
Until
(
cc
.
worker
,
time
.
Second
,
stopCh
)
}
}
<-
stopCh
<-
stopCh
glog
.
Infof
(
"Shutting down certificate controller"
)
glog
.
Infof
(
"Shutting down certificate controller"
)
cc
.
queue
.
ShutDown
()
}
}
// worker runs a thread that dequeues CSRs, handles them, and marks them done.
// worker runs a thread that dequeues CSRs, handles them, and marks them done.
func
(
cc
*
CertificateController
)
worker
()
{
func
(
cc
*
CertificateController
)
worker
()
{
for
{
for
cc
.
processNextWorkItem
()
{
func
()
{
key
,
quit
:=
cc
.
queue
.
Get
()
if
quit
{
return
}
}
defer
cc
.
queue
.
Done
(
key
)
}
err
:=
cc
.
syncHandler
(
key
.
(
string
))
if
err
!=
nil
{
// processNextWorkItem deals with one key off the queue. It returns false when it's time to quit.
glog
.
Errorf
(
"Error syncing CSR: %v"
,
err
)
func
(
cc
*
CertificateController
)
processNextWorkItem
()
bool
{
cKey
,
quit
:=
cc
.
queue
.
Get
()
if
quit
{
return
false
}
}
}()
defer
cc
.
queue
.
Done
(
cKey
)
err
:=
cc
.
syncHandler
(
cKey
.
(
string
))
if
err
==
nil
{
cc
.
queue
.
Forget
(
cKey
)
return
true
}
}
cc
.
queue
.
AddRateLimited
(
cKey
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Sync %v failed with : %v"
,
cKey
,
err
))
return
true
}
}
func
(
cc
*
CertificateController
)
enqueueCertificateRequest
(
obj
interface
{})
{
func
(
cc
*
CertificateController
)
enqueueCertificateRequest
(
obj
interface
{})
{
key
,
err
:=
controller
.
KeyFunc
(
obj
)
key
,
err
:=
controller
.
KeyFunc
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't get key for object %+v: %v"
,
obj
,
err
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Couldn't get key for object %+v: %v"
,
obj
,
err
)
)
return
return
}
}
cc
.
queue
.
Add
(
key
)
cc
.
queue
.
Add
(
key
)
...
@@ -180,7 +190,6 @@ func (cc *CertificateController) maybeSignCertificate(key string) error {
...
@@ -180,7 +190,6 @@ func (cc *CertificateController) maybeSignCertificate(key string) error {
}()
}()
obj
,
exists
,
err
:=
cc
.
csrStore
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
cc
.
csrStore
.
Store
.
GetByKey
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
cc
.
queue
.
Add
(
key
)
return
err
return
err
}
}
if
!
exists
{
if
!
exists
{
...
@@ -235,7 +244,7 @@ func (cc *CertificateController) maybeAutoApproveCSR(csr *certificates.Certifica
...
@@ -235,7 +244,7 @@ func (cc *CertificateController) maybeAutoApproveCSR(csr *certificates.Certifica
x509cr
,
err
:=
utilcertificates
.
ParseCertificateRequestObject
(
csr
)
x509cr
,
err
:=
utilcertificates
.
ParseCertificateRequestObject
(
csr
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"unable to parse csr %q: %v"
,
csr
.
ObjectMeta
.
Name
,
err
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unable to parse csr %q: %v"
,
csr
.
Name
,
err
)
)
return
csr
,
nil
return
csr
,
nil
}
}
if
!
reflect
.
DeepEqual
([]
string
{
"system:nodes"
},
x509cr
.
Subject
.
Organization
)
{
if
!
reflect
.
DeepEqual
([]
string
{
"system:nodes"
},
x509cr
.
Subject
.
Organization
)
{
...
...
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