Skip to content

Commit

Permalink
Avoid deleting local endpoint when Engine pod is restarted
Browse files Browse the repository at this point in the history
In datastoresyncer, ensureExclusiveEndpoint API when the local endpoints
are compared, they were not matching due to small mismatch in BackendConfig
and this was causing deletion of local endpoint followed by creation of
local endpoint.

Fixes issue: submariner-io#960
Signed-Off-by: Sridhar Gaddam <[email protected]>
  • Loading branch information
sridhargaddam authored and tpantelis committed Nov 23, 2020
1 parent 3953a94 commit 47689b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {

submSpec.CableDriver = strings.ToLower(submSpec.CableDriver)

localEndpoint, err := util.GetLocalEndpoint(submSpec.ClusterID, submSpec.CableDriver, map[string]string{}, submSpec.NatEnabled,
localEndpoint, err := util.GetLocalEndpoint(submSpec.ClusterID, submSpec.CableDriver, nil, submSpec.NatEnabled,
localSubnets, util.GetLocalIP())

if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/cable/wireguard/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ func NewDriver(localEndpoint types.SubmarinerEndpoint, localCluster types.Submar

pub = priv.PublicKey()

if localEndpoint.Spec.BackendConfig == nil {
localEndpoint.Spec.BackendConfig = make(map[string]string)
}

localEndpoint.Spec.BackendConfig[PublicKey] = pub.String()
w.localEndpoint.Spec.BackendConfig[PublicKey] = pub.String()

// configure the device. still not up
port := w.spec.NATTPort
Expand Down
8 changes: 6 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"net"
"os"
"reflect"
"strings"
"syscall"

Expand All @@ -15,6 +14,7 @@ import (
subv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/types"
"github.com/vishvananda/netlink"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/klog"
)

Expand Down Expand Up @@ -92,6 +92,10 @@ func GetLocalEndpoint(clusterID, backend string, backendConfig map[string]string
return types.SubmarinerEndpoint{}, fmt.Errorf("Error getting hostname: %v", err)
}

if backendConfig == nil {
backendConfig = make(map[string]string)
}

endpoint := types.SubmarinerEndpoint{
Spec: subv1.EndpointSpec{
CableName: fmt.Sprintf("submariner-cable-%s-%s", clusterID, strings.ReplaceAll(privateIP, ".", "-")),
Expand Down Expand Up @@ -154,7 +158,7 @@ func GetClusterCRDName(cluster *types.SubmarinerCluster) (string, error) {
func CompareEndpointSpec(left, right subv1.EndpointSpec) bool {
// maybe we have to use just reflect.DeepEqual(left, right), but in this case the subnets order will influence.
return left.ClusterID == right.ClusterID && left.CableName == right.CableName && left.Hostname == right.Hostname &&
left.Backend == right.Backend && reflect.DeepEqual(left.BackendConfig, right.BackendConfig)
left.Backend == right.Backend && equality.Semantic.DeepEqual(left.BackendConfig, right.BackendConfig)
}

func GetDefaultGatewayInterface() (*net.Interface, error) {
Expand Down
17 changes: 17 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ func testCompareEndpointSpec() {
BackendConfig: map[string]string{"key": "aaa"},
})).To(BeTrue())
})

It("should return true", func() {
Expect(util.CompareEndpointSpec(
subv1.EndpointSpec{
ClusterID: "east",
CableName: "submariner-cable-east-172-16-32-5",
Hostname: "my-host",
Backend: "strongswan",
BackendConfig: map[string]string{},
},
subv1.EndpointSpec{
ClusterID: "east",
CableName: "submariner-cable-east-172-16-32-5",
Hostname: "my-host",
Backend: "strongswan",
})).To(BeTrue())
})
})

Context("with different cluster IDs", func() {
Expand Down

0 comments on commit 47689b8

Please sign in to comment.