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

client-go/testing: Can't list deployments after scaling #734

Closed
lynx-coding opened this issue Jan 8, 2020 · 5 comments
Closed

client-go/testing: Can't list deployments after scaling #734

lynx-coding opened this issue Jan 8, 2020 · 5 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@lynx-coding
Copy link

What happened:
I wanted to test my method to scale deployments. But after changing the replicas by using updateScale I was not able to list deployments anymore.

What you expected to happen:

  • create fake api
  • create mock deployment
  • scale it
  • list it

How to reproduce it (as minimally and precisely as possible):

  • create fake api
  • create a mock deployment
  • scale the deployment
  • list the deployment

Anything else we need to know?:

package scaling

import (
    "testing"

    v1api "k8s.io/api/apps/v1"
    autoscalingv1 "k8s.io/api/autoscaling/v1"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    "k8s.io/client-go/kubernetes/fake"

    "github.com/stretchr/testify/require"
)

func TestScaling(t *testing.T) {
    initialReplicas := int32(3)
    cs := fake.NewSimpleClientset()
    _, err := cs.AppsV1().Deployments("test-namespace").Create(&v1api.Deployment{
        ObjectMeta: metav1.ObjectMeta{
            Name: "test-deployment",
            Labels: map[string]string{
                "app": "test-app",
            },
        },
        Spec: v1api.DeploymentSpec{
            Replicas: &initialReplicas,
        },
    })
    require.NoError(t, err)
    scale := &autoscalingv1.Scale{
        ObjectMeta: metav1.ObjectMeta{
            Name:      "test-deployment",
            Namespace: "test-namespace",
        },
        Spec: autoscalingv1.ScaleSpec{
            Replicas: 5,
        },
    }
    _, err = cs.AppsV1().Deployments("test-namespace").UpdateScale("test-deployment", scale)
    require.NoError(t, err)
    _, err = cs.AppsV1().Deployments("test-namespace").List(metav1.ListOptions{FieldSelector: "app=test-app"})
    require.NoError(t, err)
}

Run like this:

go test -run TestScaling ./scaling

This will lead to an error like the following:

item[0]: can't assign or convert v1.Scale into v1.Deployment

Environment:

  • go version: go1.13.5 linux/amd64
  • client-go version: k8s.io/client-go@v0.16.4
  • related issue(s)/pr(s):
@chrisseto
Copy link

I'm also encountering this issue with Statefulsets.

@lynx-coding have you had any luck with tracking down a fix or work around?

From digging around a bit, it looks like Scale is a psuedo resource rather than a true subresource which may be the cause for issues?

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 24, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 23, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants