Skip to content

Commit 23256d4

Browse files
committed
add github actions tests on k3d + release setup
Signed-off-by: clux <[email protected]>
1 parent 0cabcad commit 23256d4

File tree

10 files changed

+281
-4
lines changed

10 files changed

+281
-4
lines changed

.github/FUNDING.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [clux]
4+
#patreon: # Replace with a single Patreon username
5+
#open_collective: # Replace with a single Open Collective username
6+
#ko_fi: # Replace with a single Ko-fi username
7+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
#liberapay: # Replace with a single Liberapay username
10+
#issuehunt: # Replace with a single IssueHunt username
11+
#otechie: # Replace with a single Otechie username
12+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/ci.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
cargo-test:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
os: [ubuntu-latest, macos-latest]
11+
runs-on: ${{ matrix.os }}
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
override: true
17+
toolchain: stable
18+
profile: minimal
19+
- uses: Swatinem/rust-cache@v1
20+
- uses: nolar/setup-k3d-k3s@v1
21+
with:
22+
version: v1.21
23+
k3d-name: kube
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
- run: kubectl apply --force-conflicts --server-side -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.52.0/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
26+
- run: cargo build --all
27+
- run: cargo run --bin kopium -- prometheusrules.monitoring.coreos.com > gen.rs
28+
- run: echo "pub type CR = PrometheusRule;" >> gen.rs
29+
- run: kubectl apply -f test.yaml
30+
- run: cargo run --bin tester -- PrometheusRule
31+
32+
33+
rustfmt:
34+
name: Run rustfmt
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- uses: actions-rs/[email protected]
39+
with:
40+
profile: minimal
41+
toolchain: nightly
42+
components: rustfmt
43+
override: true
44+
- name: Run rustfmt
45+
id: rustfmt
46+
run: rustfmt +nightly --edition 2018 --check $(find . -type f -iname *.rs)

.github/workflows/release.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
#push:
6+
# tags:
7+
# - 'v[0-9]+.[0-9]+.[0-9]+'
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
target:
15+
- x86_64-unknown-linux-musl
16+
- x86_64-apple-darwin
17+
include:
18+
- target: x86_64-unknown-linux-musl
19+
os: ubuntu-latest
20+
- target: x86_64-apple-darwin
21+
os: macos-latest
22+
runs-on: ${{ matrix.os }}
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Build Linux
26+
if: matrix.os == 'ubuntu-latest'
27+
run: |
28+
docker run --rm -t \
29+
-v $HOME/.cargo/registry/:/root/.cargo/registry \
30+
-v "$(pwd)":/volume \
31+
clux/muslrust:stable \
32+
cargo build --release --target ${{ matrix.target }}
33+
- name: Prepare macOS
34+
if: matrix.os == 'macos-latest'
35+
uses: actions-rs/toolchain@v1
36+
with:
37+
toolchain: nightly
38+
target: ${{ matrix.target }}
39+
override: true
40+
- name: Build macOS
41+
if: matrix.os == 'macos-latest'
42+
uses: actions-rs/cargo@v1
43+
with:
44+
toolchain: stable
45+
command: build
46+
args: --release --target ${{ matrix.target }}
47+
- name: Upload
48+
uses: actions/upload-artifact@v2
49+
with:
50+
name: kopium-${{ matrix.os }}-amd64
51+
path: target/${{ matrix.target }}/release/kopium
52+
if-no-files-found: error
53+
54+
release:
55+
needs: build
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
- name: Download
60+
uses: actions/download-artifact@v2
61+
- name: Layout
62+
run: |
63+
mv kopium-ubuntu-latest-amd64/kopium ./kopium-linux-amd64
64+
mv kopium-macos-latest-amd64/kopium ./kopium-darwin-amd64
65+
rm -rf kopium-ubuntu-latest-amd64 kopium-macos-latest-amd64
66+
- name: Checksum
67+
run: make SHA256SUMS
68+
- name: Create Release
69+
id: create_release
70+
uses: actions/create-release@v1
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
with:
74+
tag_name: ${{ github.ref }}
75+
release_name: Release ${{ github.ref }}
76+
- name: Release SHA256SUMS
77+
uses: actions/upload-release-asset@v1
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
with:
81+
upload_url: ${{ steps.create_release.outputs.upload_url }}
82+
asset_path: SHA256SUMS
83+
asset_name: SHA256SUMS
84+
asset_content_type: text/plain
85+
- name: Release kopium-linux-amd64
86+
uses: actions/upload-release-asset@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
upload_url: ${{ steps.create_release.outputs.upload_url }}
91+
asset_name: kopium-linux-amd64
92+
asset_path: kopium-linux-amd64
93+
asset_content_type: application/octet-stream
94+
- name: Release kopium-macos-amd64
95+
uses: actions/upload-release-asset@v1
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
with:
99+
upload_url: ${{ steps.create_release.outputs.upload_url }}
100+
asset_path: kopium-darwin-amd64
101+
asset_name: kopium-darwin-amd64
102+
asset_content_type: application/octet-stream

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
gen.rs

Cargo.lock

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ repository = "https://github.com/kube-rs/kopium"
1212
keywords = ["kubernetes", "openapi"]
1313
categories = ["command-line-utilities"]
1414

15+
[[bin]]
16+
doc = false
17+
name = "kopium"
18+
path = "src/main.rs"
19+
20+
[[bin]]
21+
doc = false
22+
name = "tester"
23+
path = "test.rs"
24+
1525
[dependencies]
16-
kube = "0.64.0"
26+
kube = { version = "0.64.0", features = ["derive"] }
1727
k8s-openapi = { version = "0.13.1", features = ["v1_22"] }
1828
tokio = { version = "1.14.0", features = ["full"] }
1929
anyhow = "1.0.48"
@@ -22,3 +32,4 @@ env_logger = "0.9.0"
2232
serde_json = "1.0.72"
2333
clap = "3.0.0-beta.5"
2434
quote = "1.0.10"
35+
serde = { version = "1.0.130", features = ["derive"] }

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cargo install kopium
1717

1818
```sh
1919
kopium prometheusrules.monitoring.coreos.com > prometheusrule.rs
20+
rustfmt +nightly --edition 2021 prometheusrule.rs
2021
```
2122

2223
## Output
@@ -27,8 +28,13 @@ use serde::{Deserialize, Serialize};
2728
use std::collections::BTreeMap;
2829

2930
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
30-
#[kube(group = "monitoring.coreos.com", version = "v1", kind = "PrometheusRule", plural = "prometheusrules")]
31-
#[kube(Namespaced)]
31+
#[kube(
32+
group = "monitoring.coreos.com",
33+
version = "v1",
34+
kind = "PrometheusRule",
35+
plural = "prometheusrules"
36+
)]
37+
#[kube(namespaced)]
3238
#[kube(schema = "disabled")]
3339
pub struct PrometheusRuleSpec {
3440
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@@ -52,4 +58,5 @@ pub struct PrometheusRuleRules {
5258
pub labels: BTreeMap<String, String>,
5359
pub record: Option<String>,
5460
}
61+
5562
```

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async fn main() -> Result<()> {
7171
group, version, kind, plural
7272
);
7373
if scope == "Namespaced" {
74-
println!(r#"#[kube(Namespaced)]"#);
74+
println!(r#"#[kube(namespaced)]"#);
7575
}
7676
// don't support grabbing original schema atm so disable schemas:
7777
// (we coerce IntToString to String anyway so it wont match anyway)

test.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use anyhow::Result;
2+
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::{
3+
CustomResourceDefinition
4+
};
5+
use kube::{Api, Client, Resource, ResourceExt};
6+
7+
include!("./gen.rs"); // import generated test structs in scope
8+
9+
#[tokio::main]
10+
async fn main() -> Result<()> {
11+
let client = Client::try_default().await?;
12+
13+
let api: Api<CustomResourceDefinition> = Api::all(client.clone());
14+
let cr: Api<CR> = Api::default_namespaced(client);
15+
16+
println!("crd gvk {}-{}-{}", CR::group(&()), CR::version(&()), CR::kind(&()));
17+
let canonical = api.get(&format!("{}.{}", CR::plural(&()), CR::group(&()))).await?;
18+
assert_eq!(canonical.spec.names.kind, CR::kind(&()).to_string());
19+
assert_eq!(canonical.spec.names.plural, CR::plural(&()).to_string());
20+
assert_eq!(canonical.spec.group, CR::group(&()).to_string());
21+
22+
// assumes a resource of type CR has been applied with name 'gen' in the namespace
23+
let crd = cr.get("gen").await?;
24+
assert_eq!(crd.name(), "gen");
25+
26+
Ok(())
27+
}

test.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: PrometheusRule
3+
metadata:
4+
name: gen
5+
spec:
6+
groups:
7+
- name: ./pr.rules
8+
rules:
9+
- alert: PRFakeAlert
10+
labels:
11+
severity: info
12+
expr: "0"
13+
for: 10m
14+
annotations:
15+
summary: "Parsing this"

0 commit comments

Comments
 (0)