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

✨ Allow JSON merge patches for provider manifests #280

Merged
merged 5 commits into from
Nov 7, 2023

Conversation

alexander-demicev
Copy link
Contributor

@alexander-demicev alexander-demicev commented Oct 13, 2023

What this PR does / why we need it:
Allow JSON merge patches for provider manifests, this makes it possible to modify provider manifests consistently across releases, for example, if the user needs to change labels/annotations on objects, example usage:

---
apiVersion: operator.cluster.x-k8s.io/v1alpha2
kind: CoreProvider
metadata:
  name: cluster-api
  namespace: capi-system
spec:
  resourcePatches:
    - |
apiVersion: v1
kind: Service
metadata:
labels:
    test-label: test-value

As a result of this patch, all services from this provider will get an additional label. There also filtering based on API version, namespace, and name, all described in the docs update.

Code for applying patches is similar to kind https://github.com/kubernetes-sigs/kind/tree/main/pkg/internal/patch but modified for usage in CAPI operator

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 13, 2023
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 13, 2023
@alexander-demicev
Copy link
Contributor Author

@damdo this might also be interesting to you

@alexander-demicev alexander-demicev force-pushed the jsonpatches branch 3 times, most recently from cfe28fc to 522a16b Compare October 15, 2023 18:22
Copy link
Member

@furkatgofurov7 furkatgofurov7 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @alexander-demicev!

Few suggestions inline from my side:

api/v1alpha2/provider_types.go Outdated Show resolved Hide resolved
@@ -164,7 +240,16 @@ func (dst *InfrastructureProvider) ConvertFrom(srcRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.InfrastructureProvider")
}

return Convert_v1alpha2_InfrastructureProvider_To_v1alpha1_InfrastructureProvider(src, dst, nil)
if err := Convert_v1alpha2_InfrastructureProvider_To_v1alpha1_InfrastructureProvider(src, dst, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

looks like we do not have a conversion for addon provider? Is it because that was introduced in v1alpha2?

Copy link
Contributor Author

@alexander-demicev alexander-demicev Oct 23, 2023

Choose a reason for hiding this comment

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

no, we don't have addons in v1alpha1

Copy link
Member

Choose a reason for hiding this comment

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

yeah that is what I actually meant as well

internal/patch/mergepatch.go Outdated Show resolved Hide resolved
internal/patch/patch.go Outdated Show resolved Hide resolved
Comment on lines +110 to +112
- kind: ServiceAccount
name: serviceaccount-name
namespace: namespace-name
Copy link
Member

Choose a reason for hiding this comment

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

probably you don't need this as it is already in the testObjectsToPatchYaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

list of service accounts is an array so when merging it erases all previous values instead of appending

internal/patch/resource.go Outdated Show resolved Hide resolved
api/v1alpha2/provider_types.go Outdated Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
docs/README.md Show resolved Hide resolved
@alexander-demicev alexander-demicev force-pushed the jsonpatches branch 2 times, most recently from b69f7cf to 392746f Compare October 23, 2023 12:31
@alexander-demicev
Copy link
Contributor Author

/retest

Copy link
Contributor

@Fedosin Fedosin left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Fedosin

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 27, 2023
Signed-off-by: alexander-demicev <[email protected]>
@k8s-ci-robot
Copy link
Contributor

@alexander-demicev: 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-cluster-api-operator-apidiff-main 2fdc32d link false /test pull-cluster-api-operator-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

Copy link
Contributor

@Fedosin Fedosin left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 91ac7ab0f24dea11cd5ef7edd757d7b5ad37980c

@k8s-ci-robot k8s-ci-robot merged commit 4523f38 into kubernetes-sigs:main Nov 7, 2023
8 of 10 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants