Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-dp): rework on the virtual probes to support probing tcp and grpc ports #10624

Merged
merged 50 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b69d058
feat(kuma-dp): add the virtual probes component in kuma-dp
jijiechen Jun 11, 2024
22caff4
feat(kuma-dp): improve ipv6 compatibilities in virtual probes
jijiechen Jun 14, 2024
ebd1cb4
feat(kuma-dp): add virtual probes component into kuma-dp component ma…
jijiechen Jun 14, 2024
dd3896a
feat(kuma-dp): support overriding TCP & GRPC probes when injecting
jijiechen Jun 18, 2024
f08d874
feat(kuma-dp): remove probes properties from data plane object
jijiechen Jun 18, 2024
f8deb5e
feat(kuma-cni): exclude virtual probe port from CNI
jijiechen Jun 18, 2024
c5bc88f
feat(kuma-dp): test virtual probes - HTTP
jijiechen Jun 20, 2024
733024d
feat(kuma-dp): test virtual probes - TCP & gRPC
jijiechen Jun 21, 2024
17b1f92
feat(kuma-dp): test virtual probe converting
jijiechen Jun 24, 2024
593dd44
feat(kuma-dp): test virtual probe converting on pod
jijiechen Jun 24, 2024
653c32a
Merge branch 'master' into tcp-grpc-probes
jijiechen Jun 24, 2024
9b72e87
feat(kuma-cni): fix syntax errors
jijiechen Jun 24, 2024
a1cc8fc
feat(kuma-cni): log probe errors for tcpSocket probes
jijiechen Jun 24, 2024
3f8610b
feat(kuma-cni): fix logic for excluding virtual porbes port
jijiechen Jun 24, 2024
7139cb2
feat(kuma-dp): virtual probes server listen based on kuma-cp injector…
jijiechen Jun 25, 2024
ccc9d61
feat(kuma-dp): improve code formatting
jijiechen Jun 25, 2024
a1a919a
feat(kuma-dp): fix annotation assignment issue
jijiechen Jun 25, 2024
62a6694
feat(kuma-dp): support query in http virtual probes
jijiechen Jun 26, 2024
81efa48
feat(kuma-dp): fix failed unit tests
jijiechen Jun 26, 2024
b471f49
bring back field 'probes' back on Dataplane
jijiechen Jul 26, 2024
72a35de
add back probes_generator and take care of existing probes data on Da…
jijiechen Jul 26, 2024
2bf0931
Merge branch 'master' into tcp-grpc-probes
jijiechen Jul 29, 2024
1990387
fix probe fields in proto & schema files
jijiechen Jul 29, 2024
ee13481
fix virutal probes path
jijiechen Jul 29, 2024
8a59daf
fix inject golden files
jijiechen Jul 30, 2024
fd4fabf
improve probe test structure
jijiechen Jul 30, 2024
42ed8d0
don't run e2e when there is no runner
jijiechen Jul 30, 2024
89b6aa4
fix review suggestions and tests
jijiechen Aug 6, 2024
7aa979e
Merge branch 'master' into tcp-grpc-probes
jijiechen Aug 6, 2024
412d8e1
fix lint errors
jijiechen Aug 6, 2024
6207c49
fix review suggestions
jijiechen Aug 7, 2024
49c4386
Merge branch 'master' into tcp-grpc-probes
jijiechen Aug 7, 2024
8fdc388
try to fix unit tests
jijiechen Aug 7, 2024
fe445a5
fix failed unit test using different virt probe port
jijiechen Aug 7, 2024
a56273e
fix logging format
jijiechen Aug 7, 2024
76b05af
fix format
jijiechen Aug 7, 2024
e162b55
Merge branch 'master' into tcp-grpc-probes
jijiechen Aug 8, 2024
589f046
feat(kuma-dp): introduce a new annotation/configuration to support th…
jijiechen Aug 14, 2024
fa48bf1
feat(kuma-dp): fix tests: don't include virtual-probes env variables …
jijiechen Aug 14, 2024
4d019b8
feat(kuma-dp): add back virtual probes
jijiechen Aug 14, 2024
082fcae
feat(kuma-dp): fix tests when virtual probes and application probe pr…
jijiechen Aug 14, 2024
cfb9ae2
feat(kuma-dp): support explicitly enable probe proxy on certain pods
jijiechen Aug 14, 2024
2d6d0b1
feat(kuma-dp): fix test: add back probes data on Dataplane objects
jijiechen Aug 14, 2024
4477ca5
feat(kuma-dp): add deprecate notice for virtual probe annotations
jijiechen Aug 14, 2024
6bb046a
feat(kuma-dp): fix format issues
jijiechen Aug 14, 2024
1750fe6
feat(kuma-dp): fix failed tests
jijiechen Aug 14, 2024
1925856
feat(kuma-dp): fix format issues
jijiechen Aug 14, 2024
cea79a7
feat(kuma-dp): update UPGRADE.md
jijiechen Aug 14, 2024
ebebbf1
feat(kuma-dp): improve UPGRADE.md
jijiechen Aug 14, 2024
1c56071
feat(kuma-dp): improve UPGRADE.md
jijiechen Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
646 changes: 230 additions & 416 deletions api/mesh/v1alpha1/dataplane.pb.go

Large diffs are not rendered by default.

30 changes: 1 addition & 29 deletions api/mesh/v1alpha1/dataplane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -310,33 +310,5 @@ message Dataplane {
// defined at a Mesh level.
MetricsBackend metrics = 2;

message Probes {
jijiechen marked this conversation as resolved.
Show resolved Hide resolved
// Port on which the probe endpoints will be exposed. This cannot overlap
// with any other ports.
uint32 port = 1;

message Endpoint {
// Inbound port is a port of the application from which we expose the
// endpoint.
uint32 inbound_port = 1;
// Inbound path is a path of the application from which we expose the
// endpoint. It is recommended to be as specific as possible.
string inbound_path = 2;
// Path is a path on which we expose inbound path on the probes port.
string path = 3;
}

// List of endpoints to expose without mTLS.
repeated Endpoint endpoints = 2;
}

// Probes describe a list of endpoints that will be exposed without mTLS.
// This is useful to expose the health endpoints of the application so the
// orchestration system (e.g. Kubernetes) can still health check the
// application.
//
// See
// https://kuma.io/docs/latest/policies/service-health-probes/#virtual-probes
// for more information.
Probes probes = 3;
reserved 3;
}
37 changes: 37 additions & 0 deletions app/cni/pkg/cni/annotations_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
defaultIPFamilyMode = "unspecified"
defaultBuiltinDNSPort = "15053"
defaultNoRedirectUID = "5678"
defaultVirtualProbeEnabled = "true"
defaultVirtualProbePorts = "9000"
defaultRedirectExcludePort = defaultProxyStatusPort
)

Expand All @@ -34,6 +36,8 @@ var annotationRegistry = map[string]*annotationParam{
"builtinDNSPort": {"kuma.io/builtin-dns-port", defaultBuiltinDNSPort, validatePortList},
"excludeOutboundPortsForUIDs": {"traffic.kuma.io/exclude-outbound-ports-for-uids", "", alwaysValidFunc},
"noRedirectUID": {"kuma.io/sidecar-uid", defaultNoRedirectUID, alwaysValidFunc},
"virtualProbesEnabled": {"kuma.io/virtual-probes", defaultVirtualProbeEnabled, alwaysValidFunc},
"virtualProbesPort": {"kuma.io/virtual-probes-port", defaultVirtualProbePorts, validateSinglePort},
lahabana marked this conversation as resolved.
Show resolved Hide resolved
}

type IntermediateConfig struct {
Expand Down Expand Up @@ -99,6 +103,13 @@ func validatePortList(ports string) error {
return nil
}

func validateSinglePort(portString string) error {
if _, err := parsePort(portString); err != nil {
return err
}
return nil
}

func validateIpFamilyMode(val string) error {
if val == "" {
return errors.New("value is empty")
Expand Down Expand Up @@ -132,6 +143,8 @@ func getAnnotationOrDefault(name string, annotations map[string]string) (string,
// NewIntermediateConfig returns a new IntermediateConfig Object constructed from a list of ports and annotations
func NewIntermediateConfig(annotations map[string]string) (*IntermediateConfig, error) {
intermediateConfig := &IntermediateConfig{}
valTrue := "true"
valDefaultVirtualPort := defaultVirtualProbePorts

allFields := map[string]*string{
"outboundPort": &intermediateConfig.targetPort,
Expand All @@ -145,6 +158,8 @@ func NewIntermediateConfig(annotations map[string]string) (*IntermediateConfig,
"builtinDNSPort": &intermediateConfig.builtinDNSPort,
"excludeOutboundPortsForUIDs": &intermediateConfig.excludeOutboundPortsForUIDs,
"noRedirectUID": &intermediateConfig.noRedirectUID,
"virtualProbesEnabled": &valTrue,
jijiechen marked this conversation as resolved.
Show resolved Hide resolved
"virtualProbesPort": &valDefaultVirtualPort,
}

for fieldName, fieldPointer := range allFields {
Expand All @@ -155,6 +170,7 @@ func NewIntermediateConfig(annotations map[string]string) (*IntermediateConfig,

// defaults to the ipv4 port if ipv6 port is not set
assignIPv6InboundRedirectPort(allFields)
excludeVirtualProbePort(allFields)
return intermediateConfig, nil
}

Expand Down Expand Up @@ -186,3 +202,24 @@ func assignIPv6InboundRedirectPort(allFields map[string]*string) {
*v6PortFieldPointer = *allFields["inboundPort"]
}
}

func excludeVirtualProbePort(allFields map[string]*string) {
inboundPortsToExclude := allFields["excludeInboundPorts"]
enabledPtr := allFields["virtualProbesEnabled"]
enabled, err := GetEnabled(*enabledPtr)
if err != nil {
enabled = true
}

if !enabled {
return
}

virtualProbesPort := *allFields["virtualProbesPort"]
existingExcludes := *inboundPortsToExclude
if existingExcludes == "" {
*inboundPortsToExclude = virtualProbesPort
} else {
*inboundPortsToExclude = fmt.Sprintf("%s,%s", existingExcludes, virtualProbesPort)
}
}
11 changes: 11 additions & 0 deletions app/cni/pkg/cni/annotations_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ var _ = Describe("NewIntermediateConfig", func() {
Expect(cfg.ipFamilyMode).To(Equal("ipv4"))
Expect(cfg.inboundPortV6).To(Equal("0"))
})

It("should exclude virtual probe ports", func() {
a := map[string]string{
"kuma.io/virtual-probes": "true",
"kuma.io/virtual-probes-port": "19988",
"traffic.kuma.io/exclude-inbound-ports": "3355",
}
cfg, err := NewIntermediateConfig(a)
Expect(err).ToNot(HaveOccurred())
Expect(cfg.excludeInboundPorts).To(Equal("3355,19988"))
})
})
6 changes: 3 additions & 3 deletions app/cni/pkg/cni/injector_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ func mapToConfig(intermediateConfig *IntermediateConfig, logWriter *bufio.Writer

func GetEnabled(value string) (bool, error) {
switch strings.ToLower(value) {
case "enabled", "true":
case "enabled", "true", "yes":
jijiechen marked this conversation as resolved.
Show resolved Hide resolved
return true, nil
case "disabled", "false":
case "disabled", "false", "no":
return false, nil
default:
return false, errors.Errorf(`wrong value "%s", available values are: "enabled", "disabled", "true", "false"`, value)
return false, errors.Errorf(`wrong value "%s", available values are: "enabled", "disabled", "true", "false", "yes", "no"`, value)
}
}
15 changes: 10 additions & 5 deletions app/cni/pkg/cni/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func cmdAdd(args *skel.CmdArgs) error {
ctx := context.Background()
conf, err := parseConfig(args.StdinData)
if err != nil {
return errors.Wrap(err, "error parsing kuma-cni cmdAdd config")
return errorLogged(log, err, "error parsing kuma-cni cmdAdd config")
}

mainProcessStderr, err := hijackMainProcessStderr(conf.LogLevel)
Expand All @@ -139,7 +139,7 @@ func cmdAdd(args *skel.CmdArgs) error {
// Determine if running under k8s by checking the CNI args
k8sArgs := K8sArgs{}
if err := types.LoadArgs(args.Args, &k8sArgs); err != nil {
return errors.Wrap(err, "error loading kuma-cni cmdAdd args")
return errorLogged(log, err, "error loading kuma-cni cmdAdd args")
}
logger := log.WithValues(
"pod", string(k8sArgs.K8S_POD_NAME),
Expand All @@ -162,7 +162,7 @@ func cmdAdd(args *skel.CmdArgs) error {

containerCount, initContainersMap, annotations, err := getPodInfoWithRetries(ctx, conf, k8sArgs)
if err != nil {
return errors.Wrap(err, "pod excluded - error getting pod info")
return errorLogged(logger, err, "pod excluded - error getting pod info")
}

if isInitContainerPresent(initContainersMap) {
Expand All @@ -184,10 +184,10 @@ func cmdAdd(args *skel.CmdArgs) error {
}

if intermediateConfig, configErr := NewIntermediateConfig(annotations); configErr != nil {
return errors.Wrap(configErr, "pod excluded - pod intermediateConfig failed due to bad params")
return errorLogged(logger, configErr, "pod excluded - pod intermediateConfig failed due to bad params")
} else {
if err := Inject(args.Netns, logger, intermediateConfig); err != nil {
return errors.Wrap(err, "pod excluded - could not inject rules into namespace")
return errorLogged(logger, err, "pod excluded - could not inject rules into namespace")
}
}
logger.Info("successfully injected iptables rules")
Expand All @@ -208,6 +208,11 @@ func prepareResult(conf *PluginConf, logger logr.Logger) error {
return types.PrintResult(result, conf.CNIVersion)
}

func errorLogged(logger logr.Logger, err error, message string) error {
jijiechen marked this conversation as resolved.
Show resolved Hide resolved
logger.Info(fmt.Sprintf("[WARNING] %s", message), "err", err)
return errors.Wrap(err, message)
}

func excludeByMissingSidecarInjectedAnnotation(annotations map[string]string) bool {
excludePod := false
val, ok := annotations[metadata.KumaSidecarInjectedAnnotation]
Expand Down
8 changes: 8 additions & 0 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/envoy"
"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/meshmetrics"
"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/metrics"
"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/probes"
kuma_cmd "github.com/kumahq/kuma/pkg/cmd"
"github.com/kumahq/kuma/pkg/config"
kumadp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
Expand Down Expand Up @@ -240,6 +241,13 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
return err
}

if opts.Config.VirtualProbesServer.Enabled {
prober := probes.NewProber(kumaSidecarConfiguration.Networking.Address, opts.Config.VirtualProbesServer.Port)
if err := rootCtx.ComponentManager.Add(prober); err != nil {
return err
}
}

stopComponents := make(chan struct{})
go func() {
var draining bool
Expand Down
Loading
Loading