Skip to content

Commit

Permalink
seperate ansible scripts (#6484)
Browse files Browse the repository at this point in the history
* ansible scripts for infra automation, and workflow for applying and testing changes

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* fix

Signed-off-by: anandrkskd <ansingh@redhat.com>

* fix

Signed-off-by: anandrkskd <ansingh@redhat.com>

* rename requirements.yaml

Signed-off-by: anandrkskd <ansingh@redhat.com>

* change permissions

Signed-off-by: anandrkskd <ansingh@redhat.com>

* update cluster version

Signed-off-by: anandrkskd <ansingh@redhat.com>

---------

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
Signed-off-by: anandrkskd <ansingh@redhat.com>
  • Loading branch information
anandrkskd authored May 11, 2023
1 parent f491bcc commit 7ff460b
Show file tree
Hide file tree
Showing 42 changed files with 2,001 additions and 135 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/infra-apply.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Infra update
on:
push:
branches:
- main
paths:
- scripts/ansible
- '!scripts/ansible/Cluster/kubernetes-cluster/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/openshift-cluster/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/NFS-vm/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/windows-openshift-cluster/manual-changes/Readme.md'

jobs:
kubernetes-infra-stage-test:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: pre-config
run: |
echo "${{ secrets.NFSKEY }}" > ./ssh_key
chmod 600 ./ssh_key
- name: update name from Stageing to production
run: |
sed -i 's/odo-stage/odo-tests/g' scripts/ansible/Cluster/vars.yml
- name: Create Stageing Cluster
uses: dawidd6/action-ansible-playbook@v2
env:
IC_API_KEY: ${{ secrets.IC_API_KEY }}
IC_REGION: 'eu-de'
SSHKEY: './ssh_key'
with:
playbook: scripts/ansible/create-infra.yaml
requirements: scripts/ansible/requirements.yaml
52 changes: 52 additions & 0 deletions .github/workflows/infra-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: odo-infra-stage-test
on:
push:
paths:
- scripts/ansible
- '!scripts/ansible/Cluster/kubernetes-cluster/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/openshift-cluster/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/NFS-vm/manual-changes/Readme.md'
- '!scripts/ansible/Cluster/windows-openshift-cluster/manual-changes/Readme.md'
pull_request:
branches:
- main

jobs:
kubernetes-infra-stage-test:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: pre-config
run: |
echo "${{ secrets.NFSKEY }}" > ./ssh_key
chmod 600 ./ssh_key
- name: Create Stageing Cluster
uses: dawidd6/action-ansible-playbook@v2
env:
IC_API_KEY: ${{ secrets.IC_API_KEY }}
IC_REGION: 'eu-de'
SSHKEY: './ssh_key'
with:
playbook: scripts/ansible/create-infra.yaml
requirements: scripts/ansible/requirements.yaml

- name: login to the three cluster
env:
IC_API_KEY: ${{ secrets.IC_API_KEY }}
IC_REGION: 'eu-de'
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud login --apikey $IC_API_KEY -r $IC_REGION
ibmcloud plugin install ks
CLUSTER=`ibmcloud ks cluster get -c odo-test-kubernetes-cluster --output json `
ID=$(echo $CLUSTER | jq -r '.id')
ibmcloud ks cluster config --cluster $ID --admin
CLUSTER=`ibmcloud ks cluster get -c odo-test-kubernetes-cluster --output json `
ID=$(echo $CLUSTER | jq -r '.id')
ibmcloud ks cluster config --cluster $ID --admin
CLUSTER=`ibmcloud ks cluster get -c odo-test-kubernetes-cluster --output json `
ID=$(echo $CLUSTER | jq -r '.id')
ibmcloud ks cluster config --cluster $ID --admin
60 changes: 60 additions & 0 deletions scripts/ansible/Cluster/NFS-vm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ReadMe
This directory contains yaml files to create NFS server

### NFS provisioner (how to configure nfs for cluster)

You can run the following commands upon a cluster to deploy the NFS provisioner to this cluster (either Kubernetes or OpenShift). You will need to uninstall the "Block Storage for VPC" add-on installed by default, to make the NFS provisioner work correctly.

```
$ helm repo add nfs-subdir-external-provisioner \
https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
$ helm install nfs-subdir-external-provisioner \
nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
--set nfs.server=<IP_FOR_NFS> \
--set nfs.path=/mnt/nfs \
--set storageClass.defaultClass=true \
--set storageClass.onDelete=delete
--version=4.0.15
```

> learn more about nfs-subdir-external-provisioner from https://artifacthub.io/packages/helm/nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
### check if nfs is working or not

login using the floating IP

### **NOTE**

ibmcoud storage provided with cluster doesnt works with nfs storge(if nfs storage is set as default). So make sure to diable addon `vpc-block-csi-driver` from cluster for which you want to use **nfs-storage**

#### *command to delete/remove storage addons from cluster*

```shell
ibmcloud ks cluster addon disable vpc-block-csi-driver
```

### helpful commands

1. Fetch IP for nfs configuration
```shell
IP_FOR_NFS=$(ibmcloud is instance <nfs-instance-name> --output json | jq -r ".primary_network_interface.primary_ip.address")
```

2. Fetch Floating IP of NFS-Server
```shell
NFS_IP=$(ibmcloud is instance k8s-nfs-server --output json | jq -r ".primary_network_interface.floating_ips[0].address" )
```

3. Create/Delete just NFS server
> NOTE: you will need to export path to ssh_key for login pourpose (`SSHKEY` is variable name)
```
$ export SSHKEY=/path/to/ssh/key
$ ansible-playbook create.yaml \
-e name_prefix=odo-tests \
-e cluster_zone="eu-de-2"
$ ansible-playbook delete.yaml \
-e name_prefix=odo-tests
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Create OpenShift Cluster on IBM Cloud
- name: Create NFS vsi for Clusters on IBM Cloud
hosts: localhost
collections:
- ibm.cloudcollection
Expand Down Expand Up @@ -86,16 +86,17 @@
image_dict: "{{ images_list.resource.images |
items2dict(key_name='name', value_name='id') }}"

- name: Configure SSH Key
ibm_is_ssh_key:
name: "ansible-ssh-key"
public_key: "{{ ssh_public_key }}"
register: ssh_key_create_output
# uncomment if "automation-key" is deleted and re run the playbook to create sshkey
# - name: Configure SSH Key
# ibm_is_ssh_key:
# name: "{{ name_prefix }}-key"
# public_key: "{{ ssh_public_key }}"
# register: ssh_key_create_output

- name: Save SSH Key as fact
set_fact:
cacheable: True
ssh_key: "{{ ssh_key_create_output.resource }}"
# - name: Save SSH Key id as fact
# set_fact:
# cacheable: True
# ssh_key_id: "{{ ssh_key_create_output.resource.id }}"

- name: Configure VSI for NFS server
ibm_is_instance:
Expand All @@ -105,7 +106,7 @@
profile: "bx2-2x8"
image: "{{ image_dict[nfs_image] }}"
keys:
- "{{ ssh_key.id }}"
- "{{ ssh_key_id }}"
primary_network_interface:
- subnet: "{{ subnet.id }}"
zone: "{{ cluster_zone }}"
Expand All @@ -129,63 +130,23 @@
cacheable: True
nfsip: "{{ nfsip_create_output.resource }}"

- name: get ssh_key from enviroment variable
set_fact:
cacheable: True
ssh_login_key: "'{{ lookup('ansible.builtin.env', 'SSHKEY') }}'"

- name: Add NFS to Ansible inventory
add_host:
name: "{{ nfsip.address }}"
ansible_user: root
groups: new_vsi
ansible_ssh_extra_args: -o StrictHostKeyChecking=no

- name: Configure Cloud Object Storage
ibm_resource_instance:
name: "{{ name_prefix }}-cos"
resource_group_id: "{{ rg.id }}"
service: "cloud-object-storage"
plan: "standard"
location: "global"
state: available
register: cos_create_output

- name: Save Cloud ObjectStorage Subnet as fact
set_fact:
cacheable: True
cos: "{{ cos_create_output.resource }}"
when: cos_create_output.rc==0

- name: Configure cluster
ibm_container_vpc_cluster:
name: "{{ name_prefix }}-cluster"
resource_group_id: "{{ rg.id }}"
kube_version: "{{ kube_version }}"
flavor: "{{ node_flavor }}"
worker_count: "{{ workers }}"
vpc_id: "{{ vpc.id }}"
cos_instance_crn: "{{ cos.crn }}"
zones:
- {
subnet_id: "{{ subnet.id }}",
name: "{{ cluster_zone }}"
}
state: available
register: cluster_create_output

- name: Save Cluster as fact
set_fact:
cacheable: True
cluster: "{{ cluster_create_output.resource }}"
when: cluster_create_output.rc==0

- local_action:
module: copy
content: "{{ cluster.id }}"
dest: "{{ cluster_id_file }}"
ansible_ssh_extra_args: -o StrictHostKeyChecking=no -i {{ ssh_login_key }}

- local_action:
module: copy
content: "{{ nfs.primary_network_interface[0].primary_ipv4_address }}"
dest: "{{ nfs_ip_file }}"


- name: Check Ansible connection to new NFS server
hosts: new_vsi
gather_facts: False
Expand Down Expand Up @@ -215,4 +176,4 @@
- name: Restart service nfs-kernel-server
ansible.builtin.service:
name: nfs-kernel-server
state: restarted
state: restarted
Loading

0 comments on commit 7ff460b

Please sign in to comment.