Skip to content

Commit

Permalink
Merge branch 'release-2.7' into chore/backport-release-2.7-11923
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeaumont authored Nov 8, 2024
2 parents d267f42 + d91e1ef commit a0b34f3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/goburrow/cache v0.1.4
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-migrate/migrate/v4 v4.17.0 h1:rd40H3QXU0AA4IoLllFcEAEo9dYKRHYND2gB4p7xcaU=
github.com/golang-migrate/migrate/v4 v4.17.0/go.mod h1:+Cp2mtLP4/aXDTKb9wmXYitdrNx2HGs45rbWAo6OsKM=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
Expand Down
2 changes: 1 addition & 1 deletion mk/dependencies/deps.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
715143257bf862fa0be82c4c9bc744565352f3e3
e8e06c31bae5234be42cffb540eb98310bfebed2
2 changes: 1 addition & 1 deletion mk/dev.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT_TAG = $(word 2, $(BUILD_INFO))
GIT_COMMIT = $(word 3, $(BUILD_INFO))
BUILD_DATE = $(word 4, $(BUILD_INFO))
CI_TOOLS_VERSION = $(word 5, $(BUILD_INFO))
ENVOY_VERSION ?= 1.29.9
ENVOY_VERSION ?= 1.29.10
KUMA_CHARTS_URL ?= https://kumahq.github.io/charts
CHART_REPO_NAME ?= kuma
PROJECT_NAME ?= kuma
Expand Down
2 changes: 2 additions & 0 deletions pkg/core/resources/store/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func CreateWithLabels(labels map[string]string) CreateOptionsFunc {
type UpdateOptions struct {
ModificationTime time.Time
Labels map[string]string
ModifyLabels bool
}

func ModifiedAt(modificationTime time.Time) UpdateOptionsFunc {
Expand All @@ -68,6 +69,7 @@ func ModifiedAt(modificationTime time.Time) UpdateOptionsFunc {
func UpdateWithLabels(labels map[string]string) UpdateOptionsFunc {
return func(opts *UpdateOptions) {
opts.Labels = labels
opts.ModifyLabels = true
}
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/resources/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ func (s *KubernetesStore) Update(ctx context.Context, r core_model.Resource, fs
return errors.Wrapf(err, "failed to convert core model of type %s into k8s counterpart", r.Descriptor().Name)
}

labels, annotations := splitLabelsAndAnnotations(opts.Labels, obj.GetAnnotations())
updateLabels := r.GetMeta().GetLabels()
if opts.ModifyLabels {
updateLabels = opts.Labels
}
labels, annotations := splitLabelsAndAnnotations(updateLabels, obj.GetAnnotations())
obj.GetObjectMeta().SetLabels(labels)
obj.GetObjectMeta().SetAnnotations(annotations)
obj.SetMesh(r.GetMeta().GetMesh())
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/resources/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ func (c *memoryStore) Update(_ context.Context, r core_model.Resource, fs ...sto
}
meta.Version = meta.Version.Next()
meta.ModificationTime = opts.ModificationTime
meta.Labels = opts.Labels
if opts.ModifyLabels {
meta.Labels = opts.Labels
}
r.SetMeta(meta)

record.Version = meta.Version
Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/resources/postgres/pgx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (r *pgxResourceStore) Update(ctx context.Context, resource core_model.Resou
return errors.Wrap(err, "failed to convert meta version to int")
}

labels, err := prepareLabels(opts.Labels)
updateLabels := resource.GetMeta().GetLabels()
if opts.ModifyLabels {
updateLabels = opts.Labels
}
labels, err := prepareLabels(updateLabels)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/resources/postgres/pq_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func (r *postgresResourceStore) Update(_ context.Context, resource core_model.Re
return errors.Wrap(err, "failed to convert meta version to int")
}

labels, err := prepareLabels(opts.Labels)
updateLabels := resource.GetMeta().GetLabels()
if opts.ModifyLabels {
updateLabels = opts.Labels
}
labels, err := prepareLabels(updateLabels)
if err != nil {
return err
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/test/store/store_test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ func ExecuteStoreTests(
}
})

It("should preserve labels", func() {
// given
name := "to-be-updated.demo"
resource := createResource(name, "foo", "bar")

// when
resource.Spec.Conf.Destination["path"] = "new-path"
err := s.Update(context.Background(), resource)

// then
Expect(err).ToNot(HaveOccurred())

res := core_mesh.NewTrafficRouteResource()
err = s.Get(context.Background(), res, store.GetByKey(name, mesh))
Expect(err).ToNot(HaveOccurred())
Expect(res.Meta.GetLabels()).To(HaveKeyWithValue("foo", "bar"))
})

It("should delete labels", func() {
// given a resources in storage
name := "to-be-updated.demo"
resource := createResource(name, "foo", "bar")

// when
resource.Spec.Conf.Destination["path"] = "new-path"
err := s.Update(context.Background(), resource, store.UpdateWithLabels(map[string]string{}))

// then
Expect(err).ToNot(HaveOccurred())

res := core_mesh.NewTrafficRouteResource()
err = s.Get(context.Background(), res, store.GetByKey(name, mesh))
Expect(err).ToNot(HaveOccurred())
Expect(res.Meta.GetLabels()).ToNot(HaveKeyWithValue("foo", "bar"))
})

It("should update resource with status", func() {
// given
updated := meshservice_api.MeshServiceResource{
Expand Down

0 comments on commit a0b34f3

Please sign in to comment.