Skip to content

Commit 3ab6ebf

Browse files
MrFreezeexjrajahalme
authored andcommitted
clustermesh: remove GlobalServiceCache in cilium-agent
This remove the usage of GlobalServiceCache in the agent which was only useful to count the number of global Service. This count didn't accounted the local cluster and thus is misleading. While performance impact was not tested this removes managing two level of nested maps and a global lock on each remote endpoints updates which should certainly be valuable. The global services count reported through cilium-dbg and the CLI is no longer supported/exposed. Users with an older version of the CLI would always see a count of 0 reported. Global Service counts will continue to be reported per cluster along the count with other resources though. Signed-off-by: Arthur Outhenin-Chalandre <git@mrfreezeex.fr>
1 parent c22771d commit 3ab6ebf

10 files changed

Lines changed: 25 additions & 54 deletions

File tree

Documentation/operations/troubleshooting_clustermesh.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ you may perform the following steps to troubleshoot ClusterMesh issues.
7373
7474
#. Validate that ClusterMesh is healthy running ``cilium-dbg status --all-clusters`` inside each Cilium agent::
7575

76-
ClusterMesh: 1/1 remote clusters ready, 10 global-services
76+
ClusterMesh: 1/1 remote clusters ready
7777
k8s-c2: ready, 3 nodes, 25 endpoints, 8 identities, 10 services, 0 MCS-API service exports, 0 reconnections (last: never)
7878
└ etcd: 1/1 connected, leases=0, lock lease-ID=7c028201b53de662, has-quorum=true: https://k8s-c2.mesh.cilium.io:2379 - 3.5.4 (Leader)
7979
└ remote configuration: expected=true, retrieved=true, cluster-id=3, kvstoremesh=false, sync-canaries=true, service-exports=disabled

Documentation/operations/upgrade.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ communicating via the proxy must reconnect to re-establish connections.
305305
to update your network policies.
306306
* Kafka Network Policy support is deprecated and will be removed in Cilium v1.20.
307307
* Hubble field mask support was stabilized. In the Observer gRPC API, ``GetFlowsRequest.Experimental.field_mask`` was removed in favor of ``GetFlowsRequest.field_mask``. In the Hubble CLI, the ``--experimental-field-mask`` has been renamed to ``--field-mask`` and ``--experimental-use-default-field-mask`` renamed to ``-use-default-field-mask`` (now ``true`` by default).
308-
308+
* Cilium-agent ClusterMesh status will no longer report the global services count. When using the CLI
309+
with a version lower than 1.19, the global services count will be reported as 0.
309310
* ``enable-remote-node-masquerade`` config option is introduced.
310311
To masquerade traffic to remote nodes in BPF masquerading mode,
311312
use the option ``enable-remote-node-masquerade: "true"``.

api/v1/models/cluster_mesh_status.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/openapi.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,6 @@ definitions:
23392339
type: array
23402340
items:
23412341
"$ref": "#/definitions/RemoteCluster"
2342-
num-global-services:
2343-
description: Number of global services
2344-
type: integer
23452342
RemoteCluster:
23462343
description: |-
23472344
Status of remote cluster

api/v1/server/embedded_spec.go

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cilium-cli/clustermesh/clustermesh.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,6 @@ func remoteClusterStatusToError(status *models.RemoteCluster) error {
682682
}
683683

684684
func (c *ConnectivityStatus) parseAgentStatus(name string, expected []string, s *status.ClusterMeshAgentConnectivityStatus) {
685-
if c.GlobalServices.Min < 0 || c.GlobalServices.Min > s.GlobalServices {
686-
c.GlobalServices.Min = s.GlobalServices
687-
}
688-
689-
if c.GlobalServices.Max < s.GlobalServices {
690-
c.GlobalServices.Max = s.GlobalServices
691-
}
692-
693-
c.GlobalServices.Avg += float64(s.GlobalServices)
694685
c.Total++
695686

696687
ready := int64(0)

cilium-cli/status/k8s.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ func NewK8sStatusCollector(client k8sImplementation, params K8sStatusParameters)
9292
}
9393

9494
type ClusterMeshAgentConnectivityStatus struct {
95-
GlobalServices int64
96-
Clusters map[string]*models.RemoteCluster
97-
Errors ErrorCountMap
95+
Clusters map[string]*models.RemoteCluster
96+
Errors ErrorCountMap
9897
}
9998

10099
// ErrClusterMeshStatusNotAvailable is a sentinel.
@@ -117,7 +116,6 @@ func (k *K8sStatusCollector) ClusterMeshConnectivity(ctx context.Context, cilium
117116
return nil, ErrClusterMeshStatusNotAvailable
118117
}
119118

120-
c.GlobalServices = status.ClusterMesh.NumGlobalServices
121119
for _, cluster := range status.ClusterMesh.Clusters {
122120
c.Clusters[cluster.Name] = cluster
123121
}

pkg/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ func FormatStatusResponse(w io.Writer, sr *models.StatusResponse, sd StatusDetai
436436
}
437437

438438
if sr.ClusterMesh != nil {
439-
fmt.Fprintf(w, "ClusterMesh:\t%d/%d remote clusters ready, %d global-services\n",
440-
NumReadyClusters(sr.ClusterMesh.Clusters), len(sr.ClusterMesh.Clusters), sr.ClusterMesh.NumGlobalServices)
439+
fmt.Fprintf(w, "ClusterMesh:\t%d/%d remote clusters ready\n",
440+
NumReadyClusters(sr.ClusterMesh.Clusters), len(sr.ClusterMesh.Clusters))
441441

442442
verbosity := RemoteClustersStatusNotReadyOnly
443443
if sd.AllClusters {

pkg/clustermesh/clustermesh.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ type ClusterMesh struct {
110110
// common implements the common logic to connect to remote clusters.
111111
common common.ClusterMesh
112112

113-
// globalServices is a list of all global services. The datastructure
114-
// is protected by its own mutex inside the structure.
115-
globalServices *common.GlobalServiceCache
116-
117113
// nodeName is the name of the local node. This is used for logging and metrics
118114
nodeName string
119115

@@ -134,12 +130,8 @@ func NewClusterMesh(lifecycle cell.Lifecycle, c Configuration) *ClusterMesh {
134130

135131
nodeName := nodeTypes.GetName()
136132
cm := &ClusterMesh{
137-
conf: c,
138-
nodeName: nodeName,
139-
globalServices: common.NewGlobalServiceCache(
140-
c.Logger,
141-
c.Metrics.TotalGlobalServices.WithLabelValues(c.ClusterInfo.Name, nodeName),
142-
),
133+
conf: c,
134+
nodeName: nodeName,
143135
FeatureMetrics: c.FeatureMetrics,
144136
}
145137

@@ -170,6 +162,20 @@ func NewClusterMesh(lifecycle cell.Lifecycle, c Configuration) *ClusterMesh {
170162
return cm
171163
}
172164

165+
type clusterServiceObserver struct {
166+
serviceMerger ServiceMerger
167+
}
168+
169+
func (obs *clusterServiceObserver) OnUpdate(key store.Key) {
170+
svc := &(key.(*serviceStore.ValidatingClusterService).ClusterService)
171+
obs.serviceMerger.MergeExternalServiceUpdate(svc)
172+
}
173+
174+
func (obs *clusterServiceObserver) OnDelete(key store.NamedKey) {
175+
svc := &(key.(*serviceStore.ValidatingClusterService).ClusterService)
176+
obs.serviceMerger.MergeExternalServiceDelete(svc)
177+
}
178+
173179
func (cm *ClusterMesh) NewRemoteCluster(name string, status common.StatusFunc) common.RemoteCluster {
174180
rc := &remoteCluster{
175181
name: name,
@@ -203,12 +209,7 @@ func (cm *ClusterMesh) NewRemoteCluster(name string, status common.StatusFunc) c
203209
serviceStore.NamespacedNameValidator(),
204210
serviceStore.ClusterIDValidator(&rc.clusterID),
205211
),
206-
common.NewSharedServicesObserver(
207-
rc.log,
208-
cm.globalServices,
209-
cm.conf.ServiceMerger.MergeExternalServiceUpdate,
210-
cm.conf.ServiceMerger.MergeExternalServiceDelete,
211-
),
212+
&clusterServiceObserver{serviceMerger: cm.conf.ServiceMerger},
212213
store.RWSWithOnSyncCallback(func(ctx context.Context) { close(rc.synced.services) }),
213214
)
214215

@@ -281,9 +282,7 @@ func (cm *ClusterMesh) synced(ctx context.Context, toWaitFn func(*remoteCluster)
281282

282283
// Status returns the status of the ClusterMesh subsystem
283284
func (cm *ClusterMesh) Status() (status *models.ClusterMeshStatus) {
284-
status = &models.ClusterMeshStatus{
285-
NumGlobalServices: int64(cm.globalServices.Size()),
286-
}
285+
status = &models.ClusterMeshStatus{}
287286

288287
cm.common.ForEachRemoteCluster(func(rci common.RemoteCluster) error {
289288
rc := rci.(*remoteCluster)

pkg/clustermesh/remote_cluster_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import (
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
1818

19-
"github.com/cilium/cilium/pkg/clustermesh/common"
2019
serviceStore "github.com/cilium/cilium/pkg/clustermesh/store"
2120
"github.com/cilium/cilium/pkg/clustermesh/types"
2221
"github.com/cilium/cilium/pkg/identity"
2322
"github.com/cilium/cilium/pkg/identity/cache"
2423
"github.com/cilium/cilium/pkg/ipcache"
2524
"github.com/cilium/cilium/pkg/kvstore"
2625
"github.com/cilium/cilium/pkg/kvstore/store"
27-
"github.com/cilium/cilium/pkg/metrics"
2826
nodeTypes "github.com/cilium/cilium/pkg/node/types"
2927
"github.com/cilium/cilium/pkg/source"
3028
"github.com/cilium/cilium/pkg/testutils"
@@ -166,7 +164,6 @@ func TestRemoteClusterRun(t *testing.T) {
166164
FeatureMetrics: NewClusterMeshMetricsNoop(),
167165
Logger: logger,
168166
},
169-
globalServices: common.NewGlobalServiceCache(logger, metrics.NoOpGauge),
170167
FeatureMetrics: NewClusterMeshMetricsNoop(),
171168
}
172169
rc := cm.NewRemoteCluster("foo", nil).(*remoteCluster)
@@ -297,7 +294,6 @@ func TestRemoteClusterClusterIDChange(t *testing.T) {
297294
Logger: logger,
298295
},
299296
FeatureMetrics: NewClusterMeshMetricsNoop(),
300-
globalServices: common.NewGlobalServiceCache(logger, metrics.NoOpGauge),
301297
}
302298
rc := cm.NewRemoteCluster("foo", nil).(*remoteCluster)
303299

0 commit comments

Comments
 (0)