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

🐛 topology: use raw input object for patch calculation in WalkTemplates #10912

Merged

Conversation

chrischdi
Copy link
Member

What this PR does / why we need it:

This PR adjusts the WalkTemplates function provided for runtime extensions to use the original input struct to calculate patches.

Before it did use the typed objects to marshal them and create the patch.
This could lead to invalid patches because the Go struct may have fields which the original input did not have.

Example for VSphereClusterTemplate from here: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/blob/main/apis/v1beta1/vsphereclustertemplate_types.go#L33

Consider the following input from the patch request (the template referred by the ClusterClass):

{
  "apiVersion": "vmware.infrastructure.cluster.x-k8s.io/v1beta1",
  "kind": "VSphereClusterTemplate",
  "metadata": {
    "name": "quick-start-supervisor",
    "namespace": "k8s-upgrade-with-runtimesdk-csmelk",
  },
  "spec": {
    "template": {
      "spec": {}
    }
  }
}

decoding and marshalling again made the following out of it:

{
  "apiVersion": "vmware.infrastructure.cluster.x-k8s.io/v1beta1",
  "kind": "VSphereClusterTemplate",
  "metadata": {
    "name": "quick-start-supervisor",
    "namespace": "k8s-upgrade-with-runtimesdk-csmelk",
  },
  "spec": {
    "template": {
      "spec": {
        "controlPlaneEndpoint": {
          "host": "",
          "port": 0
        }
      }
    }
  }
}

Now we calculate the patch based on the following:

{
  "apiVersion": "vmware.infrastructure.cluster.x-k8s.io/v1beta1",
  "kind": "VSphereClusterTemplate",
  "metadata": {
    "name": "quick-start-supervisor",
    "namespace": "k8s-upgrade-with-runtimesdk-csmelk",
  },
  "spec": {
    "template": {
      "spec": {
        "controlPlaneEndpoint": {
          "host": "1.1.1.1",
          "port": 6443
        }
      }
    }
  }
}

The old behaviour would have created the following patch:

[
  {
    "op": "replace",
    "path": "/spec/template/spec/controlPlaneEndpoint/host",
    "value": "1.1.1.1"
  },
  {
    "op": "replace",
    "path": "/spec/template/spec/controlPlaneEndpoint/port",
    "value": 30000
  }
]

This patch would fail in CAPI to get applied to the template with following error:

error computing the desired state of the Cluster topology: failed to apply patches: failed to apply patches for patch "test-patch": failed to apply patch: error applying json patch (RFC6902): replace operation does not apply: do
c is missing path: /spec/template/spec/controlPlaneEndpoint/host: missing value

The new behaviour would create the following patch, which would work:

[
  {
    "op": "add",
    "path": "/spec/template/spec/controlPlaneEndpoint",
    "value": {
      "host": "1.1.1.1",
      "port": 6443
    },
  }
]

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 #

/area runtime-sdk

@k8s-ci-robot k8s-ci-robot added area/runtime-sdk Issues or PRs related to Runtime SDK cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 19, 2024
@chrischdi
Copy link
Member Author

/assign @fabriziopandini @sbueringer

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 19, 2024
@chrischdi
Copy link
Member Author

/test help

@k8s-ci-robot
Copy link
Contributor

@chrischdi: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-build-main
  • /test pull-cluster-api-e2e-blocking-main
  • /test pull-cluster-api-e2e-conformance-ci-latest-main
  • /test pull-cluster-api-e2e-conformance-main
  • /test pull-cluster-api-e2e-main
  • /test pull-cluster-api-e2e-mink8s-main
  • /test pull-cluster-api-e2e-upgrade-1-30-1-31-main
  • /test pull-cluster-api-test-main
  • /test pull-cluster-api-test-mink8s-main
  • /test pull-cluster-api-verify-main

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-apidiff-main

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-apidiff-main
  • pull-cluster-api-build-main
  • pull-cluster-api-e2e-blocking-main
  • pull-cluster-api-test-main
  • pull-cluster-api-verify-main

In response to this:

/test help

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-sigs/prow repository.

@chrischdi
Copy link
Member Author

/test pull-cluster-api-e2e-main

@sbueringer
Copy link
Member

Thx!

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: 75cb9509c476eb5d2eeb995bd88f830866b838ce

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Jul 22, 2024
@k8s-ci-robot k8s-ci-robot merged commit 248ce59 into kubernetes-sigs:main Jul 22, 2024
23 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.8 milestone Jul 22, 2024
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/runtime-sdk Issues or PRs related to Runtime SDK 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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants