From 2bfcde5800a2c53b5cbe7e7cc6cc8c32dee0d535 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Thu, 15 Feb 2024 14:56:35 +0100 Subject: Specify DNS record types in Azure --- .../java/com/yahoo/config/provision/NodeType.java | 38 ++++++++-------------- .../com/yahoo/vespa/hosted/provision/node/Dns.java | 15 +++++---- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java index ff2cb26f250..ec768a0271e 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.provision; -import java.util.List; import java.util.Optional; /** @@ -36,7 +35,7 @@ public enum NodeType { controllerhost("Controller host", controller); private final String description; - private final List childNodeTypes; + private final Optional childNodeType; public static Optional ofOptional(String name) { for (var type : values()) { @@ -45,13 +44,17 @@ public enum NodeType { return Optional.empty(); } - NodeType(String description, NodeType... childNodeTypes) { - this.childNodeTypes = List.of(childNodeTypes); + NodeType(String description) { + this(description, null); + } + + NodeType(String description, NodeType childNodeTypes) { + this.childNodeType = Optional.ofNullable(childNodeTypes); this.description = description; } public boolean isHost() { - return !childNodeTypes.isEmpty(); + return childNodeType.isPresent(); } /** either config server or controller */ @@ -74,32 +77,22 @@ public enum NodeType { } /** - * @return {@link NodeType} of the node(s) that run on this host + * @return {@link NodeType} of the node that run on this host * @throws IllegalStateException if this type is not a host */ public NodeType childNodeType() { - return childNodeTypes().get(0); - } - - /** - * @return all {@link NodeType}s that can run on this host - * @throws IllegalStateException if this type is not a host - */ - public List childNodeTypes() { - if (! isHost()) - throw new IllegalStateException(this + " has no children"); - return childNodeTypes; + return childNodeType.orElseThrow(() -> new IllegalStateException(this + " is not a host")); } /** Returns whether given node type can run on this */ public boolean canRun(NodeType type) { - return childNodeTypes.contains(type); + return childNodeType.map(t -> t == type).orElse(false); } /** Returns the parent host type. */ public NodeType parentNodeType() { for (var type : values()) { - if (type.childNodeTypes.contains(this)) return type; + if (type.canRun(this)) return type; } throw new IllegalStateException(this + " has no parent"); } @@ -107,11 +100,8 @@ public enum NodeType { /** Returns the host type of this */ public NodeType hostType() { if (isHost()) return this; - for (NodeType nodeType : values()) { - // Ignore host types that support multiple node types - if (nodeType.childNodeTypes.size() == 1 && nodeType.canRun(this)) { - return nodeType; - } + for (NodeType type : values()) { + if (type.canRun(this)) return type; } throw new IllegalStateException("No host of " + this + " exists"); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Dns.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Dns.java index 75ff0d29bd3..9f5aaf4b327 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Dns.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Dns.java @@ -25,12 +25,7 @@ public class Dns { /** Returns the set of DNS record types for a host and its children and the given version (ipv6), host type, etc. */ public static Set recordTypesFor(IP.Version ipVersion, NodeType hostType, CloudName cloudName, boolean enclave) { - if (cloudName == CloudName.AWS) - return enclave ? - EnumSet.of(RecordType.FORWARD, RecordType.PUBLIC_FORWARD) : - EnumSet.of(RecordType.FORWARD, RecordType.PUBLIC_FORWARD, RecordType.REVERSE); - - if (cloudName == CloudName.GCP) { + if (cloudName == CloudName.AWS || cloudName == CloudName.GCP) { if (enclave) { return ipVersion.is6() ? EnumSet.of(RecordType.FORWARD, RecordType.PUBLIC_FORWARD) : @@ -42,6 +37,14 @@ public class Dns { } } + if (cloudName == CloudName.AZURE) { + return ipVersion.is6() ? + EnumSet.noneOf(RecordType.class) : + enclave || hostType == confighost ? + EnumSet.of(RecordType.FORWARD, RecordType.PUBLIC_FORWARD) : + EnumSet.of(RecordType.FORWARD); + } + throw new IllegalArgumentException("Does not manage DNS for cloud " + cloudName); } -- cgit v1.2.3