Skip to content

Commit 99ffdbf

Browse files
committed
[Galley] Adding ServiceEntry synthesis
Added a new custom projection that is subscribed to events for k8s Pods, Nodes, Services and Endpoints. These events are absorbed and do not become part of the snapshot. Instead, synthetic ServiceEntry resources are generated and become part of the snapshot. Partially addresses #10497 and #10589
1 parent 035938b commit 99ffdbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+9672
-2689
lines changed

Gopkg.lock

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

galley/pkg/metadata/kube/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ func init() {
641641
Version: "v1",
642642
Group: "",
643643
Target: metadata.Types.Get("k8s/core/v1/services"),
644-
Converter: converter.Get("kube-service-resource"),
644+
Converter: converter.Get("identity"),
645645
})
646646

647647
b.Add(schema.ResourceSpec{

galley/pkg/metadata/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ var (
172172
// istio/networking/v1alpha3/sidecars metadata
173173
IstioNetworkingV1alpha3Sidecars resource.Info
174174

175+
// istio/networking/v1alpha3/synthetic/serviceentries metadata
176+
IstioNetworkingV1alpha3SyntheticServiceentries resource.Info
177+
175178
// istio/networking/v1alpha3/virtualservices metadata
176179
IstioNetworkingV1alpha3Virtualservices resource.Info
177180

@@ -350,6 +353,9 @@ func init() {
350353
IstioNetworkingV1alpha3Sidecars = b.Register(
351354
"istio/networking/v1alpha3/sidecars",
352355
"type.googleapis.com/istio.networking.v1alpha3.Sidecar")
356+
IstioNetworkingV1alpha3SyntheticServiceentries = b.Register(
357+
"istio/networking/v1alpha3/synthetic/serviceentries",
358+
"type.googleapis.com/istio.networking.v1alpha3.ServiceEntry")
353359
IstioNetworkingV1alpha3Virtualservices = b.Register(
354360
"istio/networking/v1alpha3/virtualservices",
355361
"type.googleapis.com/istio.networking.v1alpha3.VirtualService")

galley/pkg/runtime/groups/groups.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ package groups
1616

1717
import (
1818
mcp "istio.io/api/mcp/v1alpha1"
19+
"istio.io/istio/galley/pkg/metadata"
1920
"istio.io/istio/pkg/mcp/snapshot"
2021
)
2122

2223
const (
2324
// Default group for MCP requests.
2425
Default = "default"
26+
27+
// SyntheticServiceEntry is the group used for the SynetheticServiceEntry collection.
28+
SyntheticServiceEntry = "syntheticServiceEntry"
2529
)
2630

2731
var _ snapshot.GroupIndexFn = IndexFunction
2832

2933
// IndexFunction is a snapshot.GroupIndexFn used internally by Galley.
30-
func IndexFunction(_ string, _ *mcp.SinkNode) string {
31-
return Default
34+
// If the request is for the collection metadata.SyntheticServiceEntry,
35+
// the SyntheticServiceEntry snapshot is used. Otherwise the Default
36+
// snapshot is used.
37+
func IndexFunction(collection string, _ *mcp.SinkNode) string {
38+
switch collection {
39+
case metadata.IstioNetworkingV1alpha3SyntheticServiceentries.Collection.String():
40+
return SyntheticServiceEntry
41+
default:
42+
return Default
43+
}
3244
}

galley/pkg/runtime/groups/groups_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
. "github.com/onsi/gomega"
2121

22+
"istio.io/istio/galley/pkg/metadata"
2223
"istio.io/istio/galley/pkg/runtime/groups"
2324
)
2425

@@ -27,3 +28,9 @@ func TestDefault(t *testing.T) {
2728
actual := groups.IndexFunction("bogus", nil)
2829
g.Expect(actual).To(Equal(groups.Default))
2930
}
31+
32+
func TestSyntheticServiceEntry(t *testing.T) {
33+
g := NewGomegaWithT(t)
34+
actual := groups.IndexFunction(metadata.IstioNetworkingV1alpha3SyntheticServiceentries.Collection.String(), nil)
35+
g.Expect(actual).To(Equal(groups.SyntheticServiceEntry))
36+
}

galley/pkg/runtime/monitoring/monitoring.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func RecordStateTypeCount(collection string, count int) {
113113
if err != nil {
114114
log.Scope.Errorf("Error creating monitoring context for counting state: %v", err)
115115
} else {
116+
RecordStateTypeCountWithContext(ctx, count)
117+
}
118+
}
119+
120+
// RecordStateTypeCountWithContext
121+
func RecordStateTypeCountWithContext(ctx context.Context, count int) {
122+
if ctx != nil {
116123
stats.Record(ctx, stateTypeInstancesTotal.M(int64(count)))
117124
}
118125
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019 Istio Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package processing
16+
17+
import "istio.io/istio/galley/pkg/runtime/resource"
18+
19+
// Listener gets notified when resource of a given collection has changed.
20+
type Listener interface {
21+
CollectionChanged(c resource.Collection)
22+
}
23+
24+
// ListenerFromFn creates a listener based on the given function
25+
func ListenerFromFn(fn func(c resource.Collection)) Listener {
26+
return &fnListener{
27+
fn: fn,
28+
}
29+
}
30+
31+
var _ Listener = &fnListener{}
32+
33+
type fnListener struct {
34+
fn func(c resource.Collection)
35+
}
36+
37+
func (h *fnListener) CollectionChanged(c resource.Collection) {
38+
h.fn(c)
39+
}

0 commit comments

Comments
 (0)