ReplicaSet: Use apps/v1 for RS controller.

parent 7b8bc5db
...@@ -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 extensionslisters.ReplicaSetLister rsLister appslisters.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 extensionsinformers.ReplicaSetInformer, podInformer coreinformers.PodInformer, kubeClient clientset.Interface, burstReplicas int) *ReplicaSetController { func NewReplicaSetController(rsInformer appsinformers.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,
extensions.SchemeGroupVersion.WithKind("ReplicaSet"), apps.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 extensionsinformers.ReplicaSetInformer, podInformer coreinformers.PodInformer, kubeClient clientset.Interface, burstReplicas int, func NewBaseController(rsInformer appsinformers.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) []*extensions.ReplicaSet { func (rsc *ReplicaSetController) getPodReplicaSets(pod *v1.Pod) []*apps.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) *extensions.ReplicaSet { func (rsc *ReplicaSetController) resolveControllerRef(namespace string, controllerRef *metav1.OwnerReference) *apps.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.(*extensions.ReplicaSet) oldRS := old.(*apps.ReplicaSet)
curRS := cur.(*extensions.ReplicaSet) curRS := cur.(*apps.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 *extensions.ReplicaSet, or a DeletionFinalStateUnknown marker item. // obj could be an *apps.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 *extensions.ReplicaSet, or a DeletionFinalStateUnknown marker item. // obj could be an *apps.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 *extensions.ReplicaSet) error { func (rsc *ReplicaSetController) manageReplicas(filteredPods []*v1.Pod, rs *apps.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.ExtensionsV1beta1().ReplicaSets(rs.Namespace), rs, newStatus) updatedRS, err := updateReplicaSetStatus(rsc.kubeClient.AppsV1().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 *extensions.ReplicaSet, selector labels.Selector, filteredPods []*v1.Pod) ([]*v1.Pod, error) { func (rsc *ReplicaSetController) claimPods(rs *apps.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.ExtensionsV1beta1().ReplicaSets(rs.Namespace).Get(rs.Name, metav1.GetOptions{}) fresh, err := rsc.kubeClient.AppsV1().ReplicaSets(rs.Namespace).Get(rs.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -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/v1beta1" appsclient "k8s.io/client-go/kubernetes/typed/apps/v1"
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) (*extensions.ReplicaSet, error) { func updateReplicaSetStatus(c appsclient.ReplicaSetInterface, rs *apps.ReplicaSet, newStatus apps.ReplicaSetStatus) (*apps.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 *extensions.ReplicaSet var updatedRS *apps.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) extensions.ReplicaSetStatus { func calculateStatus(rs *apps.ReplicaSet, filteredPods []*v1.Pod, manageReplicasErr error) apps.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, extensions.ReplicaSetReplicaFailure) failureCond := GetCondition(rs.Status, apps.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(extensions.ReplicaSetReplicaFailure, v1.ConditionTrue, reason, manageReplicasErr.Error()) cond := NewReplicaSetCondition(apps.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, extensions.ReplicaSetReplicaFailure) RemoveCondition(&newStatus, apps.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) extensions.ReplicaSetCondition { func NewReplicaSetCondition(condType apps.ReplicaSetConditionType, status v1.ConditionStatus, reason, msg string) apps.ReplicaSetCondition {
return extensions.ReplicaSetCondition{ return apps.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) *extensions.ReplicaSetCondition { func GetCondition(status apps.ReplicaSetStatus, condType apps.ReplicaSetConditionType) *apps.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 extensions.ReplicaSetCondition) { func SetCondition(status *apps.ReplicaSetStatus, condition apps.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 extensions.ReplicaSetConditionType) { func RemoveCondition(status *apps.ReplicaSetStatus, condType apps.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) []extensions.ReplicaSetCondition { func filterOutCondition(conditions []apps.ReplicaSetCondition, condType apps.ReplicaSetConditionType) []apps.ReplicaSetCondition {
var newConditions []extensions.ReplicaSetCondition var newConditions []apps.ReplicaSetCondition
for _, c := range conditions { for _, c := range conditions {
if c.Type == condType { if c.Type == condType {
continue continue
......
...@@ -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 *extensions.ReplicaSet replicaset *apps.ReplicaSet
filteredPods []*v1.Pod filteredPods []*v1.Pod
expectedReplicaSetStatus extensions.ReplicaSetStatus expectedReplicaSetStatus apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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),
}, },
extensions.ReplicaSetStatus{ apps.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 = []extensions.ReplicaSetCondition{ replicaFailureRS.Status.Conditions = []apps.ReplicaSetCondition{
{ {
Type: extensions.ReplicaSetReplicaFailure, Type: apps.ReplicaSetReplicaFailure,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
}, },
} }
rsStatusConditionTests := []struct { rsStatusConditionTests := []struct {
name string name string
replicaset *extensions.ReplicaSet replicaset *apps.ReplicaSet
filteredPods []*v1.Pod filteredPods []*v1.Pod
manageReplicasErr error manageReplicasErr error
expectedReplicaSetConditions []extensions.ReplicaSetCondition expectedReplicaSetConditions []apps.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"),
[]extensions.ReplicaSetCondition{ []apps.ReplicaSetCondition{
{ {
Type: extensions.ReplicaSetReplicaFailure, Type: apps.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"),
[]extensions.ReplicaSetCondition{ []apps.ReplicaSetCondition{
{ {
Type: extensions.ReplicaSetReplicaFailure, Type: apps.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"),
[]extensions.ReplicaSetCondition{ []apps.ReplicaSetCondition{
{ {
Type: extensions.ReplicaSetReplicaFailure, Type: apps.ReplicaSetReplicaFailure,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment