Skip to content

Commit

Permalink
make injection pod and service easier to read
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
AustinAbro321 committed Oct 18, 2024
1 parent 5736f56 commit ca48559
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/pkg/cluster/injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestInjector(t *testing.T) {
// Managed fields are auto-set and contain timestamps
svc.ManagedFields = nil
require.NoError(t, err)
b, err := json.Marshal(svc)
b, err := json.MarshalIndent(svc, "", " ")
require.NoError(t, err)
require.Equal(t, strings.TrimSpace(string(expected)), string(b))

Expand Down Expand Up @@ -162,7 +162,7 @@ func TestBuildInjectionPod(t *testing.T) {
})
pod := buildInjectionPod("injection-node", "docker.io/library/ubuntu:latest", []string{"foo", "bar"}, "shasum", resReq)
require.Equal(t, "injector", *pod.Name)
b, err := json.Marshal(pod)
b, err := json.MarshalIndent(pod, "", " ")
require.NoError(t, err)

expected, err := os.ReadFile("./testdata/expected-injection-pod.json")
Expand Down
112 changes: 111 additions & 1 deletion src/pkg/cluster/testdata/expected-injection-pod.json
Original file line number Diff line number Diff line change
@@ -1 +1,111 @@
{"kind":"Pod","apiVersion":"v1","metadata":{"name":"injector","namespace":"zarf","labels":{"app":"zarf-injector","zarf.dev/agent":"ignore"}},"spec":{"volumes":[{"name":"init","configMap":{"name":"rust-binary","defaultMode":511}},{"name":"seed","emptyDir":{}},{"name":"foo","configMap":{"name":"foo"}},{"name":"bar","configMap":{"name":"bar"}}],"containers":[{"name":"injector","image":"docker.io/library/ubuntu:latest","command":["/zarf-init/zarf-injector","shasum"],"workingDir":"/zarf-init","resources":{"limits":{"cpu":"1","memory":"256Mi"},"requests":{"cpu":"500m","memory":"64Mi"}},"volumeMounts":[{"name":"init","mountPath":"/zarf-init/zarf-injector","subPath":"zarf-injector"},{"name":"seed","mountPath":"/zarf-seed"},{"name":"foo","mountPath":"/zarf-init/foo","subPath":"foo"},{"name":"bar","mountPath":"/zarf-init/bar","subPath":"bar"}],"readinessProbe":{"httpGet":{"path":"/v2/","port":5000},"periodSeconds":2,"successThreshold":1,"failureThreshold":10},"imagePullPolicy":"IfNotPresent","securityContext":{"capabilities":{"drop":["ALL"]},"runAsNonRoot":true,"readOnlyRootFilesystem":true,"allowPrivilegeEscalation":false}}],"restartPolicy":"Never","nodeName":"injection-node","securityContext":{"runAsUser":1000,"runAsGroup":2000,"fsGroup":2000,"seccompProfile":{"type":"RuntimeDefault"}}}}
{
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "injector",
"namespace": "zarf",
"labels": {
"app": "zarf-injector",
"zarf.dev/agent": "ignore"
}
},
"spec": {
"volumes": [
{
"name": "init",
"configMap": {
"name": "rust-binary",
"defaultMode": 511
}
},
{
"name": "seed",
"emptyDir": {}
},
{
"name": "foo",
"configMap": {
"name": "foo"
}
},
{
"name": "bar",
"configMap": {
"name": "bar"
}
}
],
"containers": [
{
"name": "injector",
"image": "docker.io/library/ubuntu:latest",
"command": [
"/zarf-init/zarf-injector",
"shasum"
],
"workingDir": "/zarf-init",
"resources": {
"limits": {
"cpu": "1",
"memory": "256Mi"
},
"requests": {
"cpu": "500m",
"memory": "64Mi"
}
},
"volumeMounts": [
{
"name": "init",
"mountPath": "/zarf-init/zarf-injector",
"subPath": "zarf-injector"
},
{
"name": "seed",
"mountPath": "/zarf-seed"
},
{
"name": "foo",
"mountPath": "/zarf-init/foo",
"subPath": "foo"
},
{
"name": "bar",
"mountPath": "/zarf-init/bar",
"subPath": "bar"
}
],
"readinessProbe": {
"httpGet": {
"path": "/v2/",
"port": 5000
},
"periodSeconds": 2,
"successThreshold": 1,
"failureThreshold": 10
},
"imagePullPolicy": "IfNotPresent",
"securityContext": {
"capabilities": {
"drop": [
"ALL"
]
},
"runAsNonRoot": true,
"readOnlyRootFilesystem": true,
"allowPrivilegeEscalation": false
}
}
],
"restartPolicy": "Never",
"nodeName": "injection-node",
"securityContext": {
"runAsUser": 1000,
"runAsGroup": 2000,
"fsGroup": 2000,
"seccompProfile": {
"type": "RuntimeDefault"
}
}
}
}
25 changes: 24 additions & 1 deletion src/pkg/cluster/testdata/expected-injection-service.json
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
{"kind":"Service","apiVersion":"v1","metadata":{"name":"zarf-injector","namespace":"zarf","creationTimestamp":null},"spec":{"ports":[{"port":5000,"targetPort":0}],"selector":{"app":"zarf-injector"},"type":"NodePort"},"status":{"loadBalancer":{}}}
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "zarf-injector",
"namespace": "zarf",
"creationTimestamp": null
},
"spec": {
"ports": [
{
"port": 5000,
"targetPort": 0
}
],
"selector": {
"app": "zarf-injector"
},
"type": "NodePort"
},
"status": {
"loadBalancer": {}
}
}

0 comments on commit ca48559

Please sign in to comment.