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

Make version field required #269

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions cmd/validate-krew-manifest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestValidateManifestFile(t *testing.T) {
Name: "test",
},
Spec: index.PluginSpec{
Version: "v1.0.0",
ShortDescription: "test",
Platforms: []index.Platform{{
URI: "http://test.com",
Expand Down Expand Up @@ -108,6 +109,7 @@ func TestValidateManifestFile(t *testing.T) {
},
Spec: index.PluginSpec{
ShortDescription: "test",
Version: "v1.0.0",
Platforms: []index.Platform{
{
URI: "http://test.com",
Expand Down
9 changes: 5 additions & 4 deletions docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ kind: Plugin
metadata:
name: foo # plugin name must match your manifest file name (e.g. foo.yaml)
spec:
version: "v0.0.1" # optional, only for documentation purposes
version: "v0.0.1" # required, must be in semver format, prefixed with "v"
platforms:
# specify installation script for linux and darwin (macOS)
- selector: # a regular Kubernetes selector
Expand Down Expand Up @@ -299,10 +299,11 @@ needed to run the plugin in the `caveats:` field.
### Updating existing plugins

When you have a newer version of your plugin, create a new pull request that
updates `uri` and `sha256` fields of the plugin manifest file.
updates thew `version`, `uri` and `sha256` fields of the plugin manifest file.

Optionally, you can use the `version` field to match to your plugin's released
version string.
Ideally, the `version` specified should match the release tag of the plugin.
This helps users and maintainers to easily identify which version of the plugin
they have installed.

[index]: https://github.com/kubernetes-sigs/krew-index
[plugins]: https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
2 changes: 1 addition & 1 deletion docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SHA256: 8be8ed348d02285abc46bbf7a4cc83da0ee9d54dc2c5bf86a7b64947811b843c
DESCRIPTION:
 Pretty print the current cluster certificate.
 The plugin formats the certificate in PEM following RFC1421.
VERSION: master
VERSION: v1.0.0
CAVEATS:
 This plugin needs the following programs:
 * base64
Expand Down
1 change: 1 addition & 0 deletions pkg/index/indexscanner/testdata/testindex/plugins/bar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kind: Plugin
metadata:
name: bar
spec:
version: v1.0.0
platforms:
- files:
- from: "*"
Expand Down
1 change: 1 addition & 0 deletions pkg/index/indexscanner/testdata/testindex/plugins/foo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kind: Plugin
metadata:
name: foo
spec:
version: v1.0.0
platforms:
- files:
- from: "*"
Expand Down
4 changes: 3 additions & 1 deletion pkg/index/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (p Plugin) Validate(name string) error {
if p.Kind != constants.PluginKind {
return errors.Errorf("plugin manifest has kind=%q, but only %q is supported", p.Kind, constants.PluginKind)
}

if !IsSafePluginName(name) {
return errors.Errorf("the plugin name %q is not allowed, must match %q", name, safePluginRegexp.String())
}
Expand All @@ -71,6 +70,9 @@ func (p Plugin) Validate(name string) error {
if len(p.Spec.Platforms) == 0 {
return errors.New("should have a platform specified")
}
if p.Spec.Version == "" {
return errors.New("should have a version specified")
}
for _, pl := range p.Spec.Platforms {
if err := pl.Validate(); err != nil {
return errors.Wrapf(err, "platform (%+v) is badly constructed", pl)
Expand Down
57 changes: 32 additions & 25 deletions pkg/index/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,16 @@ func TestPlugin_Validate(t *testing.T) {
wantErr bool
}{
{
name: "validate success",
name: "success",
fields: fields{
TypeMeta: metav1.TypeMeta{
APIVersion: constants.CurrentAPIVersion,
Kind: constants.PluginKind,
},
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Homepage: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -139,10 +136,8 @@ func TestPlugin_Validate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -164,11 +159,8 @@ func TestPlugin_Validate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Homepage: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -182,18 +174,16 @@ func TestPlugin_Validate(t *testing.T) {
wantErr: true,
},
{
name: "no short description",
name: "shortDescription unspecified",
fields: fields{
TypeMeta: metav1.TypeMeta{
APIVersion: constants.CurrentAPIVersion,
Kind: constants.PluginKind,
},
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "",
Description: "",
Caveats: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -207,7 +197,7 @@ func TestPlugin_Validate(t *testing.T) {
wantErr: true,
},
{
name: "no file operations",
name: "version unspecified",
fields: fields{
TypeMeta: metav1.TypeMeta{
APIVersion: constants.CurrentAPIVersion,
Expand All @@ -217,8 +207,29 @@ func TestPlugin_Validate(t *testing.T) {
Spec: PluginSpec{
Version: "",
ShortDescription: "short",
Description: "",
Caveats: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Selector: nil,
Files: []FileOperation{{"", ""}},
Bin: "foo",
}},
},
},
pluginName: "foo",
wantErr: true,
},
{
name: "no file operations",
fields: fields{
TypeMeta: metav1.TypeMeta{
APIVersion: constants.CurrentAPIVersion,
Kind: constants.PluginKind,
},
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: PluginSpec{
Version: "v1.0.0",
ShortDescription: "short",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -240,10 +251,8 @@ func TestPlugin_Validate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{Name: "wrong-name"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -265,10 +274,8 @@ func TestPlugin_Validate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{Name: "../foo"},
Spec: PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Platforms: []Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand Down
2 changes: 1 addition & 1 deletion pkg/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
},
ObjectMeta: metav1.ObjectMeta{Name: pluginName},
Spec: index.PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Expand Down
19 changes: 8 additions & 11 deletions pkg/receipt/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ import (
"sigs.k8s.io/krew/pkg/testutil"
)

const pluginName = "some"
const testPluginName = "some"

var (
plugin = index.Plugin{
testPlugin = index.Plugin{
TypeMeta: metav1.TypeMeta{
APIVersion: constants.CurrentAPIVersion,
Kind: constants.PluginKind,
},
ObjectMeta: metav1.ObjectMeta{Name: pluginName},
ObjectMeta: metav1.ObjectMeta{Name: testPluginName},
Spec: index.PluginSpec{
Version: "",
Version: "v1.0.0",
ShortDescription: "short",
Description: "",
Caveats: "",
Homepage: "",
Platforms: []index.Platform{{
URI: "http://example.com",
Sha256: "deadbeef",
Expand All @@ -58,16 +55,16 @@ func TestStore(t *testing.T) {

dest := tmpDir.Path("some.yaml")

if err := Store(plugin, dest); err != nil {
if err := Store(testPlugin, dest); err != nil {
t.Error(err)
}

actual, err := indexscanner.LoadPluginFileFromFS(tmpDir.Root(), pluginName)
actual, err := indexscanner.LoadPluginFileFromFS(tmpDir.Root(), testPluginName)
if err != nil {
t.Fatal(err)
}

if diff := cmp.Diff(&plugin, &actual); diff != "" {
t.Error(diff)
if diff := cmp.Diff(&testPlugin, &actual); diff != "" {
t.Fatal(diff)
}
}