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 #2772: Only update local Endpoint when setting HealthCheckIP #2773

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
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/submariner-io/submariner/pkg/natdiscovery"
"github.com/submariner-io/submariner/pkg/types"
"github.com/submariner-io/submariner/pkg/versions"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -112,6 +113,12 @@ func main() {
leClient, err := kubernetes.NewForConfig(rest.AddUserAgent(restConfig, "leader-election"))
logger.FatalOnError(err, "Error creating leader election kubernetes clientset")

dynClient, err := dynamic.NewForConfig(restConfig)
logger.FatalOnError(err, "Error creating dynamic client")

restMapper, err := util.BuildRestMapper(restConfig)
logger.FatalOnError(err, "Error building the REST mapper")

logger.FatalOnError(subv1.AddToScheme(scheme.Scheme), "Error adding submariner types to the scheme")

gw, err := gateway.New(&gateway.Config{
Expand All @@ -123,6 +130,8 @@ func main() {
Spec: submSpec,
SyncerConfig: broker.SyncerConfig{
LocalRestConfig: restConfig,
LocalClient: dynClient,
RestMapper: restMapper,
},
WatcherConfig: watcher.Config{
RestConfig: restConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/admiral/pkg/syncer/test"
testutil "github.com/submariner-io/admiral/pkg/test"
submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/globalnet/constants"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -133,16 +135,30 @@ func testEndpointSyncing() {
test.CreateResource(t.localNodes, node)
})

It("should update the local Endpoint's HealthCheckIP", func() {
JustBeforeEach(func() {
t.localEndpoint.Spec.HealthCheckIP = node.Annotations[constants.SmGlobalIP]
awaitEndpoint(t.localEndpoints, &t.localEndpoint.Spec)
})

It("should update the local Endpoint's HealthCheckIP", func() {
node.Annotations[constants.SmGlobalIP] = "200.0.0.100"
t.localEndpoint.Spec.HealthCheckIP = node.Annotations[constants.SmGlobalIP]

test.UpdateResource(t.localNodes, node)
awaitEndpoint(t.localEndpoints, &t.localEndpoint.Spec)
})

Context("but the local Endpoint no longer exists", func() {
It("should not recreate the local Endpoint", func() {
Expect(t.localEndpoints.Delete(context.Background(), getEndpointName(&t.localEndpoint.Spec), metav1.DeleteOptions{})).
To(Succeed())

node.Annotations[constants.SmGlobalIP] = "200.0.0.100"
test.UpdateResource(t.localNodes, node)

testutil.EnsureNoResource(resource.ForDynamic(t.localEndpoints), getEndpointName(&t.localEndpoint.Spec))
})
})
})
}

Expand Down
28 changes: 15 additions & 13 deletions pkg/controllers/datastoresyncer/datastoresyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/submariner-io/admiral/pkg/resource"
resourceSyncer "github.com/submariner-io/admiral/pkg/syncer"
"github.com/submariner-io/admiral/pkg/syncer/broker"
"github.com/submariner-io/admiral/pkg/util"
"github.com/submariner-io/admiral/pkg/watcher"
submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/cidr"
Expand All @@ -45,11 +46,11 @@ import (
)

type DatastoreSyncer struct {
localCluster types.SubmarinerCluster
localEndpoint types.SubmarinerEndpoint
localNodeName string
syncerConfig broker.SyncerConfig
localFederator federate.Federator
localCluster types.SubmarinerCluster
localEndpoint types.SubmarinerEndpoint
localNodeName string
syncerConfig broker.SyncerConfig
updateFederator federate.Federator
}

var logger = log.Logger{Logger: logf.Log.WithName("DSSyncer")}
Expand All @@ -72,6 +73,9 @@ func (d *DatastoreSyncer) Start(stopCh <-chan struct{}) error {

logger.Info("Starting the datastore syncer")

d.updateFederator = federate.NewUpdateFederator(d.syncerConfig.LocalClient, d.syncerConfig.RestMapper, d.syncerConfig.LocalNamespace,
util.CopyImmutableMetadata)

syncer, err := d.createSyncer()
if err != nil {
return err
Expand All @@ -82,17 +86,15 @@ func (d *DatastoreSyncer) Start(stopCh <-chan struct{}) error {
return errors.WithMessage(err, "error starting the syncer")
}

d.localFederator = syncer.GetLocalFederator()

if err := d.ensureExclusiveEndpoint(syncer); err != nil {
return errors.WithMessage(err, "could not ensure exclusive submariner Endpoint")
}

if err := d.createLocalCluster(); err != nil {
if err := d.createLocalCluster(syncer.GetLocalFederator()); err != nil {
return errors.WithMessage(err, "error creating the local submariner Cluster")
}

if err := d.createOrUpdateLocalEndpoint(); err != nil {
if err := d.createOrUpdateLocalEndpoint(syncer.GetLocalFederator()); err != nil {
return errors.WithMessage(err, "error creating the local submariner Endpoint")
}

Expand Down Expand Up @@ -312,7 +314,7 @@ func (d *DatastoreSyncer) createNodeWatcher(stopCh <-chan struct{}) error {
return nil
}

func (d *DatastoreSyncer) createLocalCluster() error {
func (d *DatastoreSyncer) createLocalCluster(federator federate.Federator) error {
logger.Infof("Creating local submariner Cluster: %#v ", d.localCluster)

cluster := &submarinerv1.Cluster{
Expand All @@ -322,10 +324,10 @@ func (d *DatastoreSyncer) createLocalCluster() error {
Spec: d.localCluster.Spec,
}

return d.localFederator.Distribute(cluster) //nolint:wrapcheck // Let the caller wrap it
return federator.Distribute(cluster) //nolint:wrapcheck // Let the caller wrap it
}

func (d *DatastoreSyncer) createOrUpdateLocalEndpoint() error {
func (d *DatastoreSyncer) createOrUpdateLocalEndpoint(federator federate.Federator) error {
logger.Infof("Creating local submariner Endpoint: %#v ", d.localEndpoint)

endpointName, err := d.localEndpoint.Spec.GenerateName()
Expand All @@ -340,5 +342,5 @@ func (d *DatastoreSyncer) createOrUpdateLocalEndpoint() error {
Spec: d.localEndpoint.Spec,
}

return d.localFederator.Distribute(endpoint) //nolint:wrapcheck // Let the caller wrap it
return federator.Distribute(endpoint) //nolint:wrapcheck // Let the caller wrap it
}
2 changes: 1 addition & 1 deletion pkg/controllers/datastoresyncer/node_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *DatastoreSyncer) updateLocalEndpointIfNecessary(globalIPOfNode string)
prevHealthCheckIP := d.localEndpoint.Spec.HealthCheckIP
d.localEndpoint.Spec.HealthCheckIP = globalIPOfNode

if err := d.createOrUpdateLocalEndpoint(); err != nil {
if err := d.createOrUpdateLocalEndpoint(d.updateFederator); err != nil {
logger.Warningf("Error updating the local submariner Endpoint with HealthcheckIP: %v", err)

d.localEndpoint.Spec.HealthCheckIP = prevHealthCheckIP
Expand Down