diff --git a/.github/workflows/go-presubmit.yml b/.github/workflows/go-presubmit.yml index 6b4c89e99..131dcda10 100644 --- a/.github/workflows/go-presubmit.yml +++ b/.github/workflows/go-presubmit.yml @@ -11,10 +11,10 @@ env: # Common versions GO_VERSION: '1.16' GO_REQUIRED_MIN_VERSION: '' - GOPATH: '/home/runner/work/registration-operator/registration-operator/go' + GOPATH: '/home/runner/work/placement/placement/go' defaults: run: - working-directory: go/src/open-cluster-management.io/registration-operator + working-directory: go/src/open-cluster-management.io/placement jobs: verify: @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -57,7 +57,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -73,7 +73,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -89,7 +89,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -105,7 +105,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/registration-operator + path: go/src/open-cluster-management.io/placement - name: install Go uses: actions/setup-go@v2 with: @@ -121,7 +121,7 @@ jobs: name: cluster1 - name: Load image on the nodes of the cluster run: | - kind load docker-image --name=cluster1 quay.io/open-cluster-management/registration-operator:latest + kind load docker-image --name=cluster1 quay.io/open-cluster-management/placement:latest - name: Run e2e test run: | make test-e2e diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43f7fd270..00e0ff6e5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,51 +1,83 @@ -**Table of Contents** + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - [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) - - [Pre-check before submitting a PR](#pre-check-before-submitting-a-pr) + - [Contributions](#contributions) + - [Certificate of Origin](#certificate-of-origin) + - [Contributing A Patch](#contributing-a-patch) + - [Issue and Pull Request Management](#issue-and-pull-request-management) + - [Pre-check before submitting a PR](#pre-check-before-submitting-a-pr) + - [Build images](#build-images) + + # Contributing guidelines -## Terms +## Contributions All contributions to the repository must be submitted under the terms of the [Apache Public License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ## Certificate of Origin -By contributing to this project, you agree to the Developer Certificate of Origin (DCO). This document was created by the Linux Kernel community and is a simple statement that you, as a contributor, have the legal right to make the contribution. See the [DCO](https://github.com/open-cluster-management-io/community/blob/main/DCO) file for details. +By contributing to this project you agree to the Developer Certificate of +Origin (DCO). This document was created by the Linux Kernel community and is a +simple statement that you, as a contributor, have the legal right to make the +contribution. See the [DCO](DCO) file for details. -## DCO Sign Off +## Contributing A Patch -You must sign off your commit to state that you certify the [DCO](https://github.com/open-cluster-management-io/community/blob/main/DCO). To certify your commit for DCO, add a line like the following at the end of your commit message: +1. Submit an issue describing your proposed change to the repo in question. +2. The [repo owners](OWNERS) will respond to your issue promptly. +3. Fork the desired repo, develop and test your code changes. +4. Submit a pull request. -``` -Signed-off-by: John Smith +## Issue and Pull Request Management + +Anyone may comment on issues and submit reviews for pull requests. However, in +order to be assigned an issue or pull request, you must be a member of the +[open-cluster-management](https://github.com/open-cluster-management-io) GitHub organization. + +Repo maintainers can assign you an issue or pull request by leaving a +`/assign ` comment on the issue or pull request. + +## Pre-check before submitting a PR + +After your PR is ready to commit, please run following commands to check your code. + +```shell +make verify ``` -This can be done with the `--signoff` option to `git commit`. See the [Git documentation](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--s) for details. You can also mass sign-off a whole pull request with `git rebase --signoff main`, replacing `main` with the branch you are creating a pull request into. +Run unit testing +```shell +make test-unit +``` -## Code of Conduct +Run integration testing +```shell +make test-integration +``` -The Open Cluster Management project has adopted the CNCF Code of Conduct. Refer to our [Community Code of Conduct](https://github.com/open-cluster-management-io/community/blob/main/CODE_OF_CONDUCT.md) for details. +Run e2e testing. +```shell +go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.1 -## Contributing a patch +export KUBECONFIG= -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. -3. Submit a pull request. +make images -## Issue and pull request management +kind load docker-image quay.io/open-cluster-management/placement:latest --name {your cluster name} -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 ` comment on the issue or pull request (PR). +make test-e2e +``` -## Pre-check before submitting a PR - +## Build images -Before submitting a PR, please perform the following steps: +Make sure your code build passed. -- List of steps to perform before submitting a PR. +```shell +make images +``` + +Now, you can follow the [getting started guide](./README.md#getting-started) to work with this repository. \ No newline at end of file diff --git a/Makefile b/Makefile index 185468f89..070980c50 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ IMAGE_TAG?=latest IMAGE_REGISTRY ?= quay.io/open-cluster-management IMAGE_NAME?=$(IMAGE_REGISTRY)/$(IMAGE):$(IMAGE_TAG) KUBECTL?=kubectl -KUSTOMIZE?=$(PERMANENT_TMP_GOPATH)/bin/kustomize +KUSTOMIZE?=$(PWD)/$(PERMANENT_TMP_GOPATH)/bin/kustomize KUSTOMIZE_VERSION?=v3.5.4 KUSTOMIZE_ARCHIVE_NAME?=kustomize_$(KUSTOMIZE_VERSION)_$(GOHOSTOS)_$(GOHOSTARCH).tar.gz kustomize_dir:=$(dir $(KUSTOMIZE)) @@ -39,10 +39,13 @@ $(call build-image,$(IMAGE),$(IMAGE_REGISTRY)/$(IMAGE),./Dockerfile,.) deploy-hub: ensure-kustomize cp deploy/hub/kustomization.yaml deploy/hub/kustomization.yaml.tmp - cd deploy/hub && ../../$(KUSTOMIZE) edit set image quay.io/open-cluster-management/placement:latest=$(IMAGE_NAME) + cd deploy/hub && $(KUSTOMIZE) edit set image quay.io/open-cluster-management/placement:latest=$(IMAGE_NAME) $(KUSTOMIZE) build deploy/hub | $(KUBECTL) apply -f - mv deploy/hub/kustomization.yaml.tmp deploy/hub/kustomization.yaml +undeploy-hub: + $(KUSTOMIZE) build deploy/hub | $(KUBECTL) delete --ignore-not-found -f - + build-e2e: go test -c ./test/e2e -mod=vendor diff --git a/README.md b/README.md index c7232f3c6..bec9c28d7 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,142 @@ # Placement -[![License](https://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) - -## What is the `Placement` repository? - With `Placement`, you can select a set of `ManagedClusters` from the `ManagedClusterSets` bound to the placement namespace. -Go to the [Contributing guide](CONTRIBUTING.md) to learn how to get involved. +## Community, discussion, contribution, and support -## Getting started +Check the [CONTRIBUTING Doc](CONTRIBUTING.md) for how to contribute to the repo. -run `make build` to build the binary + + +------ +## Getting Started + +### Prerequisites + +You have at least one running kubernetes cluster; + +### Deploy the placement controller +Set environment variables. +```sh +export KUBECONFIG= +``` + +Build the docker image to run the placement controller. +```sh +make images +export IMAGE_NAME= # export IMAGE_NAME=quay.io/open-cluster-management-io/placement:latest +``` + +If your are using kind, load image into kind cluster. +```sh +kind load docker-image # kind load docker-image quay.io/open-cluster-management-io/placement:latest +``` + +And then deploy placement manager on cluster +``` +make deploy-hub +``` + +### What is next +After a successful deployment, check on the cluster and see the placement controller has been deployed. +``` +kubectl -n open-cluster-management-hub get pods +NAME READY STATUS RESTARTS AGE +cluster-manager-placement-controller-cf9bbd6c-x9dnd 1/1 Running 0 2m16s +``` + +Create a clusterset.yaml as shown in this example: + +```yaml +apiVersion: cluster.open-cluster-management.io/v1alpha1 +kind: ManagedClusterSet +metadata: + name: clusterset1 +``` + +Apply the yaml file to the cluster to create a `ManagedClusterSet`. +``` +kubectl apply -f clusterset.yaml +``` + +Create a cluster.yaml: + +```yaml +apiVersion: cluster.open-cluster-management.io/v1 +kind: ManagedCluster +metadata: + name: cluster1 + labels: + cluster.open-cluster-management.io/clusterset: clusterset1 + vendor: OpenShift +spec: + hubAcceptsClient: true +``` + +Apply the yaml file to create a cluster and assign it to clusterset `clusterset1`. +``` +kubectl apply -f cluster.yaml +``` + +And then create a binding.yaml: + +```yaml +apiVersion: cluster.open-cluster-management.io/v1alpha1 +kind: ManagedClusterSetBinding +metadata: + name: clusterset1 + namespace: default +spec: + clusterSet: clusterset1 +``` + +Apply the yaml file to bind the `ManagedClusterSet` to the default namespace. +``` +kubectl apply -f binding.yaml +``` + +Now create a placement.yaml: +```yaml +apiVersion: cluster.open-cluster-management.io/v1alpha1 +kind: Placement +metadata: + name: placement1 + namespace: default +spec: + predicates: + - requiredClusterSelector: + labelSelector: + matchLabels: + vendor: OpenShift +``` +Apply the yaml file to create the placement. + +``` +kubectl apply -f placement.yaml +``` + +Check the 'PlacementDecision'created for this placement. It contains all selected clusters in status. +``` +kubectl get placementdecisions +NAME AGE +placement1-decision-1 14s +``` + +### Clean up +Undeploy placement controller from the cluster. +``` +make undeploy-hub +``` + + \ No newline at end of file