-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(xds): split MeshContext in 3 to be able to improve caching (#…
…8182) * refactor(xds): split MeshContext in 3 to be able to improve caching Currently MeshContext contains everything. Which means that whenever something changes on the mesh we pull a lot of things from the DB. In practice there are 3 types of resources: - global resources zone proxies, meshes... - zone resources that rarely change policies, externalServices ... - the rest which changes often dataplanes We now have 3 different things built independently. This will enable us to: - Not pull down policies when a dataplane changes if we make things event based. - Change cache invalidation speed depending on the type (Global stuff could be cached longer or we could decide to propagate policy changes less quickly to improve caching). - Write inspect APIs without getting the full mesh context (only the policies are useful). In its current implementation we're not expecting any strong perf improvements as we don't use the new context independently Also use fnv128 instead of sha256. The probability of collision is low and using a non crypto hash will be quicker Signed-off-by: Charly Molter <[email protected]>
- Loading branch information
Showing
65 changed files
with
1,458 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package store | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/kumahq/kuma/pkg/core/resources/model/rest" | ||
"github.com/kumahq/kuma/pkg/core/resources/store" | ||
util_yaml "github.com/kumahq/kuma/pkg/util/yaml" | ||
) | ||
|
||
func LoadResourcesFromFile(ctx context.Context, rs store.ResourceStore, fileName string) error { | ||
d, err := os.ReadFile(fileName) | ||
if err != nil { | ||
return err | ||
} | ||
return LoadResources(ctx, rs, string(d)) | ||
} | ||
|
||
func LoadResources(ctx context.Context, rs store.ResourceStore, inputs string) error { | ||
rawResources := util_yaml.SplitYAML(inputs) | ||
for i, rawResource := range rawResources { | ||
resource, err := rest.YAML.UnmarshalCore([]byte(rawResource)) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse yaml %d", i) | ||
} | ||
curResource := resource.Descriptor().NewObject() | ||
create := false | ||
if err := rs.Get(ctx, curResource, store.GetByKey(resource.GetMeta().GetName(), resource.GetMeta().GetMesh())); err != nil { | ||
if !store.IsResourceNotFound(err) { | ||
return err | ||
} | ||
create = true | ||
} | ||
|
||
if create { | ||
err = rs.Create(ctx, resource, store.CreateByKey(resource.GetMeta().GetName(), resource.GetMeta().GetMesh())) | ||
} else { | ||
_ = curResource.SetSpec(resource.GetSpec()) | ||
err = rs.Update(ctx, curResource) | ||
} | ||
if err != nil { | ||
return errors.Wrapf(err, "failed with entry %d meta: %s", i, resource.GetMeta()) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.