Skip to content

Commit

Permalink
Merge branch 'open-cluster-management-io:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqing0110 authored Aug 14, 2024
2 parents 1be7ae2 + a08afd6 commit b3a64b2
Show file tree
Hide file tree
Showing 1,904 changed files with 114,809 additions and 98,261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cloudevents-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- release-*

env:
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''

permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: 'Dependency Review'
uses: actions/dependency-review-action@72eb03d02c7872a771aacd928f3123ac62ad6d3a # v4.3.3
uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4
21 changes: 20 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ on:
- release-*

env:
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''
USE_EXISTING_CLUSTER: false # set to true to use an existing kind cluster for debugging with act

permissions:
contents: read
Expand All @@ -36,6 +37,12 @@ jobs:
uses: engineerd/setup-kind@v0.5.0
with:
version: v0.22.0
skipClusterCreation: ${{ env.USE_EXISTING_CLUSTER }}
- name: Set KUBECONFIG
run: |
mkdir -p /home/runner/.kube
kind get kubeconfig > /home/runner/.kube/config
if: ${{ env.USE_EXISTING_CLUSTER }}
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.3
- name: Build images
Expand Down Expand Up @@ -68,6 +75,12 @@ jobs:
uses: engineerd/setup-kind@v0.5.0
with:
version: v0.22.0
skipClusterCreation: ${{ env.USE_EXISTING_CLUSTER }}
- name: Set KUBECONFIG
run: |
mkdir -p /home/runner/.kube
kind get kubeconfig > /home/runner/.kube/config
if: ${{ env.USE_EXISTING_CLUSTER }}
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.3
- name: Build images
Expand Down Expand Up @@ -100,6 +113,12 @@ jobs:
uses: engineerd/setup-kind@v0.5.0
with:
version: v0.22.0
skipClusterCreation: ${{ env.USE_EXISTING_CLUSTER }}
- name: Set KUBECONFIG
run: |
mkdir -p /home/runner/.kube
kind get kubeconfig > /home/runner/.kube/config
if: ${{ env.USE_EXISTING_CLUSTER }}
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.3
- name: Build images
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ossf-scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -59,14 +59,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8
uses: github/codeql-action/upload-sarif@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # v3.26.0
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/post.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

env:
# Common versions
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''

permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- release-*

env:
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''

permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaseimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*.*.*'
env:
# Common versions
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''
GOPATH: '/home/runner/work/ocm/ocm/go'
GITHUB_REF: ${{ github.ref }}
Expand Down
182 changes: 154 additions & 28 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
**Table of Contents**

- [Contributing guidelines](#contributing-guidelines)
- [Terms](#terms)
- [Certificate of Origin](#certificate-of-origin)
- [DCO Sign Off](#dco-sign-off)
- [Code of Conduct](#code-of-conduct)
- [Contributing a patch](#contributing-a-patch)
- [Issue and pull request management](#issue-and-pull-request-management)
- [Terms](#terms)
- [Certificate of Origin](#certificate-of-origin)
- [DCO Sign Off](#dco-sign-off)
- [Code of Conduct](#code-of-conduct)
- [Contributing a patch](#contributing-a-patch)
- [Setting up your dev environment, coding, and debugging](#setting-up-your-dev-environment-coding-and-debugging)
- [Prerequisites](#prerequisites)
- [Setting up dev environment](#setting-up-dev-environment)
- [Building Images](#building-images)
- [Testing the changes in the kind cluster](#testing-the-changes-in-the-kind-cluster)
- [Integration tests](#integration-tests)
- [E2E tests](#e2e-tests)
- [Issue and pull request management](#issue-and-pull-request-management)
- [References](#references)

# Contributing guidelines

The ocm repo contains 4 core components:
The ocm repo contains 5 core components:
* registration
* placement
* work
* registration-operator

Before 0.11.0, the 4 components has independent repos, now we are going through [the task of consolidating code](https://github.com/open-cluster-management-io/OCM/issues/128) to merge all code into this repo to gain all kinds of benifits.

We're contiously working on migrate code from `/staging` folder to outside. Finally, the `/staging` folder will be empty and removed.

Here is a table of the migration status:

| Component | Status |
| --- | --- |
| registration | staging |
| placement | staging |
| work | staging |
| registration-operator | staging |

Status:
* staging: the component is having all code in `staging` folder.
* mix: the component is having code in both `staging` and outside.
* done: the component is having all code outside `staging` folder and done of the migration.

If a component is in the `staging` status, you need to open project in the `/staging` folder and contribute there.
* addon-manager

## Terms

Expand All @@ -61,9 +50,146 @@ The Open Cluster Management project has adopted the CNCF Code of Conduct. Refer
## Contributing a patch

1. Submit an issue describing your proposed change to the repository in question. The repository owners will respond to your issue promptly.
2. Fork the desired repository, then develop and test your code changes.
2. Fork the desired repository, then [develop and test](#setting-up-your-dev-environment-coding-and-debugging) your code changes.
3. Submit a pull request.

## Setting up your dev environment, coding, and debugging

### Prerequisites

- [Golang](https://go.dev/doc/install)
- Container Engin: [Docker](https://docs.docker.com/engine/install/) or [Podman](https://podman.io/docs/installation)
- [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
- [kubectl](https://kubernetes.io/docs/tasks/tools/)

### Setting up dev environment

For development purposes, we can use the [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) tool to
create a local Kubernetes cluster and deploy the Open Cluster Management components.

1. Create a kind cluster:

```bash
kind create cluster
```

2. Deploy the Open Cluster Management components referring to the [Setup hub and managed clusters](https://open-cluster-management.io/getting-started/quick-start) guide on the kind cluster created in the previous step. Summary the key steps are:

1. Install the clusteradm CLI tool:
```bash
curl -sL https://raw.githubusercontent.com/open-cluster-management/clusteradm/main/hack/install.sh | bash
```
2. Init the control plane:
```bash
clusteradm init --wait --bundle-version="latest"
```
3. Join the hub cluster as a managed cluster(self management):
```bash
clusteradm join --hub-token <hub-token> --hub-apiserver <hub-apiserver> --wait --cluster-name cluster1 --force-internal-endpoint-lookup --bundle-version="latest"
```
4. Access the hub cluster:
```bash
clusteradm accept --clusters cluster1
```

3. Check the Open Cluster Management components are running:

```bash
╰─# kubectl get clustermanager cluster-manager
NAME AGE
cluster-manager 7h36m
╰─# kubectl get managedcluster
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
cluster1 true https://kind-control-plane:6443 True True 7h36m
╰─# kubectl get deployment -A | grep open-cluster-management
open-cluster-management-agent klusterlet-registration-agent # register the managed cluster
open-cluster-management-agent klusterlet-work-agent # distribute resources to the managed cluster
open-cluster-management-hub cluster-manager-addon-manager-controller # manage the addons
open-cluster-management-hub cluster-manager-placement-controller # manage the placement
open-cluster-management-hub cluster-manager-registration-controller # manage the registration
open-cluster-management-hub cluster-manager-registration-webhook # validate managedcluster/managedclusterset
open-cluster-management-hub cluster-manager-work-webhook # validate manifestwork
open-cluster-management cluster-manager # watch clustermanager and deploy the hub components
open-cluster-management klusterlet # watch managedcluster and deploy the managed cluster components
```

Note: if klustelet is deployed in Singleton mode(`clusteradm join --hub-token <hub-token> --hub-apiserver <hub-apiserver> --wait --cluster-name cluster1 --force-internal-endpoint-lookup --bundle-version="latest" --singleton=true`), the `klusterlet-registration-agent`
and `klusterlet-work-agent` will be replaced by one deployment `klusterlet-agent`.

Once the Open Cluster Management components are deployed, you can start developing and testing your changes.

### Building Images

There are 5 core images that are built from the ocm repository: `registration`, `placement`, `work`,
`registration-operator`, and `addon-manager`.

To build all these images, you can run the following command:

```bash
# Replace the IMAGE_REGISTRY and IMAGE_TAG with your desired values
IMAGE_REGISTRY=quay.io/open-cluster-management IMAGE_TAG=test make images
```

To build a specific image, you can run the following command:

```bash
# the <image-name> can be one of the following: registration, placement, work, registration-operator, addon-manager
IMAGE_REGISTRY=quay.io/open-cluster-management IMAGE_TAG=test make image-<image-name>
```

After building the images, you can push them to the registry by docker/podman push, if you do not have a registry,
you can use the command `kind load docker-image quay.io/open-cluster-management/<image-name>:test` to load the
images into the kind cluster.

### Testing the changes in the kind cluster

After building and pushing the images, you can test the changes in the kind cluster.

1. Test the operators(deployment `cluster-manager` or `klusterlet` in the `open-cluster-management` namespace) changes
by replacing the registration-operator image for the operators deployments:

```bash
kubectl set image -n open-cluster-management deployment/cluster-manager registration-operator=$(IMAGE_REGISTRY)/registration-operator:$(IMAGE_TAG)
kubectl set image -n open-cluster-management deployment/klusterlet klusterlet=$(IMAGE_REGISTRY)/registration-operator:$(IMAGE_TAG)
```

2. Test the hub side components changes by replacing the image fields in the clustermanager spec:

```bash
kubectl edit clustermanager cluster-manager
```

3. Test the managed cluster side components changes by replacing the image fields in the klusterlet spec:

```bash
kubectl edit klusterlet klusterlet
```

### Integration tests

The integration tests are written in the [test/integration](test/integration) directory. They start a kubenretes
api server locally with [controller-runtime](https://book.kubebuilder.io/reference/envtest), and run the tests against
the local api server.

To run the integration tests, you can use the following command:

```bash
make test-integration # run all the integration tests
make test-<component>-integration # run the integration tests for a specific component
```

### E2E tests

The E2E tests are written in the [test/e2e](test/e2e) directory. You can run the E2E tests:
- referring to the steps described in the [e2e workflow](.github/workflows/e2e.yml) file
- or by the [act](https://github.com/nektos/act) command: `act -j e2e`

## Issue and pull request management

Anyone can comment on issues and submit reviews for pull requests. In order to be assigned an issue or pull request, you can leave a `/assign <your Github ID>` comment on the issue or pull request.

# References

Please refer to [the Contribution Guide](https://open-cluster-management.io/contribute/)
Loading

0 comments on commit b3a64b2

Please sign in to comment.