Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement private k8s cluster #117

Merged
merged 6 commits into from
Dec 21, 2023
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
20 changes: 20 additions & 0 deletions docs/api/managed-kubernetes/k8s_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ This is a simple module that supports creating or removing K8s Clusters. This mo
<td>List of S3 buckets configured for K8s usage. At the moment, it contains only one S3 bucket that is used to store K8s API audit logs.</td>
</tr>
<tr>
<td>public<br/><mark style="color:blue;">bool</mark></td>
<td align="center">False</td>
<td>The indicator if the cluster is public or private.</td>
</tr>
<tr>
<td>location<br/><mark style="color:blue;">str</mark></td>
<td align="center">False</td>
<td>The location of the cluster if the cluster is private. This property is immutable. The location must be enabled for your contract or you must have a Datacenter within that location. This attribute is mandatory if the cluster is private.</td>
</tr>
<tr>
<td>nat_gateway_ip<br/><mark style="color:blue;">str</mark></td>
<td align="center">False</td>
<td>The nat gateway IP of the cluster if the cluster is private.</td>
</tr>
<tr>
<td>node_subnet<br/><mark style="color:blue;">str</mark></td>
<td align="center">False</td>
<td>The node subnet of the cluster if the cluster is private.</td>
</tr>
<tr>
<td>allow_replace<br/><mark style="color:blue;">bool</mark></td>
<td align="center">False</td>
<td>Boolean indincating if the resource should be recreated when the state cannot be reached in another way. This may be used to prevent resources from being deleted from specifying a different value to an immutable property. An error will be thrown instead<br />Default: False</td>
Expand Down
49 changes: 40 additions & 9 deletions plugins/modules/k8s_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@
'type': 'list',
'elements': 'str',
},
'public': {
'description': ['The indicator if the cluster is public or private.'],
'available': ['present'],
'type': 'bool'
},
'location': {
'description': 'The location of the cluster if the cluster is private. This property is immutable. The '
'location must be enabled for your contract or you must have a Datacenter within that '
'location. This attribute is mandatory if the cluster is private.',
'available': ['present'],
'type': 'str'
},
'nat_gateway_ip': {
'description': 'The nat gateway IP of the cluster if the cluster is private.',
'available': ['present'],
'type': 'str'
},
'node_subnet': {
'description': 'The node subnet of the cluster if the cluster is private.',
'available': ['present'],
'type': 'str'
},
'allow_replace': {
'description': [
'Boolean indincating if the resource should be recreated when the state cannot be reached in '
Expand Down Expand Up @@ -297,6 +319,11 @@ def _create_object(module, client, existing_object=None):
cluster_name = module.params.get('cluster_name')
k8s_version = module.params.get('k8s_version')
maintenance = module.params.get('maintenance_window')
public = module.params.get('public')
location = module.params.get('location')
nat_gateway_ip = module.params.get('nat_gateway_ip')
node_subnet = module.params.get('node_subnet')
wait = module.params.get('wait')
api_subnet_allow_list = module.params.get('api_subnet_allow_list')
s3_buckets = list(map(lambda bucket_name: S3Bucket(name=bucket_name), module.params.get('s3_buckets_param'))) if module.params.get('s3_buckets_param') else None

Expand All @@ -316,17 +343,21 @@ def _create_object(module, client, existing_object=None):
wait_timeout = int(module.params.get('wait_timeout'))

k8s_api = ionoscloud.KubernetesApi(api_client=client)

k8s_cluster_properties = KubernetesClusterProperties(
name=cluster_name,
k8s_version=k8s_version,
maintenance_window=maintenance_window,
api_subnet_allow_list=api_subnet_allow_list,
s3_buckets=s3_buckets,
)
k8s_cluster = KubernetesCluster(properties=k8s_cluster_properties)

try:
k8s_cluster_properties = KubernetesClusterProperties(
name=cluster_name,
k8s_version=k8s_version,
maintenance_window=maintenance_window,
api_subnet_allow_list=api_subnet_allow_list,
s3_buckets=s3_buckets,
public=public,
nat_gateway_ip=nat_gateway_ip,
node_subnet=node_subnet,
location=location
)
k8s_cluster = KubernetesCluster(properties=k8s_cluster_properties)

k8s_response = k8s_api.k8s_post(kubernetes_cluster=k8s_cluster)

if wait:
Expand Down
3 changes: 3 additions & 0 deletions reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ansible-galaxy collection build . --force
ansible-galaxy collection install ionoscloudsdk-ionoscloud-7.1.0.tar.gz --force
rm ionoscloudsdk-ionoscloud-7.1.0.tar.gz
4 changes: 2 additions & 2 deletions tests/managed-kubernetes/cluster/all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
- name: Run K8s Cluster Test
import_playbook: k8s-cluster-test.yml

#- name: Run Private K8s Cluster Test
# import_playbook: private-k8s-cluster-test.yml
- name: Run Private K8s Cluster Test
import_playbook: private-k8s-cluster-test.yml
30 changes: 3 additions & 27 deletions tests/managed-kubernetes/cluster/private-k8s-cluster-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,11 @@
day_of_the_week: "Wednesday"
time: "12:02:00"
public: False
location: "{{ location }}"
node_subnet: 192.168.0.0/16
nat_gateway_ip: "{{ ipblock_response.ipblock.properties.ips[0] }}"
register: cluster_response

- name: Create k8s cluster nodepool
k8s_nodepool:
nodepool_name: "ansible-nodepool-{{100|random}}"
k8s_cluster: "{{ cluster_response.cluster.id }}"
datacenter_id: "{{ datacenter_response.datacenter.id }}"
node_count: 2
cpu_family: "INTEL_SKYLAKE"
cores_count: "1"
ram_size: "2048"
availability_zone: "AUTO"
storage_type: "HDD"
storage_size: "100"
gateway_ip: "{{ ipblock_response.ipblock.properties.ips[0] }}"
wait: true
register: nodepool_response

- name: Debug - Show nodepool
debug:
msg: "{{ nodepool_response.nodepool }}"

- name: Delete k8s cluster nodepool
k8s_nodepool:
k8s_cluster: "{{ cluster_response.cluster.id }}"
nodepool_id: "{{ nodepool_response.nodepool.id }}"
wait: true
state: absent

- name: Delete k8s cluster
k8s_cluster:
k8s_cluster: "{{ cluster_response.cluster.id }}"
Expand Down
1 change: 1 addition & 0 deletions tests/managed-kubernetes/cluster/vars.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: "AnsibleAutoTestK8sCluster"
datacenter: "AnsibleAutoTestK8sCluster"
nat: "AnsibleAutoTestNATCluster"
description: Ansible test description
server: "AnsibleAutoTestK8sCluster"
nic: "AnsibleAutoTestK8sCluster"
Expand Down
Loading