Skip to content

Commit

Permalink
Merge pull request #1751 from Adirio/plugin-version
Browse files Browse the repository at this point in the history
🌱Follow the enum pattern for the plugin version stage
  • Loading branch information
k8s-ci-robot authored Oct 30, 2020
2 parents bf3b3b4 + 63ef2be commit 9c02d55
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 308 deletions.
64 changes: 64 additions & 0 deletions pkg/plugin/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2020 The Kubernetes 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

import (
"fmt"
"path"
"strings"

"sigs.k8s.io/kubebuilder/pkg/internal/validation"
)

// DefaultNameQualifier is the suffix appended to all kubebuilder plugin names.
const DefaultNameQualifier = ".kubebuilder.io"

// Key returns a unique identifying string for a plugin's name and version.
func Key(name, version string) string {
if version == "" {
return name
}
return path.Join(name, "v"+strings.TrimLeft(version, "v"))
}

// KeyFor returns a Base plugin's unique identifying string.
func KeyFor(p Base) string {
return Key(p.Name(), p.Version().String())
}

// SplitKey returns a name and version for a plugin key.
func SplitKey(key string) (string, string) {
if !strings.Contains(key, "/") {
return key, ""
}
keyParts := strings.SplitN(key, "/", 2)
return keyParts[0], keyParts[1]
}

// GetShortName returns plugin's short name (name before domain) if name
// is fully qualified (has a domain suffix), otherwise GetShortName returns name.
func GetShortName(name string) string {
return strings.SplitN(name, ".", 2)[0]
}

// ValidateName ensures name is a valid DNS 1123 subdomain.
func ValidateName(name string) error {
if errs := validation.IsDNS1123Subdomain(name); len(errs) != 0 {
return fmt.Errorf("invalid plugin name %q: %v", name, errs)
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/plugin/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Base interface {
// i.e. have a short prefix describing the plugin type (like a language) followed by a domain.
// For example, Kubebuilder's main plugin would return "go.kubebuilder.io".
Name() string
// Version returns the plugin's version, which contains an integer and an optional stability of "alpha" or "beta".
// Version returns the plugin's version.
//
// Note: this version is different from config version.
Version() Version
Expand Down
151 changes: 0 additions & 151 deletions pkg/plugin/plugin.go

This file was deleted.

156 changes: 0 additions & 156 deletions pkg/plugin/plugin_test.go

This file was deleted.

Loading

0 comments on commit 9c02d55

Please sign in to comment.