diff --git a/cli/engine/providers/azure/APIProxy.py b/cli/engine/providers/azure/APIProxy.py index b50bba3d44..833a82498d 100644 --- a/cli/engine/providers/azure/APIProxy.py +++ b/cli/engine/providers/azure/APIProxy.py @@ -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'] if look_for_public_ip: ip = instance['virtualMachine']['network']['publicIpAddresses'][0]['ipAddress'] else: diff --git a/cli/engine/providers/azure/InfrastructureBuilder.py b/cli/engine/providers/azure/InfrastructureBuilder.py index e330b96480..c3e13b15c7 100644 --- a/cli/engine/providers/azure/InfrastructureBuilder.py +++ b/cli/engine/providers/azure/InfrastructureBuilder.py @@ -24,6 +24,18 @@ 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: + 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 = [] @@ -200,6 +212,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)}) diff --git a/docs/changelogs/CHANGELOG-1.3.md b/docs/changelogs/CHANGELOG-1.3.md index 6d9750cb62..ad29c95de4 100644 --- a/docs/changelogs/CHANGELOG-1.3.md +++ b/docs/changelogs/CHANGELOG-1.3.md @@ -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 - [#2785](https://github.com/epiphany-platform/epiphany/issues/2785) - Add configuration option to Keycloak for PROXY_ADDRESS_FORWARDING env. variable - [#2814](https://github.com/epiphany-platform/epiphany/issues/2814) - Add description how to enable TLS in Kibana - [#1076](https://github.com/epiphany-platform/epiphany/issues/2595) - Document connection protocols and ciphers diff --git a/schema/azure/defaults/epiphany-cluster.yml b/schema/azure/defaults/epiphany-cluster.yml index 8028ddd1dc..b0a37480a1 100644 --- a/schema/azure/defaults/epiphany-cluster.yml +++ b/schema/azure/defaults/epiphany-cluster.yml @@ -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 diff --git a/schema/azure/defaults/infrastructure/virtual-machine.yml b/schema/azure/defaults/infrastructure/virtual-machine.yml index e99bdbc535..eff14c400b 100644 --- a/schema/azure/defaults/infrastructure/virtual-machine.yml +++ b/schema/azure/defaults/infrastructure/virtual-machine.yml @@ -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 diff --git a/schema/azure/validation/infrastructure/virtual-machine.yml b/schema/azure/validation/infrastructure/virtual-machine.yml index 557ac842be..9148aefb0e 100644 --- a/schema/azure/validation/infrastructure/virtual-machine.yml +++ b/schema/azure/validation/infrastructure/virtual-machine.yml @@ -5,6 +5,8 @@ type: object properties: name: type: string + hostname: + type: string admin_username: type: string admin_password: diff --git a/schema/common/validation/epiphany-cluster.yml b/schema/common/validation/epiphany-cluster.yml index 0451c69c4f..71409cdaff 100644 --- a/schema/common/validation/epiphany-cluster.yml +++ b/schema/common/validation/epiphany-cluster.yml @@ -115,6 +115,14 @@ properties: - centos-7-x86_64 - centos-7-arm64 pattern: ^(default|ubuntu-18.04-x86_64|redhat-7-x86_64|centos-7-x86_64|centos-7-arm64)$ + hostname_domain_extension: + "$id": "#/properties/specification/properties/cloud/properties/hostname_domain_extension" + type: string + title: The hostname_domain_extension Schema + default: '' + examples: + - extension + pattern: "^(.*)$" components: "$id": "#/properties/components" type: object diff --git a/terraform/azure/infrastructure/virtual-machine.j2 b/terraform/azure/infrastructure/virtual-machine.j2 index 07fe76e3c0..2e81de148d 100644 --- a/terraform/azure/infrastructure/virtual-machine.j2 +++ b/terraform/azure/infrastructure/virtual-machine.j2 @@ -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 }}" diff --git a/tests/unit/engine/providers/azure/test_AzureConfigBuilder.py b/tests/unit/engine/providers/azure/test_AzureConfigBuilder.py index 03404136b6..047f8c10d1 100644 --- a/tests/unit/engine/providers/azure/test_AzureConfigBuilder.py +++ b/tests/unit/engine/providers/azure/test_AzureConfigBuilder.py @@ -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 } diff --git a/tests/unit/engine/providers/data/APIProxy_data.py b/tests/unit/engine/providers/data/APIProxy_data.py index 67c37a6870..29a110d72e 100644 --- a/tests/unit/engine/providers/data/APIProxy_data.py +++ b/tests/unit/engine/providers/data/APIProxy_data.py @@ -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': {