kubernetes-sigs / kubebuilder-declarative-pattern

A toolkit for building declarative operators with kubebuilder
Apache License 2.0
257 stars 85 forks source link

Add a kubebuilder marker to patches to preserve unknow fields #390

Closed haiyanmeng closed 5 months ago

haiyanmeng commented 5 months ago

https://book.kubebuilder.io/reference/markers/crd-processing

Currently, a MOSS controller does not support patches correctly by default. For example, applying the following object would get an error strict decoding error: unknown field "spec.patches[0].apiVersion", unknown field "spec.patches[0].kind", unknown field "spec.patches[0].metadata", unknown field "spec.patches[0].spec".

apiVersion: configdelivery.gke.io/v1beta1
kind: ConfigSync
metadata:
  name: config-sync
spec:
  version: 1.16.1
  patches:
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: reconciler-manager
      namespace: config-management-system
    spec:
      template:
        spec:
          containers:
          - name: reconciler-manager
            resources:
              limits:
                memory: "1Gi"

To fix this, we need to add x-kubernetes-preserve-unknown-fields: true into the patches field of ConfigSync CRD:

              patches:
                items:
                  type: object
                type: array
                x-kubernetes-preserve-unknown-fields: true
k8s-ci-robot commented 5 months ago

Hi @haiyanmeng. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
tomasaschan commented 5 months ago

/ok-to-test

justinsb commented 5 months ago

Thank you @haiyanmeng

/approve /lgtm

k8s-ci-robot commented 5 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haiyanmeng, justinsb, tomasaschan

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: - ~~[OWNERS](https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/OWNERS)~~ [justinsb] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment