Giter Club home page Giter Club logo

solo-kit's Introduction

solo-kit

A collection of code generation and libraries to for API development.

Description:

  • Define your declarative API in .proto files
  • APIs are defined by top-level protobuf messages in .proto files
  • Run Solo Kit's code generation and import generated files as libraries into your application.
  • These libraries provide an opinionated suite of tools for building a stateless, event-driven application.
  • Currently only Go is supported, but other languages may be supported in the future.
  • We are looking for community feedback and support!

Examples

See test/mock_resources.proto for an example of how to use solo-kit. These protos are generated using the root level generate.go file.

Build

  • clone repo locally
  • gather dependencies: go mod download
  • import cmd.Run(...) into your own code gen code

Usage

  • re-run whenever you change or add an api (.proto file)
  • api objects generated from messages defined in protobuf messages which have the following requirements fulfilled:
    • option (core.solo.io.resource).short_name = "mk";
      option (core.solo.io.resource).plural_name = "mocks";
      core.solo.io.Metadata metadata = 7;
      // Optional
      core.solo.io.Status status = 6 [(extproto.skip_hashing) = true];
      
  • run solo-kit-gen recursively at the root of an api directory containing one or more solo-kit.json files
  • generated files have the .sk.go suffix (generated test files do not include this suffix)

upgrading to v0.12.0 (solo-kit with go.mod)

As of go 1.11, go began introducing support for go modules, its dependency management system. As of solo-kit 0.12.0 we will officially support running solo-kit with go.mod outside of the GOPATH.

This change has been a lot time coming, but it also means a few changes to solo-kit.

As there is no more GOPATH, we cannot rely on the GOPATH as a method of vendoring/importing .proto files. This means that we needed a new way to reliably import protos outside of the GOPATH. Therefore we created protodep. More information on that can be found here.

Chief among the new changes is that the local vendor_any folder has become the solo-kit source of truth for both .proto files, and solo-kit.json files. The GenerateOptions struct now takes in a protodep config. An example of this can be found in generate.go. This is how solo-kit know how to vendor in the protos it needs to run. If this config is nil a warning will be printed, as technically this is valid, but will most likely lead to an error.

solo-kit's People

Contributors

arianaw66 avatar ashleywang1 avatar bslabe123 avatar davidjumani avatar eitanya avatar elcasteel avatar grahamgoudeau avatar gunnar-solo avatar ilackarms avatar infocus7 avatar jackstine avatar jahvon avatar jbohanon avatar jehawley avatar jenshu avatar joekelley avatar kdorosh avatar kevin-shelaga avatar marcogschmidt avatar mitchdraft avatar mlholland avatar nfuden avatar npolshakova avatar rachael-graham avatar saiskee avatar sam-heilbron avatar sheidkamp avatar sodman avatar soloio-bulldozer[bot] avatar yuval-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solo-kit's Issues

generate resources in sub packages

currently solo kit only generates code for resources for the package in which the solo-kit.json is found.
it would be nice if it will also generate the client code for resources in sub-packages.

related to #44

Add a check for protoc version

We implicitly depend on protoc 3.6.1 for generation. If you run protoc 3.7.x, you'll get a substantial generated diff. We should probably validate this version before running solo kit generation.

find a good place for gcp import

right now we need the following import somewhere:

	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

which is accessible both to tests and main.go for any kube-based project (that might run on GCP).

currently it's added to test packages by solo-kit; we probably want to put that in a centralized place where it's easy to access from test code as well as binaries

configmap kube resource

In order to watch kube cofig maps from event loops requires a solo-kit resource for configmaps.
Pod and namespace already exist, and now configmaps.

autogenerated API docs should output camel, not snake case

Our protos are written in snake case, but the yaml is persisted in Kube as camel case. Because the docs are written based on the protos, they are persisted as snake case. This makes it confusing to read the docs and try to update kube config via yaml.

multiwatcher

create the ability to aggregate watches for resources into a single stream of lists on a single Watch function

protoc-gen-solo-kit should exit with error if wrong metadata is supplied

After reinstalling the the protoc-gen-solo-kit plugin I was not able to generate the expected code for the vcs project. The generate.sh script would exit with a 0 code, but the files had not been generated. After doing some investigation I determined the cause to be the content of the project.json file. The one in the vcs project had

{
  "name": "gloo",
  "version": "v1"
}

instead of the now required full package name:

{
  "name": "gloo.solo.io",
  "version": "v1"
}

We should update the code generation plugin in order to exit with an error if incorrect metadata was supplied.

generated tests very slow

This is 10 seconds for an in-memory resource client test

Step #3: • [SLOW TEST:10.198 seconds]
Step #3: EndpointClient
Step #3: /workspace/gopath/src/github.com/solo-io/gloo/projects/gloo/pkg/api/v1/endpoint_client_test.go:18
Step #3:   resource client backed by memory-based
Step #3:   /workspace/gopath/src/github.com/solo-io/gloo/projects/gloo/pkg/api/v1/endpoint_client_test.go:31
Step #3:     CRUDs Endpoints
Step #3:     /workspace/gopath/src/github.com/solo-io/gloo/projects/gloo/pkg/api/v1/endpoint_client_test.go:45

remove the `ResourcesByNamespace` generated types

for multicluster to be supported, we need a new type of SnapshotEmitter that simply aggregates Lists from different watch channels into a single list of that resource type. the emitter will not know which namespaces (including the NamespaceAll) the resource lists originated from.

rather than creating a V2Snapshot i plan to remove the ByNamespaces abstraction from solo-kit. this will cause an easily resolvable compile error in most places where resource snasphots are referenced.

all calls to <TypeByNamespace>.List() will become redundant, as here: https://github.com/solo-io/solo-kit/blob/master/test/mocks/v1/testing_snapshot.sk.go#L46

func (s TestingSnapshot) hashMocks() uint64 {
	return hashutils.HashAll(s.Mocks.List().AsInterfaces()...)
}

will change to

func (s TestingSnapshot) hashMocks() uint64 {
	return hashutils.HashAll(s.Mocks.AsInterfaces()...)
}

convert "timed out after waiting 1s" to a stat

this warning is very verbose and appears all over the logs of solo kit projects at times

what it indicates is that storage events from kubernetes are being dropped (as solo-kit only buffers up to 10 events at a time)

not super important so long as the last event is captured, i.e. we are eventually consistent

we should convert this warning to a metric as it is quite verbose

tech debt in solo kit

  1. currently, resource groups must be specified on the proto messages themselves (in the comments).
  • this is annoying when you need to add resources from another project (like discovery upstreams) to your event loop.
  • what we probably want is a reference to all the resource groups for the project in the solo-kit.json (ProjectConfig)
  1. currently we hueristically detect proto messages to be resources based on the presence of the metadata field which is a core.solo.io.Metadata. this can cause weird behavior if a proto message contains a metadata but is not intended to be a resource
  • can be fixed by improving the semantics for our magic comments as well as the way other things get included in solo kit can be refined

Watch different namespaces per resource

Currently solo-kit can either watch all, or specific namespaces on an event loop level.
However, it would be very useful in many situations to be able to watch specific namespaces for specific resources.

Remove duplicated code from solo-kit which moved to go-utils

When go-utils was created the decision was made not to immediately removed duplicated code from solo-kit in an attempt to not break existing code. However, enough time has passed now, and accidentally using the wrong version is a very real possibility.

Squash history

Squash history once #2 merges, then pull in new revision of solo-kit to dependent repos

solokit generates code for dependant protos

It seems that solo kit generates code for other projects, if the protos of those other projects are included.
i.e. solokit invocation on supergloo will generate code for gloo as well.

generated test environment variables

We should have environment variable like SKIP_RESOURCE_CLIENT_TESTS=true, to skip running expensive tests that aren't really necessary to verify the generated code (because solo-kit should run those instead)

Add file-level proto option to exclude file from doc gen

Right now we have a message-level option (skip_docs_gen). If a proto file contains a message with that option set to true, the doc generator will skip that file. This approach is convoluted and not self-explanatory. It makes more sense to have this behavior determined by a file-level option.

watch all namespaces

Add a mode to watch all namespaces

Should also be able to add/remove namespaces from the watch when they are created/deleted

This will involve creating a way to create a new event loop and drain the old event loop

Provide user feedback on what is being generated and why

Several gotchas w.r.t. magic comments and generation:

  • If the top-level message definition is missing Status and Metadata, generate won't work
  • If the magic comment resource group name doesn't include the full package name at the end, the event loop won't get generated

improve kubecache stability

currently the shared cache only allows one registration per <namespace, resourceType> combination

this means that if different clients of the same resourceType re-register with the same cache, they will error with 'errors.Errorf("Shared cache already contains informer for resource [%v] and namespace [%v]", resourceType, ns)'

we should have a way to either:
1 - ensure that caches are not shared between resource clients that independently Register
2 - ensure caches can support multiple registrations

currently this isn't a problem outside of tests, as, in most projects (that i'm aware) clients are always initialized with a fresh kube cache in the root SetupSyncer.

@marcogschmidt

simple emitter

add a new type of emitter for use with multicluster

accepts a single aggregated resourcewatch and produces snapshots from it

plain configmaps client

for supergloo, need a way to read/write a prometheus configmap yaml as a map[string]string

this works for plainsecrets, but not (yet) for configmaps

automated mock generation

mockgen mocks are incredibly useful for unit testing, so in an effort to make them more accessbile we will automatically generate them for all solo-kit resources.

give reconciler default transition function

right now if the reconciler doesn't receive a transition function, it always performs an update on existing resources, even if they are equal (causing unnecessary writes)

we should prevent re-writing the same resource from happening by leveraging the Hash() function generated for sk resources

Add generic resource client to kube resource cache

Currently to implement kubernetes resources as solo-kit resources, boilerplate resource client interface code has to be created at each location. Create some generic functions which can be used for any resource type

support opts for the KubeCoreCache

right now the KubeCoreCache implicitly starts watches on:

  • namespaces
  • pods
  • configmaps
  • secrets
  • services

solo-kit dependent projects may only depend on one or some of these, and we don't want to force RBAC configuration as well as the overhead of watching/caching additional resources

the kuebcorecache should accept an opts in its constructor which allows en(dis)abling the informers/caches wrapped by the KubeCoreCache

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.