Skip to content

Commit de7990f

Browse files
committed
Kubernetes Operator for Nessie
1 parent 4b0d2c8 commit de7990f

File tree

55 files changed

+4528
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4528
-0
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ quarkus-bom = { module = "io.quarkus.platform:quarkus-bom", version.ref = "quark
149149
quarkus-cassandra-bom = { module = "io.quarkus.platform:quarkus-cassandra-bom", version.ref = "quarkus" }
150150
quarkus-google-cloud-services-bom = { module = "io.quarkus.platform:quarkus-google-cloud-services-bom", version.ref = "quarkus" }
151151
quarkus-logging-sentry = { module = "io.quarkiverse.loggingsentry:quarkus-logging-sentry", version = "2.0.5" }
152+
# references io.quarkiverse.operatorsdk:quarkus-operator-sdk:6.4.0, too old
153+
# TODO switch when quarkus 3.7 is released
154+
# quarkus-operator-sdk-bom = { module = "io.quarkus.platform:quarkus-operator-sdk-bom", version.ref = "quarkus" }
155+
quarkus-operator-sdk-bom = { module = "io.quarkiverse.operatorsdk:quarkus-operator-sdk-bom", version = "6.6.0" }
152156
rest-assured = { module = "io.rest-assured:rest-assured", version = "5.4.0" }
153157
rocksdb-jni = { module = "org.rocksdb:rocksdbjni", version = "8.10.0" }
154158
scala-library-v212 = { module = "org.scala-lang:scala-library", version = { strictly = "[2.12, 2.13[", prefer = "2.12.18" }}

gradle/projects.main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ nessie-jaxrs-testextension=servers/jax-rs-testextension
2121
nessie-jaxrs-tests=servers/jax-rs-tests
2222
nessie-keycloak-testcontainer=testing/keycloak-container
2323
nessie-nessie-testcontainer=testing/nessie-container
24+
nessie-operator=operator
2425
nessie-quarkus-auth=servers/quarkus-auth
2526
nessie-quarkus-cli=servers/quarkus-cli
2627
nessie-quarkus-common=servers/quarkus-common

operator/Makefile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
VERSION ?= 0.0.1
3+
4+
# CHANNELS define the bundle channels used in the bundle.
5+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
6+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
7+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
8+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
9+
ifneq ($(origin CHANNELS), undefined)
10+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
11+
endif
12+
13+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
14+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
15+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
16+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
17+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
18+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
19+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
20+
endif
21+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
22+
23+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
24+
# This variable is used to construct full image tags for bundle and catalog images.
25+
#
26+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
27+
# projectnessie.org/nessie-operator-bundle:$VERSION and projectnessie.org/nessie-operator-catalog:$VERSION.
28+
IMAGE_TAG_BASE ?= ghcr.io/projectnessie/nessie-operator
29+
30+
# BUNDLE_IMG defines the image:tag used for the bundle.
31+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
32+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
33+
34+
# Image URL to use all building/pushing image targets
35+
IMG ?= $(IMAGE_TAG_BASE):latest
36+
37+
PULL_POLICY ?= Always
38+
PLATFORM ?= linux/amd64
39+
40+
all: docker-build
41+
42+
##@ General
43+
44+
# The help target prints out all targets with their descriptions organized
45+
# beneath their categories. The categories are represented by '##@' and the
46+
# target descriptions by '##'. The awk commands is responsible for reading the
47+
# entire set of makefiles included in this invocation, looking for lines of the
48+
# file as xyz: ## something, and then pretty-format the target and help. Then,
49+
# if there's a line with ##@ something, that gets pretty-printed as a category.
50+
# More info on the usage of ANSI control characters for terminal formatting:
51+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
52+
# More info on the awk command:
53+
# http://linuxcommand.org/lc3_adv_awk.php
54+
55+
help: ## Display this help.
56+
@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)
57+
58+
##@ Build
59+
60+
docker-build: ## Build docker image with the manager.
61+
../gradlew --no-build-cache :nessie-operator:spotlessApply :nessie-operator:clean :nessie-operator:build -x check \
62+
-Dquarkus.container-image.image=${IMG} \
63+
-Dquarkus.jib.platforms=${PLATFORM} \
64+
-Dquarkus.kubernetes.image-pull-policy=${PULL_POLICY}
65+
66+
docker-push: ## Build and push docker image with the manager.
67+
../gradlew --no-build-cache :nessie-operator:spotlessApply :nessie-operator:clean :nessie-operator:build -x check \
68+
-Dquarkus.container-image.push=true \
69+
-Dquarkus.container-image.image=${IMG} \
70+
-Dquarkus.jib.platforms=${PLATFORM} \
71+
-Dquarkus.kubernetes.image-pull-policy=${PULL_POLICY}
72+
73+
##@ Deployment
74+
75+
install: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
76+
@$(foreach file, $(wildcard build/kubernetes/*-v1.yml), kubectl apply -f $(file);)
77+
78+
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
79+
@$(foreach file, $(wildcard build/kubernetes/*-v1.yml), kubectl delete -f $(file);)
80+
81+
deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config.
82+
kubectl apply -f build/kubernetes/kubernetes.yml
83+
84+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
85+
kubectl delete -f build/kubernetes/kubernetes.yml
86+
87+
##@Bundle
88+
.PHONY: bundle
89+
bundle: ## Generate bundle manifests and metadata, then validate generated files.
90+
## marker
91+
cat build/kubernetes/nessies.nessie.projectnessie.org-v1alpha1.yml target/kubernetes/kubernetes.yml | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
92+
operator-sdk bundle validate ./bundle
93+
94+
.PHONY: bundle-build
95+
bundle-build: ## Build the bundle image.
96+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
97+
98+
.PHONY: bundle-push
99+
bundle-push: ## Push the bundle image.
100+
docker push $(BUNDLE_IMG)

operator/PROJECT

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: projectnessie.org
6+
layout:
7+
- quarkus.javaoperatorsdk.io/v1-alpha
8+
projectName: nessie-operator
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
domain: projectnessie.org
14+
kind: Nessie
15+
version: v1alpha1
16+
version: "3"

operator/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Kubernetes Operator for Nessie
2+
3+
## Overview
4+
5+
This module is a Kubernetes Operator for Nessie.
6+
7+
**WARNING: This is a work in progress and is not ready for production use.**
8+
9+
## Usage
10+
11+
TODO describe typical deployment scenarios.
12+
13+
## Development
14+
15+
### TODOS
16+
17+
- [ ] CRD spec: move some configs to a config map ?
18+
- [ ] CRD status: conditions, etc.
19+
- [ ] CRD deletion and cleanup
20+
- [ ] CRD validation
21+
- [ ] Admission webhook ? https://github.com/operator-framework/josdk-webhooks
22+
- [ ] Operator release
23+
- [ ] Operator Lifecycle Manager (OLM)
24+
- [ ] Helm chart
25+
- [ ] Enable operator remote debugging
26+
- [ ] Tests
27+
- [ ] Unit tests
28+
- [ ] Smoke test
29+
- [ ] Missing / invalid configs
30+
- [ ] Integration tests:
31+
- [ ] All version stores
32+
- [ ] https://github.com/java-operator-sdk/jenvtest ?
33+
- Examples: https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator
34+
35+
### Known issues
36+
37+
- [ ] Including a PVC in the reconcile workflow keeps triggering the reconcile loop
38+
- [ ] Check generated RBAC rules
39+
- [ ] Helm chart has incorrect kubernetes.yml template when watching all namespaces
40+
- https://github.com/quarkiverse/quarkus-operator-sdk/pull/812
41+
42+
### Prerequisites
43+
44+
- Operator SDK: https://sdk.operatorframework.io/docs/installation/
45+
- Optional:
46+
- yq: https://github.com/mikefarah/yq
47+
48+
### Scaffolding the project
49+
50+
The initial scaffold was generated using [Operator SDK], with the Quarkus plugin:
51+
52+
```bash
53+
operator-sdk init --plugins=quarkus --domain=projectnessie.org --project-name=nessie-operator
54+
operator-sdk create api --plugins=quarkus --version=v1alpha1 --kind=Nessie
55+
```
56+
57+
[Operator SDK]:https://sdk.operatorframework.io/docs/cli/operator-sdk/
58+
59+
### Building the operator image
60+
61+
```bash
62+
make docker-build
63+
```
64+
65+
### Adhoc testing with Minikube
66+
67+
Install [minikube](https://minikube.sigs.k8s.io/docs/start/).
68+
69+
If you need ingress, install the ingress addon:
70+
71+
```bash
72+
minikube addons enable ingress
73+
minikube tunnel
74+
```
75+
76+
Create the nessie-operator and nessie-ns namespaces (only needed once):
77+
78+
```bash
79+
kubectl create namespace nessie-operator
80+
kubectl create namespace nessie-ns
81+
```
82+
83+
Grant admin rights to the nessie-operator service account (only needed once):
84+
85+
```bash
86+
kubectl apply -f examples/nessie-operator-rbac.yaml
87+
```
88+
89+
Build the operator docker image _inside_ minikube to facilitate testing (doesn't need a registry):
90+
91+
```bash
92+
eval $(minikube docker-env)
93+
make docker-build PULL_POLICY=IfNotPresent
94+
```
95+
96+
Note: the `PULL_POLICY=IfNotPresent` is required to avoid pulling the image from a registry.
97+
98+
Install the CRDs and deploy the operator in the nessie-operator namespace:
99+
100+
```bash
101+
make install deploy
102+
```
103+
104+
Create a Nessie resource in the nessie-ns namespace:
105+
106+
```bash
107+
kubectl apply -n nessie-ns -f examples/nessie-simple.yaml
108+
```
109+
110+
You should see 1 pod, 1 deployment and 1 service running.

operator/build.gradle.kts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2024 Dremio
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Copyright (C) 2024 Dremio
19+
*
20+
* Licensed under the Apache License, Version 2.0 (the "License");
21+
* you may not use this file except in compliance with the License.
22+
* You may obtain a copy of the License at
23+
*
24+
* http://www.apache.org/licenses/LICENSE-2.0
25+
*
26+
* Unless required by applicable law or agreed to in writing, software
27+
* distributed under the License is distributed on an "AS IS" BASIS,
28+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
* See the License for the specific language governing permissions and
30+
* limitations under the License.
31+
*/
32+
import org.apache.tools.ant.filters.ReplaceTokens
33+
34+
plugins {
35+
alias(libs.plugins.quarkus)
36+
id("nessie-conventions-quarkus")
37+
id("nessie-jacoco")
38+
}
39+
40+
extra["maven.name"] = "Nessie - Kubernetes Operator"
41+
42+
dependencies {
43+
implementation(enforcedPlatform(libs.quarkus.bom))
44+
implementation(enforcedPlatform(libs.quarkus.operator.sdk.bom))
45+
46+
implementation("io.quarkiverse.operatorsdk:quarkus-operator-sdk")
47+
implementation("io.quarkiverse.operatorsdk:quarkus-operator-sdk-bundle-generator")
48+
implementation("io.quarkus:quarkus-micrometer-registry-prometheus")
49+
implementation("io.quarkus:quarkus-container-image-jib")
50+
51+
compileOnly("io.sundr:builder-annotations:0.103.0")
52+
compileOnly("io.fabric8:generator-annotations:6.10.0")
53+
54+
annotationProcessor(enforcedPlatform(libs.quarkus.bom))
55+
annotationProcessor("io.sundr:builder-annotations:0.103.0")
56+
// see https://github.com/sundrio/sundrio/issues/104
57+
annotationProcessor("io.fabric8:kubernetes-client")
58+
59+
testImplementation(enforcedPlatform(libs.quarkus.bom))
60+
testImplementation("io.quarkus:quarkus-junit5")
61+
testImplementation("io.quarkus:quarkus-junit5-mockito")
62+
testImplementation("io.quarkus:quarkus-test-kubernetes-client")
63+
testImplementation("org.bouncycastle:bcpkix-jdk18on")
64+
testImplementation(platform(libs.junit.bom))
65+
testImplementation(libs.bundles.junit.testing)
66+
testImplementation(libs.awaitility)
67+
}
68+
69+
listOf("javadoc", "sourcesJar").forEach { name ->
70+
tasks.named(name).configure { dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) }
71+
}
72+
73+
listOf("checkstyleTest", "compileTestJava").forEach { name ->
74+
tasks.named(name).configure { dependsOn(tasks.named("compileQuarkusTestGeneratedSourcesJava")) }
75+
}
76+
77+
tasks.named<ProcessResources>("processTestResources").configure {
78+
inputs.property("projectVersion", project.version)
79+
filter(ReplaceTokens::class, mapOf("tokens" to mapOf("projectVersion" to project.version)))
80+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: nessie.projectnessie.org/v1alpha1
2+
kind: Nessie
3+
metadata:
4+
name: nessie-autoscaling
5+
spec:
6+
size: 1
7+
logLevel: INFO
8+
image:
9+
repository: projectnessie/nessie
10+
tag: 0.75.0
11+
versionStore:
12+
type: Jdbc
13+
jdbc:
14+
jdbcUrl: jdbc:h2:mem:nessie
15+
autoscaling:
16+
enabled: true
17+
minReplicas: 1
18+
maxReplicas: 3
19+
targetCpuUtilizationPercentage: 50
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: nessie.projectnessie.org/v1alpha1
2+
kind: Nessie
3+
metadata:
4+
name: nessie-inmemory
5+
spec:
6+
size: 1
7+
logLevel: INFO
8+
image:
9+
repository: projectnessie/nessie
10+
tag: 0.75.0
11+
serviceAccount:
12+
create: true
13+
name: nessie-inmemory-sa
14+
versionStore:
15+
type: InMemory
16+
authentication:
17+
enabled: true
18+
oidcAuthServerUrl: http://localhost:8080/auth/realms/nessie
19+
oidcClientId: quarkus-app
20+
authorization:
21+
enabled: true
22+
rules:
23+
allowViewingBranch: op=='VIEW_REFERENCE' && role.startsWith('test_user') && ref.startsWith('allowedBranch')
24+
telemetry:
25+
enabled: true
26+
endpoint: http://localhost:14268/api/traces
27+
sample: "1.0"
28+
attributes:
29+
foo: "bar"
30+
extraEnv:
31+
- name: NESSIE_QUARKUS_PROFILE
32+
value: "prod"
33+
advancedConfig:
34+
nessie.version.store.persist.cache-capacity-mb: 1024
35+
nessie.version.store.persist.cache-capacity-fraction-of-heap: 0.7
36+
nessie.version.store.persist.cache-capacity-fraction-adjust-mb: 256
37+
nessie.version.store.persist.cache-capacity-fraction-min-size-mb: 64
38+
nessie.server.default-branch: my-branch
39+
nessie.version.store.persist.repository-id: my-repository
40+
quarkus:
41+
log:
42+
console.format: "%d{HH:mm:ss} %s%e%n"
43+
category."org.projectnessie".level: "DEBUG"

0 commit comments

Comments
 (0)