Skip to content

Commit d69beae

Browse files
committed
fix(gwsync): sync externals with prefix to avoid conflicts
Signed-off-by: Sergei Lukianov <[email protected]>
1 parent f45f2fc commit d69beae

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

api/vpc/v1beta1/external_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2929
)
3030

31+
const (
32+
VPCInfoExtPrefix = "ext."
33+
)
34+
3135
var communityCheck = regexp.MustCompile("^(6553[0-5]|655[0-2][0-9]|654[0-9]{2}|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9]):(6553[0-5]|655[0-2][0-9]|654[0-9]{2}|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$")
3236

3337
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

api/vpc/v1beta1/vpc_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"net"
2020
"slices"
21+
"strings"
2122

2223
"github.com/pkg/errors"
2324
"go.githedgehog.com/fabric/api/meta"
@@ -336,6 +337,9 @@ func (vpc *VPC) Validate(ctx context.Context, kube kclient.Reader, fabricCfg *me
336337
if len(vpc.Name) > 11 {
337338
return nil, errors.Errorf("name %s is too long, must be <= 11 characters", vpc.Name)
338339
}
340+
if strings.HasPrefix(vpc.Name, VPCInfoExtPrefix) {
341+
return nil, errors.Errorf("vpc name cannot start with '%s': %s", VPCInfoExtPrefix, vpc.Name)
342+
}
339343
if vpc.Spec.IPv4Namespace == "" {
340344
return nil, errors.Errorf("ipv4Namespace is required")
341345
}

pkg/ctrl/gw_vpc_sync.go renamed to pkg/ctrl/gw_sync.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package ctrl
66
import (
77
"context"
88
"fmt"
9+
"strings"
910

1011
"go.githedgehog.com/fabric/api/meta"
1112
vpcapi "go.githedgehog.com/fabric/api/vpc/v1beta1"
@@ -169,10 +170,14 @@ func (r *GwExternalSync) enqueueForVPCInfo(ctx context.Context, obj kclient.Obje
169170
return nil
170171
}
171172

173+
if !strings.HasPrefix(vpcInfo.Name, vpcapi.VPCInfoExtPrefix) {
174+
return nil
175+
}
176+
172177
return []reconcile.Request{
173178
{NamespacedName: ktypes.NamespacedName{
174179
Namespace: vpcInfo.Namespace,
175-
Name: vpcInfo.Name,
180+
Name: strings.TrimPrefix(vpcInfo.Name, vpcapi.VPCInfoExtPrefix),
176181
}},
177182
}
178183
}
@@ -204,12 +209,12 @@ func (r *GwExternalSync) Reconcile(ctx context.Context, req kctrl.Request) (kctr
204209

205210
subnets := map[string]*gwapi.VPCInfoSubnet{}
206211
// FIXME: the external spec does not have the prefixes we are importing, they are part of the externalPeering
207-
subnets["internet"] = &gwapi.VPCInfoSubnet{
212+
subnets["external"] = &gwapi.VPCInfoSubnet{
208213
CIDR: "0.0.0.0/0",
209214
}
210215

211216
vpcInfo := &gwapi.VPCInfo{ObjectMeta: kmetav1.ObjectMeta{
212-
Name: external.Name,
217+
Name: vpcapi.VPCInfoExtPrefix + external.Name,
213218
Namespace: external.Namespace,
214219
}}
215220
if op, err := ctrlutil.CreateOrUpdate(ctx, r.Client, vpcInfo, func() error {

0 commit comments

Comments
 (0)