Skip to content

Commit

Permalink
fix(kuma-cp): fix Zone{In|E}gress sync when no mesh (backport of #8129)…
Browse files Browse the repository at this point in the history
… (#8134)

fix(kuma-cp): fix Zone{In|E}gress sync when no mesh (#8129)

- Add ZoneEgresses to AggregatetMeshContexts when there is no mesh.
- Sync ZoneIngresses and ZoneEgresses only when the hash changes.
- Return an error with the correct resource type (ZoneEgress) when
  a ZoneEgress cannot be found.

Signed-off-by: Bart Smykla <bartek@smykla.com>
Co-authored-by: Bart Smykla <bartek@smykla.com>
  • Loading branch information
kumahq[bot] and bartsmykla authored Oct 25, 2023
1 parent d1486ad commit 38ca2a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
15 changes: 14 additions & 1 deletion pkg/xds/context/aggregate_mesh_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,28 @@ func AggregateMeshContexts(
meshContextsByName[mesh.Meta.GetName()] = meshCtx
}

hash := aggregatedHash(meshContexts)

egressByName := map[string]*core_mesh.ZoneEgressResource{}
if len(meshContexts) > 0 {
for _, egress := range meshContexts[0].Resources.ZoneEgresses().Items {
egressByName[egress.Meta.GetName()] = egress
}
} else {
var egressList core_mesh.ZoneEgressResourceList
if err := resManager.List(ctx, &egressList, core_store.ListOrdered()); err != nil {
return AggregatedMeshContexts{}, err
}

for _, egress := range egressList.GetItems() {
egressByName[egress.GetMeta().GetName()] = egress.(*core_mesh.ZoneEgressResource)
}

hash = sha256.Hash(hashResources(egressList.GetItems()...))
}

result := AggregatedMeshContexts{
Hash: aggregatedHash(meshContexts),
Hash: hash,
Meshes: meshList.Items,
MeshContextsByName: meshContextsByName,
ZoneEgressByName: egressByName,
Expand Down
10 changes: 5 additions & 5 deletions pkg/xds/context/mesh_context_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,19 @@ func (m *meshContextBuilder) hash(mesh *core_mesh.MeshResource, resources Resour
allResources = append(allResources, rl.GetItems()...)
}
}
return sha256.Hash(m.hashResources(allResources...))
return sha256.Hash(hashResources(allResources...))
}

func (m *meshContextBuilder) hashResources(rs ...core_model.Resource) string {
hashes := []string{}
func hashResources(rs ...core_model.Resource) string {
var hashes []string
for _, r := range rs {
hashes = append(hashes, m.hashResource(r))
hashes = append(hashes, hashResource(r))
}
sort.Strings(hashes)
return strings.Join(hashes, ",")
}

func (m *meshContextBuilder) hashResource(r core_model.Resource) string {
func hashResource(r core_model.Resource) string {
switch v := r.(type) {
// In case of hashing Dataplane we are also adding '.Spec.Networking.Address' and `.Spec.Networking.Ingress.PublicAddress` into hash.
// The address could be a domain name and right now we resolve it right after fetching
Expand Down
12 changes: 6 additions & 6 deletions pkg/xds/sync/dataplane_watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func (d *DataplaneWatchdog) syncIngress(ctx context.Context, metadata *core_xds.
result.Status = SkipStatus
return result, nil
}
if syncForConfig {
d.log.V(1).Info("snapshot hash updated, reconcile", "prev", d.lastHash, "current", aggregatedMeshCtxs.Hash)
}

d.log.V(1).Info("snapshot hash updated, reconcile", "prev", d.lastHash, "current", aggregatedMeshCtxs.Hash)
d.lastHash = aggregatedMeshCtxs.Hash

proxy, err := d.IngressProxyBuilder.Build(ctx, d.key, aggregatedMeshCtxs)
if err != nil {
Expand Down Expand Up @@ -228,9 +228,9 @@ func (d *DataplaneWatchdog) syncEgress(ctx context.Context, metadata *core_xds.D
result.Status = SkipStatus
return result, nil
}
if syncForConfig {
d.log.V(1).Info("snapshot hash updated, reconcile", "prev", d.lastHash, "current", aggregatedMeshCtxs.Hash)
}

d.log.V(1).Info("snapshot hash updated, reconcile", "prev", d.lastHash, "current", aggregatedMeshCtxs.Hash)
d.lastHash = aggregatedMeshCtxs.Hash

proxy, err := d.EgressProxyBuilder.Build(ctx, d.key, aggregatedMeshCtxs)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/xds/sync/egress_proxy_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *EgressProxyBuilder) Build(
) (*core_xds.Proxy, error) {
zoneEgress, ok := aggregatedMeshCtxs.ZoneEgressByName[key.Name]
if !ok {
return nil, core_store.ErrorResourceNotFound(core_mesh.DataplaneType, key.Name, key.Mesh)
return nil, core_store.ErrorResourceNotFound(core_mesh.ZoneEgressType, key.Name, key.Mesh)
}

// As egress is using SNI to identify the services, we need to filter out
Expand Down

0 comments on commit 38ca2a3

Please sign in to comment.