Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Add samples for Ansible Operator #34

Merged
merged 3 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ This project is a component of the [Operator Framework](https://github.com/opera
# Operator SDK Samples
This repo contains samples of operators built using the [operator-sdk][operator_sdk].

To view operators which leverage Ansible for deployment, see the [Ansible][ansible_examples] samples section.

[operator_sdk]:https://github.com/coreos/operator-sdk
[ansible_examples]:./ansible/
7 changes: 7 additions & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This project is a component of the [Operator Framework](https://github.com/operator-framework), an open source toolkit to manage Kubernetes native applications, called Operators, in an effective, automated, and scalable way. Read more in the [introduction blog post](https://coreos.com/blog/introducing-operator-framework).

# Operator SDK Samples - Ansible
This repo contains samples of operators powered by Ansible built using the [operator-sdk][operator_sdk]. To learn more about creating an operator that leverages Ansible, check out the [Ansible user guide][ansible_user_guide].

[operator_sdk]:https://github.com/coreos/operator-sdk
[ansible_user_guide]:https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/user-guide.md
19 changes: 19 additions & 0 deletions ansible/bitcoin-sv-operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# bitcoin-sv-operator

This is an Operator which deploys [Bitcoin Satoshi Vision (SV)](https://github.com/bitcoin-sv/bitcoin-sv) - a Bitcoin Cash full node implementation - on Kubernetes/Openshift.

This Operator is an [Ansible Operator](https://github.com/water-hole/ansible-operator) which deploys a containerized version of `bitcoind` with RPC and REST capabilities.

This project was generated using [operator-sdk](https://github.com/operator-framework/operator-sdk).

To deploy the operator:
```
$ kubectl create -f deploy/rbac.yaml
$ kubectl create -f deploy/crd.yaml
$ kubectl create -f deploy/operator.yaml
```

To launch an instance of Bitcoin SV:
```
$ kubectl create -f deploy/cr.yaml
```
4 changes: 4 additions & 0 deletions ansible/bitcoin-sv-operator/deploy/cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: "bitcoin-sv.example.com/v1alpha1"
kind: "Bitd"
metadata:
name: "example"
13 changes: 13 additions & 0 deletions ansible/bitcoin-sv-operator/deploy/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: bitds.bitcoin-sv.example.com
spec:
group: bitcoin-sv.example.com
names:
kind: Bitd
listKind: BitdList
plural: bitds
singular: bitd
scope: Namespaced
version: v1alpha1
28 changes: 28 additions & 0 deletions ansible/bitcoin-sv-operator/deploy/operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bitd-operator
spec:
replicas: 1
selector:
matchLabels:
name: bitd-operator
template:
metadata:
labels:
name: bitd-operator
spec:
containers:
- name: bitd-operator
image: docker.io/dymurray/bitd-operator
ports:
- containerPort: 60000
name: metrics
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OPERATOR_NAME
value: "bitd-operator"
47 changes: 47 additions & 0 deletions ansible/bitcoin-sv-operator/deploy/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: bitd-operator
rules:
- apiGroups:
- bitcoin-sv.example.com
resources:
- "*"
verbs:
- "*"
- apiGroups:
- ""
resources:
- pods
- services
- endpoints
- persistentvolumeclaims
- events
- configmaps
- secrets
verbs:
- "*"
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- "*"

---

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: default-account-bitd-operator
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
kind: ClusterRole
name: bitd-operator
apiGroup: rbac.authorization.k8s.io
38 changes: 38 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for Bitd
2 changes: 2 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for Bitd
57 changes: 57 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
galaxy_info:
author: your name
description: your description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)

min_ansible_version: 1.2

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
24 changes: 24 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# tasks file for Bitd
- name: start bitd
k8s:
definition:
kind: Deployment
apiVersion: apps/v1
metadata:
name: '{{ meta.name }}-bitd'
namespace: '{{ meta.namespace }}'
spec:
selector:
matchLabels:
app: bitd
template:
metadata:
labels:
app: bitd
spec:
containers:
- name: bitd
image: "docker.io/dymurray/bitcoin-sv-bitd"
ports:
- containerPort: 8332
2 changes: 2 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- Bitd
2 changes: 2 additions & 0 deletions ansible/bitcoin-sv-operator/roles/Bitd/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for Bitd
4 changes: 4 additions & 0 deletions ansible/bitcoin-sv-operator/tmp/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM quay.io/water-hole/ansible-operator

COPY roles/ ${HOME}/roles/
COPY watches.yaml ${HOME}/watches.yaml
11 changes: 11 additions & 0 deletions ansible/bitcoin-sv-operator/tmp/build/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if ! which docker > /dev/null; then
echo "docker needs to be installed"
exit 1
fi

: ${IMAGE:?"Need to set IMAGE, e.g. gcr.io/<repo>/<your>-operator"}

echo "building container ${IMAGE}..."
docker build -t "${IMAGE}" -f tmp/build/Dockerfile .
5 changes: 5 additions & 0 deletions ansible/bitcoin-sv-operator/watches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- version: v1alpha1
group: bitcoin-sv.example.com
kind: Bitd
role: /opt/ansible/roles/Bitd/
2 changes: 2 additions & 0 deletions ansible/etcd-operator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
etcd-ansible-operator.iml
Loading