-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add migrate command for legacy HPAs #18517
Conversation
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. |
/cc @enj our resident migrate expert |
@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:
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. |
@enj any feedback? |
@derekwaynecarr any feedback? |
In verify-imports
Need to update generated completions and docs as well. |
Kind string | ||
} | ||
|
||
func (vk versionKind) GroupVersionKind() (schema.GroupVersionKind, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 😉
Been on PTO, still catching up. Will look shortly. |
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ==
or deep equal.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
54bb08a
to
4e9b329
Compare
@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. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
733aa58
to
1df1296
Compare
Test failed with
|
# 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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong name?
1df1296
to
e6b35ca
Compare
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.
e6b35ca
to
da442d5
Compare
/retest |
/approve Deferring LGTM to anyone who knows if we are supposed to be merging stuff or waiting until 3.10 branch. |
/retest |
/approve |
/refresh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[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 |
Master is open for 3.10 |
Pretty sure this is required for 3.9 as well. Cherrypick? |
/cherrypick release-3.9 |
@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:
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. |
/retest |
Automatic merge from submit-queue (batch tested with PRs 18666, 18810, 18430, 18517, 18653). |
@deads2k: new pull request created: #18854 In response to this:
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. |
…-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
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 |
There are current broken HPAs floating around that either use the legacy
oapi DeploymentConfig defintion (
v1.DeploymentConfig
) or the incorrectAPI group, due to the webconsole (all scalables, but with the group as
extensions/v1beta1
). This introduces a migrate command that correctsthe 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