-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mlo 133 create admission controller #906
base: master
Are you sure you want to change the base?
Changes from all commits
8a84f8d
2767261
685cd58
af03835
efaeb23
c4a5d93
3186007
10947c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.admissionController.app_name }} | ||
namespace: platform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not define namespace, helm by default installs resources in the namespace where helm release is created |
||
labels: | ||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||
service: {{ .Values.admissionController.app_name }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.admissionController.app_name }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ .Values.admissionController.app_name }} | ||
spec: | ||
serviceAccountName: {{ .Values.admissionController.app_name }} | ||
containers: | ||
- name: admission-controller | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
command: | ||
- platform-storage-admission-controller | ||
ports: | ||
- containerPort: {{ .Values.admissionController.service.port }} | ||
name: http | ||
protocol: TCP | ||
env: | ||
- name: SERVER_PORT | ||
value: {{ .Values.admissionController.service.port | quote }} | ||
{{- include "platformStorage.env" . | nindent 10 }} | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,69 @@ | ||||||
apiVersion: v1 | ||||||
kind: ServiceAccount | ||||||
metadata: | ||||||
name: {{ .Values.admissionController.app_name }} | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
|
||||||
--- | ||||||
|
||||||
apiVersion: rbac.authorization.k8s.io/v1 | ||||||
kind: Role | ||||||
metadata: | ||||||
name: {{ .Values.admissionController.app_name }} | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
rules: | ||||||
- apiGroups: [""] | ||||||
resources: ["pods"] | ||||||
verbs: ["get", "list", "watch"] | ||||||
|
||||||
--- | ||||||
|
||||||
apiVersion: rbac.authorization.k8s.io/v1 | ||||||
kind: RoleBinding | ||||||
metadata: | ||||||
name: {{ .Values.admissionController.app_name }} | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
subjects: | ||||||
- kind: ServiceAccount | ||||||
name: {{ .Values.admissionController.app_name }} | ||||||
namespace: platform | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
roleRef: | ||||||
kind: Role | ||||||
apiGroup: rbac.authorization.k8s.io | ||||||
name: {{ .Values.admissionController.app_name }} | ||||||
|
||||||
--- | ||||||
|
||||||
apiVersion: rbac.authorization.k8s.io/v1 | ||||||
kind: ClusterRole | ||||||
metadata: | ||||||
name: {{ .Values.admissionController.app_name}} | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
rules: | ||||||
- apiGroups: [""] | ||||||
resources: ["persistentvolumeclaims"] | ||||||
verbs: ["get", "list", "watch"] | ||||||
- apiGroups: [""] | ||||||
resources: ["persistentvolumes"] | ||||||
verbs: ["get", "list", "watch"] | ||||||
|
||||||
--- | ||||||
|
||||||
apiVersion: rbac.authorization.k8s.io/v1 | ||||||
kind: ClusterRoleBinding | ||||||
metadata: | ||||||
name: {{ .Values.admissionController.app_name}} | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
subjects: | ||||||
- kind: ServiceAccount | ||||||
name: {{ .Values.admissionController.app_name}} | ||||||
namespace: platform | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
roleRef: | ||||||
kind: ClusterRole | ||||||
name: {{ .Values.admissionController.app_name}} | ||||||
apiGroup: rbac.authorization.k8s.io |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Values.admissionController.app_name }}-svc | ||
namespace: platform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's remove namespace |
||
labels: | ||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||
spec: | ||
selector: | ||
app: {{ .Values.admissionController.app_name }} | ||
ports: | ||
- name: https | ||
port: 443 | ||
targetPort: 8080 | ||
protocol: TCP |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
apiVersion: admissionregistration.k8s.io/v1 | ||||||
kind: MutatingWebhookConfiguration | ||||||
metadata: | ||||||
name: platform-storage-mutating-webhook | ||||||
annotations: | ||||||
"helm.sh/hook": post-install,post-upgrade | ||||||
labels: | ||||||
{{- include "platformStorage.labels.standard" . | nindent 4 }} | ||||||
webhooks: | ||||||
- name: pod-volume-injector.apolo.us | ||||||
admissionReviewVersions: ["v1", "v1beta1"] | ||||||
sideEffects: None | ||||||
clientConfig: | ||||||
caBundle: {{ .Values.admissionController.caBundle }} | ||||||
service: | ||||||
namespace: platform | ||||||
name: {{ .Values.admissionController.app_name }}-svc | ||||||
path: /admission-controller/mutate | ||||||
rules: | ||||||
- operations: ["CREATE"] | ||||||
apiGroups: ["*"] | ||||||
apiVersions: ["*"] | ||||||
resources: ["pods"] | ||||||
failurePolicy: Fail | ||||||
objectSelector: | ||||||
matchLabels: | ||||||
platform.apolo.us/storage-injection-webhook: "enabled" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
wdyt? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ service: | |
|
||
storages: [] | ||
|
||
kube: | ||
namespace: "default" | ||
|
||
sentry: | ||
appName: platform-storage | ||
sampleRate: 0.002 | ||
|
@@ -82,3 +85,24 @@ metrics: | |
|
||
serviceMonitor: | ||
enabled: true | ||
|
||
|
||
admissionController: | ||
app_name: "storage-admission-controller" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's remove it and use generated name |
||
tlsKey: | ||
valueFrom: | ||
secretKeyRef: | ||
name: platform-storage-ac-certs | ||
key: tls.key | ||
tlsCert: | ||
valueFrom: | ||
secretKeyRef: | ||
name: platform-storage-ac-certs | ||
key: tls.crt | ||
caBundle: | ||
valueFrom: | ||
secretKeyRef: | ||
name: platform-storage-ac-certs | ||
key: ca.bundle | ||
service: | ||
port: 8080 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import asyncio | ||
import logging | ||
import os | ||
import ssl | ||
import tempfile | ||
from base64 import b64decode | ||
from typing import cast | ||
|
||
from aiohttp import web | ||
from neuro_logging import init_logging, setup_sentry | ||
|
||
from platform_storage_api.admission_controller.app import create_app | ||
from platform_storage_api.config import AdmissionControllerTlsConfig, Config | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main() -> None: | ||
init_logging() | ||
config = Config.from_environ() | ||
logging.info("Loaded config: %r", config) | ||
|
||
setup_sentry( | ||
health_check_url_path="/api/v1/ping", | ||
ignore_errors=[web.HTTPNotFound], | ||
) | ||
|
||
loop = asyncio.get_event_loop() | ||
app = loop.run_until_complete(create_app(config)) | ||
|
||
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
|
||
crt_file = tempfile.NamedTemporaryFile(mode="w", delete=False, suffix='.crt') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use it also as a context manager instead and pass delete=True, delete_on_close=False |
||
key_file = tempfile.NamedTemporaryFile(mode="w", delete=False, suffix='.key') | ||
|
||
tls_config = cast( | ||
AdmissionControllerTlsConfig, | ||
config.admission_controller_tls_config | ||
) | ||
try: | ||
# extract certificates from the env and store in a temp files | ||
crt_file.write(b64decode(tls_config.tls_cert).decode()) | ||
key_file.write(b64decode(tls_config.tls_key).decode()) | ||
crt_file.close() | ||
key_file.close() | ||
|
||
context.load_cert_chain( | ||
certfile=crt_file.name, | ||
keyfile=key_file.name, | ||
) | ||
|
||
web.run_app( | ||
app, | ||
host=config.server.host, | ||
port=config.server.port, | ||
ssl_context=context, | ||
) | ||
|
||
except Exception as e: | ||
logger.exception("Unhandled error") | ||
raise e | ||
finally: | ||
os.unlink(crt_file.name) | ||
os.unlink(key_file.name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use this name for new resources, you can define a template for it