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
8c4341de
Unverified
Commit
8c4341de
authored
Mar 19, 2018
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicaSet: Use apps/v1 for RS controller.
parent
7b8bc5db
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
52 deletions
+52
-52
replica_set.go
pkg/controller/replicaset/replica_set.go
+17
-17
replica_set_test.go
pkg/controller/replicaset/replica_set_test.go
+0
-0
replica_set_utils.go
pkg/controller/replicaset/replica_set_utils.go
+15
-15
replica_set_utils_test.go
pkg/controller/replicaset/replica_set_utils_test.go
+20
-20
No files found.
pkg/controller/replicaset/replica_set.go
View file @
8c4341de
...
@@ -36,21 +36,21 @@ import (
...
@@ -36,21 +36,21 @@ import (
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
apps
"k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
extensions
"k8s.io/api/extensions/v1beta1"
"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/labels"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
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"
coreinformers
"k8s.io/client-go/informers/core/v1"
coreinformers
"k8s.io/client-go/informers/core/v1"
extensionsinformers
"k8s.io/client-go/informers/extensions/v1beta1"
clientset
"k8s.io/client-go/kubernetes"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/kubernetes/scheme"
v1core
"k8s.io/client-go/kubernetes/typed/core/v1"
v1core
"k8s.io/client-go/kubernetes/typed/core/v1"
appslisters
"k8s.io/client-go/listers/apps/v1"
corelisters
"k8s.io/client-go/listers/core/v1"
corelisters
"k8s.io/client-go/listers/core/v1"
extensionslisters
"k8s.io/client-go/listers/extensions/v1beta1"
"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/integer"
"k8s.io/client-go/util/integer"
...
@@ -90,7 +90,7 @@ type ReplicaSetController struct {
...
@@ -90,7 +90,7 @@ type ReplicaSetController struct {
expectations
*
controller
.
UIDTrackingControllerExpectations
expectations
*
controller
.
UIDTrackingControllerExpectations
// A store of ReplicaSets, populated by the shared informer passed to NewReplicaSetController
// A store of ReplicaSets, populated by the shared informer passed to NewReplicaSetController
rsLister
extension
slisters
.
ReplicaSetLister
rsLister
app
slisters
.
ReplicaSetLister
// rsListerSynced returns true if the pod store has been synced at least once.
// rsListerSynced returns true if the pod store has been synced at least once.
// Added as a member to the struct to allow injection for testing.
// Added as a member to the struct to allow injection for testing.
rsListerSynced
cache
.
InformerSynced
rsListerSynced
cache
.
InformerSynced
...
@@ -106,12 +106,12 @@ type ReplicaSetController struct {
...
@@ -106,12 +106,12 @@ type ReplicaSetController struct {
}
}
// NewReplicaSetController configures a replica set controller with the specified event recorder
// NewReplicaSetController configures a replica set controller with the specified event recorder
func
NewReplicaSetController
(
rsInformer
extension
sinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
)
*
ReplicaSetController
{
func
NewReplicaSetController
(
rsInformer
app
sinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
)
*
ReplicaSetController
{
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
v1core
.
New
(
kubeClient
.
CoreV1
()
.
RESTClient
())
.
Events
(
""
)})
eventBroadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
v1core
.
New
(
kubeClient
.
CoreV1
()
.
RESTClient
())
.
Events
(
""
)})
return
NewBaseController
(
rsInformer
,
podInformer
,
kubeClient
,
burstReplicas
,
return
NewBaseController
(
rsInformer
,
podInformer
,
kubeClient
,
burstReplicas
,
extension
s
.
SchemeGroupVersion
.
WithKind
(
"ReplicaSet"
),
app
s
.
SchemeGroupVersion
.
WithKind
(
"ReplicaSet"
),
"replicaset_controller"
,
"replicaset_controller"
,
"replicaset"
,
"replicaset"
,
controller
.
RealPodControl
{
controller
.
RealPodControl
{
...
@@ -123,7 +123,7 @@ func NewReplicaSetController(rsInformer extensionsinformers.ReplicaSetInformer,
...
@@ -123,7 +123,7 @@ func NewReplicaSetController(rsInformer extensionsinformers.ReplicaSetInformer,
// NewBaseController is the implementation of NewReplicaSetController with additional injected
// NewBaseController is the implementation of NewReplicaSetController with additional injected
// parameters so that it can also serve as the implementation of NewReplicationController.
// parameters so that it can also serve as the implementation of NewReplicationController.
func
NewBaseController
(
rsInformer
extension
sinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
func
NewBaseController
(
rsInformer
app
sinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
gvk
schema
.
GroupVersionKind
,
metricOwnerName
,
queueName
string
,
podControl
controller
.
PodControlInterface
)
*
ReplicaSetController
{
gvk
schema
.
GroupVersionKind
,
metricOwnerName
,
queueName
string
,
podControl
controller
.
PodControlInterface
)
*
ReplicaSetController
{
if
kubeClient
!=
nil
&&
kubeClient
.
CoreV1
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
if
kubeClient
!=
nil
&&
kubeClient
.
CoreV1
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
metricOwnerName
,
kubeClient
.
CoreV1
()
.
RESTClient
()
.
GetRateLimiter
())
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
metricOwnerName
,
kubeClient
.
CoreV1
()
.
RESTClient
()
.
GetRateLimiter
())
...
@@ -194,7 +194,7 @@ func (rsc *ReplicaSetController) Run(workers int, stopCh <-chan struct{}) {
...
@@ -194,7 +194,7 @@ func (rsc *ReplicaSetController) Run(workers int, stopCh <-chan struct{}) {
}
}
// getPodReplicaSets returns a list of ReplicaSets matching the given pod.
// getPodReplicaSets returns a list of ReplicaSets matching the given pod.
func
(
rsc
*
ReplicaSetController
)
getPodReplicaSets
(
pod
*
v1
.
Pod
)
[]
*
extension
s
.
ReplicaSet
{
func
(
rsc
*
ReplicaSetController
)
getPodReplicaSets
(
pod
*
v1
.
Pod
)
[]
*
app
s
.
ReplicaSet
{
rss
,
err
:=
rsc
.
rsLister
.
GetPodReplicaSets
(
pod
)
rss
,
err
:=
rsc
.
rsLister
.
GetPodReplicaSets
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
...
@@ -210,7 +210,7 @@ func (rsc *ReplicaSetController) getPodReplicaSets(pod *v1.Pod) []*extensions.Re
...
@@ -210,7 +210,7 @@ func (rsc *ReplicaSetController) getPodReplicaSets(pod *v1.Pod) []*extensions.Re
// resolveControllerRef returns the controller referenced by a ControllerRef,
// resolveControllerRef returns the controller referenced by a ControllerRef,
// or nil if the ControllerRef could not be resolved to a matching controller
// or nil if the ControllerRef could not be resolved to a matching controller
// of the correct Kind.
// of the correct Kind.
func
(
rsc
*
ReplicaSetController
)
resolveControllerRef
(
namespace
string
,
controllerRef
*
metav1
.
OwnerReference
)
*
extension
s
.
ReplicaSet
{
func
(
rsc
*
ReplicaSetController
)
resolveControllerRef
(
namespace
string
,
controllerRef
*
metav1
.
OwnerReference
)
*
app
s
.
ReplicaSet
{
// We can't look up by UID, so look up by Name and then verify UID.
// We can't look up by UID, so look up by Name and then verify UID.
// Don't even try to look up by Name if it's the wrong Kind.
// Don't even try to look up by Name if it's the wrong Kind.
if
controllerRef
.
Kind
!=
rsc
.
Kind
{
if
controllerRef
.
Kind
!=
rsc
.
Kind
{
...
@@ -230,8 +230,8 @@ func (rsc *ReplicaSetController) resolveControllerRef(namespace string, controll
...
@@ -230,8 +230,8 @@ func (rsc *ReplicaSetController) resolveControllerRef(namespace string, controll
// callback when RS is updated
// callback when RS is updated
func
(
rsc
*
ReplicaSetController
)
updateRS
(
old
,
cur
interface
{})
{
func
(
rsc
*
ReplicaSetController
)
updateRS
(
old
,
cur
interface
{})
{
oldRS
:=
old
.
(
*
extension
s
.
ReplicaSet
)
oldRS
:=
old
.
(
*
app
s
.
ReplicaSet
)
curRS
:=
cur
.
(
*
extension
s
.
ReplicaSet
)
curRS
:=
cur
.
(
*
app
s
.
ReplicaSet
)
// You might imagine that we only really need to enqueue the
// You might imagine that we only really need to enqueue the
// replica set when Spec changes, but it is safer to sync any
// replica set when Spec changes, but it is safer to sync any
...
@@ -407,7 +407,7 @@ func (rsc *ReplicaSetController) deletePod(obj interface{}) {
...
@@ -407,7 +407,7 @@ func (rsc *ReplicaSetController) deletePod(obj interface{}) {
rsc
.
enqueueReplicaSet
(
rs
)
rsc
.
enqueueReplicaSet
(
rs
)
}
}
// obj could be an *
extension
s.ReplicaSet, or a DeletionFinalStateUnknown marker item.
// obj could be an *
app
s.ReplicaSet, or a DeletionFinalStateUnknown marker item.
func
(
rsc
*
ReplicaSetController
)
enqueueReplicaSet
(
obj
interface
{})
{
func
(
rsc
*
ReplicaSetController
)
enqueueReplicaSet
(
obj
interface
{})
{
key
,
err
:=
controller
.
KeyFunc
(
obj
)
key
,
err
:=
controller
.
KeyFunc
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -417,7 +417,7 @@ func (rsc *ReplicaSetController) enqueueReplicaSet(obj interface{}) {
...
@@ -417,7 +417,7 @@ func (rsc *ReplicaSetController) enqueueReplicaSet(obj interface{}) {
rsc
.
queue
.
Add
(
key
)
rsc
.
queue
.
Add
(
key
)
}
}
// obj could be an *
extension
s.ReplicaSet, or a DeletionFinalStateUnknown marker item.
// obj could be an *
app
s.ReplicaSet, or a DeletionFinalStateUnknown marker item.
func
(
rsc
*
ReplicaSetController
)
enqueueReplicaSetAfter
(
obj
interface
{},
after
time
.
Duration
)
{
func
(
rsc
*
ReplicaSetController
)
enqueueReplicaSetAfter
(
obj
interface
{},
after
time
.
Duration
)
{
key
,
err
:=
controller
.
KeyFunc
(
obj
)
key
,
err
:=
controller
.
KeyFunc
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -456,7 +456,7 @@ func (rsc *ReplicaSetController) processNextWorkItem() bool {
...
@@ -456,7 +456,7 @@ func (rsc *ReplicaSetController) processNextWorkItem() bool {
// manageReplicas checks and updates replicas for the given ReplicaSet.
// manageReplicas checks and updates replicas for the given ReplicaSet.
// Does NOT modify <filteredPods>.
// Does NOT modify <filteredPods>.
// It will requeue the replica set in case of an error while creating/deleting pods.
// It will requeue the replica set in case of an error while creating/deleting pods.
func
(
rsc
*
ReplicaSetController
)
manageReplicas
(
filteredPods
[]
*
v1
.
Pod
,
rs
*
extension
s
.
ReplicaSet
)
error
{
func
(
rsc
*
ReplicaSetController
)
manageReplicas
(
filteredPods
[]
*
v1
.
Pod
,
rs
*
app
s
.
ReplicaSet
)
error
{
diff
:=
len
(
filteredPods
)
-
int
(
*
(
rs
.
Spec
.
Replicas
))
diff
:=
len
(
filteredPods
)
-
int
(
*
(
rs
.
Spec
.
Replicas
))
rsKey
,
err
:=
controller
.
KeyFunc
(
rs
)
rsKey
,
err
:=
controller
.
KeyFunc
(
rs
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -626,7 +626,7 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
...
@@ -626,7 +626,7 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
newStatus
:=
calculateStatus
(
rs
,
filteredPods
,
manageReplicasErr
)
newStatus
:=
calculateStatus
(
rs
,
filteredPods
,
manageReplicasErr
)
// Always updates status as pods come up or die.
// Always updates status as pods come up or die.
updatedRS
,
err
:=
updateReplicaSetStatus
(
rsc
.
kubeClient
.
ExtensionsV1beta
1
()
.
ReplicaSets
(
rs
.
Namespace
),
rs
,
newStatus
)
updatedRS
,
err
:=
updateReplicaSetStatus
(
rsc
.
kubeClient
.
AppsV
1
()
.
ReplicaSets
(
rs
.
Namespace
),
rs
,
newStatus
)
if
err
!=
nil
{
if
err
!=
nil
{
// Multiple things could lead to this update failing. Requeuing the replica set ensures
// Multiple things could lead to this update failing. Requeuing the replica set ensures
// Returning an error causes a requeue without forcing a hotloop
// Returning an error causes a requeue without forcing a hotloop
...
@@ -641,11 +641,11 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
...
@@ -641,11 +641,11 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
return
manageReplicasErr
return
manageReplicasErr
}
}
func
(
rsc
*
ReplicaSetController
)
claimPods
(
rs
*
extension
s
.
ReplicaSet
,
selector
labels
.
Selector
,
filteredPods
[]
*
v1
.
Pod
)
([]
*
v1
.
Pod
,
error
)
{
func
(
rsc
*
ReplicaSetController
)
claimPods
(
rs
*
app
s
.
ReplicaSet
,
selector
labels
.
Selector
,
filteredPods
[]
*
v1
.
Pod
)
([]
*
v1
.
Pod
,
error
)
{
// If any adoptions are attempted, we should first recheck for deletion with
// If any adoptions are attempted, we should first recheck for deletion with
// an uncached quorum read sometime after listing Pods (see #42639).
// an uncached quorum read sometime after listing Pods (see #42639).
canAdoptFunc
:=
controller
.
RecheckDeletionTimestamp
(
func
()
(
metav1
.
Object
,
error
)
{
canAdoptFunc
:=
controller
.
RecheckDeletionTimestamp
(
func
()
(
metav1
.
Object
,
error
)
{
fresh
,
err
:=
rsc
.
kubeClient
.
ExtensionsV1beta
1
()
.
ReplicaSets
(
rs
.
Namespace
)
.
Get
(
rs
.
Name
,
metav1
.
GetOptions
{})
fresh
,
err
:=
rsc
.
kubeClient
.
AppsV
1
()
.
ReplicaSets
(
rs
.
Namespace
)
.
Get
(
rs
.
Name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/controller/replicaset/replica_set_test.go
View file @
8c4341de
This diff is collapsed.
Click to expand it.
pkg/controller/replicaset/replica_set_utils.go
View file @
8c4341de
...
@@ -24,16 +24,16 @@ import (
...
@@ -24,16 +24,16 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
apps
"k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
extensions
"k8s.io/api/extensions/v1beta1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
unversionedextensions
"k8s.io/client-go/kubernetes/typed/extensions/v1beta
1"
appsclient
"k8s.io/client-go/kubernetes/typed/apps/v
1"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
)
)
// updateReplicaSetStatus attempts to update the Status.Replicas of the given ReplicaSet, with a single GET/PUT retry.
// updateReplicaSetStatus attempts to update the Status.Replicas of the given ReplicaSet, with a single GET/PUT retry.
func
updateReplicaSetStatus
(
c
unversionedextensions
.
ReplicaSetInterface
,
rs
*
extensions
.
ReplicaSet
,
newStatus
extensions
.
ReplicaSetStatus
)
(
*
extension
s
.
ReplicaSet
,
error
)
{
func
updateReplicaSetStatus
(
c
appsclient
.
ReplicaSetInterface
,
rs
*
apps
.
ReplicaSet
,
newStatus
apps
.
ReplicaSetStatus
)
(
*
app
s
.
ReplicaSet
,
error
)
{
// This is the steady state. It happens when the ReplicaSet doesn't have any expectations, since
// This is the steady state. It happens when the ReplicaSet doesn't have any expectations, since
// we do a periodic relist every 30s. If the generations differ but the replicas are
// we do a periodic relist every 30s. If the generations differ but the replicas are
// the same, a caller might've resized to the same replica count.
// the same, a caller might've resized to the same replica count.
...
@@ -53,7 +53,7 @@ func updateReplicaSetStatus(c unversionedextensions.ReplicaSetInterface, rs *ext
...
@@ -53,7 +53,7 @@ func updateReplicaSetStatus(c unversionedextensions.ReplicaSetInterface, rs *ext
newStatus
.
ObservedGeneration
=
rs
.
Generation
newStatus
.
ObservedGeneration
=
rs
.
Generation
var
getErr
,
updateErr
error
var
getErr
,
updateErr
error
var
updatedRS
*
extension
s
.
ReplicaSet
var
updatedRS
*
app
s
.
ReplicaSet
for
i
,
rs
:=
0
,
rs
;
;
i
++
{
for
i
,
rs
:=
0
,
rs
;
;
i
++
{
glog
.
V
(
4
)
.
Infof
(
fmt
.
Sprintf
(
"Updating status for %v: %s/%s, "
,
rs
.
Kind
,
rs
.
Namespace
,
rs
.
Name
)
+
glog
.
V
(
4
)
.
Infof
(
fmt
.
Sprintf
(
"Updating status for %v: %s/%s, "
,
rs
.
Kind
,
rs
.
Namespace
,
rs
.
Name
)
+
fmt
.
Sprintf
(
"replicas %d->%d (need %d), "
,
rs
.
Status
.
Replicas
,
newStatus
.
Replicas
,
*
(
rs
.
Spec
.
Replicas
))
+
fmt
.
Sprintf
(
"replicas %d->%d (need %d), "
,
rs
.
Status
.
Replicas
,
newStatus
.
Replicas
,
*
(
rs
.
Spec
.
Replicas
))
+
...
@@ -82,7 +82,7 @@ func updateReplicaSetStatus(c unversionedextensions.ReplicaSetInterface, rs *ext
...
@@ -82,7 +82,7 @@ func updateReplicaSetStatus(c unversionedextensions.ReplicaSetInterface, rs *ext
return
nil
,
updateErr
return
nil
,
updateErr
}
}
func
calculateStatus
(
rs
*
extensions
.
ReplicaSet
,
filteredPods
[]
*
v1
.
Pod
,
manageReplicasErr
error
)
extension
s
.
ReplicaSetStatus
{
func
calculateStatus
(
rs
*
apps
.
ReplicaSet
,
filteredPods
[]
*
v1
.
Pod
,
manageReplicasErr
error
)
app
s
.
ReplicaSetStatus
{
newStatus
:=
rs
.
Status
newStatus
:=
rs
.
Status
// Count the number of pods that have labels matching the labels of the pod
// Count the number of pods that have labels matching the labels of the pod
// template of the replica set, the matching pods may have more
// template of the replica set, the matching pods may have more
...
@@ -105,7 +105,7 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
...
@@ -105,7 +105,7 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
}
}
}
}
failureCond
:=
GetCondition
(
rs
.
Status
,
extension
s
.
ReplicaSetReplicaFailure
)
failureCond
:=
GetCondition
(
rs
.
Status
,
app
s
.
ReplicaSetReplicaFailure
)
if
manageReplicasErr
!=
nil
&&
failureCond
==
nil
{
if
manageReplicasErr
!=
nil
&&
failureCond
==
nil
{
var
reason
string
var
reason
string
if
diff
:=
len
(
filteredPods
)
-
int
(
*
(
rs
.
Spec
.
Replicas
));
diff
<
0
{
if
diff
:=
len
(
filteredPods
)
-
int
(
*
(
rs
.
Spec
.
Replicas
));
diff
<
0
{
...
@@ -113,10 +113,10 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
...
@@ -113,10 +113,10 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
}
else
if
diff
>
0
{
}
else
if
diff
>
0
{
reason
=
"FailedDelete"
reason
=
"FailedDelete"
}
}
cond
:=
NewReplicaSetCondition
(
extension
s
.
ReplicaSetReplicaFailure
,
v1
.
ConditionTrue
,
reason
,
manageReplicasErr
.
Error
())
cond
:=
NewReplicaSetCondition
(
app
s
.
ReplicaSetReplicaFailure
,
v1
.
ConditionTrue
,
reason
,
manageReplicasErr
.
Error
())
SetCondition
(
&
newStatus
,
cond
)
SetCondition
(
&
newStatus
,
cond
)
}
else
if
manageReplicasErr
==
nil
&&
failureCond
!=
nil
{
}
else
if
manageReplicasErr
==
nil
&&
failureCond
!=
nil
{
RemoveCondition
(
&
newStatus
,
extension
s
.
ReplicaSetReplicaFailure
)
RemoveCondition
(
&
newStatus
,
app
s
.
ReplicaSetReplicaFailure
)
}
}
newStatus
.
Replicas
=
int32
(
len
(
filteredPods
))
newStatus
.
Replicas
=
int32
(
len
(
filteredPods
))
...
@@ -127,8 +127,8 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
...
@@ -127,8 +127,8 @@ func calculateStatus(rs *extensions.ReplicaSet, filteredPods []*v1.Pod, manageRe
}
}
// NewReplicaSetCondition creates a new replicaset condition.
// NewReplicaSetCondition creates a new replicaset condition.
func
NewReplicaSetCondition
(
condType
extensions
.
ReplicaSetConditionType
,
status
v1
.
ConditionStatus
,
reason
,
msg
string
)
extension
s
.
ReplicaSetCondition
{
func
NewReplicaSetCondition
(
condType
apps
.
ReplicaSetConditionType
,
status
v1
.
ConditionStatus
,
reason
,
msg
string
)
app
s
.
ReplicaSetCondition
{
return
extension
s
.
ReplicaSetCondition
{
return
app
s
.
ReplicaSetCondition
{
Type
:
condType
,
Type
:
condType
,
Status
:
status
,
Status
:
status
,
LastTransitionTime
:
metav1
.
Now
(),
LastTransitionTime
:
metav1
.
Now
(),
...
@@ -138,7 +138,7 @@ func NewReplicaSetCondition(condType extensions.ReplicaSetConditionType, status
...
@@ -138,7 +138,7 @@ func NewReplicaSetCondition(condType extensions.ReplicaSetConditionType, status
}
}
// GetCondition returns a replicaset condition with the provided type if it exists.
// GetCondition returns a replicaset condition with the provided type if it exists.
func
GetCondition
(
status
extensions
.
ReplicaSetStatus
,
condType
extensions
.
ReplicaSetConditionType
)
*
extension
s
.
ReplicaSetCondition
{
func
GetCondition
(
status
apps
.
ReplicaSetStatus
,
condType
apps
.
ReplicaSetConditionType
)
*
app
s
.
ReplicaSetCondition
{
for
_
,
c
:=
range
status
.
Conditions
{
for
_
,
c
:=
range
status
.
Conditions
{
if
c
.
Type
==
condType
{
if
c
.
Type
==
condType
{
return
&
c
return
&
c
...
@@ -149,7 +149,7 @@ func GetCondition(status extensions.ReplicaSetStatus, condType extensions.Replic
...
@@ -149,7 +149,7 @@ func GetCondition(status extensions.ReplicaSetStatus, condType extensions.Replic
// SetCondition adds/replaces the given condition in the replicaset status. If the condition that we
// SetCondition adds/replaces the given condition in the replicaset status. If the condition that we
// are about to add already exists and has the same status and reason then we are not going to update.
// are about to add already exists and has the same status and reason then we are not going to update.
func
SetCondition
(
status
*
extensions
.
ReplicaSetStatus
,
condition
extension
s
.
ReplicaSetCondition
)
{
func
SetCondition
(
status
*
apps
.
ReplicaSetStatus
,
condition
app
s
.
ReplicaSetCondition
)
{
currentCond
:=
GetCondition
(
*
status
,
condition
.
Type
)
currentCond
:=
GetCondition
(
*
status
,
condition
.
Type
)
if
currentCond
!=
nil
&&
currentCond
.
Status
==
condition
.
Status
&&
currentCond
.
Reason
==
condition
.
Reason
{
if
currentCond
!=
nil
&&
currentCond
.
Status
==
condition
.
Status
&&
currentCond
.
Reason
==
condition
.
Reason
{
return
return
...
@@ -159,13 +159,13 @@ func SetCondition(status *extensions.ReplicaSetStatus, condition extensions.Repl
...
@@ -159,13 +159,13 @@ func SetCondition(status *extensions.ReplicaSetStatus, condition extensions.Repl
}
}
// RemoveCondition removes the condition with the provided type from the replicaset status.
// RemoveCondition removes the condition with the provided type from the replicaset status.
func
RemoveCondition
(
status
*
extensions
.
ReplicaSetStatus
,
condType
extension
s
.
ReplicaSetConditionType
)
{
func
RemoveCondition
(
status
*
apps
.
ReplicaSetStatus
,
condType
app
s
.
ReplicaSetConditionType
)
{
status
.
Conditions
=
filterOutCondition
(
status
.
Conditions
,
condType
)
status
.
Conditions
=
filterOutCondition
(
status
.
Conditions
,
condType
)
}
}
// filterOutCondition returns a new slice of replicaset conditions without conditions with the provided type.
// filterOutCondition returns a new slice of replicaset conditions without conditions with the provided type.
func
filterOutCondition
(
conditions
[]
extensions
.
ReplicaSetCondition
,
condType
extensions
.
ReplicaSetConditionType
)
[]
extension
s
.
ReplicaSetCondition
{
func
filterOutCondition
(
conditions
[]
apps
.
ReplicaSetCondition
,
condType
apps
.
ReplicaSetConditionType
)
[]
app
s
.
ReplicaSetCondition
{
var
newConditions
[]
extension
s
.
ReplicaSetCondition
var
newConditions
[]
app
s
.
ReplicaSetCondition
for
_
,
c
:=
range
conditions
{
for
_
,
c
:=
range
conditions
{
if
c
.
Type
==
condType
{
if
c
.
Type
==
condType
{
continue
continue
...
...
pkg/controller/replicaset/replica_set_utils_test.go
View file @
8c4341de
...
@@ -23,8 +23,8 @@ import (
...
@@ -23,8 +23,8 @@ import (
"reflect"
"reflect"
"testing"
"testing"
apps
"k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
extensions
"k8s.io/api/extensions/v1beta1"
)
)
func
TestCalculateStatus
(
t
*
testing
.
T
)
{
func
TestCalculateStatus
(
t
*
testing
.
T
)
{
...
@@ -38,9 +38,9 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -38,9 +38,9 @@ func TestCalculateStatus(t *testing.T) {
rsStatusTests
:=
[]
struct
{
rsStatusTests
:=
[]
struct
{
name
string
name
string
replicaset
*
extension
s
.
ReplicaSet
replicaset
*
app
s
.
ReplicaSet
filteredPods
[]
*
v1
.
Pod
filteredPods
[]
*
v1
.
Pod
expectedReplicaSetStatus
extension
s
.
ReplicaSetStatus
expectedReplicaSetStatus
app
s
.
ReplicaSetStatus
}{
}{
{
{
"1 fully labelled pod"
,
"1 fully labelled pod"
,
...
@@ -48,7 +48,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestCalculateStatus(t *testing.T) {
[]
*
v1
.
Pod
{
[]
*
v1
.
Pod
{
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
FullyLabeledReplicas
:
1
,
FullyLabeledReplicas
:
1
,
ReadyReplicas
:
1
,
ReadyReplicas
:
1
,
...
@@ -61,7 +61,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -61,7 +61,7 @@ func TestCalculateStatus(t *testing.T) {
[]
*
v1
.
Pod
{
[]
*
v1
.
Pod
{
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
FullyLabeledReplicas
:
0
,
FullyLabeledReplicas
:
0
,
ReadyReplicas
:
1
,
ReadyReplicas
:
1
,
...
@@ -75,7 +75,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -75,7 +75,7 @@ func TestCalculateStatus(t *testing.T) {
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
2
,
Replicas
:
2
,
FullyLabeledReplicas
:
2
,
FullyLabeledReplicas
:
2
,
ReadyReplicas
:
2
,
ReadyReplicas
:
2
,
...
@@ -89,7 +89,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -89,7 +89,7 @@ func TestCalculateStatus(t *testing.T) {
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
2
,
Replicas
:
2
,
FullyLabeledReplicas
:
0
,
FullyLabeledReplicas
:
0
,
ReadyReplicas
:
2
,
ReadyReplicas
:
2
,
...
@@ -103,7 +103,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -103,7 +103,7 @@ func TestCalculateStatus(t *testing.T) {
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
notFullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod2"
,
fullyLabelledRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
2
,
Replicas
:
2
,
FullyLabeledReplicas
:
1
,
FullyLabeledReplicas
:
1
,
ReadyReplicas
:
2
,
ReadyReplicas
:
2
,
...
@@ -116,7 +116,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -116,7 +116,7 @@ func TestCalculateStatus(t *testing.T) {
[]
*
v1
.
Pod
{
[]
*
v1
.
Pod
{
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodPending
,
nil
,
true
),
newPod
(
"pod1"
,
fullyLabelledRS
,
v1
.
PodPending
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
FullyLabeledReplicas
:
1
,
FullyLabeledReplicas
:
1
,
ReadyReplicas
:
0
,
ReadyReplicas
:
0
,
...
@@ -129,7 +129,7 @@ func TestCalculateStatus(t *testing.T) {
...
@@ -129,7 +129,7 @@ func TestCalculateStatus(t *testing.T) {
[]
*
v1
.
Pod
{
[]
*
v1
.
Pod
{
newPod
(
"pod1"
,
longMinReadySecondsRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
longMinReadySecondsRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
extension
s
.
ReplicaSetStatus
{
app
s
.
ReplicaSetStatus
{
Replicas
:
1
,
Replicas
:
1
,
FullyLabeledReplicas
:
1
,
FullyLabeledReplicas
:
1
,
ReadyReplicas
:
1
,
ReadyReplicas
:
1
,
...
@@ -150,19 +150,19 @@ func TestCalculateStatusConditions(t *testing.T) {
...
@@ -150,19 +150,19 @@ func TestCalculateStatusConditions(t *testing.T) {
labelMap
:=
map
[
string
]
string
{
"name"
:
"foo"
}
labelMap
:=
map
[
string
]
string
{
"name"
:
"foo"
}
rs
:=
newReplicaSet
(
2
,
labelMap
)
rs
:=
newReplicaSet
(
2
,
labelMap
)
replicaFailureRS
:=
newReplicaSet
(
10
,
labelMap
)
replicaFailureRS
:=
newReplicaSet
(
10
,
labelMap
)
replicaFailureRS
.
Status
.
Conditions
=
[]
extension
s
.
ReplicaSetCondition
{
replicaFailureRS
.
Status
.
Conditions
=
[]
app
s
.
ReplicaSetCondition
{
{
{
Type
:
extension
s
.
ReplicaSetReplicaFailure
,
Type
:
app
s
.
ReplicaSetReplicaFailure
,
Status
:
v1
.
ConditionTrue
,
Status
:
v1
.
ConditionTrue
,
},
},
}
}
rsStatusConditionTests
:=
[]
struct
{
rsStatusConditionTests
:=
[]
struct
{
name
string
name
string
replicaset
*
extension
s
.
ReplicaSet
replicaset
*
app
s
.
ReplicaSet
filteredPods
[]
*
v1
.
Pod
filteredPods
[]
*
v1
.
Pod
manageReplicasErr
error
manageReplicasErr
error
expectedReplicaSetConditions
[]
extension
s
.
ReplicaSetCondition
expectedReplicaSetConditions
[]
app
s
.
ReplicaSetCondition
}{
}{
{
{
...
@@ -172,9 +172,9 @@ func TestCalculateStatusConditions(t *testing.T) {
...
@@ -172,9 +172,9 @@ func TestCalculateStatusConditions(t *testing.T) {
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
,
true
),
},
},
fmt
.
Errorf
(
"fake manageReplicasErr"
),
fmt
.
Errorf
(
"fake manageReplicasErr"
),
[]
extension
s
.
ReplicaSetCondition
{
[]
app
s
.
ReplicaSetCondition
{
{
{
Type
:
extension
s
.
ReplicaSetReplicaFailure
,
Type
:
app
s
.
ReplicaSetReplicaFailure
,
Status
:
v1
.
ConditionTrue
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"FailedCreate"
,
Reason
:
"FailedCreate"
,
Message
:
"fake manageReplicasErr"
,
Message
:
"fake manageReplicasErr"
,
...
@@ -190,9 +190,9 @@ func TestCalculateStatusConditions(t *testing.T) {
...
@@ -190,9 +190,9 @@ func TestCalculateStatusConditions(t *testing.T) {
newPod
(
"pod3"
,
rs
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod3"
,
rs
,
v1
.
PodRunning
,
nil
,
true
),
},
},
fmt
.
Errorf
(
"fake manageReplicasErr"
),
fmt
.
Errorf
(
"fake manageReplicasErr"
),
[]
extension
s
.
ReplicaSetCondition
{
[]
app
s
.
ReplicaSetCondition
{
{
{
Type
:
extension
s
.
ReplicaSetReplicaFailure
,
Type
:
app
s
.
ReplicaSetReplicaFailure
,
Status
:
v1
.
ConditionTrue
,
Status
:
v1
.
ConditionTrue
,
Reason
:
"FailedDelete"
,
Reason
:
"FailedDelete"
,
Message
:
"fake manageReplicasErr"
,
Message
:
"fake manageReplicasErr"
,
...
@@ -215,9 +215,9 @@ func TestCalculateStatusConditions(t *testing.T) {
...
@@ -215,9 +215,9 @@ func TestCalculateStatusConditions(t *testing.T) {
newPod
(
"pod1"
,
replicaFailureRS
,
v1
.
PodRunning
,
nil
,
true
),
newPod
(
"pod1"
,
replicaFailureRS
,
v1
.
PodRunning
,
nil
,
true
),
},
},
fmt
.
Errorf
(
"fake manageReplicasErr"
),
fmt
.
Errorf
(
"fake manageReplicasErr"
),
[]
extension
s
.
ReplicaSetCondition
{
[]
app
s
.
ReplicaSetCondition
{
{
{
Type
:
extension
s
.
ReplicaSetReplicaFailure
,
Type
:
app
s
.
ReplicaSetReplicaFailure
,
Status
:
v1
.
ConditionTrue
,
Status
:
v1
.
ConditionTrue
,
},
},
},
},
...
...
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