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

Automated backport of #1472: Handle transient ServiceImport delete in the resolver #1473

Merged
Show file tree
Hide file tree
Changes from all 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: 5 additions & 0 deletions coredns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/trace"
_ "github.com/coredns/coredns/plugin/whoami"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
admversion "github.com/submariner-io/admiral/pkg/version"
_ "github.com/submariner-io/lighthouse/coredns/plugin"
Expand Down Expand Up @@ -120,12 +121,16 @@ func init() {
}

func main() {
kzerolog.AddFlags(nil)
flag.Parse()

admversion.Print(names.LighthouseCoreDNSComponent, version)

if showVersion {
return
}

kzerolog.InitK8sLogging()

coremain.Run()
}
79 changes: 0 additions & 79 deletions coredns/plugin/coredns_log_sink.go

This file was deleted.

6 changes: 0 additions & 6 deletions coredns/plugin/lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/fall"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/go-logr/logr"
"github.com/submariner-io/lighthouse/coredns/resolver"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

const (
Expand All @@ -51,7 +49,3 @@ type Lighthouse struct {
}

var _ plugin.Handler = &Lighthouse{}

func init() {
logf.SetLogger(logr.New(&corednsLogSink{log: log}))
}
18 changes: 16 additions & 2 deletions coredns/resolver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,37 @@ var _ = Describe("Controller", func() {
})

Context("and then the EndpointSlice is deleted", func() {
Specify("GetDNSRecords should eventually return no DNS record", func() {
JustBeforeEach(func() {
t.awaitDNSRecordsFound(namespace1, service1, clusterID1, "", false, expDNSRecord)

err := t.endpointSlices.Namespace(namespace1).Delete(context.TODO(), endpointSlice.Name, metav1.DeleteOptions{})
Expect(err).To(Succeed())
})

Specify("GetDNSRecords should eventually return no DNS record", func() {
t.awaitDNSRecordsFound(namespace1, service1, "", "", false)
})

Specify("GetDNSRecords should eventually return not found after the ServiceImport is deleted", func() {
err := t.serviceImports.Namespace(namespace1).Delete(context.TODO(), service1, metav1.DeleteOptions{})
Expect(err).To(Succeed())

t.awaitDNSRecords(namespace1, service1, clusterID1, "", false)
})
})

Context("and then the ServiceImport is deleted", func() {
Specify("GetDNSRecords should eventually return not found", func() {
Specify("GetDNSRecords should eventually return not found after the EndpointSlice is deleted", func() {
t.awaitDNSRecordsFound(namespace1, service1, clusterID1, "", false, expDNSRecord)

err := t.serviceImports.Namespace(namespace1).Delete(context.TODO(), service1, metav1.DeleteOptions{})
Expect(err).To(Succeed())

t.ensureDNSRecordsFound(namespace1, service1, clusterID1, "", false, expDNSRecord)

err = t.endpointSlices.Namespace(namespace1).Delete(context.TODO(), endpointSlice.Name, metav1.DeleteOptions{})
Expect(err).To(Succeed())

t.awaitDNSRecords(namespace1, service1, clusterID1, "", false)
})
})
Expand Down
4 changes: 3 additions & 1 deletion coredns/resolver/endpoint_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ func (i *Interface) RemoveEndpointSlice(endpointSlice *discovery.EndpointSlice)

delete(serviceInfo.clusters, clusterID)

if !serviceInfo.isHeadless {
if len(serviceInfo.clusters) == 0 && !serviceInfo.isExported {
delete(i.serviceMap, key)
} else if !serviceInfo.isHeadless {
serviceInfo.mergePorts()
serviceInfo.resetLoadBalancing()
}
Expand Down
11 changes: 10 additions & 1 deletion coredns/resolver/service_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (i *Interface) PutServiceImport(serviceImport *mcsv1a1.ServiceImport) {
i.serviceMap[key] = svcInfo
}

svcInfo.isExported = true

if svcInfo.isHeadless || !isLegacy {
return
}
Expand Down Expand Up @@ -82,7 +84,14 @@ func (i *Interface) RemoveServiceImport(serviceImport *mcsv1a1.ServiceImport) {
i.mutex.Lock()
defer i.mutex.Unlock()

delete(i.serviceMap, key)
svcInfo, found := i.serviceMap[key]
if found {
if len(svcInfo.clusters) == 0 {
delete(i.serviceMap, key)
} else {
svcInfo.isExported = false
}
}
}

func getServiceImportKey(from *mcsv1a1.ServiceImport) (string, bool) {
Expand Down
1 change: 1 addition & 0 deletions coredns/resolver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ type serviceInfo struct {
clusters map[string]*clusterInfo
balancer loadbalancer.Interface
isHeadless bool
isExported bool
ports []mcsv1a1.ServicePort
}
Loading