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

fix(kuma-cp): add backward compatible reading of virtual outbound from config #7088

Merged
merged 1 commit into from
Jun 22, 2023
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
4 changes: 3 additions & 1 deletion docs/generated/kuma-cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ experimental:
kubeOutboundsAsVIPs: true # ENV: KUMA_EXPERIMENTAL_KUBE_OUTBOUNDS_AS_VIPS
# Tag first virtual outbound model is compressed version of default Virtual Outbound model
# It is recommended to use tag first model for deployments with more than 2k services
# This is not backward compatible model.
# You can enable this flag on existing deployment. In order to downgrade cp with this flag enabled
# you need to first disable this flag and redeploy cp, after config is rewritten to default
# format you can downgrade your cp
useTagFirstVirtualOutboundModel: false # ENV: KUMA_EXPERIMENTAL_USE_TAG_FIRST_VIRTUAL_OUTBOUND_MODEL
# If true, KDS will sync using incremental xDS updates
kdsDeltaEnabled: false # ENV: KUMA_EXPERIMENTAL_KDS_DELTA_ENABLED
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/app/kuma-cp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ type ExperimentalConfig struct {
KDSDeltaEnabled bool `json:"kdsDeltaEnabled" envconfig:"KUMA_EXPERIMENTAL_KDS_DELTA_ENABLED"`
// Tag first virtual outbound model is compressed version of default Virtual Outbound model
// It is recommended to use tag first model for deployments with more than 2k services
// This is not backward compatible model.
// You can enable this flag on existing deployment. In order to downgrade cp with this flag enabled
// you need to first disable this flag and redeploy cp, after config is rewritten to default
// format you can downgrade your cp
UseTagFirstVirtualOutboundModel bool `json:"useTagFirstVirtualOutboundModel" envconfig:"KUMA_EXPERIMENTAL_USE_TAG_FIRST_VIRTUAL_OUTBOUND_MODEL"`
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ experimental:
kubeOutboundsAsVIPs: true # ENV: KUMA_EXPERIMENTAL_KUBE_OUTBOUNDS_AS_VIPS
# Tag first virtual outbound model is compressed version of default Virtual Outbound model
# It is recommended to use tag first model for deployments with more than 2k services
# This is not backward compatible model.
# You can enable this flag on existing deployment. In order to downgrade cp with this flag enabled
# you need to first disable this flag and redeploy cp, after config is rewritten to default
# format you can downgrade your cp
useTagFirstVirtualOutboundModel: false # ENV: KUMA_EXPERIMENTAL_USE_TAG_FIRST_VIRTUAL_OUTBOUND_MODEL
# If true, KDS will sync using incremental xDS updates
kdsDeltaEnabled: false # ENV: KUMA_EXPERIMENTAL_KDS_DELTA_ENABLED
Expand Down
12 changes: 7 additions & 5 deletions pkg/dns/vips/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ func (m *Persistence) GetByMesh(ctx context.Context, mesh string) (*VirtualOutbo
}

var virtualOutboundView *VirtualOutboundMeshView
if m.useTagFirstView {
res := NewEmptyTagFirstOutboundView()
if err := json.Unmarshal([]byte(resource.Spec.GetConfig()), &res); err != nil {
return nil, err
}
// try reading new format
res := NewEmptyTagFirstOutboundView()
if err := json.Unmarshal([]byte(resource.Spec.GetConfig()), &res); err != nil {
return nil, err
}
if len(res.PerService) != 0 {
virtualOutboundView = res.ToVirtualOutboundView()
} else {
// fall back to default
res := map[HostnameEntry]VirtualOutbound{}
if err := json.Unmarshal([]byte(resource.Spec.GetConfig()), &res); err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions pkg/dns/vips/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ var _ = Describe("Meshed Persistence", func() {
Meta: &model.ResourceMeta{Name: "kuma-mesh-3-dns-vips"},
Spec: &system_proto.Config{Config: `{"0:backend_3":{"address":"240.0.2.1","outbounds":[{"TagSet":{"kuma.io/service":"backend_3"}}]},"0:frontend_3":{"address":"240.0.2.3","outbounds":[{"TagSet":{"kuma.io/service":"frontend_3"}}]},"1:host.com":{"address":"240.0.1.4","outbounds":[{"TagSet":{"kuma.io/service":"external-host"}}]}}`},
},
"kuma-mesh-4-dns-vips": {
Meta: &model.ResourceMeta{Name: "kuma-mesh-4-dns-vips"},
Spec: &system_proto.Config{Config: `{"v":{"backend_2":{"oe":[{"ap":[{"a":"240.0.1.1","o":"svc"}]}]},"frontend_2":{"oe":[{"ap":[{"a":"240.0.1.3","o":"svc"}]}]},"postgres_2":{"oe":[{"ap":[{"a":"240.0.1.0","o":"svc"}]}]}}}`},
},
},
}, false)
})
Expand All @@ -123,6 +127,18 @@ var _ = Describe("Meshed Persistence", func() {
Expect(err).ToNot(HaveOccurred())
Expect(actual).To(Equal(expected))
})

It("should return vips for mesh in new format", func() {
slonka marked this conversation as resolved.
Show resolved Hide resolved
actual, err := meshedPersistence.GetByMesh(context.Background(), "mesh-4")
Expect(err).ToNot(HaveOccurred())
expected, err := vips.NewVirtualOutboundView(map[vips.HostnameEntry]vips.VirtualOutbound{
vips.NewServiceEntry("backend_2"): {Address: "240.0.1.1", Outbounds: []vips.OutboundEntry{{TagSet: map[string]string{mesh_proto.ServiceTag: "backend_2"}, Origin: "service"}}},
vips.NewServiceEntry("frontend_2"): {Address: "240.0.1.3", Outbounds: []vips.OutboundEntry{{TagSet: map[string]string{mesh_proto.ServiceTag: "frontend_2"}, Origin: "service"}}},
vips.NewServiceEntry("postgres_2"): {Address: "240.0.1.0", Outbounds: []vips.OutboundEntry{{TagSet: map[string]string{mesh_proto.ServiceTag: "postgres_2"}, Origin: "service"}}},
})
Expect(err).ToNot(HaveOccurred())
Expect(actual).To(Equal(expected))
})
})

Context("Set", func() {
Expand Down