Skip to content

Commit

Permalink
test and improve kubectl port forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Sep 3, 2024
1 parent 201c5a1 commit a59037b
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9440,39 +9440,42 @@ node_types:
inputs:
playbook:
q:
- name: forward port
ansible.builtin.shell: kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306
args:
executable: /usr/bin/bash
async: 30
poll: 0
- name: wait for port
ansible.builtin.wait_for:
host: 127.0.0.1
port: 23306
delay: 5
timeout: 30
- name: create database
community.mysql.mysql_db:
name: '{{ SELF.database_name }}'
login_host: 127.0.0.1
login_password: '{{ HOST.dbms_password }}'
login_port: '23306'
login_user: root
- name: create user (with privileges)
community.mysql.mysql_user:
name: '{{ SELF.database_user }}'
password: '{{ SELF.database_password }}'
host: '%'
priv: '*.*:ALL'
login_host: 127.0.0.1
login_password: '{{ HOST.dbms_password }}'
login_port: '23306'
login_user: root
- name: unforward port
ansible.builtin.shell: pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"
args:
executable: /usr/bin/bash
- name: deploy database
block:
- name: forward port
ansible.builtin.shell: kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306
args:
executable: /usr/bin/bash
async: 30
poll: 0
- name: wait for port
ansible.builtin.wait_for:
host: 127.0.0.1
port: 23306
delay: 5
timeout: 30
- name: create database
community.mysql.mysql_db:
name: '{{ SELF.database_name }}'
login_host: 127.0.0.1
login_password: '{{ HOST.dbms_password }}'
login_port: '23306'
login_user: root
- name: create user (with privileges)
community.mysql.mysql_user:
name: '{{ SELF.database_user }}'
password: '{{ SELF.database_password }}'
host: '%'
priv: '*.*:ALL'
login_host: 127.0.0.1
login_password: '{{ HOST.dbms_password }}'
login_port: '23306'
login_user: root
always:
- name: unforward port
ansible.builtin.shell: pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"
args:
executable: /usr/bin/bash
mysql.database~mysql.database::[email protected]>virtual.machine:
derived_from: mysql.database
metadata:
Expand Down Expand Up @@ -9699,6 +9702,65 @@ node_types:
type: string
default:
get_input: k8s_client_key_file
interfaces:
Standard:
operations:
configure:
implementation:
primary: Terraform
delete:
implementation:
primary: Terraform
defaults:
inputs:
main:
terraform:
- required_providers:
- mysql:
source: petoju/mysql
version: 3.0.48
provider:
mysql:
- endpoint: ${terraform_data.forward_port.input}
password: '{{ HOST.dbms_password }}'
username: root
resource:
terraform_data:
forward_port:
- input: 127.0.0.1:23306
provisioner:
local-exec:
command: |-
(nohup kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306 > /dev/null 2>&1 &)
sleep 5s
interpreter:
- /bin/bash
- '-c'
unforward_port:
- depends_on:
- mysql_grant.user
provisioner:
local-exec:
command: pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"
interpreter:
- /bin/bash
- '-c'
mysql_database:
database:
- name: '{{ SELF.database_name }}'
mysql_user:
user:
- host: '%'
plaintext_password: '{{ SELF.database_password }}'
user: '{{ SELF.database_user }}'
mysql_grant:
user:
- database: '{{ SELF.database_name }}'
host: '%'
table: '*'
privileges:
- ALL
user: ${mysql_user.user.user}
mysql.database~mysql.database::[email protected]>virtual.machine:
derived_from: mysql.database
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ TEMPLATE_NAME="technology-gcp"
#VINTNER="node ../../../build/cli/index.js"
VINTNER="../../../task vintner"
ORCHESTRATOR="unfurl"
VARIANT="gcp"
VARIANT="kubernetes"
Original file line number Diff line number Diff line change
Expand Up @@ -9699,6 +9699,66 @@ node_types:
type: string
default:
get_input: k8s_client_key_file
interfaces:
Standard:
operations:
configure:
implementation:
primary: Terraform
delete:
implementation:
primary: Terraform
defaults:
inputs:
main:
terraform:
- required_providers:
- mysql:
source: petoju/mysql
version: 3.0.48
provider:
mysql:
- endpoint: ${terraform_data.forward_port.endpoint}
password: '{{ HOST.dbms_password }}'
username: root
resource:
terraform_data:
forward_port:
- input:
endpoint: 127.0.0.1:23306
provisioner:
local-exec:
command: |-
nohup kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306 &
sleep 5s
interpreter:
- /bin/bash
- '-c'
unforward_port:
- depends_on:
- mysql_grant.user
provisioner:
local-exec:
command: pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"
interpreter:
- /bin/bash
- '-c'
mysql_database:
database:
- name: '{{ SELF.database_name }}'
mysql_user:
user:
- host: '%'
plaintext_password: '{{ SELF.database_password }}'
user: '{{ SELF.database_user }}'
mysql_grant:
user:
- database: '{{ SELF.database_name }}'
host: '%'
table: '*'
privileges:
- ALL
user: ${mysql_user.user.user}
mysql.database~mysql.database::[email protected]>virtual.machine:
derived_from: mysql.database
metadata:
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEMPLATE_NAME="technology-maintenance"
#VINTNER="node ../../../build/cli/index.js"
VINTNER="../../../task vintner"
VARIANT="static"
VARIANT="kubernetes"

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,61 @@ const generator: ImplementationGenerator = {
playbook: {
q: [
{
name: 'forward port',
'ansible.builtin.shell':
'kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306',
args: {
executable: '/usr/bin/bash',
},
async: 30,
poll: 0,
},
{
name: 'wait for port',
'ansible.builtin.wait_for': {
host: '127.0.0.1',
port: 23306,
delay: 5,
timeout: 30,
},
},
{
name: 'create database',
'community.mysql.mysql_db': {
name: '{{ SELF.database_name }}',
login_host: '127.0.0.1',
login_password: '{{ HOST.dbms_password }}',
login_port: '23306',
login_user: 'root',
},
},
{
name: 'create user (with privileges)',
'community.mysql.mysql_user': {
name: '{{ SELF.database_user }}',
password: '{{ SELF.database_password }}',
host: '%',
priv: '*.*:ALL',
login_host: '127.0.0.1',
login_password: '{{ HOST.dbms_password }}',
login_port: '23306',
login_user: 'root',
},
},
{
name: 'unforward port',
'ansible.builtin.shell':
'pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"',
args: {
executable: '/usr/bin/bash',
},
name: 'deploy database',
block: [
{
name: 'forward port',
'ansible.builtin.shell':
'kubectl port-forward service/{{ HOST.dbms_name }} 23306:3306',
args: {
executable: '/usr/bin/bash',
},
async: 30,
poll: 0,
},
{
name: 'wait for port',
'ansible.builtin.wait_for': {
host: '127.0.0.1',
port: 23306,
delay: 5,
timeout: 30,
},
},
{
name: 'create database',
'community.mysql.mysql_db': {
name: '{{ SELF.database_name }}',
login_host: '127.0.0.1',
login_password: '{{ HOST.dbms_password }}',
login_port: '23306',
login_user: 'root',
},
},
{
name: 'create user (with privileges)',
'community.mysql.mysql_user': {
name: '{{ SELF.database_user }}',
password: '{{ SELF.database_password }}',
host: '%',
priv: '*.*:ALL',
login_host: '127.0.0.1',
login_password: '{{ HOST.dbms_password }}',
login_port: '23306',
login_user: 'root',
},
},
],
always: [
{
name: 'unforward port',
'ansible.builtin.shell':
'pkill -f "kubectl port-forward service/{{ HOST.dbms_name }}"',
args: {
executable: '/usr/bin/bash',
},
},
],
},
],
},
Expand Down
Loading

0 comments on commit a59037b

Please sign in to comment.