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

Add migrate command for legacy HPAs #18517

Conversation

DirectXMan12
Copy link
Contributor

There are current broken HPAs floating around that either use the legacy
oapi DeploymentConfig defintion (v1.DeploymentConfig) or the incorrect
API group, due to the webconsole (all scalables, but with the group as
extensions/v1beta1). This introduces a migrate command that corrects
the ScaleTargetRef of those HPAs to have correct API groups that are
usable by generic scale clients.

Related to #18377, #18380, openshift/origin-web-console#2776

cc @deads2k @liggitt @spadgett

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 7, 2018
@DirectXMan12
Copy link
Contributor Author

I'd like to also add the capability to automatically migrate arbitrary ScaleTargetRefs to the equivalent preferred version to make deprecation of scalable APIs easier, but I figured this is a good start.

@deads2k
Copy link
Contributor

deads2k commented Feb 8, 2018

/cc @enj our resident migrate expert

@openshift-ci-robot
Copy link

@deads2k: GitHub didn't allow me to request PR reviews from the following users: our, resident, migrate, expert.

Note that only openshift members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @enj our resident migrate expert

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.

@sjenning sjenning added the kind/bug Categorizes issue or PR as related to a bug. label Feb 9, 2018
@aveshagarwal
Copy link
Contributor

@enj any feedback?

@aveshagarwal
Copy link
Contributor

@derekwaynecarr any feedback?

@sjenning
Copy link
Contributor

In verify-imports

2018/02/07 22:19:29 Inspecting imports under github.com/openshift/origin/pkg/oc...
2018/02/07 22:19:32 -- validating imports for 111 packages in the tree
2018/02/07 22:19:32 -- found forbidden imports for github.com/openshift/origin/pkg/oc/admin/migrate/legacyhpa:
2018/02/07 22:19:32 	vendor/github.com/stretchr/testify/assert

Need to update generated completions and docs as well.

Kind string
}

func (vk versionKind) GroupVersionKind() (schema.GroupVersionKind, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace that with just schema.FromAPIVersionAndKind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this any more, but the reason that I didn't is because I wanted the error, not to have it fail silently

{"v1", "DeploymentConfig"}: {"apps.openshift.io/v1", "DeploymentConfig"},

// webconsole shenaniganry
{"extensions/v1beta1", "DeploymentConfig"}: {"apps.openshift.io/v1", "DeploymentConfig"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say what? That should never happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The web console was trying to target the scale subresource in the extensions/v1beta1 group (I think based on an earlier HPA API version), but the subresource was getting dropped. So it unfortunately got set as extensions/v1beta1.DeploymentConfig.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭

{"extensions/v1beta1", "DeploymentConfig"}: {"apps.openshift.io/v1", "DeploymentConfig"},
{"extensions/v1beta1", "Deployment"}: {"apps/v1", "Deployment"},
{"extensions/v1beta1", "ReplicaSet"}: {"apps/v1", "ReplicaSet"},
{"extensions/v1beta1", "ReplicationController"}: {"v1", "ReplicationController"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

func (o *MigrateLegacyHPAOptions) checkAndTransform(hpaRaw runtime.Object) (migrate.Reporter, error) {
var hpa *autoscaling.HorizontalPodAutoscaler
var wasHPA bool
if hpa, wasHPA = hpaRaw.(*autoscaling.HorizontalPodAutoscaler); !wasHPA {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version seems more readable and saves precious keystrokes:

hpa, wasHPA := hpaRaw.(*autoscaling.HorizontalPodAutoscaler)
if !wasHPA {
...

func (o *MigrateLegacyHPAOptions) save(info *resource.Info, reporter migrate.Reporter) error {
var hpa *autoscaling.HorizontalPodAutoscaler
var wasHPA bool
if hpa, wasHPA = info.Object.(*autoscaling.HorizontalPodAutoscaler); !wasHPA {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark wrt precious keystrokes 😉

@enj
Copy link
Contributor

enj commented Feb 13, 2018

@enj any feedback?

Been on PTO, still catching up. Will look shortly.

Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of little things need fixing. Agree with all the changes @soltysh suggested.

import (
"testing"

"github.com/stretchr/testify/assert"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use == or deep equal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm? What's wrong with testify?


"github.com/stretchr/testify/assert"

autoscaling "k8s.io/kubernetes/pkg/apis/autoscaling"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the unused name.

%[1]s --initial=v1.DeploymentConfig --final=apps.openshift.io/v1.DeploymentConfig --confirm`)
)

func prettyPrintMigrations(versionKinds map[versionKind]versionKind) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to do sorting so the output is stable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return strings.Join(lines, "\n")
}

type versionKind struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh this is just the TypeMeta struct, so just use that instead.

}

func (o *MigrateLegacyHPAOptions) Bind(c *cobra.Command) {
o.ResourceOptions.Bind(c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call this in NewCmdMigrateLegacyHPA and drop the Bind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. Used to have more options here -- simplified and forgot to strip it off

ErrOut: errout,

AllNamespaces: true,
Include: []string{"horizontalpodautoscalers.autoscaling"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add validation that prevents this include from being changed via the options that are binded to this command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return migrate.ReporterBool(false), nil
}

func (o *MigrateLegacyHPAOptions) latestVersionKind(current versionKind) (versionKind, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just return a TypeMeta since it cannot error.

return fmt.Errorf("unrecognized object %#v", info.Object)
}

updatedHPA, err := o.hpaClient.HorizontalPodAutoscalers(hpa.Namespace).Update(hpa)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be:

_, err := o.hpaClient.HorizontalPodAutoscalers(hpa.Namespace).Update(hpa)
return migrate.DefaultRetriable(info, err)

There is no reason to refresh the info or check the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

@DirectXMan12
Copy link
Contributor Author

@enj comments addressed, except for the testify one. For future reference, what's wrong with just using testify?

@enj
Copy link
Contributor

enj commented Feb 27, 2018

@enj comments addressed, except for the testify one. For future reference, what's wrong with just using testify?

That is a kube only depedency. Using it here turns in into an OpenShift dependency. We are actively trying to remove dependencies (and not add new ones), and we do not use that anywhere else in OS (hence the angry message from verify imports). Please remove it.

Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DirectXMan12 can you add a simple CLI test that migrate one "old" HPA to a "new" HPA. Doesn't need to be fancy, just enough to fail if the command doesn't work at all.

migrate.ResourceOptions
}

func (o *MigrateLegacyHPAOptions) Bind(c *cobra.Command) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to delete this.

@DirectXMan12 DirectXMan12 force-pushed the feature/migrate-oapi-hpa branch 2 times, most recently from 733aa58 to 1df1296 Compare February 28, 2018 22:06
@sjenning
Copy link
Contributor

sjenning commented Mar 1, 2018

Test failed with

Error from server (AlreadyExists): error when creating "test/testdata/hpa/legacy-and-normal-hpa.yaml": horizontalpodautoscalers.autoscaling "legacy-hpa" already exists

# create a legacy and a normal HPA
os::cmd::expect_success 'oc create -f test/testdata/hpa/legacy-and-normal-hpa.yaml'
# verify dry run
os::cmd::expect_success_and_text 'oc adm migrate legacy-hpa' 'migrated=1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you also need to run once with --confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, whoops

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: legacy-hpa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong name?

There are current broken HPAs floating around that either use the legacy
oapi DeploymentConfig defintion (`v1.DeploymentConfig`) or the incorrect
API group, due to the webconsole (all scalables, but with the group as
`extensions/v1beta1`).  This introduces a migrate command that corrects
the ScaleTargetRef of those HPAs to have correct API groups that are
usable by generic scale clients.
@DirectXMan12
Copy link
Contributor Author

/retest

@enj
Copy link
Contributor

enj commented Mar 2, 2018

/approve

Deferring LGTM to anyone who knows if we are supposed to be merging stuff or waiting until 3.10 branch.

@DirectXMan12
Copy link
Contributor Author

/retest

@enj
Copy link
Contributor

enj commented Mar 4, 2018

/approve
/retest

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2018
@enj
Copy link
Contributor

enj commented Mar 4, 2018

/refresh

Copy link
Member

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 5, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12, enj, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@soltysh
Copy link
Member

soltysh commented Mar 5, 2018

Deferring LGTM to anyone who knows if we are supposed to be merging stuff or waiting until 3.10 branch.

Master is open for 3.10
/retest

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

Deferring LGTM to anyone who knows if we are supposed to be merging stuff or waiting until 3.10 branch.

Pretty sure this is required for 3.9 as well. Cherrypick?

@deads2k
Copy link
Contributor

deads2k commented Mar 5, 2018

/cherrypick release-3.9

@openshift-cherrypick-robot

@deads2k: once the present PR merges, I will cherry-pick it on top of release-3.9 in a new PR and assign it to you.

In response to this:

/cherrypick release-3.9

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.

@sjenning
Copy link
Contributor

sjenning commented Mar 5, 2018

/retest

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 18666, 18810, 18430, 18517, 18653).

@openshift-merge-robot openshift-merge-robot merged commit f2c2c9c into openshift:master Mar 6, 2018
@openshift-cherrypick-robot

@deads2k: new pull request created: #18854

In response to this:

/cherrypick release-3.9

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.

@DirectXMan12 DirectXMan12 deleted the feature/migrate-oapi-hpa branch March 6, 2018 18:53
openshift-merge-robot added a commit that referenced this pull request Mar 8, 2018
…-18517-to-release-3.9

Automatic merge from submit-queue.

[release-3.9] Add migrate command for legacy HPAs

This is an automated cherry-pick of #18517

/assign deads2k
@liggitt
Copy link
Contributor

liggitt commented Mar 27, 2018

@deads2k
Copy link
Contributor

deads2k commented Mar 27, 2018

does this let us drop https://github.com/openshift/kubernetes/blob/release-1.9.1/pkg/controller/podautoscaler/patch_dc.go in 3.10?

No. You could still create them from an old manifest unless we decide to break backward compatibility or carry a different patch on the kube-apiserver to rewrite the data instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet