Skip to content

Commit

Permalink
Infer gossip DNS from cluster name
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Oct 2, 2022
1 parent 4412d82 commit 1785662
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion nodeup/pkg/model/dns/builder.go
Expand Up @@ -32,7 +32,7 @@ var _ fi.ModelBuilder = &GossipBuilder{}

// Build is responsible for configuring the gossip DNS tasks.
func (b *GossipBuilder) Build(c *fi.ModelBuilderContext) error {
useGossip := dns.IsGossipHostname(b.Cluster.Spec.MasterInternalName)
useGossip := dns.IsGossipHostname(b.Cluster.Name)
if !useGossip {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions nodeup/pkg/model/protokube.go
Expand Up @@ -48,7 +48,7 @@ var _ fi.ModelBuilder = &ProtokubeBuilder{}

// Build is responsible for generating the options for protokube
func (t *ProtokubeBuilder) Build(c *fi.ModelBuilderContext) error {
useGossip := dns.IsGossipHostname(t.Cluster.Spec.MasterInternalName)
useGossip := dns.IsGossipHostname(t.Cluster.Name)

// check is not a master and we are not using gossip (https://github.com/kubernetes/kops/pull/3091)
if !t.IsMaster && !useGossip {
Expand Down Expand Up @@ -209,8 +209,8 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube
// argv = append(argv, "--zone=*/*")
}

if dns.IsGossipHostname(t.Cluster.Spec.MasterInternalName) {
klog.Warningf("MasterInternalName %q implies gossip DNS", t.Cluster.Spec.MasterInternalName)
if dns.IsGossipHostname(t.Cluster.Name) {
klog.Warningf("Cluster name %q implies gossip DNS", t.Cluster.Name)
f.Gossip = fi.Bool(true)
if t.Cluster.Spec.GossipConfig != nil {
f.GossipProtocol = t.Cluster.Spec.GossipConfig.Protocol
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/validation/validation.go
Expand Up @@ -1614,7 +1614,7 @@ func validateExternalDNS(cluster *kops.Cluster, spec *kops.ExternalDNSConfig, fl
}

if spec.Provider == kops.ExternalDNSProviderExternalDNS {
if dns.IsGossipHostname(cluster.Spec.MasterInternalName) {
if dns.IsGossipHostname(cluster.Name) {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("provider"), "external-dns does not support gossip clusters"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/awsmodel/iam.go
Expand Up @@ -237,7 +237,7 @@ func (b *IAMModelBuilder) buildIAMRolePolicy(role iam.Subject, iamName string, i
},
}

if !dns.IsGossipHostname(b.Cluster.ObjectMeta.Name) {
if !dns.IsGossipHostname(b.Cluster.Name) {
// This is slightly tricky; we need to know the hosted zone id,
// but we might be creating the hosted zone dynamically.
// We create a stub-reference which will be combined by the execution engine.
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/etcdmanager/model.go
Expand Up @@ -293,7 +293,7 @@ func (b *EtcdManagerBuilder) buildPod(etcdCluster kops.EtcdClusterSpec, instance
// The dns suffix logic mirrors the existing logic, so we should be compatible with existing clusters
// (etcd makes it difficult to change peer urls, treating it as a cluster event, for reasons unknown)
dnsInternalSuffix := ""
if dns.IsGossipHostname(b.Cluster.Spec.MasterInternalName) {
if dns.IsGossipHostname(b.Cluster.Name) {
// @TODO: This is hacky, but we want it so that we can have a different internal & external name
dnsInternalSuffix = b.Cluster.Spec.MasterInternalName
dnsInternalSuffix = strings.TrimPrefix(dnsInternalSuffix, "api.")
Expand Down
6 changes: 3 additions & 3 deletions upup/pkg/fi/cloudup/apply_cluster.go
Expand Up @@ -302,7 +302,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
if cluster.Spec.KubernetesVersion == "" {
return fmt.Errorf("KubernetesVersion not set")
}
if cluster.Spec.DNSZone == "" && !dns.IsGossipHostname(cluster.ObjectMeta.Name) {
if cluster.Spec.DNSZone == "" && !dns.IsGossipHostname(cluster.Name) {
return fmt.Errorf("DNSZone not set")
}

Expand Down Expand Up @@ -483,7 +483,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
modelContext.SSHPublicKeys = sshPublicKeys
modelContext.Region = cloud.Region()

if dns.IsGossipHostname(cluster.ObjectMeta.Name) {
if dns.IsGossipHostname(cluster.Name) {
klog.V(2).Infof("Gossip DNS: skipping DNS validation")
} else {
err = validateDNS(cluster, cloud)
Expand Down Expand Up @@ -1306,7 +1306,7 @@ func (n *nodeUpConfigBuilder) BuildConfig(ig *kops.InstanceGroup, apiserverAddit
return nil, nil, fmt.Errorf("cannot determine role for instance group: %v", ig.ObjectMeta.Name)
}

useGossip := dns.IsGossipHostname(cluster.Spec.MasterInternalName)
useGossip := dns.IsGossipHostname(cluster.Name)
isMaster := role == kops.InstanceGroupRoleMaster
hasAPIServer := isMaster || role == kops.InstanceGroupRoleAPIServer

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/populate_cluster_spec.go
Expand Up @@ -220,7 +220,7 @@ func (c *populateClusterSpec) run(clientset simple.Clientset) error {
klog.V(2).Infof("Normalizing kubernetes version: %q -> %q", cluster.Spec.KubernetesVersion, versionWithoutV)
cluster.Spec.KubernetesVersion = versionWithoutV
}
if cluster.Spec.DNSZone == "" && !dns.IsGossipHostname(cluster.ObjectMeta.Name) {
if cluster.Spec.DNSZone == "" && !dns.IsGossipHostname(cluster.Name) {
dns, err := cloud.DNS()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions upup/pkg/fi/cloudup/template_functions.go
Expand Up @@ -127,7 +127,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS
dest["GossipDomains"] = func() []string {
var names []string

if dns.IsGossipHostname(cluster.Spec.MasterInternalName) {
if dns.IsGossipHostname(cluster.Name) {
names = append(names, "k8s.local")
}

Expand Down Expand Up @@ -485,7 +485,7 @@ func (tf *TemplateFunctions) DNSControllerArgv() ([]string, error) {
}
}

if dns.IsGossipHostname(cluster.Spec.MasterInternalName) {
if dns.IsGossipHostname(cluster.Name) {
argv = append(argv, "--dns=gossip")

// Configuration specifically for the DNS controller gossip
Expand Down Expand Up @@ -665,7 +665,7 @@ func (tf *TemplateFunctions) KopsControllerConfig() (string, error) {
config.EnableCloudIPAM = true
}

if dns.IsGossipHostname(cluster.Spec.MasterInternalName) {
if dns.IsGossipHostname(cluster.Name) {
config.Discovery = &kopscontrollerconfig.DiscoveryOptions{
Enabled: true,
}
Expand Down

0 comments on commit 1785662

Please sign in to comment.