Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin context sharing types #127

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkg/plugin/context_sharing_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2023 The Knative Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package plugin

// Manifest represents plugin metadata
type Manifest struct {
// Path to external plugin binary. Always empty for inlined plugins.
Path string `json:"path,omitempty"`

// Plugin declares its own manifest to be included in Context Sharing feature
HasManifest bool `json:"hasManifest"`

// ProducesContextDataKeys is a list of keys for the ContextData that
// a plugin can produce. Nil or an empty list declares that this
// plugin is not ContextDataProducer
ProducesContextDataKeys []string `json:"producesKeys,omitempty"`

// ConsumesContextDataKeys is a list of keys from a ContextData that a
// plugin is interested in to consume. Nil or an empty list declares
// that this plugin is not a ContextDataConsumer
ConsumesContextDataKeys []string `json:"consumesKeys,omitempty"`
}

// PluginWithManifest represents extended plugin support for Manifest and Context Sharing feature
type PluginWithManifest interface {
// Plugin original interface wrapper
Plugin

// GetManifest
GetManifest() *Manifest

// GetContextData
GetContextData() map[string]string

// ExecuteWithContext
ExecuteWithContext(ctx map[string]string, args []string) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reading this, and I wonder whether we shouldn't use just a regular Golang context, alone to avoid confusion ? (at the end this is also only a map)

At least it should be then called ExecuteWithContextData but at the end I would move to Context instead of ContextData in the the whole interface definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We opted for contextData in a map directly. Basically I've refactored the interface from Context to plain map. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit more straight-forward to work with map, rather than context.Context, than init context and add values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see, but then maybe just rename to "WithContextData" ?

}