Skip to content

Commit

Permalink
Tidy test annotation handling
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
  • Loading branch information
bleggett committed Apr 30, 2024
1 parent 2cc64a6 commit 57ee6a4
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 329 deletions.
2 changes: 1 addition & 1 deletion istioctl/pkg/injector/injector-list_test.go
Expand Up @@ -93,7 +93,7 @@ func Test_getNamespaces(t *testing.T) {
}),
createNamespace("no-ambient", map[string]string{
constants.DataplaneModeLabel: constants.DataplaneModeAmbient,
"istio-injection": "enabled",
"istio-injection": "enabled",
}),
}

Expand Down
5 changes: 3 additions & 2 deletions istioctl/pkg/waypoint/waypoint.go
Expand Up @@ -95,7 +95,7 @@ func Cmd(ctx cli.Context) *cobra.Command {
if gw.Labels == nil {
gw.Labels = map[string]string{}
}
gw.Labels[constants.AmbientWaypointForTrafficType] = trafficType
gw.Labels[constants.AmbientWaypointForTrafficTypeLabel] = trafficType

if revision != "" {
gw.Labels = map[string]string{label.IoIstioRev.Name: revision}
Expand Down Expand Up @@ -214,7 +214,8 @@ func Cmd(ctx cli.Context) *cobra.Command {
if err != nil {
return fmt.Errorf("failed to label namespace with waypoint: %v", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "namespace %v labeled with \"%v: %v\"\n", ctx.NamespaceOrDefault(ctx.Namespace()), constants.AmbientUseWaypoint, gw.Name)
fmt.Fprintf(cmd.OutOrStdout(), "namespace %v labeled with \"%v: %v\"\n", ctx.NamespaceOrDefault(ctx.Namespace()),
constants.AmbientUseWaypointLabel, gw.Name)
}
return nil
},
Expand Down
Expand Up @@ -1574,9 +1574,9 @@ func (s *ambientTestServer) addWaypoint(t *testing.T, ip, name, trafficType stri
}
labels := make(map[string]string, 2)
if trafficType != "" && validTrafficTypes.Contains(trafficType) {
labels[constants.AmbientWaypointForTrafficType] = trafficType
labels[constants.AmbientWaypointForTrafficTypeLabel] = trafficType
} else {
labels[constants.AmbientWaypointForTrafficType] = constants.ServiceTraffic
labels[constants.AmbientWaypointForTrafficTypeLabel] = constants.ServiceTraffic
}
gateway.Labels = labels

Expand Down
Expand Up @@ -145,7 +145,7 @@ func fetchWaypointForWorkload(ctx krt.HandlerContext, Waypoints krt.Collection[W
// if there is no namespace provided in the label the default namespace will be used
// defaultNamespace avoids the need to infer when object meta from a namespace was given
func getUseWaypoint(meta metav1.ObjectMeta, defaultNamespace string) (named *krt.Named, isNone bool) {
if labelValue, ok := meta.Labels[constants.AmbientUseWaypointLabelLabel]; ok {
if labelValue, ok := meta.Labels[constants.AmbientUseWaypointLabel]; ok {
if labelValue == "#none" || labelValue == "~" {
return nil, true
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func WaypointsCollection(
}

// Check for a declared traffic type that is allowed to pass through the Waypoint
if tt, found := gateway.Labels[constants.AmbientWaypointForTrafficType]; found {
if tt, found := gateway.Labels[constants.AmbientWaypointForTrafficTypeLabel]; found {
return makeWaypoint(gateway, gatewayClass, serviceAccounts, tt)
}
// If a value is not declared on a Gateway or its associated GatewayClass
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/analysis/analyzers/maturity/maturity.go
Expand Up @@ -73,8 +73,8 @@ var AlwaysIgnoredAnnotations = map[string]bool{
// They are added automatically, and should not be alerted on.
// Delete these related annotations once they are stable.
// Ref: https://github.com/istio/api/pull/2695
constants.AmbientWaypointForTrafficType: true,
constants.AmbientRedirection: true,
constants.AmbientWaypointForTrafficTypeLabel: true,
constants.AmbientRedirection: true,
}

// Analyze implements analysis.Analyzer
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/constants/constants.go
Expand Up @@ -186,7 +186,7 @@ const (
ListenerModeAutoPassthrough = "auto-passthrough"

// DataplaneModeLabel namespace label for determining ambient mesh behavior
DataplaneModeLabel = "istio.io/dataplane-mode"
DataplaneModeLabel = "istio.io/dataplane-mode"
DataplaneModeAmbient = "ambient"

// AmbientRedirection specifies whether a pod has ambient redirection (to ztunnel) configured.
Expand All @@ -197,11 +197,11 @@ const (
// AmbientRedirectionDisabled is an opt-out, configured by user.
AmbientRedirectionDisabled = "disabled"

// AmbientUseWaypointLabelLabel is the label used to specify which waypoint should be used for a given pod, service, etc...
// AmbientUseWaypointLabelLabel is the label used to specify which waypoint should be used for a given pod, service, etc...
AmbientUseWaypointLabel = "istio.io/use-waypoint"
// AmbientWaypointForTrafficType is the label used to specify which traffic is allowed through the Waypoint.
// AmbientWaypointForTrafficTypeLabel is the label used to specify which traffic is allowed through the Waypoint.
// This label is applied to the Waypoint. Valid traffic types are "service", "workload", "all", and "none".
AmbientWaypointForTrafficType = "istio.io/waypoint-for"
AmbientWaypointForTrafficTypeLabel = "istio.io/waypoint-for"

// AmbientWaypointInboundBinding has the format `<protocol>` or `<protocol>/<port>`. If the waypoint is
// captured by a zTunnel, the zTunnel will send traffic to the specified port with tunnel information
Expand Down
166 changes: 0 additions & 166 deletions pkg/test/framework/components/echo/annotations.go

This file was deleted.

25 changes: 9 additions & 16 deletions pkg/test/framework/components/echo/common/deployment/echos.go
Expand Up @@ -17,12 +17,12 @@ package deployment
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/hashicorp/go-multierror"
"golang.org/x/sync/errgroup"

"istio.io/api/annotation"
"istio.io/api/label"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/test"
Expand Down Expand Up @@ -241,11 +241,7 @@ func (c *Config) DefaultEchoConfigs(t resource.Context) []echo.Config {
Ports: ports.All(),
Subsets: []echo.SubsetConfig{
{
Annotations: map[echo.Annotation]*echo.AnnotationValue{
echo.SidecarInject: {
Value: strconv.FormatBool(false),
},
},
Annotations: map[string]string{annotation.SidecarInject.Name: "false"},
Labels: map[string]string{
label.SidecarInject.Name: "false",
constants.AmbientRedirection: constants.AmbientRedirectionDisabled,
Expand All @@ -259,7 +255,7 @@ func (c *Config) DefaultEchoConfigs(t resource.Context) []echo.Config {
ServiceAccount: true,
Ports: ports.All(),
Subsets: []echo.SubsetConfig{{
Annotations: echo.NewAnnotations().Set(echo.SidecarInterceptionMode, "TPROXY"),
Annotations: map[string]string{annotation.SidecarInterceptionMode.Name: "TPROXY"},
Labels: map[string]string{
constants.AmbientRedirection: constants.AmbientRedirectionDisabled,
},
Expand Down Expand Up @@ -303,15 +299,16 @@ func (c *Config) DefaultEchoConfigs(t resource.Context) []echo.Config {
defaultConfigs = append(defaultConfigs, dSvc, eSvc)
}

sotw := `{"proxyMetadata": {"ISTIO_DELTA_XDS": "false"}}`

if !t.Settings().Skip(echo.Sotw) {
sotw := echo.Config{
Service: SotwSvc,
ServiceAccount: true,
Ports: ports.All(),
Subsets: []echo.SubsetConfig{{
Labels: map[string]string{label.SidecarInject.Name: "true"},
Annotations: echo.NewAnnotations().Set(echo.SidecarProxyConfig, `proxyMetadata:
ISTIO_DELTA_XDS: "false"`),
Labels: map[string]string{label.SidecarInject.Name: "true"},
Annotations: map[string]string{annotation.ProxyConfig.Name: sotw},
}},
}
defaultConfigs = append(defaultConfigs, sotw)
Expand All @@ -325,12 +322,8 @@ func (c *Config) DefaultEchoConfigs(t resource.Context) []echo.Config {
Ports: ports.All(),
Subsets: []echo.SubsetConfig{
{
Labels: map[string]string{label.SidecarInject.Name: "true"},
Annotations: map[echo.Annotation]*echo.AnnotationValue{
echo.SidecarInjectTemplates: {
Value: "grpc-agent",
},
},
Labels: map[string]string{label.SidecarInject.Name: "true"},
Annotations: map[string]string{annotation.InjectTemplates.Name: "grpc-agent"},
},
},
}
Expand Down
10 changes: 3 additions & 7 deletions pkg/test/framework/components/echo/common/deployment/external.go
Expand Up @@ -16,8 +16,8 @@ package deployment

import (
"path"
"strconv"

"istio.io/api/annotation"
"istio.io/istio/pkg/test/echo/common"
"istio.io/istio/pkg/test/env"
"istio.io/istio/pkg/test/framework/components/echo"
Expand Down Expand Up @@ -60,12 +60,8 @@ func (e External) build(t resource.Context, b deployment.Builder) deployment.Bui
},
Subsets: []echo.SubsetConfig{
{
Version: "v1",
Annotations: map[echo.Annotation]*echo.AnnotationValue{
echo.SidecarInject: {
Value: strconv.FormatBool(false),
},
},
Version: "v1",
Annotations: map[string]string{annotation.SidecarInject.Name: "false"},
},
},
}
Expand Down

0 comments on commit 57ee6a4

Please sign in to comment.