Skip to content

Commit

Permalink
Merge pull request #22 from adamcstephens/addon_refactor
Browse files Browse the repository at this point in the history
refactor addons to read state and support arbitrary args
  • Loading branch information
istvano authored Oct 14, 2021
2 parents ade097f + 3ac2de3 commit f7a50b1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 59 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Some variables available in this role are listed here. The full set is
defined in `[defaults/main.yml](defaults/main.yml)`.

* `microk8s_version`: Version to use, defaults to `1.19/stable`.
* `microk8s_plugins`: Enable/disable various plugins.
* `microk8s_plugins`: Enable/disable various plugins. A string will be passed as `arg` when enabling addon using `name:arg`
* `microk8s_enable_HA`: Enable/disable high-availability.
* `microk8s_group_HA`: Hostgroup whose members will form HA cluster.
* `microk8s_csr_template`: If defined, will cause a custom CSR to be used in
Expand All @@ -38,6 +38,7 @@ defined in `[defaults/main.yml](defaults/main.yml)`.
- role: istvano.microk8s
vars:
microk8s_plugins:
dns: "1.1.1.1"
istio: true
ingress: true
```
Expand Down
49 changes: 24 additions & 25 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ microk8s_version: "1.19/stable"
microk8s_disable_snap_autoupdate: false

# plugin configuration
microk8s_dns_resolvers: 8.8.8.8,8.8.4.4
registry_size: 20Gi
microk8s_plugins:
dashboard: true # The Kubernetes dashboard
dns: true # CoreDNS
helm3: true # Helm 3 - Kubernetes package manager
host-access: true # Allow Pods connecting to Host services smoothly
ingress: true # Ingress controller for external access
metrics-server: true # K8s Metrics Server for API access to service metrics
rbac: true # Role-Based Access Control for authorisation
registry: true # Private image registry exposed on localhost:32000
storage: true # Storage class; allocates storage from host directory
ambassador: false # Ambassador API Gateway and Ingress
cilium: false # SDN, fast with full network policy
fluentd: false # Elasticsearch-Fluentd-Kibana logging and monitoring
gpu: false # Automatic enablement of Nvidia CUDA
helm: false # Helm 2 - the package manager for Kubernetes
istio: false # Core Istio service mesh services
jaeger: false # Kubernetes Jaeger operator with its simple config
knative: false # The Knative framework on Kubernetes.
kubeflow: false # Kubeflow for easy ML deployments
linkerd: false # Linkerd is a service mesh for Kubernetes and other frameworks
metallb: false # Loadbalancer for your Kubernetes cluster
multus: false # Multus CNI enables attaching multiple network interfaces to pods
prometheus: false # Prometheus operator for monitoring and logging
dashboard: true # The Kubernetes dashboard
dns: "{{ microk8s_dns_resolvers }}" # CoreDNS
helm3: true # Helm 3 - Kubernetes package manager
host-access: true # Allow Pods connecting to Host services smoothly
ingress: true # Ingress controller for external access
metrics-server: true # K8s Metrics Server for API access to service metrics
rbac: true # Role-Based Access Control for authorisation
registry: "{{ registry_size }}" # Private image registry exposed on localhost:32000
storage: true # Storage class; allocates storage from host directory
ambassador: false # Ambassador API Gateway and Ingress
cilium: false # SDN, fast with full network policy
fluentd: false # Elasticsearch-Fluentd-Kibana logging and monitoring
gpu: false # Automatic enablement of Nvidia CUDA
helm: false # Helm 2 - the package manager for Kubernetes
istio: false # Core Istio service mesh services
jaeger: false # Kubernetes Jaeger operator with its simple config
knative: false # The Knative framework on Kubernetes.
kubeflow: false # Kubeflow for easy ML deployments
linkerd: false # Linkerd is a service mesh for Kubernetes and other frameworks
metallb: false # Loadbalancer for your Kubernetes cluster
multus: false # Multus CNI enables attaching multiple network interfaces to pods
prometheus: false # Prometheus operator for monitoring and logging
traefik: false

microk8s_dns_resolvers: 8.8.8.8,8.8.4.4

registry_size: 20Gi
helm3_repositories:
- name: stable
url: https://charts.helm.sh/stable
Expand Down
58 changes: 26 additions & 32 deletions tasks/addons.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
- name: Enable plugins
- name: get current addons state
become: yes
loop: "{{ microk8s_plugins | dict2items }}"
command: "microk8s.enable {{ item.key }}"
loop_control:
label: "{{ item.key }}"
register: command_result
changed_when: "'Addon ' + item.key + ' is already enabled' not in command_result.stdout"
when:
- item.value
- item.key != "dns"
- item.key != "registry"
command:
cmd: microk8s.status --format yaml
changed_when: no
register: microk8s_status

- name: Disable plugins
become: yes
loop: "{{ microk8s_plugins | dict2items }}"
command: "microk8s.disable {{ item.key }}"
loop_control:
label: "{{ item.key }}"
register: command_result
changed_when: "'Addon ' + item.key + ' is already disabled' not in command_result.stdout"
when: not item.value
- name: set current state fact
set_fact:
microk8s_status: "{{ microk8s_status.stdout | from_yaml }}"

- name: Enable dns
- name: enable addons
become: yes
command: "microk8s.enable dns:{{ microk8s_dns_resolvers }}"
register: command_result
changed_when: "'Addon dns is already enabled' not in command_result.stdout"
loop: "{{ microk8s_status.addons }}"
loop_control:
label: "{{ item.name }}"
command:
cmd: microk8s.enable {{ item.name }}{% if microk8s_plugins[item.name] != True %}:{{ microk8s_plugins[item.name] }}{% endif %}
when:
- "'dns' in microk8s_plugins"
- microk8s_plugins.dns
- item.status == 'disabled'
- item.name in microk8s_plugins
- microk8s_plugins[item.name]

- name: Enable registry
- name: disable addons
become: yes
command: "microk8s.enable registry:size={{ registry_size }}"
register: command_result
changed_when: "'Addon registry is already enabled' not in command_result.stdout"
loop: "{{ microk8s_status.addons }}"
loop_control:
label: "{{ item.name }}"
command:
cmd: microk8s.disable {{ item.name }}
when:
- "'registry' in microk8s_plugins"
- microk8s_plugins.registry
- item.status == 'enabled'
- item.name in microk8s_plugins
- not microk8s_plugins[item.name]
4 changes: 3 additions & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
command: "snap alias microk8s.helm3 helm"
changed_when: false
register: aliashelmout
when: microk8s_plugins.helm3
when:
- "'helm3' in microk8s_plugins"
- microk8s_plugins.helm3

- name: Create custom certificates
become: yes
Expand Down

0 comments on commit f7a50b1

Please sign in to comment.