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
217dbeaf
Commit
217dbeaf
authored
Nov 13, 2018
by
stewart-yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove duplicated import
parent
89bdc42f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
controller.go
staging/src/k8s.io/sample-controller/controller.go
+9
-10
No files found.
staging/src/k8s.io/sample-controller/controller.go
View file @
217dbeaf
...
@@ -25,7 +25,6 @@ import (
...
@@ -25,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
appsinformers
"k8s.io/client-go/informers/apps/v1"
appsinformers
"k8s.io/client-go/informers/apps/v1"
...
@@ -150,7 +149,7 @@ func NewController(
...
@@ -150,7 +149,7 @@ func NewController(
// is closed, at which point it will shutdown the workqueue and wait for
// is closed, at which point it will shutdown the workqueue and wait for
// workers to finish processing their current work items.
// workers to finish processing their current work items.
func
(
c
*
Controller
)
Run
(
threadiness
int
,
stopCh
<-
chan
struct
{})
error
{
func
(
c
*
Controller
)
Run
(
threadiness
int
,
stopCh
<-
chan
struct
{})
error
{
defer
runtime
.
HandleCrash
()
defer
util
runtime
.
HandleCrash
()
defer
c
.
workqueue
.
ShutDown
()
defer
c
.
workqueue
.
ShutDown
()
// Start the informer factories to begin populating the informer caches
// Start the informer factories to begin populating the informer caches
...
@@ -213,7 +212,7 @@ func (c *Controller) processNextWorkItem() bool {
...
@@ -213,7 +212,7 @@ func (c *Controller) processNextWorkItem() bool {
// Forget here else we'd go into a loop of attempting to
// Forget here else we'd go into a loop of attempting to
// process a work item that is invalid.
// process a work item that is invalid.
c
.
workqueue
.
Forget
(
obj
)
c
.
workqueue
.
Forget
(
obj
)
runtime
.
HandleError
(
fmt
.
Errorf
(
"expected string in workqueue but got %#v"
,
obj
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"expected string in workqueue but got %#v"
,
obj
))
return
nil
return
nil
}
}
// Run the syncHandler, passing it the namespace/name string of the
// Run the syncHandler, passing it the namespace/name string of the
...
@@ -231,7 +230,7 @@ func (c *Controller) processNextWorkItem() bool {
...
@@ -231,7 +230,7 @@ func (c *Controller) processNextWorkItem() bool {
}(
obj
)
}(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
runtime
.
HandleError
(
err
)
util
runtime
.
HandleError
(
err
)
return
true
return
true
}
}
...
@@ -245,7 +244,7 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -245,7 +244,7 @@ func (c *Controller) syncHandler(key string) error {
// Convert the namespace/name string into a distinct namespace and name
// Convert the namespace/name string into a distinct namespace and name
namespace
,
name
,
err
:=
cache
.
SplitMetaNamespaceKey
(
key
)
namespace
,
name
,
err
:=
cache
.
SplitMetaNamespaceKey
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
runtime
.
HandleError
(
fmt
.
Errorf
(
"invalid resource key: %s"
,
key
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"invalid resource key: %s"
,
key
))
return
nil
return
nil
}
}
...
@@ -255,7 +254,7 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -255,7 +254,7 @@ func (c *Controller) syncHandler(key string) error {
// The Foo resource may no longer exist, in which case we stop
// The Foo resource may no longer exist, in which case we stop
// processing.
// processing.
if
errors
.
IsNotFound
(
err
)
{
if
errors
.
IsNotFound
(
err
)
{
runtime
.
HandleError
(
fmt
.
Errorf
(
"foo '%s' in work queue no longer exists"
,
key
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"foo '%s' in work queue no longer exists"
,
key
))
return
nil
return
nil
}
}
...
@@ -267,7 +266,7 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -267,7 +266,7 @@ func (c *Controller) syncHandler(key string) error {
// We choose to absorb the error here as the worker would requeue the
// We choose to absorb the error here as the worker would requeue the
// resource otherwise. Instead, the next time the resource is updated
// resource otherwise. Instead, the next time the resource is updated
// the resource will be queued again.
// the resource will be queued again.
runtime
.
HandleError
(
fmt
.
Errorf
(
"%s: deployment name must be specified"
,
key
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"%s: deployment name must be specified"
,
key
))
return
nil
return
nil
}
}
...
@@ -340,7 +339,7 @@ func (c *Controller) enqueueFoo(obj interface{}) {
...
@@ -340,7 +339,7 @@ func (c *Controller) enqueueFoo(obj interface{}) {
var
key
string
var
key
string
var
err
error
var
err
error
if
key
,
err
=
cache
.
MetaNamespaceKeyFunc
(
obj
);
err
!=
nil
{
if
key
,
err
=
cache
.
MetaNamespaceKeyFunc
(
obj
);
err
!=
nil
{
runtime
.
HandleError
(
err
)
util
runtime
.
HandleError
(
err
)
return
return
}
}
c
.
workqueue
.
AddRateLimited
(
key
)
c
.
workqueue
.
AddRateLimited
(
key
)
...
@@ -357,12 +356,12 @@ func (c *Controller) handleObject(obj interface{}) {
...
@@ -357,12 +356,12 @@ func (c *Controller) handleObject(obj interface{}) {
if
object
,
ok
=
obj
.
(
metav1
.
Object
);
!
ok
{
if
object
,
ok
=
obj
.
(
metav1
.
Object
);
!
ok
{
tombstone
,
ok
:=
obj
.
(
cache
.
DeletedFinalStateUnknown
)
tombstone
,
ok
:=
obj
.
(
cache
.
DeletedFinalStateUnknown
)
if
!
ok
{
if
!
ok
{
runtime
.
HandleError
(
fmt
.
Errorf
(
"error decoding object, invalid type"
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"error decoding object, invalid type"
))
return
return
}
}
object
,
ok
=
tombstone
.
Obj
.
(
metav1
.
Object
)
object
,
ok
=
tombstone
.
Obj
.
(
metav1
.
Object
)
if
!
ok
{
if
!
ok
{
runtime
.
HandleError
(
fmt
.
Errorf
(
"error decoding object tombstone, invalid type"
))
util
runtime
.
HandleError
(
fmt
.
Errorf
(
"error decoding object tombstone, invalid type"
))
return
return
}
}
klog
.
V
(
4
)
.
Infof
(
"Recovered deleted object '%s' from tombstone"
,
object
.
GetName
())
klog
.
V
(
4
)
.
Infof
(
"Recovered deleted object '%s' from tombstone"
,
object
.
GetName
())
...
...
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