Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pet Set] petset internal replicas type should be int32 #33160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/apis/apps/types.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apps/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/apps/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions pkg/apis/apps/v1alpha1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/petset/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/petset/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/petset/pet_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/petset/pet_set_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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
for i, ps := 0, &ps; ; i++ {
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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 9 additions & 8 deletions test/e2e/petset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -593,15 +594,15 @@ 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 })

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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down