Add nodepool deployment

This commit is contained in:
Tristan Cacqueray 2019-04-10 02:49:54 +00:00
parent 5aa579c027
commit 4e088cc5d2
6 changed files with 166 additions and 1 deletions

View File

@ -6,6 +6,7 @@ A Zuul Operator PoC
* [OKD](https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz)
* [SDK](https://github.com/operator-framework/operator-sdk#quick-start)
* [Zookeeper Operator](https://github.com/pravega/zookeeper-operator#install-the-operator)
* [Postgresql Operator](https://operatorhub.io/operator/alpha/postgres-operator.v3.5.0)
## Prepare cluster
@ -78,7 +79,11 @@ metadata:
name: example-zuul
spec:
# Optional user-provided ssh key
sshsecretename: ""
#sshsecretename: ""
# Optional user-provided clouds.yaml
#cloudssecretname: ""
# Optional user-provided kube/config
#kubesecretname: ""
merger:
min: 0
max: 10
@ -87,6 +92,8 @@ spec:
max: 5
web:
min: 1
launcher:
min: 1
connections: []
tenants:
- tenant:
@ -106,6 +113,7 @@ ssh-rsa AAAAB3Nza...
$ oc get pods
NAME READY STATUS RESTARTS AGE
example-zuul-executor-696f969c4-6cpjv 1/1 Running 0 8s
example-zuul-launcher-5974789746-wbwpv 1/1 Running 0 9s
example-zuul-pg-5dfc477bff-8426l 1/1 Running 0 30s
example-zuul-scheduler-77b6cf7967-ksh64 1/1 Running 0 11s
example-zuul-web-5f744f89c9-qjp9l 1/1 Running 0 6s

View File

@ -7,6 +7,12 @@ tenants:
name: demo
source: {}
connections: []
providers: []
labels:
- name: okd-fedora
min-ready: 1
launcher:
min: 1
merger:
min: 0
max: 5
@ -22,17 +28,23 @@ state: "present"
zuul_app_name: "zuul"
zuul_cluster_name: "{{ meta.name }}"
sshsecretname: "{{ zuul_cluster_name }}-ssh-secret"
kubesecretname: "{{ zuul_cluster_name }}-kube-secret"
cloudssecretname: "{{ zuul_cluster_name }}-clouds-secret"
zuul_version: "latest" #"3.7.1"
nodepool_version: "latest"
# Use local image for https://review.openstack.org/650246
#zuul_image_name_base: "docker.io/zuul/zuul"
#nodepool_image_name_base: "docker.io/zuul/nodepool"
zuul_image_name_base: "172.30.1.1:5000/myproject/zuul"
nodepool_image_name_base: "172.30.1.1:5000/myproject/nodepool"
zuul_image_name:
scheduler: "{{ zuul_image_name_base }}-scheduler:{{ zuul_version }}"
merger: "{{ zuul_image_name_base }}-merger:{{ zuul_version }}"
executor: "{{ zuul_image_name_base }}-executor:{{ zuul_version }}"
web: "{{ zuul_image_name_base }}-web:{{ zuul_version }}"
launcher: "{{ nodepool_image_name_base }}-launcher:{{ nodepool_version }}"
zuul_service_account_name: "zuul-operator"
zuul_image_pull_policy: "IfNotPresent"

View File

@ -69,6 +69,48 @@
# TODO: cleanup key file from operator pod
- name: Create cloud config
when: not zuul_clouds_secret
k8s:
state: "{{ state }}"
definition:
apiVersion: v1
kind: Secret
metadata:
labels:
app: "{{ zuul_app_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
name: "{{ cloudssecretname }}"
namespace: "{{ namespace }}"
type: Opaque
stringData:
clouds.yaml: |
cache:
expiration:
server: 5
port: 5
floating-ip: 5
- name: Create kube config
when: not zuul_kube_secret
k8s:
state: "{{ state }}"
definition:
apiVersion: v1
kind: Secret
metadata:
labels:
app: "{{ zuul_app_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
name: "{{ kubesecretname }}"
namespace: "{{ namespace }}"
type: Opaque
stringData:
config: |
apiVersion: v1
clusters: []
contexts: []
- name: Create the scheduler configmap
k8s:
state: "{{ state }}"
@ -170,3 +212,26 @@
{% endif %}{% endfor %}
{% endfor %}
- name: Create the nodepool configmap
k8s:
state: "{{ state }}"
definition:
kind: ConfigMap
apiVersion: v1
metadata:
name: "{{ zuul_configmap_name }}-nodepool"
namespace: "{{ namespace }}"
labels:
app: "{{ zuul_app_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
data:
"nodepool.yaml": |
{{ ({'labels': labels})|to_yaml }}
{{ ({'providers': providers})|to_yaml }}
webapp:
port: 8006
zookeeper-servers:
- host: {{ zk_cluster_name }}-client
port: 2181
register: nodepool_config

View File

@ -0,0 +1,72 @@
# TODO:
- name: Get autoscale count
# TODO: look for replicas count in zk requests list
# autoscale_zk:
# service: {{ deployment_name }}
# zkhost: "{{ zk_cluster_name }}-client:2181"
# min: {{ deployment_conf.min|default(0) }}
# register: autoscale
set_fact:
autoscale:
count: "{{ deployment_conf.min|default(0) }}"
- name: Create Deployment
k8s:
state: "{{ state }}"
definition:
kind: "Deployment"
apiVersion: "extensions/v1beta1"
metadata:
name: "{{ zuul_cluster_name }}-{{ deployment_name }}"
namespace: "{{ namespace }}"
labels:
app: "{{ zuul_app_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
annotations:
configHash: ""
spec:
replicas: "{{ autoscale.count }}"
selector:
matchLabels:
app: "{{ zuul_cluster_name }}-{{ deployment_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
template:
metadata:
name: "{{ zuul_cluster_name }}-{{ deployment_name }}"
labels:
app: "{{ zuul_cluster_name }}-{{ deployment_name }}"
zuul_cluster: "{{ zuul_cluster_name }}"
spec:
containers:
- name: "{{ zuul_cluster_name }}-{{ deployment_name }}"
image: "{{ zuul_image_name[deployment_name] }}"
imagePullPolicy: "{{ zuul_image_pull_policy }}"
env:
- name: CONFIG_CHECKSUM
value: "{{ nodepool_config.result.data | checksum }}"
volumeMounts:
- mountPath: "/etc/nodepool"
name: nodepool-config-volume
readOnly: true
- mountPath: "/var/lib/nodepool"
name: nodepool-data-volume
- mountPath: "/var/lib/nodepool/.kube"
name: nodepool-kube-volume
- mountPath: "/var/lib/nodepool/.config/openstack"
name: nodepool-clouds-volume
command:
- "/uid_entrypoint"
- "nodepool-{{ deployment_name }}"
- "-d"
volumes:
- name: nodepool-config-volume
configMap:
name: "{{ zuul_configmap_name }}-nodepool"
- name: nodepool-data-volume
emptyDir: {}
- name: nodepool-kube-volume
secret:
secretName: "{{ kubesecretname }}"
- name: nodepool-clouds-volume
secret:
secretName: "{{ cloudssecretname }}"

View File

@ -1,4 +1,10 @@
---
- name: Nodepool Deployment
vars:
deployment_name: launcher
deployment_conf: "{{ launcher }}"
include_tasks: "./create_nodepool_deployment.yaml"
- name: Save queue
include_tasks: "./queue_save.yaml"
when:

View File

@ -13,6 +13,8 @@
set_fact:
zuul_pg_user: "{{ secrets_lookup | json_query(pg_user_query) }}"
zuul_ssh_key: "{{ lookup('k8s', api_version='v1', kind='Secret', namespace=namespace, resource_name=sshsecretname) }}"
zuul_clouds_secret: "{{ lookup('k8s', api_version='v1', kind='Secret', namespace=namespace, resource_name=cloudssecretname) }}"
zuul_kube_secret: "{{ lookup('k8s', api_version='v1', kind='Secret', namespace=namespace, resource_name=kubesecretname) }}"
- name: lookup k8s postgres cr
set_fact: