Rewrite to jsonnet because reasons

trunk
HeNine 3 years ago committed by henine
parent da29cc90c6
commit 66750faf92

@ -1,16 +0,0 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- postgres.yaml
- rabbitmq.yaml
configMapGenerator:
- name: rabbitmq-config
files:
- enabled_plugins=etc/rabbitmq/enabled_plugins
- rabbitmq.conf=etc/rabbitmq/rabbitmq.conf
- rmq_schema.json=etc/rabbitmq/rmq_schema.json
- name: postgres-dbinit
files:
- piccdb.sql

@ -1,57 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
type: LoadBalancer
selector:
app: postgres
ports:
- protocol: TCP
port: 5432
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
serviceName: "postgres"
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: docker.io/postgres:13
ports:
- containerPort: 5432
name: db
env:
- name: POSTGRES_DB
value: picc
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-password
key: password
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: dbinit
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: dbinit
configMap:
name: postgres-dbinit
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 100Mi

@ -1,53 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: rabbitmq
spec:
type: LoadBalancer
selector:
app: rabbitmq
ports:
- name: amqp
port: 5672
- name: web
port: 15672
- name: mqtt
port: 1883
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rabbitmq
labels:
app: rabbitmq
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq
template:
metadata:
labels:
app: rabbitmq
spec:
containers:
- name: rabbitmq
image: docker.io/rabbitmq:3
ports:
- containerPort: 5672
- containerPort: 15672
- containerPort: 1883
volumeMounts:
- mountPath: "/etc/rabbitmq"
name: config
volumes:
- name: config
configMap:
name: rabbitmq-config
items:
- key: "enabled_plugins"
path: "enabled_plugins"
- key: "rabbitmq.conf"
path: "rabbitmq.conf"
- key: "rmq_schema.json"
path: "rmq_schema.json"

@ -0,0 +1,4 @@
function(namespace){
picc_app: import "picc_app.jsonnet",
picc_config: (import "picc_config.jsonnet")(namespace),
}

@ -0,0 +1,71 @@
{
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "picc",
labels: {
app: "picc"
}
},
spec: {
replicas: 1,
selector: {
matchLabels: {
app: "picc"
}
},
template: {
metadata: {
labels: {
app: "picc"
}
},
spec: {
containers: [
{
name: "picc",
image: "docker.raptorpond.com/picc",
env: [
{
name: "RABBITMQ_HOST",
valueFrom: {
configMapKeyRef: {
name: "picc-config",
key: "rabbitmq_host"
}
}
},
{
name: "RABBITMQ_PORT",
valueFrom: {
configMapKeyRef: {
name: "picc-config",
key: "rabbitmq_port"
}
}
},
{
name: "POSTGRES_HOST",
valueFrom: {
configMapKeyRef: {
name: "picc-config",
key: "postgres_host"
}
}
},
{
name: "POSTGRES_PASSWORD",
valueFrom: {
secretKeyRef: {
name: "postgres-password",
key: "password"
}
}
}
]
}
]
}
}
}
}

@ -0,0 +1,12 @@
function(namespace){
kind: "ConfigMap",
apiVersion: "v1",
metadata: {
name: "picc-config"
},
data: {
rabbitmq_host: "rabbitmq.%s" % [namespace],
rabbitmq_port: "5672",
postgres_host: "postgres.%s" % [namespace]
}
}

@ -0,0 +1,12 @@
local utils = import "../../lib/picc-k8s.libsonnet";
function(password=null, ip=null){
postgres_app: import "postgres_app.jsonnet",
postgres_service: utils.service(name="postgres", ports=[{name: "postgres", protocol: "TCP", port:5432}], ip=ip),
postgres_password:
if password != null then
(import "postgres_password.jsonnet")(password)
else
(import "postgres_password.jsonnet")(),
postgres_dbinit: import "postgres_dbinit.jsonnet"
}

@ -0,0 +1,80 @@
{
apiVersion: "apps/v1",
kind: "StatefulSet",
metadata: {
name: "postgres"
},
spec: {
selector: {
matchLabels: {
app: "postgres"
}
},
serviceName: "postgres",
template: {
metadata:{
labels: {
app: "postgres"
}
},
spec: {
containers: [
{
name: "postgres",
image: "docker.io/postgres:13",
ports: [
{containerPort: 5432,
name: "db"}
],
env: [
{
name: "POSTGRES_DB",
value: "picc"
},
{
name: "POSTGRES_PASSWORD",
valueFrom: {
secretKeyRef: {
name: "postgres-password",
key: "password"
}
}
}
],
volumeMounts: [
{
name: "postgres-data",
mountPath: "/var/lib/postgresql/data"
},
{
name: "dbinit",
mountPath: "/docker-entrypoint-initdb.d"
}
]
}
],
volumes: [
{
name: "dbinit",
configMap: {
name: "postgres-dbinit"
}
}
]
}
},
volumeClaimTemplates : [{
metadata: {
name: "postgres-data"
},
spec: {
accessModes: ["ReadWriteOnce"],
resources: {
requests: {
storage: "100Mi"
}
}
}
}]
}
}

@ -0,0 +1,10 @@
{
kind: "ConfigMap",
apiVersion: "v1",
metadata: {
name: "postgres-dbinit"
},
data: {
"piccdb.sql": importstr "piccdb.sql"
}
}

@ -0,0 +1,11 @@
function(password = "piccpass") {
kind: "Secret",
apiVersion: "v1",
metadata: {
name: "postgres-password"
},
data: {
"password": std.base64(password)
},
type: "Opaque"
}

@ -0,0 +1,11 @@
local utils = import "../../lib/picc-k8s.libsonnet";
function(ip=null){
rabbitmq_app: import "rabbitmq_app.jsonnet",
rabbitmq_service: utils.service(name="rabbitmq",
ports=[{name: "amqp", port: 5672},
{name: "web", port: 15672},
{name: "mqtt", port: 1883}],
ip=ip),
rabbitmq_conf: import "rabbitmq_config.jsonnet"
}

@ -0,0 +1,60 @@
{
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "rabbitmq",
labels: {
app: "rabbitmq"
}
},
spec: {
replicas: 1,
selector: {
matchLabels: {
app: "rabbitmq"
}
},
template: {
metadata: {
labels: {
app: "rabbitmq"
}
},
spec: {
containers: [
{
name: "rabbitmq",
image: "docker.io/rabbitmq:3",
ports: [
{containerPort: 5672},
{containerPort: 15672},
{containerPort: 1883}
],
volumeMounts: [
{
mountPath: "/etc/rabbitmq",
name: "config"
}
]
}
],
volumes: [
{
name: "config",
configMap: {
name: "rabbitmq-config",
items: [
{key: "enabled_plugins",
path: "enabled_plugins"},
{key: "rabbitmq.conf",
path: "rabbitmq.conf"},
{key: "rmq_schema.json",
path: "rmq_schema.json"}
]
}
}
]
}
}
}
}

@ -0,0 +1,12 @@
{
kind: "ConfigMap",
apiVersion: "v1",
metadata: {
name: "rabbitmq-config"
},
data: {
"enabled_plugins": importstr "etc/rabbitmq/enabled_plugins",
"rabbitmq.conf": importstr "etc/rabbitmq/rabbitmq.conf",
"rmq_schema.json": importstr "etc/rabbitmq/rmq_schema.json"
}
}

@ -0,0 +1,35 @@
{
addNamespace(manifest, namespace)::
manifest +
{
metadata+: {
namespace: namespace
}
},
createNamespace(namespace)::
{
apiVersion: "v1",
kind: "Namespace",
metadata: {
name: namespace
}
},
service(name, ports, ip=null)::
{
apiVersion: "v1",
kind: "Service",
metadata: {
name: name
},
spec: {
type: "LoadBalancer",
selector: {
app: name
},
ports: ports,
[if ip != null then "loadBalancerIP"]: ip
}
}
}

@ -1,29 +0,0 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: picc-dev
resources:
- namespace.yaml
- ../../base
secretGenerator:
- name: postgres-password
literals:
- password=piccpass
patches:
- patch: |-
- op: add
path: /spec/loadBalancerIP
value: 192.168.2.201
target:
kind: Service
name: postgres
- patch: |-
- op: add
path: /spec/loadBalancerIP
value: 192.168.2.200
target:
kind: Service
name: rabbitmq

@ -1,6 +0,0 @@
kind: Namespace
apiVersion: v1
metadata:
name: picc-dev
labels:
name: picc-dev

@ -1,6 +0,0 @@
kind: Namespace
apiVersion: v1
metadata:
name: picc-prod
labels:
name: picc-prod

@ -0,0 +1,13 @@
local namespace="picc-dev";
local utils = import "../lib/picc-k8s.libsonnet";
local postgres = import "../deployments/postgres/postgres.jsonnet";
local postgres_manifests = postgres(ip="192.168.2.201");
local rabbitmq = import "../deployments/rabbitmq/rabbitmq.jsonnet";
local rabbitmq_manifests = rabbitmq(ip="192.168.2.200");
[utils.createNamespace(namespace),] +
[utils.addNamespace(postgres_manifests[manifest], namespace) for manifest in std.objectFields(postgres_manifests)] +
[utils.addNamespace(rabbitmq_manifests[manifest], namespace) for manifest in std.objectFields(rabbitmq_manifests)]

@ -0,0 +1,18 @@
local namespace="picc-prod";
local utils = import "../lib/picc-k8s.libsonnet";
local postgres = import "../deployments/postgres/postgres.jsonnet";
local rabbitmq = import "../deployments/rabbitmq/rabbitmq.jsonnet";
local picc = import "../deployments/picc/picc.jsonnet";
function(postgres_password)
local postgres_manifests = postgres(password=postgres_password);
local rabbitmq_manifests = rabbitmq();
local picc_manifests = picc(namespace);
[utils.createNamespace(namespace),] +
[utils.addNamespace(postgres_manifests[manifest], namespace) for manifest in std.objectFields(postgres_manifests)] +
[utils.addNamespace(rabbitmq_manifests[manifest], namespace) for manifest in std.objectFields(rabbitmq_manifests)] +
[utils.addNamespace(picc_manifests[manifest], namespace) for manifest in std.objectFields(picc_manifests)]
Loading…
Cancel
Save