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

Use jq --compact-output option in the binding update command #6843

Merged
merged 3 commits into from
Oct 18, 2022

Conversation

shafeeqes
Copy link
Contributor

@shafeeqes shafeeqes commented Oct 17, 2022

How to categorize this PR?

/area control-plane-migration
/kind bug

What this PR does / why we need it:
After #6727, the command

kubectl -n ${NAMESPACE} get shoot ${SHOOT_NAME} -o json | jq -c '.spec.seedName = "<destination-seed>"' | kubectl replace --raw /apis/core.gardener.cloud/v1beta1/namespaces/${NAMESPACE}/shoots/${SHOOT_NAME}/binding -f - | jq -r '.spec.seedName'

throws error:

Error from server (Forbidden): shoots.core.gardener.cloud "shoot" is forbidden: only spec.seedName can be changed using the binding subresource when the shoot is being rescheduled to a new seed

After checking what's the spec change, it's only how it is represented by jq.
This PR adds -c or --compact-output to the jq command, so that the expected and provided format remains same.

I have also added a validation to reject the update of binding if seedName is same.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
/cc @plkokanov

Release note:

The documentation for triggering control-plane migration is updated with a slight change.

@gardener-prow gardener-prow bot added area/control-plane-migration Control plane migration related kind/bug Bug cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 17, 2022
@shafeeqes shafeeqes marked this pull request as draft October 17, 2022 11:01
@gardener-prow gardener-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 17, 2022
@plkokanov
Copy link
Contributor

After digging some more, jq was not the only thing that was causing the problem. Here's a more detailed description of what was happening and why the updated was rejected by the admission plugin:
There are fields in the shoot which are of type RawExtension. These fields will be represented as []byte arrays containing (most likely) some json data and the keys in that data might not be sorted. Additionally that data does not contain any new line characters.
However, when you retrieve the shoot via kubectl get shoot -o json the json output will sort all keys and properly format the json output with new lines so that the output is easier to read. This also includes json objects that are in the RawExtension fields.
When the shoot is reapplied with kubectl replace --raw, the sorted json object with the new lines will be passed to the apiserver which means that the []byte RawExtensions will get populated with the passed-in data directly - containing sorted keys and new lines. This will differ from the []byte array that of the old object has during the admission checks and therefore the update will be forbidden.

Using jq -c is not enough due to the sorted keys retrieved when calling kubectl get ... -o json. Instead the following command should do the trick:

kubectl get --raw /apis/core.gardener.cloud/v1beta1/namespaces/${NAMESPACE}/shoots/${SHOOT_NAME} | jq -c '.spec.seedName = "<destination-seed>"' | kubectl replace --raw /apis/core.gardener.cloud/v1beta1/namespaces/${NAMESPACE}/shoots/${SHOOT_NAME}/binding -f - | jq -r '.spec.seedName'

@gardener-prow gardener-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 18, 2022
@shafeeqes shafeeqes marked this pull request as ready for review October 18, 2022 03:48
@gardener-prow gardener-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 18, 2022
@gardener-prow
Copy link
Contributor

gardener-prow bot commented Oct 18, 2022

@shafeeqes: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-gardener-check-vulnerabilities 238f6fa link false /test pull-gardener-check-vulnerabilities

Full PR test history. Your PR dashboard. Command help for this repository.
Please help us cut down on flakes by linking this test failure to an open flake report or filing a new flake report if you can't find an existing one. Also see our testing guideline for how to avoid and hunt flakes.

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. I understand the commands that are listed here.

@plkokanov
Copy link
Contributor

Thanks!

/lgtm
/approve

@gardener-prow gardener-prow bot added the lgtm Indicates that a PR is ready to be merged. label Oct 18, 2022
@gardener-prow
Copy link
Contributor

gardener-prow bot commented Oct 18, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: plkokanov

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

@gardener-prow gardener-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 18, 2022
@gardener-prow gardener-prow bot merged commit 40b0bf1 into gardener:master Oct 18, 2022
@shafeeqes shafeeqes deleted the fix/binding branch October 18, 2022 08:02
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. area/control-plane-migration Control plane migration related cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. kind/bug Bug lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants