Skip to content

Commit ecd6416

Browse files
Merge pull request #196 from syntasso/blog/378/debugging
Blog/378/debugging
2 parents e6865df + 1ab0d8d commit ecd6416

File tree

8 files changed

+619
-19
lines changed

8 files changed

+619
-19
lines changed

assets/runtime-promise/.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export PATH="$(pwd)/internal/scripts:$PATH"

assets/runtime-promise/internal/configure-pipeline/resource-configure

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ if [ -n "${configMapDomain}" ]; then
2121
domainPort="${configMapDomainPort}"
2222
fi
2323

24+
mkdir /kratix/output/${lifecycle}
25+
2426
kubectl create deployment ${name} \
2527
--image=${image} --namespace=${namespace} \
2628
--replicas=${replicas} \
2729
--dry-run=client -o yaml > deployment.yaml
2830

29-
yq '.spec.template.spec.containers[0].env = env(applicationEnv)' deployment.yaml > /kratix/output/deployment.yaml
31+
yq '.spec.template.spec.containers[0].env = env(applicationEnv)' deployment.yaml > /kratix/output/${lifecycle}/deployment.yaml
3032

3133
kubectl create service nodeport ${name} \
3234
--namespace=${namespace} \
3335
--tcp=${service_port}\
3436
--dry-run=client \
35-
--output yaml > /kratix/output/service.yaml
37+
--output yaml > /kratix/output/${lifecycle}/service.yaml
3638

3739
kubectl create ingress ${name} \
3840
--namespace=${namespace} \
3941
--class="nginx" \
4042
--rule="${name}.${namespace}.${domain}/*=${name}:${service_port}" \
4143
--dry-run=client \
42-
--output yaml > /kratix/output/ingress.yaml
44+
--output yaml > /kratix/output/${lifecycle}/ingress.yaml
4345

4446
echo """
4547
- matchLabels:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: platform.kratix.io/v1alpha1
2+
kind: PromiseRelease
3+
metadata:
4+
name: runtime
5+
spec:
6+
version: v1.0.0
7+
sourceRef:
8+
type: http
9+
url: https://raw.githubusercontent.com/syntasso/kratix-marketplace/refs/heads/main/runtime/promise.yaml

assets/runtime-promise/promise.yaml

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
apiVersion: platform.kratix.io/v1alpha1
22
kind: Promise
33
metadata:
4-
name: runtime
54
labels:
65
kratix.io/promise-version: v1.0.0
6+
name: runtime
77
spec:
8-
destinationSelectors:
9-
- matchLabels:
10-
environment: dev
118
api:
129
apiVersion: apiextensions.k8s.io/v1
1310
kind: CustomResourceDefinition
@@ -75,6 +72,9 @@ spec:
7572
type: object
7673
served: true
7774
storage: true
75+
destinationSelectors:
76+
- matchLabels:
77+
environment: dev
7878
workflows:
7979
promise:
8080
configure:
@@ -91,19 +91,12 @@ spec:
9191
- apiVersion: platform.kratix.io/v1alpha1
9292
kind: Pipeline
9393
metadata:
94+
creationTimestamp: null
9495
name: instance
9596
spec:
96-
rbac:
97-
permissions:
98-
- apiGroups:
99-
- ""
100-
resources:
101-
- configmaps
102-
verbs:
103-
- get
104-
- list
105-
resourceNames: [ runtime-domain ]
10697
containers:
107-
- image: ghcr.io/syntasso/kratix-marketplace/runtime-configure-pipeline:v0.1.0
98+
- command:
99+
- resource-configure
100+
image: ghcr.io/syntasso/kratix-docs/runtime-configure-pipeline:v0.1.0
108101
name: resource-configure
109-
command: [ resource-configure ]
102+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM "alpine"
2+
3+
RUN apk update && apk add --no-cache yq curl
4+
5+
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.18.3
6+
7+
ADD scripts/pipeline.sh /usr/bin/pipeline.sh
8+
ADD resources resources
9+
10+
RUN chmod +x /usr/bin/pipeline.sh
11+
12+
CMD [ "sh", "-c", "pipeline.sh" ]
13+
ENTRYPOINT []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
image="$(yq eval '.spec.image' /kratix/input/object.yaml)"
6+
7+
echo "Scanning ${image}"
8+
9+
if [ $DEBUG = "true" ]; then
10+
DEBUG_MODE=true
11+
echo "Running in debug mode"
12+
else
13+
DEBUG_MODE=false
14+
fi
15+
16+
TRIVY_DEBUG=$DEBUG_MODE trivy image --format=json --output=results.json "${image}" > results.json
17+
18+
health_state="healthy"
19+
20+
if [ "$(jq '.[] | select(.Vulnerabilities != null) | length' results.json)" != "" ]; then
21+
health_state="degraded"
22+
fi
23+
24+
resource_name=$(yq '.metadata.name' /kratix/input/object.yaml)
25+
namespace="default"
26+
27+
mkdir -p /kratix/output/platform/
28+
29+
cat <<EOF > /kratix/output/platform/health-record.yaml
30+
apiVersion: platform.kratix.io/v1alpha1
31+
kind: HealthRecord
32+
metadata:
33+
name: runtime-${resource_name}
34+
namespace: ${namespace}
35+
data:
36+
promiseRef:
37+
name: runtime
38+
resourceRef:
39+
name: ${resource_name}
40+
namespace: ${namespace}
41+
state: ${health_state}
42+
lastRun: $(date +%s)
43+
details:
44+
results: ""
45+
EOF
46+
47+
cat results.json | yq -P > results.yaml
48+
yq e -i '.data.details.results = load("results.yaml")' /kratix/output/platform/health-record.yaml
49+
50+
cat <<EOF > /kratix/metadata/destination-selectors.yaml
51+
- directory: platform
52+
matchLabels:
53+
environment: platform
54+
EOF

blog/2025-03-05-debugging/app.png

923 KB
Loading

0 commit comments

Comments
 (0)