change petset replicas type from int to int32

Change-Id: I0b8c30083e4a221421de46d9d4dcb21b1f5bb36f
pull/6/head
m1093782566 2016-09-19 22:12:16 +08:00
parent 46c009952d
commit fd47b6d4d1
10 changed files with 33 additions and 28 deletions

View File

@ -639,7 +639,7 @@ func (x *PetSetSpec) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() {
x.Replicas = 0
} else {
x.Replicas = int(r.DecodeInt(codecSelferBitsize1234))
x.Replicas = int32(r.DecodeInt(32))
}
case "selector":
if r.TryDecodeAsNil() {
@ -711,7 +711,7 @@ func (x *PetSetSpec) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() {
x.Replicas = 0
} else {
x.Replicas = int(r.DecodeInt(codecSelferBitsize1234))
x.Replicas = int32(r.DecodeInt(32))
}
yyj59++
if yyhl59 {
@ -977,7 +977,7 @@ func (x *PetSetStatus) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() {
x.Replicas = 0
} else {
x.Replicas = int(r.DecodeInt(codecSelferBitsize1234))
x.Replicas = int32(r.DecodeInt(32))
}
default:
z.DecStructFieldNotFound(-1, yys79)
@ -1033,7 +1033,7 @@ func (x *PetSetStatus) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() {
x.Replicas = 0
} else {
x.Replicas = int(r.DecodeInt(codecSelferBitsize1234))
x.Replicas = int32(r.DecodeInt(32))
}
for {
yyj83++

View File

@ -49,7 +49,7 @@ type PetSetSpec struct {
// same Template, but individual replicas also have a consistent identity.
// If unspecified, defaults to 1.
// TODO: Consider a rename of this field.
Replicas int `json:"replicas,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
// Selector is a label query over pods that should match the replica count.
// If empty, defaulted to labels on the pod template.
@ -85,7 +85,7 @@ type PetSetStatus struct {
ObservedGeneration *int64 `json:"observedGeneration,omitempty"`
// Replicas is the number of actual replicas.
Replicas int `json:"replicas"`
Replicas int32 `json:"replicas"`
}
// PetSetList is a collection of PetSets.

View File

@ -28,7 +28,7 @@ import (
)
func addConversionFuncs(scheme *runtime.Scheme) error {
// Add non-generated conversion functions to handle the *int32 -> int
// Add non-generated conversion functions to handle the *int32 -> int32
// conversion. A pointer is useful in the versioned type so we can default
// it, but a plain int32 is more convenient in the internal type. These
// functions are the same as the autogenerated ones in every other way.
@ -54,7 +54,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
func Convert_v1alpha1_PetSetSpec_To_apps_PetSetSpec(in *PetSetSpec, out *apps.PetSetSpec, s conversion.Scope) error {
if in.Replicas != nil {
out.Replicas = int(*in.Replicas)
out.Replicas = *in.Replicas
}
if in.Selector != nil {
in, out := &in.Selector, &out.Selector
@ -85,7 +85,7 @@ func Convert_v1alpha1_PetSetSpec_To_apps_PetSetSpec(in *PetSetSpec, out *apps.Pe
func Convert_apps_PetSetSpec_To_v1alpha1_PetSetSpec(in *apps.PetSetSpec, out *PetSetSpec, s conversion.Scope) error {
out.Replicas = new(int32)
*out.Replicas = int32(in.Replicas)
*out.Replicas = in.Replicas
if in.Selector != nil {
in, out := &in.Selector, &out.Selector
*out = new(unversioned.LabelSelector)

View File

@ -141,7 +141,9 @@ func Convert_apps_PetSetList_To_v1alpha1_PetSetList(in *apps.PetSetList, out *Pe
}
func autoConvert_v1alpha1_PetSetSpec_To_apps_PetSetSpec(in *PetSetSpec, out *apps.PetSetSpec, s conversion.Scope) error {
// WARNING: in.Replicas requires manual conversion: inconvertible types (*int32 vs int)
if err := api.Convert_Pointer_int32_To_int32(&in.Replicas, &out.Replicas, s); err != nil {
return err
}
out.Selector = in.Selector
if err := v1.Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
return err
@ -163,7 +165,9 @@ func autoConvert_v1alpha1_PetSetSpec_To_apps_PetSetSpec(in *PetSetSpec, out *app
}
func autoConvert_apps_PetSetSpec_To_v1alpha1_PetSetSpec(in *apps.PetSetSpec, out *PetSetSpec, s conversion.Scope) error {
// WARNING: in.Replicas requires manual conversion: inconvertible types (int vs *int32)
if err := api.Convert_int32_To_Pointer_int32(&in.Replicas, &out.Replicas, s); err != nil {
return err
}
out.Selector = in.Selector
if err := v1.Convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
return err
@ -186,7 +190,7 @@ func autoConvert_apps_PetSetSpec_To_v1alpha1_PetSetSpec(in *apps.PetSetSpec, out
func autoConvert_v1alpha1_PetSetStatus_To_apps_PetSetStatus(in *PetSetStatus, out *apps.PetSetStatus, s conversion.Scope) error {
out.ObservedGeneration = in.ObservedGeneration
out.Replicas = int(in.Replicas)
out.Replicas = in.Replicas
return nil
}
@ -196,7 +200,7 @@ func Convert_v1alpha1_PetSetStatus_To_apps_PetSetStatus(in *PetSetStatus, out *a
func autoConvert_apps_PetSetStatus_To_v1alpha1_PetSetStatus(in *apps.PetSetStatus, out *PetSetStatus, s conversion.Scope) error {
out.ObservedGeneration = in.ObservedGeneration
out.Replicas = int32(in.Replicas)
out.Replicas = in.Replicas
return nil
}

View File

@ -84,7 +84,7 @@ func newPetSetWithVolumes(replicas int, name string, petMounts []api.VolumeMount
Selector: &unversioned.LabelSelector{
MatchLabels: map[string]string{"foo": "bar"},
},
Replicas: replicas,
Replicas: int32(replicas),
Template: api.PodTemplateSpec{
Spec: api.PodSpec{
Containers: []api.Container{

View File

@ -111,7 +111,7 @@ type petSetIterator struct {
// errs is a list because we always want the iterator to drain.
errs []error
// petCount is the number of pets iterated over.
petCount int
petCount int32
}
// Next returns true for as long as there are elements in the underlying queue.

View File

@ -88,7 +88,7 @@ func scalePetSet(t *testing.T, ps *apps.PetSet, psc *PetSetController, fc *fakeP
}
func saturatePetSet(t *testing.T, ps *apps.PetSet, psc *PetSetController, fc *fakePetClient) {
err := scalePetSet(t, ps, psc, fc, ps.Spec.Replicas)
err := scalePetSet(t, ps, psc, fc, int(ps.Spec.Replicas))
if err != nil {
t.Errorf("Error scalePetSet: %v", err)
}
@ -302,7 +302,7 @@ func (c *fakeApps) PetSets(namespace string) unversioned.PetSetInterface {
type fakePetSetClient struct {
*fake.FakePetSets
Namespace string
replicas int
replicas int32
}
func (f *fakePetSetClient) UpdateStatus(petSet *apps.PetSet) (*apps.PetSet, error) {

View File

@ -45,7 +45,7 @@ func (o overlappingPetSets) Less(i, j int) bool {
// updatePetCount attempts to update the Status.Replicas of the given PetSet, with a single GET/PUT retry.
func updatePetCount(psClient appsclientset.PetSetsGetter, ps apps.PetSet, numPets int) (updateErr error) {
if ps.Status.Replicas == numPets || psClient == nil {
if ps.Status.Replicas == int32(numPets) || psClient == nil {
return nil
}
var getErr error
@ -53,7 +53,7 @@ func updatePetCount(psClient appsclientset.PetSetsGetter, ps apps.PetSet, numPet
glog.V(4).Infof(fmt.Sprintf("Updating replica count for PetSet: %s/%s, ", ps.Namespace, ps.Name) +
fmt.Sprintf("replicas %d->%d (need %d), ", ps.Status.Replicas, numPets, ps.Spec.Replicas))
ps.Status = apps.PetSetStatus{Replicas: numPets}
ps.Status = apps.PetSetStatus{Replicas: int32(numPets)}
_, updateErr = psClient.PetSets(ps.Namespace).UpdateStatus(ps)
if updateErr == nil || i >= statusUpdateRetries {
return updateErr

View File

@ -344,7 +344,7 @@ func (scaler *PetSetScaler) ScaleSimple(namespace, name string, preconditions *S
return "", err
}
}
ps.Spec.Replicas = int(newSize)
ps.Spec.Replicas = int32(newSize)
updatedPetSet, err := scaler.c.PetSets(namespace).Update(ps)
if err != nil {
if errors.IsConflict(err) {

View File

@ -573,7 +573,8 @@ func (p *petSetTester) execInPets(ps *apps.PetSet, cmd string) error {
func (p *petSetTester) saturate(ps *apps.PetSet) {
// TODO: Watch events and check that creation timestamps don't overlap
for i := 0; i < ps.Spec.Replicas; i++ {
var i int32
for i = 0; i < ps.Spec.Replicas; i++ {
framework.Logf("Waiting for pet at index " + fmt.Sprintf("%v", i+1) + " to enter Running")
p.waitForRunning(i+1, ps)
framework.Logf("Marking pet at index " + fmt.Sprintf("%v", i) + " healthy")
@ -593,7 +594,7 @@ func (p *petSetTester) deletePetAtIndex(index int, ps *apps.PetSet) {
}
}
func (p *petSetTester) scale(ps *apps.PetSet, count int) error {
func (p *petSetTester) scale(ps *apps.PetSet, count int32) error {
name := ps.Name
ns := ps.Namespace
p.update(ns, name, func(ps *apps.PetSet) { ps.Spec.Replicas = count })
@ -601,7 +602,7 @@ func (p *petSetTester) scale(ps *apps.PetSet, count int) error {
var petList *api.PodList
pollErr := wait.PollImmediate(petsetPoll, petsetTimeout, func() (bool, error) {
petList = p.getPodList(ps)
if len(petList.Items) == count {
if int32(len(petList.Items)) == count {
return true, nil
}
return false, nil
@ -665,15 +666,15 @@ func (p *petSetTester) confirmPetCount(count int, ps *apps.PetSet, timeout time.
}
}
func (p *petSetTester) waitForRunning(numPets int, ps *apps.PetSet) {
func (p *petSetTester) waitForRunning(numPets int32, ps *apps.PetSet) {
pollErr := wait.PollImmediate(petsetPoll, petsetTimeout,
func() (bool, error) {
podList := p.getPodList(ps)
if len(podList.Items) < numPets {
if int32(len(podList.Items)) < numPets {
framework.Logf("Found %d pets, waiting for %d", len(podList.Items), numPets)
return false, nil
}
if len(podList.Items) > numPets {
if int32(len(podList.Items)) > numPets {
return false, fmt.Errorf("Too many pods scheduled, expected %d got %d", numPets, len(podList.Items))
}
for _, p := range podList.Items {
@ -712,7 +713,7 @@ func (p *petSetTester) setHealthy(ps *apps.PetSet) {
}
}
func (p *petSetTester) waitForStatus(ps *apps.PetSet, expectedReplicas int) {
func (p *petSetTester) waitForStatus(ps *apps.PetSet, expectedReplicas int32) {
ns, name := ps.Namespace, ps.Name
pollErr := wait.PollImmediate(petsetPoll, petsetTimeout,
func() (bool, error) {
@ -840,7 +841,7 @@ func newPVC(name string) api.PersistentVolumeClaim {
}
}
func newPetSet(name, ns, governingSvcName string, replicas int, petMounts []api.VolumeMount, podMounts []api.VolumeMount, labels map[string]string) *apps.PetSet {
func newPetSet(name, ns, governingSvcName string, replicas int32, petMounts []api.VolumeMount, podMounts []api.VolumeMount, labels map[string]string) *apps.PetSet {
mounts := append(petMounts, podMounts...)
claims := []api.PersistentVolumeClaim{}
for _, m := range petMounts {