diff --git a/docs/generated/raw/kuma-cp.yaml b/docs/generated/raw/kuma-cp.yaml index 5663fb6554be..93b024b82cab 100644 --- a/docs/generated/raw/kuma-cp.yaml +++ b/docs/generated/raw/kuma-cp.yaml @@ -794,6 +794,11 @@ policies: - meshtraces - meshtrafficpermissions coreResources: + status: + # How often we compute status of MeshMultiZoneService + meshMultiZoneServiceInterval: 5s # ENV: KUMA_CORE_RESOURCES_STATUS_MESH_MULTI_ZONE_SERVICE_INTERVAL + # How often we compute status of MeshService + meshServiceInterval: 5s # ENV: KUMA_CORE_RESOURCES_STATUS_MESH_SERVICE_INTERVAL enabled: # ENV: KUMA_CORE_RESOURCES_ENABLED - hostnamegenerators - meshexternalservices diff --git a/pkg/config/app/kuma-cp/kuma-cp.defaults.yaml b/pkg/config/app/kuma-cp/kuma-cp.defaults.yaml index 5663fb6554be..93b024b82cab 100644 --- a/pkg/config/app/kuma-cp/kuma-cp.defaults.yaml +++ b/pkg/config/app/kuma-cp/kuma-cp.defaults.yaml @@ -794,6 +794,11 @@ policies: - meshtraces - meshtrafficpermissions coreResources: + status: + # How often we compute status of MeshMultiZoneService + meshMultiZoneServiceInterval: 5s # ENV: KUMA_CORE_RESOURCES_STATUS_MESH_MULTI_ZONE_SERVICE_INTERVAL + # How often we compute status of MeshService + meshServiceInterval: 5s # ENV: KUMA_CORE_RESOURCES_STATUS_MESH_SERVICE_INTERVAL enabled: # ENV: KUMA_CORE_RESOURCES_ENABLED - hostnamegenerators - meshexternalservices diff --git a/pkg/config/core/resources/apis/config.go b/pkg/config/core/resources/apis/config.go index e1afa917b57e..4d4dde770bf4 100644 --- a/pkg/config/core/resources/apis/config.go +++ b/pkg/config/core/resources/apis/config.go @@ -1,7 +1,33 @@ package apis +import ( + "time" + + config_types "github.com/kumahq/kuma/pkg/config/types" +) + type Config struct { + // List of enabled core resources Enabled []string `json:"enabled" envconfig:"KUMA_CORE_RESOURCES_ENABLED" default:""` + // Status of core resources + Status ConfigStatus `json:"status"` +} + +type ConfigStatus struct { + // How often we compute status of MeshMultiZoneService + MeshMultiZoneServiceInterval config_types.Duration `json:"meshMultiZoneServiceInterval" envconfig:"KUMA_CORE_RESOURCES_STATUS_MESH_MULTI_ZONE_SERVICE_INTERVAL"` + // How often we compute status of MeshService + MeshServiceInterval config_types.Duration `json:"meshServiceInterval" envconfig:"KUMA_CORE_RESOURCES_STATUS_MESH_SERVICE_INTERVAL"` +} + +func Default() *Config { + return &Config{ + Enabled: DefaultEnabled, + Status: ConfigStatus{ + MeshMultiZoneServiceInterval: config_types.Duration{Duration: 5 * time.Second}, + MeshServiceInterval: config_types.Duration{Duration: 5 * time.Second}, + }, + } } func (c *Config) PostProcess() error { diff --git a/pkg/config/core/resources/apis/zz_generated.policies.go b/pkg/config/core/resources/apis/zz_generated.policies.go index 5a34668a5f05..d9ecb6761c70 100644 --- a/pkg/config/core/resources/apis/zz_generated.policies.go +++ b/pkg/config/core/resources/apis/zz_generated.policies.go @@ -9,9 +9,3 @@ var DefaultEnabled = []string{ "meshmultizoneservices", "meshservices", } - -func Default() *Config { - return &Config{ - Enabled: DefaultEnabled, - } -} diff --git a/pkg/config/loader_test.go b/pkg/config/loader_test.go index 273660958af3..f3ad904fc8f6 100644 --- a/pkg/config/loader_test.go +++ b/pkg/config/loader_test.go @@ -376,6 +376,10 @@ var _ = Describe("Config loader", func() { Expect(cfg.IPAM.MeshService.CIDR).To(Equal("251.0.0.0/8")) Expect(cfg.IPAM.MeshExternalService.CIDR).To(Equal("252.0.0.0/8")) Expect(cfg.IPAM.AllocationInterval.Duration).To(Equal(7 * time.Second)) + + Expect(cfg.CoreResources.Enabled).To(Equal([]string{"meshservice"})) + Expect(cfg.CoreResources.Status.MeshServiceInterval.Duration).To(Equal(6 * time.Second)) + Expect(cfg.CoreResources.Status.MeshMultiZoneServiceInterval.Duration).To(Equal(7 * time.Second)) }, Entry("from config file", testCase{ envVars: map[string]string{}, @@ -745,6 +749,9 @@ eventBus: coreResources: enabled: - meshservice + status: + meshServiceInterval: 6s + meshMultiZoneServiceInterval: 7s policies: pluginPoliciesEnabled: - meshaccesslog @@ -1038,6 +1045,8 @@ ipam: "KUMA_EVENT_BUS_BUFFER_SIZE": "30", "KUMA_PLUGIN_POLICIES_ENABLED": "meshaccesslog,meshcircuitbreaker", "KUMA_CORE_RESOURCES_ENABLED": "meshservice", + "KUMA_CORE_RESOURCES_STATUS_MESH_SERVICE_INTERVAL": "6s", + "KUMA_CORE_RESOURCES_STATUS_MESH_MULTI_ZONE_SERVICE_INTERVAL": "7s", "KUMA_IPAM_MESH_SERVICE_CIDR": "251.0.0.0/8", "KUMA_IPAM_MESH_EXTERNAL_SERVICE_CIDR": "252.0.0.0/8", "KUMA_IPAM_ALLOCATION_INTERVAL": "7s", diff --git a/pkg/config/plugins/policies/config.go b/pkg/config/plugins/policies/config.go index a62a5709668f..4a7076dadd97 100644 --- a/pkg/config/plugins/policies/config.go +++ b/pkg/config/plugins/policies/config.go @@ -14,3 +14,9 @@ func (c *Config) Sanitize() { func (c *Config) Validate() error { return nil } + +func Default() *Config { + return &Config{ + Enabled: DefaultEnabled, + } +} diff --git a/pkg/config/plugins/policies/zz_generated.policies.go b/pkg/config/plugins/policies/zz_generated.policies.go index e9d0903fd99b..7d48fd8fc543 100644 --- a/pkg/config/plugins/policies/zz_generated.policies.go +++ b/pkg/config/plugins/policies/zz_generated.policies.go @@ -20,9 +20,3 @@ var DefaultEnabled = []string{ "meshtraces", "meshtrafficpermissions", } - -func Default() *Config { - return &Config{ - Enabled: DefaultEnabled, - } -} diff --git a/pkg/core/resources/apis/meshmultizoneservice/status_updater.go b/pkg/core/resources/apis/meshmultizoneservice/status_updater.go new file mode 100644 index 000000000000..fa5cc0b0d7de --- /dev/null +++ b/pkg/core/resources/apis/meshmultizoneservice/status_updater.go @@ -0,0 +1,139 @@ +package meshmultizoneservice + +import ( + "context" + "reflect" + "sort" + "time" + + "github.com/go-logr/logr" + "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" + + meshmzservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice/api/v1alpha1" + meshservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/api/v1alpha1" + "github.com/kumahq/kuma/pkg/core/resources/manager" + "github.com/kumahq/kuma/pkg/core/runtime/component" + "github.com/kumahq/kuma/pkg/core/user" + core_metrics "github.com/kumahq/kuma/pkg/metrics" + util_maps "github.com/kumahq/kuma/pkg/util/maps" +) + +type StatusUpdater struct { + roResManager manager.ReadOnlyResourceManager + resManager manager.ResourceManager + logger logr.Logger + metric prometheus.Summary + interval time.Duration +} + +var _ component.Component = &StatusUpdater{} + +func NewStatusUpdater( + logger logr.Logger, + roResManager manager.ReadOnlyResourceManager, + resManager manager.ResourceManager, + interval time.Duration, + metrics core_metrics.Metrics, +) (component.Component, error) { + metric := prometheus.NewSummary(prometheus.SummaryOpts{ + Name: "component_mzms_status_updater", + Help: "Summary of MeshMultizoneService Updater component", + Objectives: core_metrics.DefaultObjectives, + }) + if err := metrics.Register(metric); err != nil { + return nil, err + } + return &StatusUpdater{ + roResManager: roResManager, + resManager: resManager, + logger: logger, + metric: metric, + interval: interval, + }, nil +} + +func (s *StatusUpdater) Start(stop <-chan struct{}) error { + s.logger.Info("starting") + ticker := time.NewTicker(s.interval) + ctx := user.Ctx(context.Background(), user.ControlPlane) + + for { + select { + case <-ticker.C: + start := time.Now() + if err := s.updateStatus(ctx); err != nil { + s.logger.Error(err, "could not update status of mesh multizone services") + } + s.metric.Observe(float64(time.Since(start).Milliseconds())) + case <-stop: + s.logger.Info("stopping") + return nil + } + } +} + +func (s *StatusUpdater) updateStatus(ctx context.Context) error { + mzSvcList := &meshmzservice_api.MeshMultiZoneServiceResourceList{} + if err := s.roResManager.List(ctx, mzSvcList); err != nil { + return errors.Wrap(err, "could not list of MeshMultiZoneServices") + } + if len(mzSvcList.Items) == 0 { + // skip fetching other resources if MeshMultiZoneService is not used + return nil + } + + msList := &meshservice_api.MeshServiceResourceList{} + if err := s.roResManager.List(ctx, msList); err != nil { + return errors.Wrap(err, "could not list of MeshServices") + } + + for _, mzSvc := range mzSvcList.Items { + var matched []meshmzservice_api.MatchedMeshService + ports := map[uint32]meshservice_api.Port{} + for _, svc := range msList.Items { + if matchesService(mzSvc, svc) { + matched = append(matched, meshmzservice_api.MatchedMeshService{ + Name: svc.Meta.GetName(), + }) + for _, port := range svc.Spec.Ports { + ports[port.Port] = port + } + } + } + + var sortedPorts []meshservice_api.Port + for _, port := range util_maps.SortedKeys(ports) { + sortedPorts = append(sortedPorts, ports[port]) + } + + sort.Slice(matched, func(i, j int) bool { + return matched[i].Name < matched[j].Name + }) + + if !reflect.DeepEqual(mzSvc.Status.Ports, sortedPorts) || + !reflect.DeepEqual(mzSvc.Status.MeshServices, matched) { + log := s.logger.WithValues("meshmultizoneservice", mzSvc.Meta.GetName()) + mzSvc.Status.Ports = sortedPorts + mzSvc.Status.MeshServices = matched + log.Info("updating ports and mesh services", "matchedMeshServices", matched, "ports", sortedPorts) + if err := s.resManager.Update(ctx, mzSvc); err != nil { + log.Error(err, "could not update ports and mesh services") + } + } + } + return nil +} + +func matchesService(mzSvc *meshmzservice_api.MeshMultiZoneServiceResource, svc *meshservice_api.MeshServiceResource) bool { + for label, value := range mzSvc.Spec.Selector.MeshService.MatchLabels { + if svc.Meta.GetLabels()[label] != value { + return false + } + } + return true +} + +func (s *StatusUpdater) NeedLeaderElection() bool { + return true +} diff --git a/pkg/core/resources/apis/meshmultizoneservice/status_updater_test.go b/pkg/core/resources/apis/meshmultizoneservice/status_updater_test.go new file mode 100644 index 000000000000..ea676c91f81c --- /dev/null +++ b/pkg/core/resources/apis/meshmultizoneservice/status_updater_test.go @@ -0,0 +1,112 @@ +package meshmultizoneservice_test + +import ( + "context" + "time" + + "github.com/go-logr/logr" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" + core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh" + "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice" + meshmzservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice/api/v1alpha1" + meshservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/api/v1alpha1" + "github.com/kumahq/kuma/pkg/core/resources/manager" + "github.com/kumahq/kuma/pkg/core/resources/model" + "github.com/kumahq/kuma/pkg/core/resources/store" + core_metrics "github.com/kumahq/kuma/pkg/metrics" + "github.com/kumahq/kuma/pkg/plugins/resources/memory" + test_metrics "github.com/kumahq/kuma/pkg/test/metrics" + "github.com/kumahq/kuma/pkg/test/resources/samples" +) + +var _ = Describe("Updater", func() { + var stopCh chan struct{} + var resManager manager.ResourceManager + var metrics core_metrics.Metrics + + BeforeEach(func() { + m, err := core_metrics.NewMetrics("") + Expect(err).ToNot(HaveOccurred()) + metrics = m + resManager = manager.NewResourceManager(memory.NewStore()) + + updater, err := meshmultizoneservice.NewStatusUpdater(logr.Discard(), resManager, resManager, 50*time.Millisecond, m) + Expect(err).ToNot(HaveOccurred()) + stopCh = make(chan struct{}) + go func() { + defer GinkgoRecover() + Expect(updater.Start(stopCh)).To(Succeed()) + }() + + Expect(samples.MeshDefaultBuilder().Create(resManager)).To(Succeed()) + }) + + AfterEach(func() { + close(stopCh) + }) + + It("should add mesh services and port to the status of multizone service", func() { + // when + ms1Builder := samples.MeshServiceBackendBuilder(). + WithName("backend"). + WithDataplaneTagsSelector(map[string]string{ + "app": "backend", + }). + WithLabels(map[string]string{ + mesh_proto.DisplayName: "backend", + mesh_proto.ZoneTag: "east", + }) + Expect(ms1Builder.Create(resManager)).To(Succeed()) + Expect(samples.MeshServiceWebBuilder().Create(resManager)).To(Succeed()) // to check if we ignore it + Expect(samples.MeshMultiZoneServiceBackendBuilder().Create(resManager)).To(Succeed()) + + // then + Eventually(func(g Gomega) { + mzsvc := meshmzservice_api.NewMeshMultiZoneServiceResource() + + err := resManager.Get(context.Background(), mzsvc, store.GetByKey("backend", model.DefaultMesh)) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(mzsvc.Status.MeshServices).To(Equal([]meshmzservice_api.MatchedMeshService{{Name: "backend"}})) + g.Expect(mzsvc.Status.Ports).To(Equal(ms1Builder.Build().Spec.Ports)) + }, "10s", "100ms").Should(Succeed()) + + // when new service is added + ms2Builder := samples.MeshServiceBackendBuilder(). + WithName("backend-syncedhash"). + WithDataplaneTagsSelector(map[string]string{ + "app": "backend", + }). + AddIntPort(71, 8081, core_mesh.ProtocolHTTP). + WithLabels(map[string]string{ + mesh_proto.DisplayName: "backend", + mesh_proto.ZoneTag: "west", + }) + Expect(ms2Builder.Create(resManager)).To(Succeed()) + + // then + Eventually(func(g Gomega) { + mzsvc := meshmzservice_api.NewMeshMultiZoneServiceResource() + + err := resManager.Get(context.Background(), mzsvc, store.GetByKey("backend", model.DefaultMesh)) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(mzsvc.Status.MeshServices).To(Equal([]meshmzservice_api.MatchedMeshService{ + {Name: "backend"}, + {Name: "backend-syncedhash"}, + })) + // ports are sorted + g.Expect(mzsvc.Status.Ports).To(Equal([]meshservice_api.Port{ + ms2Builder.Build().Spec.Ports[1], + ms1Builder.Build().Spec.Ports[0], + })) + }, "10s", "100ms").Should(Succeed()) + }) + + It("should emit metric", func() { + Eventually(func(g Gomega) { + g.Expect(test_metrics.FindMetric(metrics, "component_mzms_status_updater")).ToNot(BeNil()) + }, "10s", "100ms").Should(Succeed()) + }) +}) diff --git a/pkg/core/resources/apis/meshmultizoneservice/suite_test.go b/pkg/core/resources/apis/meshmultizoneservice/suite_test.go new file mode 100644 index 000000000000..8a136009a957 --- /dev/null +++ b/pkg/core/resources/apis/meshmultizoneservice/suite_test.go @@ -0,0 +1,11 @@ +package meshmultizoneservice_test + +import ( + "testing" + + "github.com/kumahq/kuma/pkg/test" +) + +func TestMeshMultizoneService(t *testing.T) { + test.RunSpecs(t, "MeshMultiZoneService Suite") +} diff --git a/pkg/insights/components.go b/pkg/insights/components.go index 8291b977cef2..e88a739844d3 100644 --- a/pkg/insights/components.go +++ b/pkg/insights/components.go @@ -1,10 +1,9 @@ package insights import ( - "time" - config_core "github.com/kumahq/kuma/pkg/config/core" "github.com/kumahq/kuma/pkg/core" + "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice" "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/status" "github.com/kumahq/kuma/pkg/core/resources/registry" "github.com/kumahq/kuma/pkg/core/runtime" @@ -18,7 +17,7 @@ func Setup(rt runtime.Runtime) error { logger, rt.ReadOnlyResourceManager(), rt.ResourceManager(), - 10*time.Second, // todo config + rt.Config().CoreResources.Status.MeshServiceInterval.Duration, rt.Metrics(), rt.Config().Multizone.Zone.Name, ) @@ -33,6 +32,26 @@ func Setup(rt runtime.Runtime) error { ); err != nil { return err } + + logger = core.Log.WithName("meshmultizoneservice").WithName("status-updater") + meshmzsvcUpdater, err := meshmultizoneservice.NewStatusUpdater( + logger, + rt.ReadOnlyResourceManager(), + rt.ResourceManager(), + rt.Config().CoreResources.Status.MeshMultiZoneServiceInterval.Duration, + rt.Metrics(), + ) + if err != nil { + return err + } + if err := rt.Add(component.NewResilientComponent( + logger, + meshmzsvcUpdater, + rt.Config().General.ResilientComponentBaseBackoff.Duration, + rt.Config().General.ResilientComponentMaxBackoff.Duration), + ); err != nil { + return err + } } if rt.Config().IsFederatedZoneCP() { return nil diff --git a/pkg/test/resources/builders/meshmultizoneservice_builder.go b/pkg/test/resources/builders/meshmultizoneservice_builder.go new file mode 100644 index 000000000000..325587f4a43b --- /dev/null +++ b/pkg/test/resources/builders/meshmultizoneservice_builder.go @@ -0,0 +1,68 @@ +package builders + +import ( + "context" + + meshmzservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice/api/v1alpha1" + core_model "github.com/kumahq/kuma/pkg/core/resources/model" + "github.com/kumahq/kuma/pkg/core/resources/store" + test_model "github.com/kumahq/kuma/pkg/test/resources/model" +) + +type MeshMultiZoneServiceBuilder struct { + res *meshmzservice_api.MeshMultiZoneServiceResource +} + +func MeshMultiZoneService() *MeshMultiZoneServiceBuilder { + return &MeshMultiZoneServiceBuilder{ + res: &meshmzservice_api.MeshMultiZoneServiceResource{ + Meta: &test_model.ResourceMeta{ + Mesh: core_model.DefaultMesh, + Name: "backend", + }, + Spec: &meshmzservice_api.MeshMultiZoneService{}, + Status: &meshmzservice_api.MeshMultiZoneServiceStatus{}, + }, + } +} + +func (m *MeshMultiZoneServiceBuilder) WithLabels(labels map[string]string) *MeshMultiZoneServiceBuilder { + m.res.Meta.(*test_model.ResourceMeta).Labels = labels + return m +} + +func (m *MeshMultiZoneServiceBuilder) WithName(name string) *MeshMultiZoneServiceBuilder { + m.res.Meta.(*test_model.ResourceMeta).Name = name + return m +} + +func (m *MeshMultiZoneServiceBuilder) WithMesh(mesh string) *MeshMultiZoneServiceBuilder { + m.res.Meta.(*test_model.ResourceMeta).Mesh = mesh + return m +} + +func (m *MeshMultiZoneServiceBuilder) WithServiceLabelSelector(labels map[string]string) *MeshMultiZoneServiceBuilder { + m.res.Spec.Selector.MeshService.MatchLabels = labels + return m +} + +func (m *MeshMultiZoneServiceBuilder) Build() *meshmzservice_api.MeshMultiZoneServiceResource { + if err := m.res.Validate(); err != nil { + panic(err) + } + return m.res +} + +func (m *MeshMultiZoneServiceBuilder) Create(s store.ResourceStore) error { + opts := []store.CreateOptionsFunc{ + store.CreateBy(m.Key()), + } + if ls := m.res.GetMeta().GetLabels(); len(ls) > 0 { + opts = append(opts, store.CreateWithLabels(ls)) + } + return s.Create(context.Background(), m.Build(), opts...) +} + +func (m *MeshMultiZoneServiceBuilder) Key() core_model.ResourceKey { + return core_model.MetaToResourceKey(m.res.GetMeta()) +} diff --git a/pkg/test/resources/samples/meshmultizoneservice_samples.go b/pkg/test/resources/samples/meshmultizoneservice_samples.go new file mode 100644 index 000000000000..e37e2d05a072 --- /dev/null +++ b/pkg/test/resources/samples/meshmultizoneservice_samples.go @@ -0,0 +1,17 @@ +package samples + +import ( + mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" + meshmzservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice/api/v1alpha1" + "github.com/kumahq/kuma/pkg/test/resources/builders" +) + +func MeshMultiZoneServiceBackendBuilder() *builders.MeshMultiZoneServiceBuilder { + return builders.MeshMultiZoneService().WithServiceLabelSelector(map[string]string{ + mesh_proto.DisplayName: "backend", + }) +} + +func MeshMultiZoneServiceBackend() *meshmzservice_api.MeshMultiZoneServiceResource { + return MeshMultiZoneServiceBackendBuilder().Build() +} diff --git a/pkg/test/resources/samples/meshservice_samples.go b/pkg/test/resources/samples/meshservice_samples.go index f9b5071deed7..7ab18d56b842 100644 --- a/pkg/test/resources/samples/meshservice_samples.go +++ b/pkg/test/resources/samples/meshservice_samples.go @@ -18,3 +18,17 @@ func MeshServiceBackendBuilder() *builders.MeshServiceBuilder { func MeshServiceBackend() *v1alpha1.MeshServiceResource { return MeshServiceBackendBuilder().Build() } + +func MeshServiceWebBuilder() *builders.MeshServiceBuilder { + return builders.MeshService(). + WithName("web"). + WithDataplaneTagsSelector(map[string]string{ + mesh_proto.ServiceTag: "web", + }). + WithKumaVIP("240.0.0.2"). + AddIntPort(builders.FirstInboundPort, builders.FirstInboundPort, "http") +} + +func MeshServiceWeb() *v1alpha1.MeshServiceResource { + return MeshServiceBackendBuilder().Build() +} diff --git a/test/e2e_env/multizone/meshservice/sync.go b/test/e2e_env/multizone/meshservice/sync.go index e082067d00b5..a4153a7bea85 100644 --- a/test/e2e_env/multizone/meshservice/sync.go +++ b/test/e2e_env/multizone/meshservice/sync.go @@ -5,7 +5,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/util/intstr" + meshmzservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshmultizoneservice/api/v1alpha1" "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/api/v1alpha1" "github.com/kumahq/kuma/pkg/core/resources/model/rest" "github.com/kumahq/kuma/pkg/kds/hash" @@ -22,6 +24,16 @@ func Sync() { Expect(NewClusterSetup(). Install(MTLSMeshUniversal(meshName)). Install(MeshTrafficPermissionAllowAllUniversal(meshName)). + Install(YamlUniversal(` +type: MeshMultiZoneService +name: backend +mesh: meshservice +spec: + selector: + meshService: + matchLabels: + test-name: backend +`)). Setup(multizone.Global)).To(Succeed()) Expect(WaitForMesh(meshName, multizone.Zones())).To(Succeed()) @@ -32,6 +44,7 @@ name: backend mesh: meshservice labels: kuma.io/origin: zone + test-name: backend spec: selector: dataplaneTags: @@ -54,6 +67,7 @@ name: backend mesh: meshservice labels: kuma.io/origin: zone + test-name: backend spec: selector: dataplaneTags: @@ -168,4 +182,21 @@ spec: g.Expect(err).ToNot(HaveOccurred()) }, "30s", "1s").Should(Succeed()) }) + + It("should update MeshMultiZoneService status", func() { + Eventually(func(g Gomega) { + out, err := multizone.UniZone1.GetKumactlOptions().RunKumactlAndGetOutput("get", "meshmultizoneservice", "-m", meshName, hash.HashedName(meshName, "backend"), "-ojson") + g.Expect(err).ToNot(HaveOccurred()) + res, err := rest.JSON.Unmarshal([]byte(out), meshmzservice_api.MeshMultiZoneServiceResourceTypeDescriptor) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(res.GetStatus().(*meshmzservice_api.MeshMultiZoneServiceStatus).MeshServices).To(HaveLen(2)) + g.Expect(res.GetStatus().(*meshmzservice_api.MeshMultiZoneServiceStatus).Ports).To(Equal([]v1alpha1.Port{ + { + Port: 80, + TargetPort: intstr.FromInt32(80), + AppProtocol: "http", + }, + })) + }, "30s", "1s").Should(Succeed()) + }) } diff --git a/tools/policy-gen/generate-policy-config.sh b/tools/policy-gen/generate-policy-config.sh index a27f0c76fa5a..17042f4dfce0 100755 --- a/tools/policy-gen/generate-policy-config.sh +++ b/tools/policy-gen/generate-policy-config.sh @@ -28,11 +28,6 @@ var DefaultEnabled = []string{ $policies } -func Default() *Config { - return &Config{ - Enabled: DefaultEnabled, - } -} " > "${CONFIG_POLICIES_FILE}" gofmt -w "${CONFIG_POLICIES_FILE}"