Skip to content

Commit

Permalink
Run golangci-lint --fix (comments, newlines, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincepri committed Jan 5, 2023
1 parent 4d956d0 commit 0454ea6
Show file tree
Hide file tree
Showing 115 changed files with 191 additions and 229 deletions.
2 changes: 1 addition & 1 deletion cmd/apigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func resolveLatestAPIResourceSchemas(logger logr.Logger, previous, current map[m
}

// compareSchemas compares JSON Schemas by unmarshalling them and comparing their values, instead
// of comparing their raw []byte() representations, as those are not semantically meaningful
// of comparing their raw []byte() representations, as those are not semantically meaningful.
func compareSchemas() cmp.Option {
return cmp.FilterPath(func(path cmp.Path) bool {
return path.String() == "Versions.Schema.Raw"
Expand Down
2 changes: 1 addition & 1 deletion config/rootcompute/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
//go:embed *.yaml
var fs embed.FS

// RootComuteWorkspace is the workspace to host common kubernetes APIs
// RootComputeClusterName is the workspace to host common kubernetes APIs.
var RootComputeClusterName = logicalcluster.NewPath("root:compute")

// Bootstrap creates resources in this package by continuously retrying the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *crdNoOverlappingGVRAdmission) ValidateInitialization() error {
return nil
}

// Validate checks if the given CRD's Group and Resource don't overlap with bound CRDs
// Validate checks if the given CRD's Group and Resource don't overlap with bound CRDs.
func (p *crdNoOverlappingGVRAdmission) Validate(ctx context.Context, a admission.Attributes, _ admission.ObjectInterfaces) error {
if a.GetResource().GroupResource() != apiextensions.Resource("customresourcedefinitions") {
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/admission/limitranger/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
PluginName = "WorkspaceLimitRanger"
)

// Register registers a plugin
// Register registers a plugin.
func Register(plugins *admission.Plugins) {
plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) {
return &workspaceLimitRanger{
Expand All @@ -52,7 +52,7 @@ func Register(plugins *admission.Plugins) {
})
}

// workspaceLimitRanger is a delegating multiplexer for the Kubernetes LimitRanger admission control plugin
// workspaceLimitRanger is a delegating multiplexer for the Kubernetes LimitRanger admission control plugin.
type workspaceLimitRanger struct {
*admission.Handler
client kcpkubernetesclient.ClusterInterface
Expand Down Expand Up @@ -84,7 +84,7 @@ func (l *workspaceLimitRanger) ValidateInitialization() error {
return nil
}

// Admit admits resources into cluster that do not violate any defined LimitRange in the namespace
// Admit admits resources into cluster that do not violate any defined LimitRange in the namespace.
func (l *workspaceLimitRanger) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
clusterName, err := genericapirequest.ClusterNameFrom(ctx)
if err != nil {
Expand All @@ -97,7 +97,7 @@ func (l *workspaceLimitRanger) Admit(ctx context.Context, a admission.Attributes
return delegate.Admit(ctx, a, o)
}

// Validate admits resources into cluster that do not violate any defined LimitRange in the namespace
// Validate admits resources into cluster that do not violate any defined LimitRange in the namespace.
func (l *workspaceLimitRanger) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
clusterName, err := genericapirequest.ClusterNameFrom(ctx)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/admission/namespacelifecycle/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import (
)

const (
// PluginName indicates the name of admission plug-in
// PluginName indicates the name of admission plug-in.
PluginName = "WorkspaceNamespaceLifecycle"
)

// Register registers a plugin
// Register registers a plugin.
func Register(plugins *admission.Plugins) {
plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) {
return newWorkspaceNamespaceLifecycle()
Expand Down Expand Up @@ -91,7 +91,7 @@ var _ = kcpinitializers.WantsKcpInformers(&workspaceNamespaceLifecycle{})
var _ = initializer.WantsExternalKubeInformerFactory(&workspaceNamespaceLifecycle{})
var _ = initializer.WantsExternalKubeClientSet(&workspaceNamespaceLifecycle{})

// Admit makes an admission decision based on the request attributes
// Admit makes an admission decision based on the request attributes.
func (l *workspaceNamespaceLifecycle) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) error {
// call legacy namespace lifecycle at first
admissionErr := l.legacyNamespaceLifecycle.Admit(ctx, a, o)
Expand Down
14 changes: 7 additions & 7 deletions pkg/admission/pathannotation/pathannotation_admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ func (p *pathAnnotationPlugin) Validate(ctx context.Context, a admission.Attribu
return nil
}

func (o *pathAnnotationPlugin) ValidateInitialization() error {
if o.logicalClusterLister == nil {
func (p *pathAnnotationPlugin) ValidateInitialization() error {
if p.logicalClusterLister == nil {
return fmt.Errorf(PluginName + " plugin needs an LogicalCluster lister")
}
return nil
}

func (o *pathAnnotationPlugin) SetKcpInformers(informers kcpinformers.SharedInformerFactory) {
func (p *pathAnnotationPlugin) SetKcpInformers(informers kcpinformers.SharedInformerFactory) {
logicalClusterReady := informers.Core().V1alpha1().LogicalClusters().Informer().HasSynced
o.SetReadyFunc(func() bool {
p.SetReadyFunc(func() bool {
return logicalClusterReady()
})
o.logicalClusterLister = informers.Core().V1alpha1().LogicalClusters().Lister()
o.getLogicalCluster = func(clusterName logicalcluster.Name, name string) (*corev1alpha1.LogicalCluster, error) {
return o.logicalClusterLister.Cluster(clusterName).Get(name)
p.logicalClusterLister = informers.Core().V1alpha1().LogicalClusters().Lister()
p.getLogicalCluster = func(clusterName logicalcluster.Name, name string) (*corev1alpha1.LogicalCluster, error) {
return p.logicalClusterLister.Cluster(clusterName).Get(name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (m *mutatingPermissionClaims) Admit(ctx context.Context, a admission.Attrib
u.SetLabels(labels)

return nil

}

func (m *mutatingPermissionClaims) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/admission/reservedcrdgroups/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type reservedCRDGroups struct {
// Ensure that the required admission interfaces are implemented.
var _ = admission.ValidationInterface(&reservedCRDGroups{})

// Ensure that CRDs in *.kcp.io group are only created inside system:system-crds workspace
// Ensure that CRDs in *.kcp.dev group are only created inside system:system-crds workspace.
func (o *reservedCRDGroups) Validate(ctx context.Context, a admission.Attributes, _ admission.ObjectInterfaces) (err error) {
if a.GetResource().GroupResource() != apiextensions.Resource("customresourcedefinitions") {
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/admission/workspacetypeexists/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (o *workspacetypeExists) resolveTypeRef(workspacePath logicalcluster.Path,

// Validate ensures that
// - has a valid type
// - has valid initializers when transitioning to initializing
// - has valid initializers when transitioning to initializing.
func (o *workspacetypeExists) Validate(ctx context.Context, a admission.Attributes, _ admission.ObjectInterfaces) (err error) {
clusterName, err := genericapirequest.ClusterNameFrom(ctx)
if err != nil {
Expand Down Expand Up @@ -385,7 +385,7 @@ func addAdditionalWorkspaceLabels(
}
}

// TODO: Move this out of admission to some shared location
// TODO: Move this out of admission to some shared location.
type TransitiveTypeResolver interface {
Resolve(t *tenancyv1alpha1.WorkspaceType) ([]*tenancyv1alpha1.WorkspaceType, error)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/authorization/bootstrap/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
SystemKcpWorkspaceAccessGroup = "system:kcp:workspace:access"
)

// ClusterRoleBindings return default rolebindings to the default roles
// ClusterRoleBindings return default rolebindings to the default roles.
func clusterRoleBindings() []rbacv1.ClusterRoleBinding {
return []rbacv1.ClusterRoleBinding{
clusterRoleBindingCustomName(rbacv1helpers.NewClusterBinding("cluster-admin").Groups(SystemKcpAdminGroup).BindingOrDie(), "system:kcp:admin:cluster-admin"),
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
type shardKey int

const (
// shardContextKey is the context key for a request
// shardContextKey is the context key for a request.
shardContextKey shardKey = iota
)

// WithShardInContext returns a context with the given shard set
// WithShardInContext returns a context with the given shard set.
func WithShardInContext(parent context.Context, shard shard.Name) context.Context {
return context.WithValue(parent, shardContextKey, shard)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/cache/client/round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ var (
//
// Example: shards/name/remainder
// Example: /shards/name/remainder
// Example: prefix/shards/name/remainder
// Example: prefix/shards/name/remainder.
shardNameRegex = regexp.MustCompile(`shards/([^/]+)/.+`)
)

// WithShardNameFromContextRoundTripper wraps an existing config's with ShardRoundTripper.
//
// Note: it is the caller responsibility to make a copy of the rest config
// Note: it is the caller responsibility to make a copy of the rest config.
func WithShardNameFromContextRoundTripper(cfg *rest.Config) *rest.Config {
cfg.Wrap(func(rt http.RoundTripper) http.RoundTripper {
return NewShardRoundTripper(rt)
Expand All @@ -56,12 +56,12 @@ func WithShardNameFromContextRoundTripper(cfg *rest.Config) *rest.Config {
// It changes the URL path to target a shard from the context.
//
// For example given "amber" shard name in the context it will change
// apis/apis.kcp.io/v1alpha1/apiexports to /shards/amber/apis/apis.kcp.io/v1alpha1/apiexports
// apis/apis.kcp.io/v1alpha1/apiexports to /shards/amber/apis/apis.kcp.io/v1alpha1/apiexports.
type ShardRoundTripper struct {
delegate http.RoundTripper
}

// NewShardRoundTripper creates a new shard aware round tripper
// NewShardRoundTripper creates a new shard aware round tripper.
func NewShardRoundTripper(delegate http.RoundTripper) *ShardRoundTripper {
return &ShardRoundTripper{
delegate: delegate,
Expand All @@ -87,7 +87,7 @@ func (c *ShardRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
return c.delegate.RoundTrip(req)
}

// generatePath formats the request path to target the specified shard
// generatePath formats the request path to target the specified shard.
func generatePath(originalPath string, shard clientshard.Name) (string, error) {
// if the originalPath already has the shard then the path was already modified and no change needed
if strings.HasPrefix(originalPath, shard.Path()) {
Expand Down Expand Up @@ -122,21 +122,21 @@ func generatePath(originalPath string, shard clientshard.Name) (string, error) {

// WithDefaultShardRoundTripper wraps an existing config's with DefaultShardRoundTripper
//
// Note: it is the caller responsibility to make a copy of the rest config
// Note: it is the caller responsibility to make a copy of the rest config.
func WithDefaultShardRoundTripper(cfg *rest.Config, shard clientshard.Name) *rest.Config {
cfg.Wrap(func(rt http.RoundTripper) http.RoundTripper {
return NewDefaultShardRoundTripper(rt, shard)
})
return cfg
}

// DefaultShardRoundTripper is a http.RoundTripper that sets a default shard name if not specified in the context
// DefaultShardRoundTripper is a http.RoundTripper that sets a default shard name if not specified in the context.
type DefaultShardRoundTripper struct {
delegate http.RoundTripper
shard clientshard.Name
}

// NewDefaultShardRoundTripper creates a new round tripper that sets a default shard name
// NewDefaultShardRoundTripper creates a new round tripper that sets a default shard name.
func NewDefaultShardRoundTripper(delegate http.RoundTripper, shard clientshard.Name) *DefaultShardRoundTripper {
return &DefaultShardRoundTripper{
delegate: delegate,
Expand All @@ -153,7 +153,7 @@ func (c *DefaultShardRoundTripper) RoundTrip(req *http.Request) (*http.Response,

// WithShardNameFromObjectRoundTripper wraps an existing config with ShardNameFromObjectRoundTripper.
//
// Note: it is the caller responsibility to make a copy of the rest config
// Note: it is the caller responsibility to make a copy of the rest config.
func WithShardNameFromObjectRoundTripper(cfg *rest.Config, requestInfoResolver func(*http.Request) (string, string, error), supportedResources ...string) *rest.Config {
cfg.Wrap(func(rt http.RoundTripper) http.RoundTripper {
return NewShardNameFromObjectRoundTripper(rt, requestInfoResolver, supportedResources...)
Expand All @@ -162,7 +162,7 @@ func WithShardNameFromObjectRoundTripper(cfg *rest.Config, requestInfoResolver f
return cfg
}

// NewShardNameFromObjectRoundTripper creates a new ShardNameFromObjectRoundTripper for the given resources
// NewShardNameFromObjectRoundTripper creates a new ShardNameFromObjectRoundTripper for the given resources.
func NewShardNameFromObjectRoundTripper(delegate http.RoundTripper, requestInfoResolver func(*http.Request) (string, string, error), supportedResources ...string) *ShardNameFromObjectRoundTripper {
return &ShardNameFromObjectRoundTripper{
delegate: delegate,
Expand Down Expand Up @@ -234,7 +234,7 @@ type CacheServiceRoundTripper struct {
delegate http.RoundTripper
}

// NewCacheServiceRoundTripper creates a new CacheServiceRoundTripper
// NewCacheServiceRoundTripper creates a new CacheServiceRoundTripper.
func NewCacheServiceRoundTripper(delegate http.RoundTripper) *CacheServiceRoundTripper {
return &CacheServiceRoundTripper{
delegate: delegate,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/client/shard/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (n Name) String() string {
return string(n)
}

// Empty returns true if the name of the shard is empty
// Empty returns true if the name of the shard is empty.
func (n Name) Empty() bool {
return n == ""
}
2 changes: 1 addition & 1 deletion pkg/cache/server/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// We use the same name as the KCP for symmetry.
var SystemCRDLogicalCluster = logicalcluster.Name("system:system-crds")

// SystemCacheServerShard holds a default shard name
// SystemCacheServerShard holds a default shard name.
const SystemCacheServerShard = "system:cache:server"

func Bootstrap(ctx context.Context, apiExtensionsClusterClient kcpapiextensionsclientset.ClusterInterface) error {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cache/server/crd_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/kcp-dev/kcp/pkg/cache/server/bootstrap"
)

// crdClusterLister is a CRD lister
// crdClusterLister is a CRD lister.
type crdClusterLister struct {
lister kcpapiextensionsv1listers.CustomResourceDefinitionClusterLister
}
Expand All @@ -48,15 +48,15 @@ func (c *crdClusterLister) Cluster(name logicalcluster.Name) kcp.ClusterAwareCRD

var _ kcp.ClusterAwareCRDClusterLister = &crdClusterLister{}

// crdLister is a CRD lister
// crdLister is a CRD lister.
type crdLister struct {
*crdClusterLister
cluster logicalcluster.Name
}

var _ kcp.ClusterAwareCRDLister = &crdLister{}

// List lists all CustomResourceDefinitions
// List lists all CustomResourceDefinitions.
func (c *crdLister) List(ctx context.Context, selector labels.Selector) ([]*apiextensionsv1.CustomResourceDefinition, error) {
// TODO: make it shard and cluster aware, for now just return what we have in the system ws
return c.lister.List(selector)
Expand All @@ -66,7 +66,7 @@ func (c *crdLister) Refresh(crd *apiextensionsv1.CustomResourceDefinition) (*api
return crd, nil
}

// Get gets a CustomResourceDefinition
// Get gets a CustomResourceDefinition.
func (c *crdLister) Get(ctx context.Context, name string) (*apiextensionsv1.CustomResourceDefinition, error) {
// TODO: make it shard and cluster aware, for now just return what we have in the system ws
return c.lister.Cluster(c.cluster).Get(name)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func init() {
//
// Note:
// not all paths require to have a valid shard name,
// as of today the following paths pass through: "/livez", "/readyz", "/healthz"
// as of today the following paths pass through: "/livez", "/readyz", "/healthz".
func WithShardScope(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if path := req.URL.Path; path == "/livez" || path == "/readyz" || path == "/healthz" {
Expand Down Expand Up @@ -122,7 +122,7 @@ func WithShardScope(handler http.Handler) http.Handler {
// WithServiceScope an HTTP filter that trims "/services/cache" prefix from the URL.
//
// for example: /services/cache/shards/amber/clusters/*/apis/apis.kcp.io/v1alpha1/apiexports
// is truncated to /shards/amber/clusters/*/apis/apis.kcp.io/v1alpha1/apiexports
// is truncated to /shards/amber/clusters/*/apis/apis.kcp.io/v1alpha1/apiexports.
func WithServiceScope(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if path := req.URL.Path; strings.HasPrefix(path, "/services/cache") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cliplugins/bind/plugin/bind_compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (o *BindComputeOptions) Validate() error {
return nil
}

// Run creates a placement in the workspace, linking to the location workspace
// Run creates a placement in the workspace, linking to the location workspace.
func (o *BindComputeOptions) Run(ctx context.Context) error {
config, err := o.ClientConfig.ClientConfig()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cliplugins/claims/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/kcp-dev/kcp/pkg/cliplugins/claims/plugin"
)

// TODO: Add examples for edit and update claims
// TODO: Add examples for edit and update claims.
var (
claimsExample = `
# Lists the permission claims and their respective status related to a specific APIBinding.
Expand All @@ -40,7 +40,6 @@ var (

// New returns a cobra.Command for claims related actions.
func New(streams genericclioptions.IOStreams) *cobra.Command {

cliName := "kubectl"
if pflag.CommandLine.Name() == "kubectl-kcp" {
cliName = "kubectl kcp"
Expand Down
4 changes: 2 additions & 2 deletions pkg/cliplugins/crd/plugin/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type SnapshotOptions struct {
OutputFormat string
}

// NewSnapshotOptions provides an instance of SnapshotOptions with default values
// NewSnapshotOptions provides an instance of SnapshotOptions with default values.
func NewSnapshotOptions(streams genericclioptions.IOStreams) *SnapshotOptions {
o := &SnapshotOptions{
Options: base.NewOptions(streams),
Expand All @@ -59,7 +59,7 @@ func NewSnapshotOptions(streams genericclioptions.IOStreams) *SnapshotOptions {
}

// BindFlags binds the arguments common to all sub-commands,
// to the corresponding main command flags
// to the corresponding main command flags.
func (o *SnapshotOptions) BindFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.Filename, "filename", "f", o.Filename, "Path to a file containing the CRD to convert to an APIResourceSchema, or - for stdin")
cmd.Flags().StringVar(&o.Prefix, "prefix", o.Prefix, "Prefix to use for the APIResourceSchema's name, before <resource>.<group>")
Expand Down
3 changes: 1 addition & 2 deletions pkg/cliplugins/workload/plugin/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (o *SyncOptions) enableSyncerForWorkspace(ctx context.Context, config *rest
return string(saTokenBytes), syncerID, syncTarget, nil
}

// mergeOwnerReference: merge a slice of ownerReference with a given ownerReferences
// mergeOwnerReference: merge a slice of ownerReference with a given ownerReferences.
func mergeOwnerReference(ownerReferences, newOwnerReferences []metav1.OwnerReference) []metav1.OwnerReference {
var merged []metav1.OwnerReference

Expand All @@ -658,7 +658,6 @@ func mergeOwnerReference(ownerReferences, newOwnerReferences []metav1.OwnerRefer
}

return merged

}

// templateInput represents the external input required to render the resources to
Expand Down
Loading

0 comments on commit 0454ea6

Please sign in to comment.