Skip to content

Commit 068d2ed

Browse files
committed
feat(backstage): enable pod deletion, improve RBAC and Kubernetes metadata integration
- Added pod deletion support in Backstage Kubernetes plugin (frontend.podDelete.enabled) - Set serviceAccountNamespace to backstage-system in clusterLocator config - Enhanced RBAC to allow Backstage to delete pods using a new ClusterRole - Labeled pods and deployments for improved entity linking in Backstage - Adjusted catalog rules and template ownership for xqueue-claim scaffolder
1 parent 17489f3 commit 068d2ed

File tree

6 files changed

+55
-19
lines changed

6 files changed

+55
-19
lines changed

.bootstrap/backstage/manifests/deployment.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ kind: Deployment
33
metadata:
44
name: backstage
55
namespace: backstage-system
6+
labels:
7+
app: backstage
8+
backstage.io/kubernetes-id: backstage
9+
backstage.io/kubernetes-namespace: backstage-system
610
spec:
711
replicas: 1
812
selector:
@@ -13,7 +17,9 @@ spec:
1317
labels:
1418
app: backstage
1519
backstage.io/kubernetes-id: backstage
20+
backstage.io/kubernetes-namespace: backstage-system
1621
spec:
22+
serviceAccountName: backstage-user
1723
containers:
1824
- name: backstage
1925
image: backstage:latest
@@ -28,12 +34,22 @@ spec:
2834
name: postgres-secrets
2935
- secretRef:
3036
name: backstage-secrets
37+
env:
38+
- name: SERVICE_ACCOUNT_TOKEN
39+
valueFrom:
40+
secretKeyRef:
41+
name: backstage-token
42+
key: token
3143
---
3244
apiVersion: apps/v1
3345
kind: Deployment
3446
metadata:
3547
name: postgres
3648
namespace: backstage-system
49+
labels:
50+
app: postgres
51+
backstage.io/kubernetes-id: backstage-postgres
52+
backstage.io/kubernetes-namespace: backstage-system
3753
spec:
3854
replicas: 1
3955
selector:
@@ -43,7 +59,8 @@ spec:
4359
metadata:
4460
labels:
4561
app: postgres
46-
backstage.io.kubernetes-id: backstage-postgres
62+
backstage.io/kubernetes-id: backstage-postgres
63+
backstage.io/kubernetes-namespace: backstage-system
4764
spec:
4865
containers:
4966
- name: postgres

.bootstrap/backstage/manifests/rbac.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ subjects:
7070
- kind: ServiceAccount
7171
name: backstage-user
7272
namespace: backstage-system
73+
---
74+
apiVersion: rbac.authorization.k8s.io/v1
75+
kind: ClusterRole
76+
metadata:
77+
name: backstage-k8s-pod-actions
78+
rules:
79+
- apiGroups: [""]
80+
resources: ["pods"]
81+
verbs: ["get", "list", "watch", "delete"]
82+
---
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
kind: ClusterRoleBinding
85+
metadata:
86+
name: backstage-k8s-pod-actions-binding
87+
roleRef:
88+
apiGroup: rbac.authorization.k8s.io
89+
kind: ClusterRole
90+
name: backstage-k8s-pod-actions
91+
subjects:
92+
- kind: ServiceAccount
93+
name: backstage-user
94+
namespace: backstage-system

.bootstrap/backstage/up.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ kind load docker-image "$IMAGE" --name "$CLUSTER_NAME"
4545
echo "Applying manifests from $MANIFESTS_DIR..."
4646
kubectl apply -f "$MANIFESTS_DIR" --recursive --namespace "$NS"
4747

48-
# Wait for the ServiceAccount Secret to be created
49-
echo "Waiting for backstage-token to be created..."
50-
until kubectl get secret -n "$NS" backstage-token >/dev/null 2>&1; do
51-
sleep 1
52-
done
53-
54-
# Injecting SERVICE_ACCOUNT_TOKEN into backstage-secrets...
55-
echo "Injecting SERVICE_ACCOUNT_TOKEN into backstage-secrets..."
56-
SERVICE_ACCOUNT_TOKEN=$(kubectl get secret -n "$NS" backstage-token -o jsonpath='{.data.token}' | base64 --decode)
57-
58-
kubectl patch secret backstage-secrets \
59-
-n "$NS" \
60-
--type='merge' \
61-
-p "{\"data\": {\"SERVICE_ACCOUNT_TOKEN\": \"$(echo -n "$SERVICE_ACCOUNT_TOKEN" | base64)\"}}"
62-
6348
# Wait for postgres deployment to be ready
6449
echo "Waiting for postgres deployment to be ready..."
6550
kubectl rollout status deployment/postgres -n "$NS" --timeout=120s || {

backstage/app-config.production.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ catalog:
5353
entityFilename: catalog-info.yaml
5454
pullRequestBranchName: backstage-integration
5555
rules:
56-
- allow: ['*']
56+
- allow: [Component, System, API, Resource, Location]
5757
locations:
5858
# All Templates
5959
- type: url
6060
target: https://github.com/wnqueiroz/platform-engineering-backstack/blob/main/backstage/catalog/all.yaml
61+
rules:
62+
- allow: [Template, System, User, Group]
6163

6264
# Experimental: Always use the search method in UrlReaderProcessor.
6365
# New adopters are encouraged to enable it as this behavior will be the default in a future release.
6466
useUrlReadersSearch: true
6567

6668
kubernetes:
6769
# see https://backstage.io/docs/features/kubernetes/configuration for kubernetes configuration options
70+
frontend:
71+
podDelete:
72+
enabled: true
6873
serviceLocatorMethod:
6974
type: 'multiTenant'
7075
clusterLocatorMethods:
@@ -76,3 +81,4 @@ kubernetes:
7681
skipTLSVerify: true
7782
skipMetricsLookup: true
7883
serviceAccountToken: ${SERVICE_ACCOUNT_TOKEN}
84+
serviceAccountNamespace: backstage-system

backstage/app-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ catalog:
7676
entityFilename: catalog-info.yaml
7777
pullRequestBranchName: backstage-integration
7878
rules:
79-
- allow: ['*']
79+
- allow: [Component, System, API, Resource, Location]
8080
locations:
8181
# All Templates
8282
- type: url
8383
target: https://github.com/wnqueiroz/platform-engineering-backstack/blob/main/backstage/catalog/all.yaml
84+
rules:
85+
- allow: [Template, System, User, Group]
8486

8587
# Local example data, file locations are relative to the backend process, typically `packages/backend`
8688
- type: file
@@ -113,6 +115,9 @@ catalog:
113115

114116
kubernetes:
115117
# see https://backstage.io/docs/features/kubernetes/configuration for kubernetes configuration options
118+
frontend:
119+
podDelete:
120+
enabled: true
116121
serviceLocatorMethod:
117122
type: 'multiTenant'
118123
clusterLocatorMethods:
@@ -124,6 +129,7 @@ kubernetes:
124129
skipTLSVerify: true
125130
skipMetricsLookup: true
126131
serviceAccountToken: ${SERVICE_ACCOUNT_TOKEN}
132+
serviceAccountNamespace: backstage-system
127133

128134
# see https://backstage.io/docs/permissions/getting-started for more on the permission framework
129135
permission:

backstage/catalog/templates/xqueue-claim/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
title: Create XQueue Claim
66
description: Creates a Crossplane XQueueClaim and opens a PR with the YAML.
77
spec:
8-
owner: user:guest
8+
owner: guests
99
type: infrastructure
1010

1111
parameters:

0 commit comments

Comments
 (0)