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-cp): allow skipping certain label propagation on multizone #11918

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ var _ = Describe("Config loader", func() {
Expect(cfg.Multizone.Global.KDS.ZoneHealthCheck.PollInterval.Duration).To(Equal(11 * time.Second))
Expect(cfg.Multizone.Global.KDS.ZoneHealthCheck.Timeout.Duration).To(Equal(110 * time.Second))
Expect(cfg.Multizone.Global.KDS.Tracing.Enabled).To(BeFalse())
Expect(cfg.Multizone.Global.KDS.Labels.SkipPrefixes).To(Equal([]string{"argocd.argoproj.io"}))
Expect(cfg.Multizone.Zone.GlobalAddress).To(Equal("grpc://1.1.1.1:5685"))
Expect(cfg.Multizone.Zone.Name).To(Equal("zone-1"))
Expect(cfg.Multizone.Zone.KDS.RootCAFile).To(Equal("/rootCa"))
Expand All @@ -276,6 +277,7 @@ var _ = Describe("Config loader", func() {
Expect(cfg.Multizone.Zone.KDS.NackBackoff.Duration).To(Equal(21 * time.Second))
Expect(cfg.Multizone.Zone.KDS.ResponseBackoff.Duration).To(Equal(2 * time.Second))
Expect(cfg.Multizone.Zone.KDS.TlsSkipVerify).To(BeTrue())
Expect(cfg.Multizone.Zone.KDS.Labels.SkipPrefixes).To(Equal([]string{"argocd.argoproj.io"}))

Expect(cfg.Defaults.SkipMeshCreation).To(BeTrue())
Expect(cfg.Defaults.SkipTenantResources).To(BeTrue())
Expand Down Expand Up @@ -624,6 +626,8 @@ multizone:
timeout: 110s
tracing:
enabled: false
labels:
skipPrefixes: ["argocd.argoproj.io"]
zone:
globalAddress: "grpc://1.1.1.1:5685"
name: "zone-1"
Expand All @@ -635,6 +639,8 @@ multizone:
nackBackoff: 21s
responseBackoff: 2s
tlsSkipVerify: true
labels:
skipPrefixes: ["argocd.argoproj.io"]
disableOriginLabelValidation: true
ingressUpdateInterval: 2s
dnsServer:
Expand Down Expand Up @@ -968,6 +974,7 @@ meshService:
"KUMA_MULTIZONE_GLOBAL_KDS_ZONE_HEALTH_CHECK_POLL_INTERVAL": "11s",
"KUMA_MULTIZONE_GLOBAL_KDS_ZONE_HEALTH_CHECK_TIMEOUT": "110s",
"KUMA_MULTIZONE_GLOBAL_KDS_TRACING_ENABLED": "false",
"KUMA_MULTIZONE_GLOBAL_KDS_LABELS_SKIP_PREFIXES": "argocd.argoproj.io",
"KUMA_MULTIZONE_ZONE_GLOBAL_ADDRESS": "grpc://1.1.1.1:5685",
"KUMA_MULTIZONE_ZONE_NAME": "zone-1",
"KUMA_MULTIZONE_ZONE_KDS_ROOT_CA_FILE": "/rootCa",
Expand All @@ -979,6 +986,7 @@ meshService:
"KUMA_MULTIZONE_ZONE_KDS_TLS_SKIP_VERIFY": "true",
"KUMA_MULTIZONE_ZONE_DISABLE_ORIGIN_LABEL_VALIDATION": "true",
"KUMA_MULTIZONE_ZONE_INGRESS_UPDATE_INTERVAL": "2s",
"KUMA_MULTIZONE_ZONE_KDS_LABELS_SKIP_PREFIXES": "argocd.argoproj.io",
"KUMA_MULTIZONE_GLOBAL_KDS_ZONE_INSIGHT_FLUSH_INTERVAL": "5s",
"KUMA_DEFAULTS_SKIP_MESH_CREATION": "true",
"KUMA_DEFAULTS_SKIP_HOSTNAME_GENERATORS": "true",
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/multizone/kds.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type KdsServerConfig struct {
// ZoneHealthCheck holds config for ensuring zones are online
ZoneHealthCheck ZoneHealthCheckConfig `json:"zoneHealthCheck"`
Tracing KDSServerTracing `json:"tracing"`
// Labels allows for customizing label handling
Labels GlobalLabels `json:"labels"`
}

var _ config.Config = &KdsServerConfig{}
Expand Down Expand Up @@ -103,6 +105,8 @@ type KdsClientConfig struct {
// ResponseBackoff is a time Zone CP waits before sending ACK/NACK.
// This is a way to slow down Global CP from sending resources too often.
ResponseBackoff config_types.Duration `json:"responseBackoff" envconfig:"kuma_multizone_zone_kds_response_backoff"`
// Labels allows for customizing label handling
Labels ZoneLabels `json:"labels"`
}

var _ config.Config = &KdsClientConfig{}
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/multizone/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package multizone

type GlobalLabels struct {
// Labels with any of these prefixes won't be synced between control planes
SkipPrefixes []string `json:"skipPrefixes,omitempty" envconfig:"kuma_multizone_global_kds_labels_skip_prefixes"`
}
type ZoneLabels struct {
// Labels with any of these prefixes won't be synced between control planes
SkipPrefixes []string `json:"skipPrefixes,omitempty" envconfig:"kuma_multizone_zone_kds_labels_skip_prefixes"`
}
6 changes: 5 additions & 1 deletion pkg/kds/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func DefaultContext(
}

globalMappers := []reconcile_v2.ResourceMapper{
UpdateResourceMeta(util.WithLabel(mesh_proto.ResourceOriginLabel, string(mesh_proto.GlobalResourceOrigin))),
UpdateResourceMeta(
util.WithLabel(mesh_proto.ResourceOriginLabel, string(mesh_proto.GlobalResourceOrigin)),
util.WithoutLabelPrefixes(cfg.Multizone.Global.KDS.Labels.SkipPrefixes...),
),
reconcile_v2.If(
reconcile_v2.And(
reconcile_v2.TypeIs(system.GlobalSecretType),
Expand Down Expand Up @@ -104,6 +107,7 @@ func DefaultContext(
util.WithLabel(mesh_proto.ZoneTag, cfg.Multizone.Zone.Name),
util.WithoutLabel(mesh_proto.DeletionGracePeriodStartedLabel),
util.If(util.IsKubernetes(cfg.Store.Type), util.PopulateNamespaceLabelFromNameExtension()),
util.WithoutLabelPrefixes(cfg.Multizone.Zone.KDS.Labels.SkipPrefixes...),
),
MapInsightResourcesZeroGeneration,
reconcile_v2.If(
Expand Down
13 changes: 13 additions & 0 deletions pkg/kds/util/meta.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"strings"
"time"

"golang.org/x/exp/maps"
Expand Down Expand Up @@ -59,6 +60,18 @@ func WithoutLabel(key string) CloneResourceMetaOpt {
}
}

func WithoutLabelPrefixes(prefixes ...string) CloneResourceMetaOpt {
return func(m *resourceMeta) {
for label := range m.labels {
for _, prefix := range prefixes {
if strings.HasPrefix(label, prefix) {
delete(m.labels, label)
}
}
}
}
}

func If(condition func(resource model.ResourceMeta) bool, fn CloneResourceMetaOpt) CloneResourceMetaOpt {
return func(meta *resourceMeta) {
if condition(meta) {
Expand Down
33 changes: 32 additions & 1 deletion test/e2e_env/multizone/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ func Sync() {
meshName := "sync"

BeforeAll(func() {
Expect(multizone.Global.Install(MTLSMeshUniversal(meshName))).To(Succeed())
Expect(
multizone.Global.Install(MTLSMeshUniversal(meshName)),
).To(Succeed())
Expect(
multizone.Global.Install(YamlUniversal(fmt.Sprintf(`
type: MeshTrafficPermission
name: allow-to-client
mesh: %s
labels:
argocd.argoproj.io/instance: something
spec:
targetRef:
kind: Mesh
from:
- targetRef:
kind: MeshService
name: client-server_kuma-test_svc_80 # this is just something to sync
default:
action: Allow
`, meshName)),
)).To(Succeed())
Expect(WaitForMesh(meshName, multizone.Zones())).To(Succeed())

err := NewClusterSetup().
Expand Down Expand Up @@ -104,6 +124,17 @@ func Sync() {
g.Expect(strings.Count(out, "Online")).To(Equal(2))
}, "30s", "1s").Should(Succeed())
})

It("should drop unwanted labels", func() {
Eventually(func(g Gomega) {
out, err := multizone.Global.GetKumactlOptions().RunKumactlAndGetOutput("get", "meshtrafficpermissions", "--mesh", meshName, "-o", "yaml")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(strings.Count(out, "argocd.argoproj.io")).To(Equal(1))
out, err = multizone.KubeZone1.GetKumactlOptions().RunKumactlAndGetOutput("get", "meshtrafficpermissions", "--mesh", meshName, "-o", "yaml")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(strings.Count(out, "argocd.argoproj.io")).To(Equal(0))
}, "30s", "1s").Should(Succeed())
})
})

Context("from Global to Zone", func() {
Expand Down
3 changes: 3 additions & 0 deletions test/framework/envs/multizone/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func setupKubeZone(wg *sync.WaitGroup, clusterName string, extraOptions ...frame
// 100s and 80s are values that we also use in mesh-perf when we put a lot of pressure on the CP.
framework.WithEnv("KUMA_RUNTIME_KUBERNETES_LEADER_ELECTION_LEASE_DURATION", "100s"),
framework.WithEnv("KUMA_RUNTIME_KUBERNETES_LEADER_ELECTION_RENEW_DEADLINE", "80s"),
framework.WithEnv("KUMA_MULTIZONE_ZONE_KDS_LABELS_SKIP_PREFIXES", "argocd.argoproj.io"),
lahabana marked this conversation as resolved.
Show resolved Hide resolved
}
options = append(options, extraOptions...)
zone := NewK8sCluster(NewTestingT(), clusterName, Verbose)
Expand All @@ -87,6 +88,7 @@ func setupUniZone(wg *sync.WaitGroup, clusterName string, extraOptions ...framew
WithIngressEnvoyAdminTunnel(),
WithEnv("KUMA_XDS_DATAPLANE_DEREGISTRATION_DELAY", "0s"), // we have only 1 Kuma CP instance so there is no risk setting this to 0
WithEnv("KUMA_MULTIZONE_ZONE_KDS_NACK_BACKOFF", "1s"),
WithEnv("KUMA_MULTIZONE_ZONE_KDS_LABELS_SKIP_PREFIXES", "argocd.argoproj.io"),
},
extraOptions...,
)
Expand All @@ -110,6 +112,7 @@ func SetupAndGetState() []byte {
globalOptions := append(
[]framework.KumaDeploymentOption{
WithEnv("KUMA_MULTIZONE_GLOBAL_KDS_NACK_BACKOFF", "1s"),
WithEnv("KUMA_MULTIZONE_GLOBAL_KDS_LABELS_SKIP_PREFIXES", "argocd.argoproj.io"),
},
framework.KumaDeploymentOptionsFromConfig(framework.Config.KumaCpConfig.Multizone.Global)...)
Expect(Global.Install(Kuma(core.Global, globalOptions...))).To(Succeed())
Expand Down
Loading