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

Added hostname_domain_extension. #2790

Merged
merged 6 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion cli/engine/providers/azure/APIProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def get_ips_for_feature(self, component_key):
for instance in running_instances:
if isinstance(instance, list):
instance = instance[0]
name = instance['virtualMachine']['name']
if self.cluster_model.specification.cloud.hostname_domain_extension != '':
name = instance['virtualMachine']['name'] + f'.{self.cluster_model.specification.cloud.hostname_domain_extension}'
else:
name = instance['virtualMachine']['name']
atsikham marked this conversation as resolved.
Show resolved Hide resolved
if look_for_public_ip:
ip = instance['virtualMachine']['network']['publicIpAddresses'][0]['ipAddress']
else:
Expand Down
17 changes: 17 additions & 0 deletions cli/engine/providers/azure/InfrastructureBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ def __init__(self, docs, manifest_docs=[]):
self.docs = docs
self.manifest_docs = manifest_docs

# Check if there is a hostname_domain_extension we already applied and we want to retain.
# The same as VM images we want to preserve hostname_domain_extension over versions.
self.hostname_domain_extension = self.cluster_model.specification.cloud.hostname_domain_extension
manifest_cluster_model = select_first(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster')
if self.manifest_docs:
if 'hostname_domain_extension' in manifest_cluster_model.specification.cloud:
if manifest_cluster_model.specification.cloud.hostname_domain_extension != '':
seriva marked this conversation as resolved.
Show resolved Hide resolved
old_hostname_domain_extension = manifest_cluster_model.specification.cloud.hostname_domain_extension
if old_hostname_domain_extension != self.hostname_domain_extension:
self.logger.warning(f"Re-applying a different hostname_domain_extension might lead to data loss and/or other issues. Preserving the previous hostname_domain_extension: '{old_hostname_domain_extension}'.")
self.cluster_model.specification.cloud.hostname_domain_extension = old_hostname_domain_extension
self.hostname_domain_extension = old_hostname_domain_extension

def run(self):
infrastructure = []

Expand Down Expand Up @@ -200,6 +213,10 @@ def get_storage_share_config(self):
def get_vm(self, component_key, vm_config, availability_set, network_interface_name, index):
vm = dict_to_objdict(deepcopy(vm_config))
vm.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'vm' + '-' + str(index), component_key)
if self.hostname_domain_extension != '':
vm.specification.hostname = resource_name(self.cluster_prefix, self.cluster_name, 'vm' + '-' + str(index) + f'.{self.hostname_domain_extension}', component_key)
else:
vm.specification.hostname = vm.specification.name
vm.specification.admin_username = self.cluster_model.specification.admin_user.name
vm.specification.network_interface_name = network_interface_name
vm.specification.tags.append({'cluster': cluster_tag(self.cluster_prefix, self.cluster_name)})
Expand Down
1 change: 1 addition & 0 deletions docs/changelogs/CHANGELOG-1.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [#2644](https://github.com/epiphany-platform/epiphany/issues/2644) - Add validation to check hostnames for on-prem deployment
- [#2703](https://github.com/epiphany-platform/epiphany/issues/2703) - Add tests for docker and kubelet cgroup driver
- [#1076](https://github.com/epiphany-platform/epiphany/issues/1076) - Add sorting entries in the inventory file
- [#2768](https://github.com/epiphany-platform/epiphany/issues/2768) - Add posibility to provide custom hostnames

### Fixed

Expand Down
1 change: 1 addition & 0 deletions schema/azure/defaults/epiphany-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ specification:
network:
use_network_security_groups: True
default_os_image: default
hostname_domain_extension: '' # Domain name that will be added to every machines hostname with a . seperator
components:
kubernetes_master:
count: 1
Expand Down
1 change: 1 addition & 0 deletions schema/azure/defaults/infrastructure/virtual-machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ provider: azure
name: default
specification:
name: SET_BY_AUTOMATION
hostname: SET_BY_AUTOMATION
admin_username: SET_BY_AUTOMATION
admin_password: SET_BY_AUTOMATION
public_key: SET_BY_AUTOMATION
Expand Down
2 changes: 2 additions & 0 deletions schema/azure/validation/infrastructure/virtual-machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type: object
properties:
name:
type: string
hostname:
type: string
admin_username:
type: string
admin_password:
Expand Down
2 changes: 1 addition & 1 deletion terraform/azure/infrastructure/virtual-machine.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "azurerm_virtual_machine" "{{ specification.name }}" {
}

os_profile {
computer_name = "{{ specification.name }}"
computer_name = "{{ specification.hostname }}"
admin_username = "{{ specification.admin_username }}"
{%- if specification.os_type == "windows" %}
admin_password = "{{ specification.admin_password }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_cluster_model(address_pool='10.22.0.0/22', cluster_name='EpiphanyTestClu
'vnet_address_pool': address_pool,
'use_public_ips': True,
'default_os_image': 'default',
'hostname_domain_extension': '',
'network': {
'use_network_security_groups': True
}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/engine/providers/data/APIProxy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def CLUSTER_MODEL(provider: str) -> ObjDict:
'use_service_principal': False,
'region': 'West Europe',
'network': {'use_network_security_groups': True},
'default_os_image': 'default'
'default_os_image': 'default',
'hostname_domain_extension': ''
},
'components': {
'service': {
Expand Down