Skip to content

Commit 57e25d0

Browse files
committed
fix shape of istio plugin
1 parent bd1930f commit 57e25d0

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

projects/gateway2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test:
1414
test-full:
1515
go test -ldflags=$(LDFLAGS) -count=1 ./...
1616

17-
# internal target used by controller_suite_test.go
17+
# internal target used by ./controller/controller_suite_test.go & ./setup/ggv2setup_test.go
1818
envtest:
1919
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)"
2020

projects/gateway2/extensions2/plugins/istio/plugin.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
structpb "github.com/golang/protobuf/ptypes/struct"
1010
"google.golang.org/protobuf/types/known/anypb"
11+
"istio.io/istio/pkg/kube/krt"
1112
"k8s.io/apimachinery/pkg/runtime/schema"
1213

1314
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
@@ -58,6 +59,8 @@ func (i IstioSettings) Equals(in any) bool {
5859
var _ ir.PolicyIR = &IstioSettings{}
5960

6061
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionsplug.Plugin {
62+
p := plugin{}
63+
6164
// TODO: if plumb settings from gw class; then they should be in the new translation pass
6265
// the problem is that they get applied to an upstream, and currently we don't have access to the gateway
6366
// when translating upstreams. if we want we can add the gateway to the context of PerClientProcessUpstream
@@ -67,23 +70,22 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
6770
EnableIstioIntegration: commoncol.Settings.IstioIntegration,
6871
EnableIstioSidecarOnGateway: sidecarEnabled,
6972
}
70-
p := plugin{
71-
settings: istioSettings,
72-
}
7373

7474
return extensionsplug.Plugin{
7575
ContributesPolicies: map[schema.GroupKind]extensionsplug.PolicyPlugin{
7676
VirtualIstioGK: {
7777
Name: "istio",
7878
ProcessUpstream: p.processUpstream,
79+
GlobalPolicies: func(_ krt.HandlerContext, _ extensionsplug.AttachmentPoints) ir.PolicyIR {
80+
// return static settings which do not change post plugin creation
81+
return istioSettings
82+
},
7983
},
8084
},
8185
}
8286
}
8387

84-
type plugin struct {
85-
settings IstioSettings
86-
}
88+
type plugin struct{}
8789

8890
func isDisabledForUpstream(_ ir.Upstream) bool {
8991
// return in.GetDisableIstioAutoMtls().GetValue()
@@ -100,24 +102,27 @@ func doesClusterHaveSslConfigPresent(_ *envoy_config_cluster_v3.Cluster) bool {
100102
return false
101103
}
102104

103-
func (p plugin) processUpstream(ctx context.Context, _ ir.PolicyIR, in ir.Upstream, out *envoy_config_cluster_v3.Cluster) {
105+
func (p plugin) processUpstream(ctx context.Context, ir ir.PolicyIR, in ir.Upstream, out *envoy_config_cluster_v3.Cluster) {
104106
var socketmatches []*envoy_config_cluster_v3.Cluster_TransportSocketMatch
105107

108+
st, ok := ir.(IstioSettings)
109+
if !ok {
110+
return
111+
}
106112
// Istio automtls will only be applied when:
107113
// 1) automtls is enabled on the settings
108114
// 2) the upstream has not disabled auto mtls
109115
// 3) the upstream has no sslConfig
110-
//if p.settings.GetGloo().GetIstioOptions().GetEnableAutoMtls().GetValue() && !in.GetDisableIstioAutoMtls().GetValue() && sslConfig == nil {
111-
if p.settings.EnableAutoMTLS && !isDisabledForUpstream(in) && !doesClusterHaveSslConfigPresent(out) {
116+
if st.EnableAutoMTLS && !isDisabledForUpstream(in) && !doesClusterHaveSslConfigPresent(out) {
112117
// Istio automtls config is not applied if istio integration is disabled on the helm chart.
113118
// When istio integration is disabled via istioSds.enabled=false, there is no sds or istio-proxy sidecar present
114-
if !p.settings.EnableIstioIntegration {
119+
if !st.EnableIstioIntegration {
115120
contextutils.LoggerFrom(ctx).Desugar().Error("Istio integration must be enabled to use auto mTLS. Enable integration with istioIntegration.enabled=true")
116121
} else {
117122
// Note: If EnableIstioSidecarOnGateway is enabled, Istio automtls will not be able to generate the endpoint
118123
// metadata from the Pod to match the transport socket match. We will still translate the transport socket match
119124
// configuration. EnableIstioSidecarOnGateway should be removed as part of: https://github.com/solo-io/solo-projects/issues/5743
120-
if p.settings.EnableIstioSidecarOnGateway {
125+
if st.EnableIstioSidecarOnGateway {
121126
contextutils.LoggerFrom(ctx).Desugar().Warn("Istio sidecar injection (istioIntegration.EnableIstioSidecarOnGateway) should be disabled for Istio automtls mode")
122127
}
123128

projects/gateway2/setup/ggv2setup_test.go

+26-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
envoylistener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
2222
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
2323
envoyhttp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
24-
cache "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
2524
jsonpb "google.golang.org/protobuf/encoding/protojson"
2625
corev1 "k8s.io/api/core/v1"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -111,7 +110,12 @@ func init() {
111110
func TestScenarios(t *testing.T) {
112111
proxy_syncer.UseDetailedUnmarshalling = true
113112
writer.set(t)
114-
os.Setenv("POD_NAMESPACE", "gwtest")
113+
114+
os.Setenv("POD_NAMESPACE", "gwtest") // TODO: is this still needed?
115+
// set global settings env vars; current ggv2setup_tests all assume these are set to true
116+
os.Setenv("KGW_ISTIOINTEGRATION", "true")
117+
os.Setenv("KGW_ENABLEAUTOMTLS", "true")
118+
115119
testEnv := &envtest.Environment{
116120
CRDDirectoryPaths: []string{
117121
filepath.Join("..", "crds"),
@@ -213,19 +217,27 @@ func TestScenarios(t *testing.T) {
213217
// that we get test pollution.
214218
// once we change it to only include the ones in the proxy, we can re-enable this
215219
// t.Parallel()
216-
testScenario(t, ctx, setupOpts.KrtDebugger, snapCache, client, xdsPort, fullpath)
220+
testScenario(t, ctx, setupOpts.KrtDebugger, client, xdsPort, fullpath)
217221

218222
})
219223
}
220224
}
221225
}
222226

223-
func testScenario(t *testing.T, ctx context.Context, kdbg *krt.DebugHandler,
224-
snapCache cache.SnapshotCache, client istiokube.CLIClient, xdsPort int, f string) {
227+
func testScenario(
228+
t *testing.T,
229+
ctx context.Context,
230+
kdbg *krt.DebugHandler,
231+
client istiokube.CLIClient,
232+
xdsPort int,
233+
f string,
234+
) {
225235
fext := filepath.Ext(f)
226236
fpre := strings.TrimSuffix(f, fext)
227-
fout := fpre + "-out" + fext
237+
t.Logf("running scenario for test file: %s", f)
238+
228239
// read the out file
240+
fout := fpre + "-out" + fext
229241
write := false
230242
ya, err := os.ReadFile(fout)
231243
// if not exist
@@ -535,14 +547,16 @@ func (x *xdsDump) Compare(t *testing.T, other xdsDump) {
535547
for _, c := range x.Clusters {
536548
clusterset[c.Name] = c
537549
}
538-
for _, c := range other.Clusters {
539-
otherc := clusterset[c.Name]
540-
if otherc == nil {
541-
t.Errorf("cluster %v not found", c.Name)
550+
for _, otherc := range other.Clusters {
551+
ourc := clusterset[otherc.Name]
552+
if ourc == nil {
553+
t.Errorf("cluster %v not found", otherc.Name)
542554
continue
543555
}
544-
if !proto.Equal(c, otherc) {
545-
t.Errorf("cluster %v not equal", c.Name)
556+
if !proto.Equal(otherc, ourc) {
557+
t.Errorf("cluster %v not equal", otherc.Name)
558+
t.Errorf("got: %s", ourc.String())
559+
t.Errorf("expected: %s", otherc.String())
546560
}
547561
}
548562
listenerset := map[string]*envoylistener.Listener{}

0 commit comments

Comments
 (0)