Skip to content

Commit afeda83

Browse files
committed
Add Kubernetes operator deployment files and certificates
1 parent a2688df commit afeda83

15 files changed

+591
-15
lines changed

.config/dotnet-tools.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"kubeops.cli": {
6-
"version": "9.0.0",
6+
"version": "9.8.2",
77
"commands": [
88
"kubeops"
9-
]
9+
],
10+
"rollForward": false
1011
}
1112
}
1213
}

Docker/Converters/ContainerConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ protected virtual V1PodSpec GeneratePodSpec(string name, DockerService service,
287287
{
288288
if ((sentryDeployment.Spec.Resources?.TryGetValue(name, out var resource) ?? false) && resource.Requests != null)
289289
{
290-
return resource.Requests;
290+
return resource.Requests.ToDictionary();
291291
}
292292

293293
return name switch
@@ -336,7 +336,7 @@ _ when name.Contains("replacer") => sentryDeployment.Spec.Resources?.Replacer?.R
336336
{
337337
if ((sentryDeployment.Spec.Resources?.TryGetValue(name, out var resource) ?? false) && resource.Limits != null)
338338
{
339-
return resource.Limits;
339+
return resource.Limits.ToDictionary();
340340
}
341341

342342
return name switch

Entities/SentryDeployment.cs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,61 @@ public class SentryDeploymentCertificateConfig
6767
public string[] CustomHosts { get; set; } = Array.Empty<string>();
6868
}
6969

70-
public class ResourceLimitConfig : Dictionary<string, V1ResourceRequirements>
70+
public class ResourceLimitConfig : Dictionary<string, ResourceRequirementDefinition>
7171
{
72-
public V1ResourceRequirements? Web { get; set; }
73-
public V1ResourceRequirements? Worker { get; set; }
74-
public V1ResourceRequirements? Cron { get; set; }
75-
public V1ResourceRequirements? Snuba { get; set; }
76-
public V1ResourceRequirements? Relay { get; set; }
77-
public V1ResourceRequirements? Consumer { get; set; }
78-
public V1ResourceRequirements? Ingest { get; set; }
79-
public V1ResourceRequirements? Forwarder { get; set; }
80-
public V1ResourceRequirements? Replacer { get; set; }
72+
public ResourceRequirementDefinition? Web { get; set; }
73+
public ResourceRequirementDefinition? Worker { get; set; }
74+
public ResourceRequirementDefinition? Cron { get; set; }
75+
public ResourceRequirementDefinition? Snuba { get; set; }
76+
public ResourceRequirementDefinition? Relay { get; set; }
77+
public ResourceRequirementDefinition? Consumer { get; set; }
78+
public ResourceRequirementDefinition? Ingest { get; set; }
79+
public ResourceRequirementDefinition? Forwarder { get; set; }
80+
public ResourceRequirementDefinition? Replacer { get; set; }
8181
// ReSharper disable once InconsistentNaming
82-
public V1ResourceRequirements? GeoIP { get; set; }
82+
public ResourceRequirementDefinition? GeoIP { get; set; }
83+
}
84+
85+
public class ResourceRequirementDefinition
86+
{
87+
public ResourceRequirement? Limits { get; set; }
88+
public ResourceRequirement? Requests { get; set; }
89+
}
90+
91+
public class ResourceRequirement
92+
{
93+
public string? Cpu { get; set; }
94+
public string? Memory { get; set; }
95+
96+
public ResourceRequirement(string? cpu, string? memory)
97+
{
98+
Cpu = cpu;
99+
Memory = memory;
100+
}
101+
102+
public ResourceRequirement() {}
103+
104+
public static implicit operator Dictionary<string, ResourceQuantity>(ResourceRequirement requirement)
105+
{
106+
return requirement.ToDictionary();
107+
}
108+
109+
public Dictionary<string, ResourceQuantity> ToDictionary()
110+
{
111+
var result = new Dictionary<string, ResourceQuantity>();
112+
if (Cpu != null)
113+
{
114+
result["cpu"] = new ResourceQuantity(Cpu);
115+
}
116+
if (Memory != null)
117+
{
118+
result["memory"] = new ResourceQuantity(Memory);
119+
}
120+
return result;
121+
}
122+
123+
public override string ToString()
124+
{
125+
return $"Cpu: {Cpu}, Memory: {Memory}";
126+
}
83127
}

config/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:latest as build
2+
WORKDIR /operator
3+
4+
COPY ./ ./
5+
RUN dotnet publish -c Release /p:AssemblyName=operator -o out
6+
7+
# The runner for the application
8+
FROM mcr.microsoft.com/dotnet/aspnet:latest as final
9+
10+
RUN addgroup k8s-operator && useradd -G k8s-operator operator-user
11+
12+
WORKDIR /operator
13+
COPY --from=build /operator/out/ ./
14+
RUN chown operator-user:k8s-operator -R .
15+
16+
USER operator-user
17+
18+
ENTRYPOINT [ "dotnet", "operator.dll" ]

config/ca.pem

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBljCCATugAwIBAgIIIFBZeo8c6QAwCgYIKoZIzj0EAwQwPjETMBEGA1UEBxMK
3+
S3ViZXJuZXRlczEMMAoGA1UEBhMDREVWMRkwFwYDVQQDExBPcGVyYXRvciBSb290
4+
IENBMB4XDTI1MDYyNDAwMDAwMFoXDTMwMDYyNDAwMDAwMFowPjETMBEGA1UEBxMK
5+
S3ViZXJuZXRlczEMMAoGA1UEBhMDREVWMRkwFwYDVQQDExBPcGVyYXRvciBSb290
6+
IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEXZS0HVIV3WM0BLzrsL86npUk
7+
w0jOfB/UmlJNowlBBCaa1tzCiNt2mpARiX8peMm2pzvkcZkYEoXR578r+ttGnqMj
8+
MCEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCASYwCgYIKoZIzj0EAwQD
9+
SQAwRgIhAPNoj/wfQ9ZEqY50ai8yP8YmDXhDgl248I2lFDCh83lvAiEA4QuA2M7C
10+
AuAad+ugXoFGHQWk2ZleltKhS5mTfC15L94=
11+
-----END CERTIFICATE-----

config/deployment.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
operator-deployment: kubernetes-operator
6+
name: operator
7+
spec:
8+
replicas: 1
9+
revisionHistoryLimit: 0
10+
selector:
11+
matchLabels:
12+
operator-deployment: kubernetes-operator
13+
template:
14+
metadata:
15+
labels:
16+
operator-deployment: kubernetes-operator
17+
spec:
18+
containers:
19+
- env:
20+
- name: POD_NAMESPACE
21+
valueFrom:
22+
fieldRef:
23+
fieldPath: metadata.namespace
24+
envFrom:
25+
- configMapRef:
26+
name: webhook-config
27+
image: operator
28+
name: operator
29+
ports:
30+
- containerPort: 5001
31+
name: https
32+
resources:
33+
limits:
34+
cpu: 100m
35+
memory: 128Mi
36+
requests:
37+
cpu: 100m
38+
memory: 64Mi
39+
volumeMounts:
40+
- mountPath: /certs
41+
name: certificates
42+
readOnly: true
43+
- mountPath: /ca
44+
name: ca-certificates
45+
readOnly: true
46+
terminationGracePeriodSeconds: 10
47+
volumes:
48+
- name: certificates
49+
secret:
50+
secretName: webhook-cert
51+
- name: ca-certificates
52+
secret:
53+
secretName: webhook-ca

config/kustomization.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace: sentryoperator-system
2+
namePrefix: sentryoperator-
3+
labels:
4+
- includeSelectors: true
5+
pairs:
6+
operator: sentryoperator
7+
resources:
8+
- operator-role.yaml
9+
- operator-role-binding.yaml
10+
- deployment.yaml
11+
- service.yaml
12+
- validators.yaml
13+
- sentrydeployments_sentry_io.yaml
14+
- namespace.yaml
15+
images:
16+
- name: operator
17+
newName: accessible-docker-image
18+
newTag: latest
19+
configMapGenerator:
20+
- name: webhook-config
21+
literals:
22+
- KESTREL__ENDPOINTS__HTTP__URL=http://0.0.0.0:5000
23+
- KESTREL__ENDPOINTS__HTTPS__URL=https://0.0.0.0:5001
24+
- KESTREL__ENDPOINTS__HTTPS__CERTIFICATE__PATH=/certs/svc.pem
25+
- KESTREL__ENDPOINTS__HTTPS__CERTIFICATE__KEYPATH=/certs/svc-key.pem
26+
secretGenerator:
27+
- name: webhook-ca
28+
files:
29+
- ca.pem
30+
- ca-key.pem
31+
- name: webhook-cert
32+
files:
33+
- svc.pem
34+
- svc-key.pem
35+
apiVersion: kustomize.config.k8s.io/v1beta1
36+
kind: Kustomization

config/namespace.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: system

config/operator-role-binding.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: operator-role-binding
5+
roleRef:
6+
apiGroup: rbac.authorization.k8s.io
7+
kind: ClusterRole
8+
name: operator-role
9+
subjects:
10+
- kind: ServiceAccount
11+
name: default
12+
namespace: system

config/operator-role.yaml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: operator-role
5+
rules:
6+
- apiGroups:
7+
- cert-manager.io
8+
nonResourceURLs: []
9+
resources:
10+
- certificates
11+
verbs:
12+
- get
13+
- create
14+
- patch
15+
- delete
16+
- apiGroups:
17+
- sentry.io
18+
resources:
19+
- sentrydeployments
20+
verbs:
21+
- '*'
22+
- apiGroups:
23+
- ""
24+
resources:
25+
- pods
26+
- services
27+
- secrets
28+
- configmaps
29+
verbs:
30+
- get
31+
- list
32+
- create
33+
- update
34+
- patch
35+
- delete
36+
- apiGroups:
37+
- apps
38+
resources:
39+
- deployments
40+
verbs:
41+
- get
42+
- list
43+
- create
44+
- update
45+
- patch
46+
- delete
47+
- apiGroups:
48+
- ""
49+
resources:
50+
- events
51+
verbs:
52+
- get
53+
- list
54+
- create
55+
- update
56+
- apiGroups:
57+
- coordination.k8s.io
58+
resources:
59+
- leases
60+
verbs:
61+
- get
62+
- list
63+
- watch
64+
- create
65+
- update
66+
- patch
67+
- delete
68+
- apiGroups:
69+
- sentry.io
70+
resources:
71+
- sentrydeployments/status
72+
verbs:
73+
- get
74+
- update
75+
- patch
76+
- apiGroups:
77+
- ""
78+
resources:
79+
- pods/status
80+
verbs:
81+
- get
82+
- update
83+
- patch
84+
- apiGroups:
85+
- apps
86+
resources:
87+
- deployments/status
88+
verbs:
89+
- get
90+
- update
91+
- patch
92+
- apiGroups:
93+
- ""
94+
resources:
95+
- services/status
96+
verbs:
97+
- get
98+
- update
99+
- patch

0 commit comments

Comments
 (0)