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

[COR-155] 'coredb install' to install operator #57

Merged
merged 12 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .github/workflows/operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ jobs:
prefix-key: "coredb-operator-functional-test"
workspaces: |
coredb-operator
- name: Check CRD is updated in the yaml directory
run: |
set -xe
cargo run --bin crdgen > yaml/crd.yaml
git diff --exit-code yaml/crd.yaml
Comment on lines +88 to +92
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part will fail if CRD definition is changed but yaml directory not updated

- name: Run functional / integration tests
run: |
set -xe
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/publish_operator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# TODO: replace with push to CoreDB Quay, and versioned pushes.
# This is to enable demo 'coredb install' on the CLI.
#
on:
push:
branches:
- main
- cli
sjmiller609 marked this conversation as resolved.
Show resolved Hide resolved
paths:
- 'coredb-operator/**'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: sjmiller609
password: ${{ secrets.STEVEN_DOCKERHUB_PAT }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: ./coredb-operator
push: true
tags: latest
1 change: 1 addition & 0 deletions coredb-cli/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl SubCommand for CreateCommand {

if !status.success() {
eprintln!("kubectl apply failed with status {:?}", status);
eprintln!("\n\nHint: Is CoreDB installed in the cluster?\n\nTry running 'coredb install'");
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions coredb-cli/src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use super::SubCommand;
use clap::Args;
use std::process::Command;

#[derive(Args)]
pub struct InstallCommand {}

impl SubCommand for InstallCommand {
fn execute(&self) {
let output = Command::new("kubectl")
.arg("apply")
.arg("-f")
.arg("https://raw.githubusercontent.com/CoreDB-io/coredb/main/coredb-operator/yaml/crd.yaml")
.output()
.expect("Failed to execute 'kubectl' command.");
println!("{}", String::from_utf8_lossy(&output.stdout));
let output = Command::new("kubectl")
.arg("apply")
.arg("-f")
.arg("https://raw.githubusercontent.com/CoreDB-io/coredb/main/coredb-operator/yaml/install.yaml")
.output()
.expect("Failed to execute 'kubectl' command.");
println!("{}", String::from_utf8_lossy(&output.stdout));
}
}
1 change: 1 addition & 0 deletions coredb-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod create;
pub mod get;
pub mod install;
use clap::ValueEnum;

#[derive(ValueEnum, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions coredb-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ struct Cli {
enum SubCommands {
Get(commands::get::GetCommand),
Create(commands::create::CreateCommand),
Install(commands::install::InstallCommand),
}

impl SubCommand for SubCommands {
fn execute(&self) {
match self {
SubCommands::Get(cmd) => cmd.execute(),
SubCommands::Create(cmd) => cmd.execute(),
SubCommands::Install(cmd) => cmd.execute(),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions coredb-operator/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target/**
target
Dockerfile
.dockerignore
.git
.gitignore
17 changes: 15 additions & 2 deletions coredb-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
FROM gcr.io/distroless/static:nonroot
COPY --chown=nonroot:nonroot ./controller /app/
FROM clux/muslrust:stable AS builder

COPY . .

RUN cargo build --release

FROM alpine:latest

RUN adduser -D nonroot

COPY --chown=nonroot:nonroot --from=builder target/x86_64-unknown-linux-musl/release/controller /app/controller
COPY --chown=nonroot:nonroot --from=builder target/x86_64-unknown-linux-musl/release/crdgen /app/crdgen

USER nonroot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although rust compiles to a binary, by default that binary has dependencies in the system like openssl and libc. If we build with MUSL we can avoid that - like clux did in the controller example.

EXPOSE 8080
ENTRYPOINT ["/app/controller"]
14 changes: 12 additions & 2 deletions coredb-operator/yaml/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ spec:

This provides a hook for generating the CRD yaml (in crdgen.rs)
properties:
image:
default: docker.io/postgres:15
type: string
port:
default: 5432
format: int32
type: integer
replicas:
default: 1
format: int32
type: integer
uid:
default: 999
format: int32
type: integer
required:
- replicas
type: object
status:
description: The status object of `CoreDB`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ spec:
serviceAccountName: coredb-controller
containers:
- name: coredb-controller
image: localhost:5001/controller:ac593af6da990c911652c6e35fb777f36498d6dc
image: sjmiller609/coredb-operator:latest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace this with quay when ian is back

imagePullPolicy: Always
resources:
limits:
Expand Down