Skip to content

Commit

Permalink
Implement GetConfiguredPlugins (#2880)
Browse files Browse the repository at this point in the history
* Rework plugin loading into plugins.go and store actual plugins.

* Use constructor for new kapp_controller server.
  • Loading branch information
absoludity committed May 25, 2021
1 parent e6dfc82 commit 49fa927
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 271 deletions.
27 changes: 22 additions & 5 deletions cmd/kubeapps-apis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ I0514 14:14:52.975884 1932386 server.go:129] Successfully registered plugin "/ho
I0511 11:39:56.444553 4116647 server.go:25] Starting server on :50051
```

You can then verify the (currently stubbed) configured plugins endpoint via http:
You can then verify the configured plugins endpoint via http:

```bash
curl http://localhost:50051/core/plugins/v1alpha1/configured-plugins

{"plugins":["foobar.package.v1"]}
curl -s http://localhost:50051/core/plugins/v1alpha1/configured-plugins | jq .
{
"plugins": [
{
"name": "fluxv2.packages",
"version": "v1alpha1"
},
{
"name": "kapp_controller.packages",
"version": "v1alpha1"
}
]
}
```

or via gRPC (using the [grpcurl tool](https://github.com/fullstorydev/grpcurl)):
Expand All @@ -57,7 +67,14 @@ or via gRPC (using the [grpcurl tool](https://github.com/fullstorydev/grpcurl)):
grpcurl -plaintext localhost:50051 kubeappsapis.core.plugins.v1alpha1.PluginsService.GetConfiguredPlugins
{
"plugins": [
"foobar.package.v1"
{
"name": "fluxv2.packages",
"version": "v1alpha1"
},
{
"name": "kapp_controller.packages",
"version": "v1alpha1"
}
]
}
```
Expand Down
172 changes: 123 additions & 49 deletions cmd/kubeapps-apis/gen/core/plugins/v1alpha1/plugins.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"google.golang.org/grpc"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
plugins "github.com/kubeapps/kubeapps/cmd/kubeapps-apis/gen/core/plugins/v1alpha1"
v1alpha1 "github.com/kubeapps/kubeapps/cmd/kubeapps-apis/gen/plugins/fluxv2/packages/v1alpha1"
)

Expand All @@ -31,3 +32,11 @@ func RegisterWithGRPCServer(s grpc.ServiceRegistrar) {
func RegisterHTTPHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
return v1alpha1.RegisterPackagesServiceHandlerFromEndpoint(ctx, mux, endpoint, opts)
}

// GetPluginDetail returns a core.plugins.Plugin describing itself.
func GetPluginDetail() *plugins.Plugin {
return &plugins.Plugin{
Name: "fluxv2.packages",
Version: "v1alpha1",
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ import (
"google.golang.org/grpc"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
plugins "github.com/kubeapps/kubeapps/cmd/kubeapps-apis/gen/core/plugins/v1alpha1"
v1alpha1 "github.com/kubeapps/kubeapps/cmd/kubeapps-apis/gen/plugins/kapp_controller/packages/v1alpha1"
)

// RegisterWithGRPCServer enables a plugin to register with a gRPC server.
func RegisterWithGRPCServer(s grpc.ServiceRegistrar) {
v1alpha1.RegisterPackagesServiceServer(s, &Server{})
v1alpha1.RegisterPackagesServiceServer(s, NewServer())
}

// RegisterHTTPHandlerFromEndpoint enables a plugin to register an http
// handler to translate to the gRPC request.
func RegisterHTTPHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
return v1alpha1.RegisterPackagesServiceHandlerFromEndpoint(ctx, mux, endpoint, opts)
}

// GetPluginDetail returns a core.plugins.Plugin describing itself.
func GetPluginDetail() *plugins.Plugin {
return &plugins.Plugin{
Name: "kapp_controller.packages",
Version: "v1alpha1",
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ import "google/api/annotations.proto";
// The Core API service provides generic functionality shared across all
// plugins, such as querying for enabled plugins (which can be used as a
// liveness check). There may be other general functionality for use by all
// plugins in the future such as creating credentials.
// plugins in the future such as checking authz to the k8s api server using
// the callers token.

// A plugin can implement multiple services and multiple versions of a service.
message Plugin {
// The name of the plugin, such as `fluxv2.packages` or `kapp_controller.packages`.
string name = 1;

// The version of the plugin, such as v1alpha1
string version = 2;
}

message GetConfiguredPluginsRequest {}
message GetConfiguredPluginsResponse {
repeated string plugins = 1;
repeated Plugin plugins = 1;
}
service PluginsService {
// GetConfiguredPlugins returns a map of short and longnames for the configured plugins.
Expand Down

0 comments on commit 49fa927

Please sign in to comment.