mirror of
https://github.com/imjasonh/krust
synced 2026-07-08 06:45:32 +00:00
implement resolve and apply
Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
parent
3b1b7ab2ec
commit
1ed99cbe07
18 changed files with 877 additions and 11 deletions
32
tests/testdata/apply_basic.txt
vendored
Normal file
32
tests/testdata/apply_basic.txt
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Test basic apply command (requires kubectl)
|
||||
|
||||
[!exec:kubectl] skip 'kubectl not available'
|
||||
|
||||
-- Cargo.toml --
|
||||
[package]
|
||||
name = "test-app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
-- src/main.rs --
|
||||
fn main() {
|
||||
println!("Hello from test-app!");
|
||||
}
|
||||
|
||||
-- deployment.yaml --
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: test-config
|
||||
data:
|
||||
key: value
|
||||
|
||||
# Apply should resolve and apply with kubectl
|
||||
# Note: This test only verifies the command runs, not the actual k8s deployment
|
||||
# since we don't have a test cluster
|
||||
env KRUST_REPO=ttl.sh/test
|
||||
! exec ./krust apply -f deployment.yaml
|
||||
# kubectl will fail with connection error in test environment, but that's expected
|
||||
stderr 'kubectl'
|
||||
32
tests/testdata/resolve_basic.txt
vendored
Normal file
32
tests/testdata/resolve_basic.txt
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Test basic resolve with single YAML file and single krust:// reference
|
||||
|
||||
-- Cargo.toml --
|
||||
[package]
|
||||
name = "test-app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
-- src/main.rs --
|
||||
fn main() {
|
||||
println!("Hello from test-app!");
|
||||
}
|
||||
|
||||
-- deployment.yaml --
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pod
|
||||
spec:
|
||||
containers:
|
||||
- name: app
|
||||
image: krust://.
|
||||
|
||||
# Resolve should build and replace reference
|
||||
env KRUST_REPO=ttl.sh/test
|
||||
exec ./krust resolve -f deployment.yaml
|
||||
stdout 'ttl.sh/test/test-app@sha256:'
|
||||
! stdout 'krust://'
|
||||
stderr 'Found 1 unique krust:// reference'
|
||||
stderr 'Building image for: krust://.'
|
||||
38
tests/testdata/resolve_dedup.txt
vendored
Normal file
38
tests/testdata/resolve_dedup.txt
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Test that multiple references to the same path are deduplicated
|
||||
|
||||
-- Cargo.toml --
|
||||
[package]
|
||||
name = "test-app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
-- src/main.rs --
|
||||
fn main() {
|
||||
println!("Hello!");
|
||||
}
|
||||
|
||||
-- deployment.yaml --
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test-pod
|
||||
spec:
|
||||
containers:
|
||||
- name: app1
|
||||
image: krust://.
|
||||
- name: app2
|
||||
image: krust://.
|
||||
initContainers:
|
||||
- name: init
|
||||
image: krust://.
|
||||
|
||||
# Should find only 1 unique reference and build once
|
||||
env KRUST_REPO=ttl.sh/test
|
||||
exec ./krust resolve -f deployment.yaml
|
||||
stdout 'ttl.sh/test/test-app@sha256:'
|
||||
stderr 'Found 1 unique krust:// reference'
|
||||
! stderr 'Found 3'
|
||||
# All three references should be replaced with same digest
|
||||
stdout -count=3 'ttl.sh/test/test-app@sha256:'
|
||||
43
tests/testdata/resolve_directory.txt
vendored
Normal file
43
tests/testdata/resolve_directory.txt
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Test resolving references in a directory of YAML files
|
||||
|
||||
-- Cargo.toml --
|
||||
[package]
|
||||
name = "test-app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
-- src/main.rs --
|
||||
fn main() {
|
||||
println!("Hello!");
|
||||
}
|
||||
|
||||
-- k8s/deployment.yaml --
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: krust://.
|
||||
|
||||
-- k8s/service.yaml --
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: app-service
|
||||
spec:
|
||||
selector:
|
||||
app: test
|
||||
|
||||
# Resolve should process all YAML files in directory
|
||||
env KRUST_REPO=ttl.sh/test
|
||||
exec ./krust resolve -f k8s
|
||||
stdout 'kind: Deployment'
|
||||
stdout 'kind: Service'
|
||||
stdout 'ttl.sh/test/test-app@sha256:'
|
||||
! stdout 'krust://'
|
||||
stderr 'Found 1 unique krust:// reference'
|
||||
47
tests/testdata/resolve_multi_document.txt
vendored
Normal file
47
tests/testdata/resolve_multi_document.txt
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Test YAML file with multiple documents separated by ---
|
||||
|
||||
-- Cargo.toml --
|
||||
[package]
|
||||
name = "test-app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
-- src/main.rs --
|
||||
fn main() {
|
||||
println!("Hello!");
|
||||
}
|
||||
|
||||
-- manifests.yaml --
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config
|
||||
data:
|
||||
key: value
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: pod1
|
||||
spec:
|
||||
containers:
|
||||
- image: krust://.
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: pod2
|
||||
spec:
|
||||
containers:
|
||||
- image: krust://.
|
||||
|
||||
# Should handle multiple documents and preserve structure
|
||||
env KRUST_REPO=ttl.sh/test
|
||||
exec ./krust resolve -f manifests.yaml
|
||||
stdout 'kind: ConfigMap'
|
||||
stdout 'kind: Pod'
|
||||
stdout -count=2 'ttl.sh/test/test-app@sha256:'
|
||||
stdout -count=2 '---'
|
||||
stderr 'Found 1 unique krust:// reference'
|
||||
Loading…
Add table
Add a link
Reference in a new issue