Add Readme and deploy roles
This commit is contained in:
parent
a8f69d62e5
commit
9cbe822f81
86
README.md
86
README.md
@ -1,2 +1,86 @@
|
||||
# zuul-operator
|
||||
A Zuul Operator PoC
|
||||
=======
|
||||
|
||||
## Requirements:
|
||||
|
||||
* [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)
|
||||
|
||||
## Prepare cluster
|
||||
|
||||
```shell
|
||||
sudo -i oc cluster up
|
||||
sudo chown root:fedora /var/run/docker.sock
|
||||
|
||||
oc login -u developer -p dev
|
||||
docker login -u developer -p $(oc whoami -t) $(oc registry info)
|
||||
|
||||
# Log as admin to install crd
|
||||
sudo cat /root/.kube/config > ~/.kube/config
|
||||
oc login -u system:admin
|
||||
oc project default
|
||||
```
|
||||
|
||||
## Install Zookeeper Operator
|
||||
|
||||
Perhaps this should be part of the zuul operator
|
||||
|
||||
```shell
|
||||
oc create -f https://raw.githubusercontent.com/pravega/zookeeper-operator/master/deploy/crds/zookeeper_v1beta1_zookeepercluster_crd.yaml
|
||||
oc create -f https://raw.githubusercontent.com/pravega/zookeeper-operator/master/deploy/default_ns/rbac.yaml
|
||||
oc create -f https://raw.githubusercontent.com/pravega/zookeeper-operator/master/deploy/default_ns/operator.yaml
|
||||
```
|
||||
|
||||
|
||||
## Install Zuul Operator
|
||||
|
||||
```shell
|
||||
operator-sdk build 172.30.1.1:5000/myproject/zuul-operator:latest
|
||||
docker push 172.30.1.1:5000/myproject/zuul-operator:latest
|
||||
|
||||
oc create -f deploy/crds/zuul-ci_v1alpha1_zuul_crd.yaml
|
||||
oc create -f deploy/rbac.yaml
|
||||
oc create -f deploy/operator.yaml
|
||||
```
|
||||
|
||||
Look for operator pod and check it's output
|
||||
|
||||
```shell
|
||||
$ oc get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
zuul-operator-c64756f66-rbdmg 2/2 Running 0 3s
|
||||
$ oc logs zuul-operator-c64756f66-rbdmg -c operator
|
||||
...
|
||||
{"level":"info","ts":1554197305.5853095,"logger":"cmd","msg":"Go Version: go1.10.3"}
|
||||
{"level":"info","ts":1554197305.5854425,"logger":"cmd","msg":"Go OS/Arch: linux/amd64"}
|
||||
{"level":"info","ts":1554197305.5854564,"logger":"cmd","msg":"Version of operator-sdk: v0.6.0"}
|
||||
{"level":"info","ts":1554197305.5855,"logger":"cmd","msg":"Watching namespace.","Namespace":"default"}
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
$ oc apply -f - <<EOF
|
||||
apiVersion: zuul-ci.org/v1alpha1
|
||||
kind: Zuul
|
||||
metadata:
|
||||
name: example-zuul
|
||||
spec:
|
||||
merger:
|
||||
instances: 0
|
||||
executor:
|
||||
instances: 1
|
||||
web:
|
||||
instances: 1
|
||||
connections: []
|
||||
tenants: []
|
||||
EOF
|
||||
zuul.zuul-ci.org/example-zuul created
|
||||
|
||||
$ oc get zuul
|
||||
NAME AGE
|
||||
example-zuul 16s
|
||||
```
|
||||
|
@ -1,9 +1,30 @@
|
||||
---
|
||||
namespace: "default"
|
||||
state: "present"
|
||||
|
||||
zuul_app_name: "zuul"
|
||||
zuul_cluster_name: "zuul"
|
||||
|
||||
zuul_version: "3.7.1"
|
||||
zuul_image_name: "zuul/zuul:{{ zuul_version }}"
|
||||
zuul_version: "latest" #"3.7.1"
|
||||
zuul_image_name: "docker.io/zuul/zuul"
|
||||
zuul_image_name_scheduler: "{{ zuul_image_name }}-scheduler:{{ zuul_version }}"
|
||||
zuul_image_name_merger: "{{ zuul_image_name }}-merger:{{ zuul_version }}"
|
||||
zuul_image_name_executor: "{{ zuul_image_name }}-executor:{{ zuul_version }}"
|
||||
zuul_image_name_web: "{{ zuul_image_name }}-web:{{ zuul_version }}"
|
||||
zuul_service_account_name: "zuul-operator"
|
||||
|
||||
zuul_configmap_name: "{{ zuul_cluster_name }}-config"
|
||||
|
||||
zk_cluster_name: "example-zk"
|
||||
zk_api_version: "zookeeper.pravega.io/v1beta1"
|
||||
|
||||
|
||||
# Default cr spec
|
||||
tenants: []
|
||||
connections: []
|
||||
merger:
|
||||
instances: 0
|
||||
executor:
|
||||
instances: 1
|
||||
web:
|
||||
instances: 1
|
||||
|
@ -1,5 +1,42 @@
|
||||
---
|
||||
- name: create a configmap
|
||||
- name: Create the scheduler configmap
|
||||
k8s:
|
||||
state: "{{ state }}"
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: "{{ zuul_configmap_name }}-scheduler"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
data:
|
||||
"zuul.conf": |
|
||||
[gearman]
|
||||
server=localhost
|
||||
port=4730
|
||||
|
||||
[zookeeper]
|
||||
hosts={{ zk_cluster_name }}-client:2181
|
||||
|
||||
[gearman_server]
|
||||
start=true
|
||||
|
||||
[scheduler]
|
||||
tenant_config=/etc/zuul/main.yaml
|
||||
|
||||
{% for connection in connections %}
|
||||
[connection {{ connection["name"] }}]
|
||||
driver={{ connection["driver"] }}
|
||||
server={{ connection["server"] }}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
"main.yaml": |
|
||||
{{ tenants|to_yaml }}
|
||||
|
||||
- name: Create the zuul service configmap
|
||||
k8s:
|
||||
state: "{{ state }}"
|
||||
definition:
|
||||
@ -12,13 +49,17 @@
|
||||
app: "{{ zuul_app_name }}"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
data:
|
||||
"zuul.conf":
|
||||
"zuul.conf": |
|
||||
[gearman]
|
||||
server=zuul-scheduler-{{ zuul_app_name }}
|
||||
server=zuul-scheduler
|
||||
port=4730
|
||||
|
||||
[zookeeper]
|
||||
hosts=zk-{{ zuul_app_name }}
|
||||
hosts={{ zk_cluster_name }}-client:2181
|
||||
|
||||
[gearman_server]
|
||||
start=true
|
||||
{% for connection in connections %}
|
||||
[connection {{ connection["name"] }}]
|
||||
driver={{ connection["driver"] }}
|
||||
server={{ connection["server"] }}
|
||||
|
||||
{% endfor %}
|
||||
|
1
ansible/roles/deploy/defaults/main.yaml
Normal file
1
ansible/roles/deploy/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
zuul_image_pull_policy: IfNotPresent
|
229
ansible/roles/deploy/tasks/main.yaml
Normal file
229
ansible/roles/deploy/tasks/main.yaml
Normal file
@ -0,0 +1,229 @@
|
||||
---
|
||||
- name: Scheduler Deployment
|
||||
k8s:
|
||||
definition:
|
||||
kind: "Deployment"
|
||||
apiVersion: "extensions/v1beta1"
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-scheduler"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-scheduler"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ zuul_app_name }}-scheduler"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
template:
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-scheduler"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-scheduler"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
serviceAccountName: "{{ zuul_service_account_name }}"
|
||||
containers:
|
||||
- name: zuul-scheduler
|
||||
image: "{{ zuul_image_name_scheduler }}"
|
||||
imagePullPolicy: "{{ zuul_image_pull_policy }}"
|
||||
ports:
|
||||
- containerPort: 4730
|
||||
protocol: "TCP"
|
||||
volumeMounts:
|
||||
- mountPath: "/etc/zuul"
|
||||
name: zuul-config-volume
|
||||
readOnly: true
|
||||
- mountPath: "/var/lib/zuul"
|
||||
name: zuul-data-volume
|
||||
command:
|
||||
- "zuul-scheduler"
|
||||
- "-d"
|
||||
volumes:
|
||||
- name: zuul-config-volume
|
||||
configMap:
|
||||
name: "{{ zuul_configmap_name }}-scheduler"
|
||||
- name: zuul-data-volume
|
||||
emptyDir: {}
|
||||
|
||||
- name: Create Scheduler service
|
||||
k8s:
|
||||
state: "{{ state }}"
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-scheduler"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: "{{ zuul_app_name }}-scheduler"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
ports:
|
||||
- name: "gearman"
|
||||
port: 4730
|
||||
protocol: TCP
|
||||
when: (services_lookup|default([])|length==0)
|
||||
|
||||
- name: Merger Deployment
|
||||
k8s:
|
||||
definition:
|
||||
kind: "Deployment"
|
||||
apiVersion: "extensions/v1beta1"
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-merger"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-merger"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
replicas: "{{ merger.instances }}"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ zuul_app_name }}-merger"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
template:
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-merger"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-merger"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
serviceAccountName: "{{ zuul_service_account_name }}"
|
||||
containers:
|
||||
- name: zuul-merger
|
||||
image: "{{ zuul_image_name_merger }}"
|
||||
imagePullPolicy: "{{ zuul_image_pull_policy }}"
|
||||
volumeMounts:
|
||||
- mountPath: "/etc/zuul"
|
||||
name: zuul-config-volume
|
||||
readOnly: true
|
||||
- mountPath: "/var/lib/zuul"
|
||||
name: zuul-data-volume
|
||||
command:
|
||||
- "zuul-merger"
|
||||
- "-d"
|
||||
volumes:
|
||||
- name: zuul-config-volume
|
||||
configMap:
|
||||
name: "{{ zuul_configmap_name }}"
|
||||
- name: zuul-data-volume
|
||||
emptyDir: {}
|
||||
|
||||
- name: Executor Deployment
|
||||
k8s:
|
||||
definition:
|
||||
kind: "Deployment"
|
||||
apiVersion: "extensions/v1beta1"
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-executor"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-executor"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
replicas: "{{ executor.instances }}"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ zuul_app_name }}-executor"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
template:
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-executor"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-executor"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
serviceAccountName: "{{ zuul_service_account_name }}"
|
||||
containers:
|
||||
- name: zuul-executor
|
||||
image: "{{ zuul_image_name_executor }}"
|
||||
imagePullPolicy: "{{ zuul_image_pull_policy }}"
|
||||
volumeMounts:
|
||||
- mountPath: "/etc/zuul"
|
||||
name: zuul-config-volume
|
||||
readOnly: true
|
||||
- mountPath: "/var/lib/zuul"
|
||||
name: zuul-data-volume
|
||||
command:
|
||||
- "zuul-executor"
|
||||
- "-d"
|
||||
volumes:
|
||||
- name: zuul-config-volume
|
||||
configMap:
|
||||
name: "{{ zuul_configmap_name }}"
|
||||
- name: zuul-data-volume
|
||||
emptyDir: {}
|
||||
|
||||
- name: Web Deployment
|
||||
k8s:
|
||||
definition:
|
||||
kind: "Deployment"
|
||||
apiVersion: "extensions/v1beta1"
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-web"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-web"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
replicas: "{{ web.instances }}"
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "{{ zuul_app_name }}-web"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
template:
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-web"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}-web"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
serviceAccountName: "{{ zuul_service_account_name }}"
|
||||
containers:
|
||||
- name: zuul-web
|
||||
image: "{{ zuul_image_name_web }}"
|
||||
imagePullPolicy: "{{ zuul_image_pull_policy }}"
|
||||
volumeMounts:
|
||||
- mountPath: "/etc/zuul"
|
||||
name: zuul-config-volume
|
||||
readOnly: true
|
||||
- mountPath: "/var/lib/zuul"
|
||||
name: zuul-data-volume
|
||||
command:
|
||||
- "zuul-web"
|
||||
- "-d"
|
||||
volumes:
|
||||
- name: zuul-config-volume
|
||||
configMap:
|
||||
name: "{{ zuul_configmap_name }}"
|
||||
- name: zuul-data-volume
|
||||
emptyDir: {}
|
||||
|
||||
- name: Create Web service
|
||||
k8s:
|
||||
state: "{{ state }}"
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: "{{ zuul_cluster_name }}-web"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: "{{ zuul_app_name }}-web"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
ports:
|
||||
- name: "web"
|
||||
port: 9000
|
||||
protocol: TCP
|
||||
targetPort: 9000
|
14
ansible/roles/deploy_zk/tasks/main.yaml
Normal file
14
ansible/roles/deploy_zk/tasks/main.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
- name: Zookeeper Deployment
|
||||
k8s:
|
||||
definition:
|
||||
apiVersion: "{{ zk_api_version }}"
|
||||
kind: "ZookeeperCluster"
|
||||
metadata:
|
||||
name: "{{ zk_cluster_name }}"
|
||||
namespace: "{{ namespace }}"
|
||||
labels:
|
||||
app: "{{ zuul_app_name }}"
|
||||
zuul_cluster: "{{ zuul_cluster_name }}"
|
||||
spec:
|
||||
size: 1
|
||||
version: "3.5.3-beta"
|
@ -6,6 +6,10 @@
|
||||
set_fact:
|
||||
secrets_lookup: "{{ lookup('k8s', api_version='v1', kind='Secret', namespace=namespace, label_selector=label_selector_value) }}"
|
||||
|
||||
- name: lookup k8s zookeeper cr
|
||||
set_fact:
|
||||
zk_cr_lookup: "{{ lookup('k8s', api_version=zk_api_version, kind='ZookeeperCluster', namespace=namespace, resource_name=zk_cluster_name) }}"
|
||||
|
||||
- name: lookup k8s configmap
|
||||
set_fact:
|
||||
configmap_lookup: "{{ lookup('k8s', api_version='v1', kind='ConfigMap', namespace=namespace, resource_name=zuul_configmap_name) }}"
|
||||
@ -26,7 +30,3 @@
|
||||
- debug:
|
||||
msg: "Zuul Version has CHANGED to '{{ zuul_version }}' - Currently at {{ current_deployed_image }}"
|
||||
when: (current_deployed_image is defined) and (current_deployed_image != zuul_image_name)
|
||||
|
||||
- debug:
|
||||
msg: "Zuul Nodes has CHANGED - updating deployment.spec.replicas value"
|
||||
when: (zuul_deployment_lookup.spec is defined) and (zuul_deployment_lookup.spec.replicas != zuul_replica_size)
|
||||
|
@ -1,8 +1,14 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- debug: msg="Running Zuul Operator Playbook"
|
||||
- import_role:
|
||||
name: get_status
|
||||
- import_role:
|
||||
name: deploy_zk
|
||||
when: (zk_cr_lookup|length==0)
|
||||
- import_role:
|
||||
name: create_config
|
||||
- import_role:
|
||||
name: deploy
|
||||
|
@ -2,4 +2,6 @@ FROM quay.io/operator-framework/ansible-operator:v0.6.0
|
||||
|
||||
COPY watches.yaml ${HOME}/watches.yaml
|
||||
|
||||
COPY ansible/ ${HOME}/ansible/
|
||||
COPY ansible/zuul.yaml ${HOME}/zuul.yaml
|
||||
COPY ansible/group_vars/ ${HOME}/group_vars/
|
||||
COPY ansible/roles/ ${HOME}/roles/
|
||||
|
@ -4,6 +4,10 @@ metadata:
|
||||
name: example-zuul
|
||||
spec:
|
||||
merger:
|
||||
instances: 0
|
||||
executor:
|
||||
instances: 1
|
||||
web:
|
||||
instances: 1
|
||||
connections: []
|
||||
tenants: []
|
||||
|
@ -1,3 +1,10 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: zuul-operator
|
||||
|
||||
---
|
||||
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
@ -24,6 +31,7 @@ rules:
|
||||
- get
|
||||
- apiGroups:
|
||||
- apps
|
||||
- extensions
|
||||
resources:
|
||||
- deployments
|
||||
- daemonsets
|
||||
@ -52,3 +60,30 @@ rules:
|
||||
- '*'
|
||||
verbs:
|
||||
- '*'
|
||||
|
||||
|
||||
---
|
||||
|
||||
kind: RoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: zuul-operator
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: zuul-operator
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: zuul-operator
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
---
|
||||
kind: RoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: zuul-operator-zookeeper
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: zuul-operator
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: zookeeper-operator
|
||||
apiGroup: rbac.authorization.k8s.io
|
@ -9,3 +9,15 @@ roleRef:
|
||||
kind: Role
|
||||
name: zuul-operator
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
---
|
||||
kind: RoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: zookeeper-operator
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: zuul-operator
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: zookeeper-operator
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
|
@ -1,4 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: zuul-operator
|
Loading…
x
Reference in New Issue
Block a user