Skip to content

Commit

Permalink
Remove unused DNS logic from Protokube
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed May 28, 2022
1 parent 288d205 commit 4553d7b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 305 deletions.
45 changes: 2 additions & 43 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,11 @@ type ProtokubeFlags struct {
Cloud *string `json:"cloud,omitempty" flag:"cloud"`
Containerized *bool `json:"containerized,omitempty" flag:"containerized"`
DNSInternalSuffix *string `json:"dnsInternalSuffix,omitempty" flag:"dns-internal-suffix"`
DNSProvider *string `json:"dnsProvider,omitempty" flag:"dns"`
Gossip *bool `json:"gossip,omitempty" flag:"gossip"`
LogLevel *int32 `json:"logLevel,omitempty" flag:"v"`
Master *bool `json:"master,omitempty" flag:"master"`
Zone []string `json:"zone,omitempty" flag:"zone"`

// RemoveDNSNames allows us to remove dns records, so that they can be managed elsewhere
// We use it e.g. for the switch to etcd-manager
RemoveDNSNames string `json:"removeDNSNames,omitempty" flag:"remove-dns-names"`

// BootstrapMasterNodeLabels applies the critical node-role labels to our node,
// which lets us bring up the controllers that can only run on masters, which are then
// responsible for node labels. The node is specified by NodeName
Expand Down Expand Up @@ -215,7 +211,7 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube

if dns.IsGossipHostname(t.Cluster.Spec.MasterInternalName) {
klog.Warningf("MasterInternalName %q implies gossip DNS", t.Cluster.Spec.MasterInternalName)
f.DNSProvider = fi.String("gossip")
f.Gossip = fi.Bool(true)
if t.Cluster.Spec.GossipConfig != nil {
f.GossipProtocol = t.Cluster.Spec.GossipConfig.Protocol
f.GossipListen = t.Cluster.Spec.GossipConfig.Listen
Expand All @@ -236,19 +232,6 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube

if t.CloudProvider != "" {
f.Cloud = fi.String(string(t.CloudProvider))

if f.DNSProvider == nil {
switch t.CloudProvider {
case kops.CloudProviderAWS:
f.DNSProvider = fi.String("aws-route53")
case kops.CloudProviderDO:
f.DNSProvider = fi.String("digitalocean")
case kops.CloudProviderGCE:
f.DNSProvider = fi.String("google-clouddns")
default:
klog.Warningf("Unknown cloudprovider %q; won't set DNS provider", t.CloudProvider)
}
}
}

if f.DNSInternalSuffix == nil {
Expand All @@ -265,30 +248,6 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube
f.NodeName = nodeName
}

// Remove DNS names since we're using etcd-manager
{
var names []string

// Mirroring the logic used to construct DNS names in protokube/pkg/protokube/etcd_cluster.go
suffix := fi.StringValue(f.DNSInternalSuffix)
if !strings.HasPrefix(suffix, ".") {
suffix = "." + suffix
}

for _, c := range t.Cluster.Spec.EtcdClusters {
clusterName := "etcd-" + c.Name
if clusterName == "etcd-main" {
clusterName = "etcd"
}
for _, m := range c.Members {
name := clusterName + "-" + m.Name + suffix
names = append(names, name)
}
}

f.RemoveDNSNames = strings.Join(names, ",")
}

return f, nil
}

Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/tests/protokube/tasks-protokube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ definition: |
Documentation=https://kops.sigs.k8s.io
[Service]
ExecStart=/opt/kops/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --cluster-id=minimal.example.com --containerized=false --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --master=true --node-name=master.hostname.invalid --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 --zone=*/Z1AFAKE1ZON3YO
ExecStart=/opt/kops/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --cluster-id=minimal.example.com --containerized=false --dns-internal-suffix=.internal.minimal.example.com --master=true --node-name=master.hostname.invalid --v=4 --zone=*/Z1AFAKE1ZON3YO
EnvironmentFile=/etc/sysconfig/protokube
Restart=always
RestartSec=3s
Expand Down
56 changes: 0 additions & 56 deletions protokube/cmd/protokube/dns_cleanup.go

This file was deleted.

80 changes: 11 additions & 69 deletions protokube/cmd/protokube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@ package main
import (
"flag"
"fmt"
"io"
"net"
"os"
"path"
"strings"

"github.com/spf13/pflag"
"k8s.io/klog/v2"
"k8s.io/kops/dns-controller/pkg/dns"
"k8s.io/kops/dnsprovider/pkg/dnsprovider"
"k8s.io/kops/pkg/wellknownports"
"k8s.io/kops/protokube/pkg/gossip"
gossiputils "k8s.io/kops/protokube/pkg/gossip"
gossipdns "k8s.io/kops/protokube/pkg/gossip/dns"
_ "k8s.io/kops/protokube/pkg/gossip/memberlist"
_ "k8s.io/kops/protokube/pkg/gossip/mesh"
"k8s.io/kops/protokube/pkg/protokube"

// Load DNS plugins
_ "k8s.io/kops/dnsprovider/pkg/dnsprovider/providers/aws/route53"
_ "k8s.io/kops/dnsprovider/pkg/dnsprovider/providers/do"
_ "k8s.io/kops/dnsprovider/pkg/dnsprovider/providers/google/clouddns"
)

var (
Expand All @@ -63,12 +55,13 @@ func main() {
// run is responsible for running the protokube service controller
func run() error {
var zones []string
var containerized, master bool
var cloud, clusterID, dnsProviderID, dnsInternalSuffix, gossipSecret, gossipListen, gossipProtocol, gossipSecretSecondary, gossipListenSecondary, gossipProtocolSecondary string
var containerized, master, gossip bool
var cloud, clusterID, dnsInternalSuffix, gossipSecret, gossipListen, gossipProtocol, gossipSecretSecondary, gossipListenSecondary, gossipProtocolSecondary string
var flagChannels string
var dnsUpdateInterval int

flag.BoolVar(&containerized, "containerized", containerized, "Set if we are running containerized.")
flag.BoolVar(&containerized, "containerized", containerized, "Set if we are running containerized")
flag.BoolVar(&master, "gossip", gossip, "Set if we are using gossip dns")
flag.BoolVar(&master, "master", master, "Whether or not this node is a master")
flag.StringVar(&cloud, "cloud", "aws", "CloudProvider we are using (aws,digitalocean,gce,openstack)")
flag.StringVar(&clusterID, "cluster-id", clusterID, "Cluster ID for internal domain names")
Expand All @@ -82,7 +75,6 @@ func run() error {
flag.StringVar(&gossipListenSecondary, "gossip-listen-secondary", fmt.Sprintf("0.0.0.0:%d", wellknownports.ProtokubeGossipMemberlist), "address:port on which to bind for gossip")
flags.StringVar(&gossipSecretSecondary, "gossip-secret-secondary", gossipSecret, "Secret to use to secure gossip")
flags.StringSliceVarP(&zones, "zone", "z", []string{}, "Configure permitted zones and their mappings")
flags.StringVar(&dnsProviderID, "dns", "aws-route53", "DNS provider we should use (aws-route53, google-clouddns, digitalocean)")

bootstrapMasterNodeLabels := false
flag.BoolVar(&bootstrapMasterNodeLabels, "bootstrap-master-node-labels", bootstrapMasterNodeLabels, "Bootstrap the labels for master nodes (required in k8s 1.16)")
Expand Down Expand Up @@ -199,14 +191,12 @@ func run() error {

protokube.RootFS = rootfs

var dnsProvider protokube.DNSProvider

if dnsProviderID == "gossip" {
if gossip {
dnsTarget := &gossipdns.HostsFile{
Path: path.Join(rootfs, "etc/hosts"),
}

var gossipSeeds gossip.SeedProvider
var gossipSeeds gossiputils.SeedProvider
var err error
var gossipName string
if cloud == "aws" {
Expand Down Expand Up @@ -250,23 +240,23 @@ func run() error {
}

channelName := "dns"
var gossipState gossip.GossipState
var gossipState gossiputils.GossipState

gossipState, err = gossip.GetGossipState(gossipProtocol, gossipListen, channelName, gossipName, []byte(gossipSecret), gossipSeeds)
gossipState, err = gossiputils.GetGossipState(gossipProtocol, gossipListen, channelName, gossipName, []byte(gossipSecret), gossipSeeds)
if err != nil {
klog.Errorf("Error initializing gossip: %v", err)
os.Exit(1)
}

if gossipProtocolSecondary != "" {

secondaryGossipState, err := gossip.GetGossipState(gossipProtocolSecondary, gossipListenSecondary, channelName, gossipName, []byte(gossipSecretSecondary), gossipSeeds)
secondaryGossipState, err := gossiputils.GetGossipState(gossipProtocolSecondary, gossipListenSecondary, channelName, gossipName, []byte(gossipSecretSecondary), gossipSeeds)
if err != nil {
klog.Errorf("Error initializing secondary gossip: %v", err)
os.Exit(1)
}

gossipState = &gossip.MultiGossipState{
gossipState = &gossiputils.MultiGossipState{
Primary: gossipState,
Secondary: secondaryGossipState,
}
Expand All @@ -292,51 +282,8 @@ func run() error {
gossipdns.RunDNSUpdates(dnsTarget, dnsView)
klog.Fatalf("RunDNSUpdates exited unexpectedly")
}()

dnsProvider = &protokube.GossipDnsProvider{DNSView: dnsView, Zone: zoneInfo}
} else {
var dnsScope dns.Scope
var dnsController *dns.DNSController
{
var file io.Reader

dnsProvider, err := dnsprovider.GetDnsProvider(dnsProviderID, file)
if err != nil {
return fmt.Errorf("Error initializing DNS provider %q: %v", dnsProviderID, err)
}
if dnsProvider == nil {
return fmt.Errorf("DNS provider %q could not be initialized", dnsProviderID)
}

zoneRules, err := dns.ParseZoneRules(zones)
if err != nil {
return fmt.Errorf("unexpected zone flags: %q", err)
}

dnsController, err = dns.NewDNSController([]dnsprovider.Interface{dnsProvider}, zoneRules, dnsUpdateInterval)
if err != nil {
return err
}

dnsScope, err = dnsController.CreateScope("protokube")
if err != nil {
return err
}

// We don't really use readiness - our records are simple
dnsScope.MarkReady()
}

dnsProvider = &protokube.KopsDnsProvider{
DNSScope: dnsScope,
DNSController: dnsController,
}
}

go func() {
removeDNSRecords(removeDNSNames, dnsProvider)
}()

var channels []string
if flagChannels != "" {
channels = strings.Split(flagChannels, ",")
Expand All @@ -346,17 +293,12 @@ func run() error {
BootstrapMasterNodeLabels: bootstrapMasterNodeLabels,
NodeName: nodeName,
Channels: channels,
DNS: dnsProvider,
InternalDNSSuffix: dnsInternalSuffix,
InternalIP: internalIP,
Kubernetes: protokube.NewKubernetesContext(),
Master: master,
}

if dnsProvider != nil {
go dnsProvider.Run()
}

k.RunSyncLoop()

return fmt.Errorf("Unexpected exit")
Expand Down
53 changes: 0 additions & 53 deletions protokube/pkg/protokube/gossipdns.go

This file was deleted.

2 changes: 0 additions & 2 deletions protokube/pkg/protokube/kube_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type KubeBoot struct {
InternalDNSSuffix string
// InternalIP is the internal ip address of the node
InternalIP net.IP
// DNS is the dns provider
DNS DNSProvider
// Kubernetes holds a kubernetes client
Kubernetes *KubernetesContext
// Master indicates we are a master node
Expand Down
Loading

0 comments on commit 4553d7b

Please sign in to comment.