From 1a33f1034762714183a629c73b38cac5d2bb31f2 Mon Sep 17 00:00:00 2001 From: Omar Farag Date: Mon, 31 Mar 2025 23:16:08 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=96=20add=20api/crd=20update=20doc=20(?= =?UTF-8?q?#913)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add api/crd update doc Signed-off-by: Omar Farag * make requested changes Signed-off-by: Omar Farag * Use command instead of editing file Co-authored-by: Jian Zhu Signed-off-by: Omar Farag --------- Signed-off-by: Omar Farag Co-authored-by: Jian Zhu --- CONTRIBUTING.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d66d5d59f..8fa4d535c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,7 @@ - [Prerequisites](#prerequisites) - [Setting up dev environment](#setting-up-dev-environment) - [Building Images](#building-images) + - [Making changes to the API and CRDs](#making-changes-to-the-api-and-crds) - [Testing the changes in the kind cluster](#testing-the-changes-in-the-kind-cluster) - [Integration tests](#integration-tests) - [E2E tests](#e2e-tests) @@ -143,6 +144,54 @@ After building the images, you can push them to the registry by docker/podman pu you can use the command `kind load docker-image quay.io/open-cluster-management/:test` to load the images into the kind cluster. +### Making changes to the API and CRDs + +In order to change Custom Resource Definitions and the API in [ocm](https://github.com/open-cluster-management-io/ocm), one needs to make changes to the [api](https://github.com/open-cluster-management-io/api) repository and then use them in the [ocm](https://github.com/open-cluster-management-io/ocm) repository. This section aims to walk you through these steps with an example. + + +1. Clone a fork of both ocm and api to your machine + ```shell + git clone git@github.com:/api.git + git clone git@github.com:/ocm.git + ``` + +2. Make your API changes + + Make your changes in your api repository. For example, let's say you wanted to change the `ClientCertExpirationSeconds` to be `ClientCertExpirationMinutes` for some reason: + + + ```go + type RegistrationConfiguration struct { + // clientCertExpirationMinutes represents the minutes of a client certificate to expire. If it is not set or 0, the default + // duration minutes will be set by the hub cluster. If the value is larger than the max signing duration minutes set on + // the hub cluster, the max signing duration minutes will be set. + // +optional + ClientCertExpirationMinutes int32 `json:"clientCertExpirationMinutes,omitempty"` + ... + ``` + In your api repository, run the following to generate CRDs and DeepCopy functions + ```shell + user@fedora:~/api$ make update + ``` + + You'll notice that a few files such as `operator/v1/zz_generated.deepcopy.go` and `operator/v1/0000_00_operator.open-cluster-management.io_klusterlets.crd.yaml` have been changed to reflect the changes in the API and CRD. +3. Sync API updates with ocm repository + + In order to use the new API, you'll have to sync them to your ocm repository. In your ocm repository, go to your go.mod file and replace `open-cluster-management.io/api` with your own updated version. This can be done by using the `replace` directive. At the end of the go.mod file, add: + + ```go + go mod edit -replace open-cluster-management.io/api=/home//api #path to my local api repo w/ changes + ``` + + _Note: Only use the replace directive during development/debugging. Make sure to remove it before making a PR to [ocm](https://github.com/open-cluster-management-io/ocm) and once changes to the upstream [api repo](https://github.com/open-cluster-management-io/api) are merged._ + + Then, in your ocm repository, run the following: + ```shell + user@fedora:~/ocm$ go mod tidy + user@fedora:~/ocm$ go mod vendor + user@fedora:~/ocm$ make update + ``` + ### Testing the changes in the kind cluster After building and pushing the images, you can test the changes in the kind cluster.