diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f24fb138..55f0c667 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,7 +1,6 @@ name: Generate release artefact on: - workflow_dispatch: push: tags: - "v*.*.*" @@ -18,3 +17,45 @@ jobs: uses: actions/setup-go@v3 with: go-version: "^1.17" + + - name: Install tools + uses: redhat-actions/openshift-tools-installer@v1 + with: + source: "github" + kustomize: "latest" + operator-sdk: "latest" + ko: "latest" + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ndb-operator + sep-tags: "," + sep-labels: "," + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=sha + + - name: Test build + run: make test + + - name: Build container + env: + KO_DOCKER_REPO: ghcr.io/${{ github.repository }}/controller + TAGS: ${{ steps.meta.outputs.tags }} + LABELS: ${{ steps.meta.outputs.labels }} + PLATFORMS: linux/amd64,linux/arm64,linux/arm + run: | + PTAGS=`echo $TAGS | sed 's/ndb-operator://g'` + export SOURCE_DATE_EPOCH=$(date +%s) + ko build --bare --image-label "$LABELS" -t "$PTAGS" --platform=$PLATFORMS . diff --git a/Makefile b/Makefile index 8885732d..82103c54 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) # # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both # nutanix.com/ndb-operator-bundle:$VERSION and nutanix.com/ndb-operator-catalog:$VERSION. -IMAGE_TAG_BASE ?= nutanix.com/ndb-operator +IMAGE_TAG_BASE ?= ghcr.io/nutanix-cloud-native/ndb-operator/controller # BUNDLE_IMG defines the image:tag used for the bundle. # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) @@ -47,7 +47,7 @@ ifeq ($(USE_IMAGE_DIGESTS), true) endif # Image URL to use all building/pushing image targets -IMG ?= controller:latest +IMG ?= $(IMAGE_TAG_BASE):v$(VERSION) # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.24.1 @@ -160,14 +160,14 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.9.0 +KUSTOMIZE_VERSION ?= v4.5.5 +CONTROLLER_TOOLS_VERSION ?= v0.9.2 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. $(KUSTOMIZE): $(LOCALBIN) - curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN) + test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); } .PHONY: controller-gen controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. diff --git a/README.md b/README.md index b289e407..84944ffd 100644 --- a/README.md +++ b/README.md @@ -9,33 +9,12 @@ The NDB operator brings automated and simplified database administration, provis 3. The operator-sdk installed. 4. A clone of the source code ([this](https://github.com/nutanix-cloud-native/ndb-operator) repository). ### Installation and Running on the cluster -1. Install the CRDs into the cluster: - -```sh -make install -``` - -2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running): - -```sh -make run -``` - -**NOTE:** You can also run this in one step by running: `make install run` -
-### Modifying the API definitions -If you are editing the API definitions, generate the manifests such as CRs or CRDs using: +Deploy the controller on the cluster: ```sh -make generate manifests +make deploy ``` -**NOTE:** Run `make --help` for more information on all potential `make` targets - -More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html) - -
- ### Using the Operator 1. To create instances of custom resources (provision databases), edit [ndb_v1alpha1_database.yaml](config/samples/ndb_v1alpha1_database.yaml) file with the NDB installation and database instance details and run: @@ -83,7 +62,36 @@ spec: type: postgres ``` -
+ + + +## Developement + +### Installation and Running the controller locally +1. Install the CRDs into the cluster: + +```sh +make install +``` + +2. Run your controller locally (this will run in the foreground, so switch to a new terminal if you want to leave it running): + +```sh +make run +``` + +**NOTE:** You can also run this in one step by running: `make install run` + +### Modifying the API definitions +If you are editing the API definitions, generate the manifests such as CRs or CRDs using: + +```sh +make generate manifests +``` + +**NOTE:** Run `make --help` for more information on all potential `make` targets + +More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html) ### Building and pushing to an image registry Build and push your image to the location specified by `IMG`: @@ -92,8 +100,6 @@ Build and push your image to the location specified by `IMG`: make docker-build docker-push IMG=/ndb-operator:tag ``` -
- ### Deploy the operator pushed to an image registry Deploy the controller to the cluster with the image specified by `IMG`: @@ -109,13 +115,14 @@ make uninstall ``` ### Undeploy controller -UnDeploy the controller to the cluster: +To remove the controller from the cluster: ```sh make undeploy ``` -### How it works +## How it works + This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/) diff --git a/config/crd/bases/ndb.nutanix.com_databases.yaml b/config/crd/bases/ndb.nutanix.com_databases.yaml index 3dd07cf1..95f14b44 100644 --- a/config/crd/bases/ndb.nutanix.com_databases.yaml +++ b/config/crd/bases/ndb.nutanix.com_databases.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.0 + controller-gen.kubebuilder.io/version: v0.9.2 creationTimestamp: null name: databases.ndb.nutanix.com spec: diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 7874768e..a7e9d238 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -34,38 +34,34 @@ spec: # seccompProfile: # type: RuntimeDefault containers: - - command: - - /manager - args: - - --leader-elect - image: controller:latest - name: manager - securityContext: - allowPrivilegeEscalation: false - # TODO(user): uncomment for common cases that do not require escalating privileges - # capabilities: - # drop: - # - "ALL" - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 20 - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 10 - # TODO(user): Configure the resources accordingly based on the project requirements. - # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ - resources: - limits: - cpu: 500m - memory: 128Mi - requests: - cpu: 10m - memory: 64Mi + - args: + - --leader-elect + image: controller:latest + name: manager + securityContext: + allowPrivilegeEscalation: false + # TODO(user): uncomment for common cases that do not require escalating privileges + # capabilities: + # drop: + # - "ALL" + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi serviceAccountName: controller-manager terminationGracePeriodSeconds: 10