Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deployment with kustomize #118

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pr_comment_finished.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
echo "<!-- 🔥config summary -->" > fireconfig-comment.md
echo "## Kubernetes Object DAG" >> fireconfig-comment.md
cat k8s-plan-artifacts/dag.mermaid >> fireconfig-comment.md
echo '<img src="${ASSETS_URL}/new.png" width=10/> New object' >> fireconfig-comment.md
echo '<img src="${ASSETS_URL}/removed.png" width=10/> Deleted object' >> fireconfig-comment.md
echo '<img src="${ASSETS_URL}/changed.png" width=10/> Updated object' >> fireconfig-comment.md
echo '<img src="${ASSETS_URL}/pod_recreate.png" width=10/> Updated object (causes pod recreation)' \
echo "<img src=\"${ASSETS_URL}/new.png\" width=10/> New object" >> fireconfig-comment.md
echo "<img src=\"${ASSETS_URL}/removed.png\" width=10/> Deleted object" >> fireconfig-comment.md
echo "<img src=\"${ASSETS_URL}/changed.png\" width=10/> Updated object" >> fireconfig-comment.md
echo "<img src=\"${ASSETS_URL}/pod_recreate.png\" width=10/> Updated object (causes pod recreation)" \
>> fireconfig-comment.md
echo "## Detailed Diff" >> fireconfig-comment.md
cat k8s-plan-artifacts/k8s.df >> fireconfig-comment.md
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ jobs:
run: |
rustup toolchain install nightly-x86_64-unknown-linux-gnu
rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install poetry
uses: snok/install-poetry@v1
- name: Run pre-commit
uses: pre-commit/[email protected]
- name: Format Rust code
Expand Down
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ repos:
- id: fmt
name: rust-fmt
args: ['--', '--unstable-features']
- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: isort
args:
- --sl
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: flake8
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: local
hooks:
- id: check-crds
name: Check Generated CRDs
- id: check-k8s
name: Check Generated K8s YAML
language: system
entry: bash -c 'make crd && git diff --quiet'
entry: bash -c 'make kustomize && git diff --quiet'
pass_filenames: false
files: 'lib/api/v1/.*'
files: 'lib/api/v1/.*|k8s/.*|Cargo.toml'
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends: default
ignore:
- examples/metrics
- k8s/raw/simkube.io_simulations.yml
- k8s/kustomize

rules:
line-length:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ anyhow = { version = "1.0.75", features = ["backtrace"] }
async-recursion = "1.0.5"
bytes = "1.5.0"
chrono = "0.4.26"
clap = { version = "4.3.21", features = ["cargo", "derive"] }
clap = { version = "4.3.21", features = ["cargo", "derive", "string"] }
either = "1.12.0"
futures = "0.3.28"
json-patch = "1.2.0"
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DOCKER_ARGS=-it --init
endif

RUST_COVER_FILE=$(COVERAGE_DIR)/rust-coverage.$(RUST_COVER_TYPE)
APP_VERSION_CMD=cargo read-manifest | jq -r .version
APP_VERSION=$(shell $(APP_VERSION_CMD))

include build/base.mk
include build/k8s.mk
Expand Down Expand Up @@ -51,6 +53,9 @@ unit:
itest:
$(CARGO_TEST_PREFIX) cargo test --features=testutils itest -- --nocapture --test-threads=1

lint:
pre-commit run --all

cover:
grcov . --binary-path $(BUILD_DIR)/debug/deps -s . -t $(RUST_COVER_TYPE) -o $(RUST_COVER_FILE) --branch \
--ignore '../*' \
Expand All @@ -65,10 +70,20 @@ cover:
--excl-start '#\[cfg\((test|feature = "testutils")'
@if [ "$(RUST_COVER_TYPE)" = "markdown" ]; then cat $(RUST_COVER_FILE); fi

.PHONY: release-patch release-minor release-major
release-patch release-minor release-major:
cargo set-version --bump $(subst release-,,$@)
make kustomize
NEW_APP_VERSION=`$(APP_VERSION_CMD)` && \
git commit -a -m "Release version v$$NEW_APP_VERSION" && \
git tag v$$NEW_APP_VERSION

.PHONY: crd
crd: skctl
$(BUILD_DIR)/skctl crd > k8s/raw/simkube.io_simulations.yml

pre-k8s:: crd

.PHONY: api
api:
openapi-generator generate -i api/v1/simkube.yml -g rust --global-property models -o generated-api
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This package provides the following components:

[![Watch the video](https://img.youtube.com/vi/Q1XpH1H4It8/hqdefault.jpg)](https://www.youtube.com/watch?v=Q1XpH1H4It8)

## Installation

`kubectl apply -k k8s/kustomize`

## Documentation

Full [documentation for SimKube](https://appliedcomputing.io/simkube/index.html) is available on Applied
Expand Down
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+9 −2 k8s.mk
4 changes: 4 additions & 0 deletions cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::fs;

use clap::crate_version;
use simkube::api::v1::{
SimulationDriverConfig,
SimulationHooksConfig,
};
use simkube::metrics::api::prometheus::PrometheusRemoteWrite;
use simkube::prelude::*;

const DRIVER_IMAGE: &str = "quay.io/appliedcomputing/sk-driver";

#[derive(clap::Args)]
#[command(disable_help_flag = true, disable_version_flag = true)]
pub struct Args {
Expand All @@ -33,6 +36,7 @@ pub struct Args {
short = 'I',
long,
long_help = "name of the docker image to use for sk-driver",
default_value = format!("{DRIVER_IMAGE}:v{}", crate_version!()),
help_heading = "Driver"
)]
pub driver_image: String,
Expand Down
11 changes: 9 additions & 2 deletions docs/dev/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ In addition to the project prerequisites, you will need to have the following in
- [pre-commit](https://pre-commit.com)
- Nightly version of rustfmt

SimKube uses [🔥Config](https://github.com/acrlabs/fireconfig) to generate Kubernetes manifests from definitions located
in `./k8s/`. If you want to make changes to the generated Kubernetes manifests, you will need to install the
following additional dependencies:

- Python 3.11
- Python Poetry (https://python-poetry.org/docs/)
- NodeJS

### Optional prerequisites

- [grcov](https://github.com/mozilla/grcov) (if you want to generate coverage reports locally)
- [openapi-generator](https://openapi-generator.tech) (if you need to make changes to the SimKube API)
- [delve](https://github.com/go-delve/delve) (for debugging Golang code)
- [msgpack-tools](https://github.com/ludocode/msgpack-tools) (for inspecting the contents of exported trace files)

### Setup
Expand Down Expand Up @@ -119,7 +126,7 @@ tests, do `make test`.
### Linting your changes

Code linting rules are defined in `.rustfmt.toml`. We also use [clippy](https://doc.rust-lang.org/stable/clippy/usage.html)
for additional Rust linting and checks. We use a _nightly_ version of rustfmt to take advantage of unstable formatting
for additional Rust linting and checks. We use a _nightly_ version of rustfmt to take advantage of unstable formatting
rules, so you will need to install a nightly toolchain here. (Note that all actual Rust code does not use any nightly
features). You can run all lints with `make lint`.

Expand Down
74 changes: 26 additions & 48 deletions docs/intro/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,30 @@ Additional prerequisites are necessary for your simulation cluster:

### Optional Prerequisites

SimKube uses [🔥Config](https://github.com/acrlabs/fireconfig) to generate Kubernetes manifests from definitions located
in `./k8s/`. If you want to use this mechanism for generating Kubernetes manifests, you will need to install the
following additional dependencies:

- Python 3.10
- Python Poetry (https://python-poetry.org/docs/)
- NodeJS

Additionally, if you want to run SimKube on a local development cluster, [kind](https://kind.sigs.k8s.io) >= 0.19 is the
supported tooling for doing so.
If you want to run SimKube on a local development cluster, [kind](https://kind.sigs.k8s.io) >= 0.19 is the supported
tooling for doing so.

If you want to test autoscaling, SimKube currently supports either the [Kubernetes Cluster Autoscaler](https://github.com/kubernetes/autoscaler)
or [Karpenter](https://karpenter.sh). You will need to install and configure these applications to use the
corresponding KWOK provider. For the Kubernetes Cluster Autoscaler, a KWOK [cloud provider](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/cloudprovider/kwok)
is available, and for Karpenter, a basic [KWOK provider](https://github.com/kubernetes-sigs/karpenter/tree/main/kwok) is
used. See [Autoscaling](../adv/autoscaling.md) for more information on configuring these tools.

## Building SimKube
## Installation using hosted quay.io images and kustomize

SimKube images are [hosted on quay.io](https://quay.io/organization/appliedcomputing); the easiest way to install and
run SimKube in your cluster is to use these images along with the provided [kustomize](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/)
YAML files in `k8s/kustomize`:

```
kubectl apply -k k8s/kustomize
```

## Installation from source

If you instead want to build and install SimKube from source, you can follow these steps:

### Building SimKube

To build all SimKube artifacts for the first time run:

Expand All @@ -53,6 +59,10 @@ For all subsequent builds of SimKube artifacts, run only `make build` from the r

To build and push Docker images for all the artifacts, run `DOCKER_REGISTRY=path_to_your_registry:5000 make image`

### Running the artifacts:

To run the artifacts using the images you built in the previous step, run `make run`.

### Cleaning up

All build artifacts are placed in the `.build/` directory. You can remove this directory or run `make clean` to clean
Expand Down Expand Up @@ -146,30 +156,11 @@ spec:
> kubectl apply -f self-signed.yml
```

## Deploying SimKube
## Customizing SimKube

### Generating Kubernetes Manifests
The following section describes some options for customizing the behaviour of your SimKube installation

SimKube currently uses [🔥Config](https://github.com/acrlabs/fireconfig) to generate Kubernetes manifests. You can
generate the required manifests for all SimKube components by running `make k8s` from the root of this repository.

> [!NOTE]
> 🔥Config uses [cdk8s](https://cdk8s.io) internally, which (unfortunately) runs a NodeJS subprocess. If you don't have
> NodeJS and/or Poetry installed, you can generate the manifests inside a Docker container (thanks
> [@vsoch](https://github.com/vsoch)!):<br>
>
> `> docker run -it --entrypoint bash -v $PWD/:/code node:bookworm`<br>
> `> apt-get update && apt-get install -y python3-poetry`<br>
> `> make k8s`<br>

<br>

> [!WARNING]
> The generated manifests are fairly primitive right now and you may need to customize them in order to get them to
> install in your environment. We also don't (currently) have any Helm charts available, but we'd welcome a
> contribution! (See this [GitHub issue](https://github.com/acrlabs/simkube/issues/97))

### Running `sk-tracer`
### Configuration `sk-tracer`

The SimKube tracer runs in a real cluster and collects data about changes to objects in that cluster. You can configure
what objects it watches via a config file. Here is an example config file you can use to watch changes to Deployments,
Expand All @@ -195,13 +186,6 @@ trackedObjects:
as well as pods. For example, if you use the above configuration, you will need the following RBAC policy attached to
the service account used by `sk-tracer`:

To install `sk-tracer` into your cluster, run

```
> kubectl apply -f .build/manifests/0000-global.k8s.yaml
> kubectl apply -f .build/manifests/0001-sk-tracer.k8s.yaml
```

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand All @@ -219,16 +203,10 @@ rules:
verbs: ["get", "watch", "list"]
```

### Running `sk-ctrl`
### Configuring `sk-ctrl`

The SimKube controller just needs the SimKube custom resources installed in the target environment, and needs no other
configuration. After running `make k8s`, run the following commands to install everything:

```
> kubectl apply -f .build/manifests/raw
> kubectl apply -f .build/manifests/0000-global.k8s.yaml
> kubectl apply -f .build/manifests/0002-sk-ctrl.k8s.yaml
```
configuration.

The SimKube controller needs, at a minimum, write access for all of the objects that it will be simulating. In theory,
since this is an isolated (or potentially even local) environment, it should be safe to give it `cluster-admin`, which
Expand Down
4 changes: 4 additions & 0 deletions k8s/kustomize/0000-global.k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: simkube
Loading
Loading