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
386e0014
Commit
386e0014
authored
Jan 18, 2018
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upgrade to apps/v1 deployment
parent
b7100f1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
controller.go
staging/src/k8s.io/sample-controller/controller.go
+12
-12
No files found.
staging/src/k8s.io/sample-controller/controller.go
View file @
386e0014
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
appsv1
beta2
"k8s.io/api/apps/v1beta2
"
appsv1
"k8s.io/api/apps/v1
"
corev1
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
"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"
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/kubernetes/scheme"
typedcorev1
"k8s.io/client-go/kubernetes/typed/core/v1"
typedcorev1
"k8s.io/client-go/kubernetes/typed/core/v1"
appslisters
"k8s.io/client-go/listers/apps/v1
beta2
"
appslisters
"k8s.io/client-go/listers/apps/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"k8s.io/client-go/util/workqueue"
...
@@ -93,7 +93,7 @@ func NewController(
...
@@ -93,7 +93,7 @@ func NewController(
// obtain references to shared index informers for the Deployment and Foo
// obtain references to shared index informers for the Deployment and Foo
// types.
// types.
deploymentInformer
:=
kubeInformerFactory
.
Apps
()
.
V1
beta2
()
.
Deployments
()
deploymentInformer
:=
kubeInformerFactory
.
Apps
()
.
V1
()
.
Deployments
()
fooInformer
:=
sampleInformerFactory
.
Samplecontroller
()
.
V1alpha1
()
.
Foos
()
fooInformer
:=
sampleInformerFactory
.
Samplecontroller
()
.
V1alpha1
()
.
Foos
()
// Create event broadcaster
// Create event broadcaster
...
@@ -134,8 +134,8 @@ func NewController(
...
@@ -134,8 +134,8 @@ func NewController(
deploymentInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
deploymentInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
AddFunc
:
controller
.
handleObject
,
AddFunc
:
controller
.
handleObject
,
UpdateFunc
:
func
(
old
,
new
interface
{})
{
UpdateFunc
:
func
(
old
,
new
interface
{})
{
newDepl
:=
new
.
(
*
appsv1
beta2
.
Deployment
)
newDepl
:=
new
.
(
*
appsv1
.
Deployment
)
oldDepl
:=
old
.
(
*
appsv1
beta2
.
Deployment
)
oldDepl
:=
old
.
(
*
appsv1
.
Deployment
)
if
newDepl
.
ResourceVersion
==
oldDepl
.
ResourceVersion
{
if
newDepl
.
ResourceVersion
==
oldDepl
.
ResourceVersion
{
// Periodic resync will send update events for all known Deployments.
// Periodic resync will send update events for all known Deployments.
// Two different versions of the same Deployment will always have different RVs.
// Two different versions of the same Deployment will always have different RVs.
...
@@ -277,7 +277,7 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -277,7 +277,7 @@ func (c *Controller) syncHandler(key string) error {
deployment
,
err
:=
c
.
deploymentsLister
.
Deployments
(
foo
.
Namespace
)
.
Get
(
deploymentName
)
deployment
,
err
:=
c
.
deploymentsLister
.
Deployments
(
foo
.
Namespace
)
.
Get
(
deploymentName
)
// If the resource doesn't exist, we'll create it
// If the resource doesn't exist, we'll create it
if
errors
.
IsNotFound
(
err
)
{
if
errors
.
IsNotFound
(
err
)
{
deployment
,
err
=
c
.
kubeclientset
.
AppsV1
beta2
()
.
Deployments
(
foo
.
Namespace
)
.
Create
(
newDeployment
(
foo
))
deployment
,
err
=
c
.
kubeclientset
.
AppsV1
()
.
Deployments
(
foo
.
Namespace
)
.
Create
(
newDeployment
(
foo
))
}
}
// If an error occurs during Get/Create, we'll requeue the item so we can
// If an error occurs during Get/Create, we'll requeue the item so we can
...
@@ -299,8 +299,8 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -299,8 +299,8 @@ func (c *Controller) syncHandler(key string) error {
// number does not equal the current desired replicas on the Deployment, we
// number does not equal the current desired replicas on the Deployment, we
// should update the Deployment resource.
// should update the Deployment resource.
if
foo
.
Spec
.
Replicas
!=
nil
&&
*
foo
.
Spec
.
Replicas
!=
*
deployment
.
Spec
.
Replicas
{
if
foo
.
Spec
.
Replicas
!=
nil
&&
*
foo
.
Spec
.
Replicas
!=
*
deployment
.
Spec
.
Replicas
{
glog
.
V
(
4
)
.
Infof
(
"Foo
r: %d, deplR: %d"
,
*
foo
.
Spec
.
Replicas
,
*
deployment
.
Spec
.
Replicas
)
glog
.
V
(
4
)
.
Infof
(
"Foo
%s replicas: %d, deployment replicas: %d"
,
name
,
*
foo
.
Spec
.
Replicas
,
*
deployment
.
Spec
.
Replicas
)
deployment
,
err
=
c
.
kubeclientset
.
AppsV1
beta2
()
.
Deployments
(
foo
.
Namespace
)
.
Update
(
newDeployment
(
foo
))
deployment
,
err
=
c
.
kubeclientset
.
AppsV1
()
.
Deployments
(
foo
.
Namespace
)
.
Update
(
newDeployment
(
foo
))
}
}
// If an error occurs during Update, we'll requeue the item so we can
// If an error occurs during Update, we'll requeue the item so we can
...
@@ -321,7 +321,7 @@ func (c *Controller) syncHandler(key string) error {
...
@@ -321,7 +321,7 @@ func (c *Controller) syncHandler(key string) error {
return
nil
return
nil
}
}
func
(
c
*
Controller
)
updateFooStatus
(
foo
*
samplev1alpha1
.
Foo
,
deployment
*
appsv1
beta2
.
Deployment
)
error
{
func
(
c
*
Controller
)
updateFooStatus
(
foo
*
samplev1alpha1
.
Foo
,
deployment
*
appsv1
.
Deployment
)
error
{
// NEVER modify objects from the store. It's a read-only, local cache.
// NEVER modify objects from the store. It's a read-only, local cache.
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// Or create a copy manually for better performance
// Or create a copy manually for better performance
...
@@ -391,12 +391,12 @@ func (c *Controller) handleObject(obj interface{}) {
...
@@ -391,12 +391,12 @@ func (c *Controller) handleObject(obj interface{}) {
// newDeployment creates a new Deployment for a Foo resource. It also sets
// newDeployment creates a new Deployment for a Foo resource. It also sets
// the appropriate OwnerReferences on the resource so handleObject can discover
// the appropriate OwnerReferences on the resource so handleObject can discover
// the Foo resource that 'owns' it.
// the Foo resource that 'owns' it.
func
newDeployment
(
foo
*
samplev1alpha1
.
Foo
)
*
appsv1
beta2
.
Deployment
{
func
newDeployment
(
foo
*
samplev1alpha1
.
Foo
)
*
appsv1
.
Deployment
{
labels
:=
map
[
string
]
string
{
labels
:=
map
[
string
]
string
{
"app"
:
"nginx"
,
"app"
:
"nginx"
,
"controller"
:
foo
.
Name
,
"controller"
:
foo
.
Name
,
}
}
return
&
appsv1
beta2
.
Deployment
{
return
&
appsv1
.
Deployment
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
foo
.
Spec
.
DeploymentName
,
Name
:
foo
.
Spec
.
DeploymentName
,
Namespace
:
foo
.
Namespace
,
Namespace
:
foo
.
Namespace
,
...
@@ -408,7 +408,7 @@ func newDeployment(foo *samplev1alpha1.Foo) *appsv1beta2.Deployment {
...
@@ -408,7 +408,7 @@ func newDeployment(foo *samplev1alpha1.Foo) *appsv1beta2.Deployment {
}),
}),
},
},
},
},
Spec
:
appsv1
beta2
.
DeploymentSpec
{
Spec
:
appsv1
.
DeploymentSpec
{
Replicas
:
foo
.
Spec
.
Replicas
,
Replicas
:
foo
.
Spec
.
Replicas
,
Selector
:
&
metav1
.
LabelSelector
{
Selector
:
&
metav1
.
LabelSelector
{
MatchLabels
:
labels
,
MatchLabels
:
labels
,
...
...
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