Skip to content

Commit

Permalink
Kubernetes Operator for Nessie
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Jan 19, 2024
1 parent 7cf65f0 commit d6d439d
Show file tree
Hide file tree
Showing 22 changed files with 1,582 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ quarkus-bom = { module = "io.quarkus.platform:quarkus-bom", version.ref = "quark
quarkus-cassandra-bom = { module = "io.quarkus.platform:quarkus-cassandra-bom", version.ref = "quarkus" }
quarkus-google-cloud-services-bom = { module = "io.quarkus.platform:quarkus-google-cloud-services-bom", version.ref = "quarkus" }
quarkus-logging-sentry = { module = "io.quarkiverse.loggingsentry:quarkus-logging-sentry", version = "2.0.4" }
# references io.quarkiverse.operatorsdk:quarkus-operator-sdk:6.4.0, too old
# TODO switch when quarkus 3.7 is released
# quarkus-operator-sdk-bom = { module = "io.quarkus.platform:quarkus-operator-sdk-bom", version.ref = "quarkus" }
quarkus-operator-sdk-bom = { module = "io.quarkiverse.operatorsdk:quarkus-operator-sdk-bom", version = "6.5.1" }
rest-assured = { module = "io.rest-assured:rest-assured", version = "5.4.0" }
rocksdb-jni = { module = "org.rocksdb:rocksdbjni", version = "8.9.1" }
scala-library-v212 = { module = "org.scala-lang:scala-library", version = { strictly = "[2.12, 2.13[", prefer = "2.12.18" }}
Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ nessie-jaxrs-testextension=servers/jax-rs-testextension
nessie-jaxrs-tests=servers/jax-rs-tests
nessie-keycloak-testcontainer=testing/keycloak-container
nessie-nessie-testcontainer=testing/nessie-container
nessie-operator=operator
nessie-quarkus-auth=servers/quarkus-auth
nessie-quarkus-cli=servers/quarkus-cli
nessie-quarkus-common=servers/quarkus-common
Expand Down
99 changes: 99 additions & 0 deletions operator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

VERSION ?= 0.0.1

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif

# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# projectnessie.org/nessie-operator-bundle:$VERSION and projectnessie.org/nessie-operator-catalog:$VERSION.
IMAGE_TAG_BASE ?= projectnessie/nessie-operator

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)

# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):latest

PULL_POLICY ?= Always

all: docker-build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

docker-build: ## Build docker image with the manager.
../gradlew --no-build-cache :nessie-operator:clean :nessie-operator:build \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.image=${IMG} \
-Dquarkus.kubernetes.image-pull-policy=${PULL_POLICY}

docker-push: ## Build and push docker image with the manager.
../gradlew --no-build-cache :nessie-operator:clean :nessie-operator:build \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.push=true \
-Dquarkus.container-image.image=${IMG} \
-Dquarkus.kubernetes.image-pull-policy=${PULL_POLICY}

##@ Deployment

install: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@$(foreach file, $(wildcard build/kubernetes/*-v1.yml), kubectl apply -f $(file);)

uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
@$(foreach file, $(wildcard build/kubernetes/*-v1.yml), kubectl delete -f $(file);)

deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config.
kubectl apply -f build/kubernetes/kubernetes.yml

undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
kubectl delete -f build/kubernetes/kubernetes.yml

##@Bundle
.PHONY: bundle
bundle: ## Generate bundle manifests and metadata, then validate generated files.
## marker
cat build/kubernetes/nessies.nessie.projectnessie.org-v1alpha1.yml target/kubernetes/kubernetes.yml | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
docker push $(BUNDLE_IMG)
17 changes: 17 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: projectnessie.org
layout:
- quarkus.javaoperatorsdk.io/v1-alpha
projectName: nessie-operator
resources:
- api:
crdVersion: v1
namespaced: true
domain: projectnessie.org
group: nessie
kind: Nessie
version: v1alpha1
version: "3"
89 changes: 89 additions & 0 deletions operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Kubernetes Operator for Nessie

## Overview

This module is a Kubernetes Operator for Nessie.

**WARNING: This is a work in progress and is not ready for production use.**

## Usage

TODO describe typical deployment scenarios.

## Development

### Prerequisites

Install the following tools:

- Kubectl: https://kubernetes.io/docs/tasks/tools/
- Operator SDK: https://sdk.operatorframework.io/docs/installation/
- Optional:
- yq: https://github.com/mikefarah/yq

**IMPORTANT**: The current Operator SDK version, 1.33.0, has [a bug] that prevents it from working
with the latest version of the Kubernetes API (or Quarkus plugin). To work around this, install the
version 1.32.0 of the operator-sdk.

[a bug]:https://github.com/operator-framework/operator-sdk/issues/6645

Using brew:

```bash
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/6b039d0d8907b70704cd1d87ad235705a77620ae/Formula/o/operator-sdk.rb
brew install -s operator-sdk.rb
operator-sdk version
```

### Project generation

```bash
operator-sdk init --plugins=quarkus --domain=projectnessie.org --project-name=nessie-operator
operator-sdk create api --plugins=quarkus --group nessie --version=v1alpha1 --kind=Nessie
```

### Building the operator image

```bash
make docker-build
```

### Adhoc testing with Minikube

Install [minikube](https://minikube.sigs.k8s.io/docs/start/).

Build the operator docker image _inside_ minikube to facilitate testing (doesn't need a registry):

```bash
eval $(minikube docker-env)
make docker-build PULL_POLICY=IfNotPresent
```

Note: the `PULL_POLICY=IfNotPresent` is required to avoid pulling the image from a registry.

Create the nessie-operator and nessie-ns namespaces:

```bash
kubectl create namespace nessie-operator
kubectl create namespace nessie-ns
```

Install the CRDs and deploy the operator in the nessie-operator namespace:

```bash
make install deploy
```

Grant admin rights to the nessie-operator service account:

```bash
kubectl apply -f examples/nessie-operator-rbac.yaml
```

Create a Nessie resource in the nessie-ns namespace:

```bash
kubectl apply -n nessie-ns -f examples/nessie.yaml
```

You should see 1 pod, 1 deployment and 1 service running.
50 changes: 50 additions & 0 deletions operator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2024 Dremio
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.quarkus)
id("nessie-conventions-quarkus")
id("nessie-jacoco")
}

extra["maven.name"] = "Nessie - Kubernetes Operator"

dependencies {
implementation(enforcedPlatform(libs.quarkus.bom))
implementation(enforcedPlatform(libs.quarkus.operator.sdk.bom))

implementation("io.quarkiverse.operatorsdk:quarkus-operator-sdk")
implementation("io.quarkiverse.operatorsdk:quarkus-operator-sdk-bundle-generator")
implementation("io.quarkus:quarkus-micrometer-registry-prometheus")
implementation("io.quarkus:quarkus-container-image-jib")

testImplementation(enforcedPlatform(libs.quarkus.bom))
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.quarkus:quarkus-junit5-mockito")
testImplementation("io.quarkus:quarkus-test-kubernetes-client")
testImplementation("org.bouncycastle:bcpkix-jdk18on")
testImplementation(platform(libs.junit.bom))
testImplementation(libs.bundles.junit.testing)
testImplementation(libs.awaitility)
}

listOf("javadoc", "sourcesJar").forEach { name ->
tasks.named(name).configure { dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) }
}

listOf("checkstyleTest", "compileTestJava").forEach { name ->
tasks.named(name).configure { dependsOn(tasks.named("compileQuarkusTestGeneratedSourcesJava")) }
}
12 changes: 12 additions & 0 deletions operator/examples/nessie-operator-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: nessie-operator-admin
subjects:
- kind: ServiceAccount
name: nessie-operator
namespace: nessie-operator
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: ""
8 changes: 8 additions & 0 deletions operator/examples/nessie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: nessie.projectnessie.org/v1alpha1
kind: Nessie
metadata:
name: nessie1
spec:
size: 1
versionStoreType: IN_MEMORY
logLevel: INFO
Loading

0 comments on commit d6d439d

Please sign in to comment.