Skip to content

Commit

Permalink
Refactor plugin manifest and patching api types; use manifest in plug…
Browse files Browse the repository at this point in the history
…in loader client to verify plugins before loading
  • Loading branch information
kralicky committed Dec 9, 2022
1 parent 6f263dc commit fb301d1
Show file tree
Hide file tree
Showing 43 changed files with 1,092 additions and 994 deletions.
6 changes: 4 additions & 2 deletions apis/core/v1beta1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ type OpenIDConfigSpec struct {
type GatewaySpec struct {
Image *opnimeta.ImageSpec `json:"image,omitempty"`
//+kubebuilder:validation:Required
Auth AuthSpec `json:"auth,omitempty"`
Hostname string `json:"hostname,omitempty"`
Auth AuthSpec `json:"auth,omitempty"`
Hostname string `json:"hostname,omitempty"`

// Deprecated: this field is ignored.
PluginSearchDirs []string `json:"pluginSearchDirs,omitempty"`

Alerting AlertingSpec `json:"alerting,omitempty"`
Expand Down
15 changes: 0 additions & 15 deletions apis/monitoring/v1beta1/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ type BootstrapTokenList struct {
Items []BootstrapToken `json:"items"`
}

// +kubebuilder:object:root=true
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec *opnicorev1.Cluster `json:"spec,omitempty"`
}

// +kubebuilder:object:root=true
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}

// +kubebuilder:object:root=true
type Role struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -78,7 +64,6 @@ type KeyringList struct {
func init() {
SchemeBuilder.Register(
&BootstrapToken{}, &BootstrapTokenList{},
&Cluster{}, &ClusterList{},
&Role{}, &RoleList{},
&RoleBinding{}, &RoleBindingList{},
&Keyring{}, &KeyringList{},
Expand Down
61 changes: 0 additions & 61 deletions apis/monitoring/v1beta1/zz_generated.deepcopy.go

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

53 changes: 53 additions & 0 deletions config/crd/bases/logging.opni.io_opniopensearches.yaml

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

116 changes: 0 additions & 116 deletions config/crd/bases/monitoring.opni.io_clusters.yaml

This file was deleted.

1 change: 0 additions & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ resources:
- bases/logging.opni.io_multiclusterusers.yaml
- bases/logging.opni.io_opniopensearches.yaml
- bases/monitoring.opni.io_bootstraptokens.yaml
- bases/monitoring.opni.io_clusters.yaml
- bases/monitoring.opni.io_keyrings.yaml
- bases/monitoring.opni.io_rolebindings.yaml
- bases/monitoring.opni.io_roles.yaml
Expand Down
2 changes: 1 addition & 1 deletion internal/ginkgo/run.cue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
}
Build: {
Race: bool | *true
Cover: true
Cover: bool | *true
CoverMode: string | *"atomic"
CoverPkg: string | *""
Vet: string | *""
Expand Down
4 changes: 1 addition & 3 deletions packages/opni/opni/charts/crds/crds.yaml

Large diffs are not rendered by default.

24 changes: 10 additions & 14 deletions pkg/agent/v2/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net"
"net/http"
"path"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -273,14 +272,14 @@ func New(ctx context.Context, conf *v1beta1.AgentConfig, opts ...AgentOption) (*

pl.Hook(hooks.OnLoadMC(func(hc controlv1.HealthClient, m meta.PluginMeta, cc *grpc.ClientConn) {
client := controlv1.NewHealthClient(cc)
hm.AddClient(path.Base(m.BinaryPath), client)
hm.AddClient(m.Filename(), client)
}))

pl.Hook(hooks.OnLoadMC(func(ext types.StreamAPIExtensionPlugin, md meta.PluginMeta, cc *grpc.ClientConn) {
lg.With(
zap.String("plugin", md.Module),
).Debug("loaded stream api extension plugin")
gatewayClient.RegisterSplicedStream(cc, md.ShortName())
gatewayClient.RegisterSplicedStream(cc, md.Filename())
}))

return &Agent{
Expand Down Expand Up @@ -355,7 +354,9 @@ func (a *Agent) ListenAndServe(ctx context.Context) error {
close(done)
}))

a.pluginLoader.LoadPlugins(ctx, a.config.Plugins, plugins.AgentScheme)
a.pluginLoader.LoadPlugins(ctx, a.config.Plugins, plugins.AgentScheme,
plugins.WithManifest(manifests),
)

select {
case <-done:
Expand Down Expand Up @@ -410,7 +411,7 @@ func setupPluginRoutes(
).Named("api")
forwarder := fwd.To(cfg.HttpAddr,
fwd.WithLogger(sampledLogger),
fwd.WithDestHint(path.Base(pluginMeta.BinaryPath)),
fwd.WithDestHint(pluginMeta.Filename()),
)
ROUTES:
for _, route := range cfg.Routes {
Expand Down Expand Up @@ -490,12 +491,12 @@ func (a *Agent) syncPlugins(ctx context.Context) (_ *controlv1.PluginManifest, r

manifestClient := controlv1.NewPluginSyncClient(a.gatewayClient.ClientConn())
// read local plugins on disk here
localManifests, err := patch.GetFilesystemPlugins(a.config.Plugins, a.Logger)
archive, err := patch.GetFilesystemPlugins(a.config.Plugins, a.Logger)
if err != nil {
return nil, err
}

patchList, err := manifestClient.SyncPluginManifest(ctx, localManifests, grpc.UseCompressor("zstd"))
syncResp, err := manifestClient.SyncPluginManifest(ctx, archive.ToManifest(), grpc.UseCompressor("zstd"))
if err != nil {
return nil, err
}
Expand All @@ -505,15 +506,10 @@ func (a *Agent) syncPlugins(ctx context.Context) (_ *controlv1.PluginManifest, r
if err != nil {
return nil, err
}
if err := patchClient.Patch(patchList); err != nil {
return nil, err
}

// read local manifests again
localManifests, err = patch.GetFilesystemPlugins(a.config.Plugins, a.Logger)
err = patchClient.Patch(syncResp.RequiredPatches)
if err != nil {
return nil, err
}

return localManifests, nil
return syncResp.DesiredState, nil
}
2 changes: 1 addition & 1 deletion pkg/agent/v2/v2_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (

func TestV2(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "V2 Suite")
RunSpecs(t, "Agent V2 Suite")
}
Loading

0 comments on commit fb301d1

Please sign in to comment.