Skip to content
Open
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: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@b002b6ecfcabe6ac0e2c6cba1bcc779eb34ac51f # v9
with:
version: v2.5.0
version: v2.11.4
only-new-issues: true
args: --timeout 5m $(go list -f '{{.Dir}}/...' -m | tr '\n' ' ')
test:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ check-go-version:
exit 1; \
fi

LINTER_VERSION := 2.5.0
LINTER_VERSION := 2.11.4
LINTER_BINARY := $(BIN_DIR)/golangci-lint-$(LINTER_VERSION)

.PHONY: lint
Expand Down
3 changes: 3 additions & 0 deletions app/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (m *ManifestData) Validate() error {
}

// Kinds returns a list of ManifestKinds parsed from Versions, for compatibility with kind-centric usage
//
// Deprecated: this exists to support current workflows, and should not be used for new ones.
func (m *ManifestData) Kinds() []ManifestKind {
kinds := make(map[string]ManifestKind)
Expand Down Expand Up @@ -244,6 +245,7 @@ func (m *ManifestData) Kinds() []ManifestKind {

// ManifestKind is the manifest for a particular kind, including its Kind, Scope, and Versions.
// The values for Kind, Plural, Scope, and Conversion are hoisted up from their namesakes in Versions entries
//
// Deprecated: this is used only for the deprecated method ManifestData.Kinds()
type ManifestKind struct {
// Kind is the name of the kind
Expand All @@ -259,6 +261,7 @@ type ManifestKind struct {
}

// ManifestKindVersion is an extension on ManifestVersionKind that adds the version name
//
// Deprecated: this type if used only as part of the deprecated method ManifestData.Kinds()
type ManifestKindVersion struct {
ManifestVersionKind `json:",inline" yaml:",inline"`
Expand Down
2 changes: 1 addition & 1 deletion app/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (d *DynamicMultiRunner) HealthChecks() []health.Check {
}
func (d *DynamicMultiRunner) runTuple(tpl *dynamicMultiRunnerTuple) {
d.wg.Add(1)
ctx, cancel := context.WithCancel(d.runCtx)
ctx, cancel := context.WithCancel(d.runCtx) //nolint:gosec
tpl.cancelFunc = cancel
go func() {
err := tpl.runner.Run(ctx)
Expand Down
6 changes: 3 additions & 3 deletions cmd/grafana-app-sdk/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"os"
"regexp"
"sort"
"slices"

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
Expand Down Expand Up @@ -49,8 +49,8 @@ func getManifestLatestVersion(manifestDir string) (string, error) {
if len(versions) == 0 {
return "", errNoVersions
}
sort.Slice(versions, func(i, j int) bool {
return k8sversion.CompareKubeAwareVersionStrings(versions[i], versions[j]) > 0
slices.SortFunc(versions, func(a, b string) int {
return -k8sversion.CompareKubeAwareVersionStrings(a, b)
})
return versions[0], nil
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/grafana-app-sdk/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func projectAddKindCUE(srcPath, manifestFileName, fieldName, kindName, version,
if err != nil {
return nil, err
}
files := make(codejen.Files, 2)
files := make(codejen.Files, 2) //nolint:prealloc
files[0] = codejen.File{
RelativePath: fmt.Sprintf("%s.cue", strings.ToLower(kindName)),
Data: buf.Bytes(),
Expand Down Expand Up @@ -856,19 +856,19 @@ func moveFiles(srcDir, destDir string) error {
if err != nil {
return err
}
if err = os.Remove(path); err != nil {
if err = os.Remove(path); err != nil { //nolint:gosec
return err
}
return fs.SkipDir
}
err = os.Rename(path, filepath.Join(destDir, d.Name()))
err = os.Rename(path, filepath.Join(destDir, d.Name())) //nolint:gosec
if err != nil {
return err
}
return fs.SkipDir
}

return os.Rename(path, filepath.Join(destDir, d.Name()))
return os.Rename(path, filepath.Join(destDir, d.Name())) //nolint:gosec
})
}

Expand Down
5 changes: 3 additions & 2 deletions codegen/jennies/gotypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ type goTypesGenerateFilesConfig struct {
//nolint:goconst
func (g *GoTypes) generateFilesAtDepth(v cue.Value, schemaPath cue.Path, currDepth int, cfg goTypesGenerateFilesConfig) (codejen.Files, error) {
if currDepth == g.Depth {
fieldName := make([]string, 0)
for _, s := range TrimPathPrefix(v.Path(), schemaPath).Selectors() {
selectors := TrimPathPrefix(v.Path(), schemaPath).Selectors()
fieldName := make([]string, 0, len(selectors))
for _, s := range selectors {
fieldName = append(fieldName, s.String())
}
exclude := false
Expand Down
9 changes: 4 additions & 5 deletions codegen/jennies/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"maps"
"path/filepath"
"slices"
"sort"
"strings"

"cuelang.org/go/cue"
Expand Down Expand Up @@ -90,7 +89,7 @@ func (m *ManifestGenerator) Generate(appManifest codegen.AppManifest) (codejen.F
}
output["spec"] = manifestSpec

files := make(codejen.Files, 0)
files := make(codejen.Files, 0, 1)
out, err := m.Encoder(output)
if err != nil {
return nil, err
Expand Down Expand Up @@ -160,7 +159,7 @@ func (g *ManifestGoGenerator) Generate(appManifest codegen.AppManifest) (codejen
}
}

files := make(codejen.Files, 0)
files := make(codejen.Files, 0, 1)
files = append(files, codejen.File{
Data: formatted,
RelativePath: filepath.Join(g.DestinationPath, fmt.Sprintf("%s_manifest.go", appManifest.Properties().Group)),
Expand Down Expand Up @@ -415,7 +414,7 @@ func buildDefaultManifestRolesAndBindings(m codegen.AppManifest) (map[string]cod
for k := range kindListMap {
kindList = append(kindList, k)
}
sort.Strings(kindList)
slices.Sort(kindList)
allKindsDesc := joinKindNames(kindList)
roles := map[string]codegen.AppManifestPropertiesRole{
readerKey: {
Expand Down Expand Up @@ -766,7 +765,7 @@ func cueSchemaToParameters(v cue.Value) ([]*spec3.Parameter, error) {
for name := range schemaProps.Properties {
paramNames = append(paramNames, name)
}
sort.Strings(paramNames)
slices.Sort(paramNames)

parameters := make([]*spec3.Parameter, 0, len(paramNames))
// Iterate through sorted names
Expand Down
5 changes: 3 additions & 2 deletions codegen/jennies/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ func (j TypeScriptTypes) generateFiles(version string, kind *codegen.VersionedKi

func (j TypeScriptTypes) generateFilesAtDepth(v cue.Value, version string, vk *codegen.VersionedKind, currDepth int, pathPrefix string, prefix string) (codejen.Files, error) {
if currDepth == j.Depth {
fieldName := make([]string, 0)
for _, s := range TrimPathPrefix(v.Path(), vk.Schema.Path()).Selectors() {
selectors := TrimPathPrefix(v.Path(), vk.Schema.Path()).Selectors()
fieldName := make([]string, 0, len(selectors))
for _, s := range selectors {
fieldName = append(fieldName, s.String())
}
tsBytes, err := generateTypescriptBytes(v, ToPackageName(version), exportField(strings.Join(fieldName, "")), cog.TypescriptConfig{
Expand Down
3 changes: 2 additions & 1 deletion codegen/jennies/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ func ToPackageName(input string) string {
// generated code should be grouped by kind or by GroupVersion.
// When groupByKind is true, the path will be <kind>/<version>.
// When groupByKind is false, the path will be <group>/<version>.
//
// Deprecated: Use GetGeneratedGoTypePath instead.
//
//nolint:revive
//nolint:revive,staticcheck
func GetGeneratedPath(groupByKind bool, kind codegen.Kind, version string) string {
if groupByKind {
return filepath.Join(ToPackageName(kind.Properties().MachineName), ToPackageName(version))
Expand Down
1 change: 1 addition & 0 deletions codegen/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// Kind is a common interface declaration for code generation.
// Any type parser should be able to parse a kind into this definition to supply
// to various common Jennies in the codegen package.
//
// Deprecated: use AppManifest instead
type Kind interface {
Name() string
Expand Down
5 changes: 3 additions & 2 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ type SchemaMetadataSelectableField struct {
}

func (SchemaMetadata) ToObjectPath(s string) string {
parts := make([]string, 0)
if len(s) > 0 && s[0] == '.' {
s = s[1:]
}
for i, part := range strings.Split(s, ".") {
split := strings.Split(s, ".")
parts := make([]string, 0, len(split))
for i, part := range split {
if i == 0 && part == "metadata" {
part = "ObjectMeta"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/resource/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func useStore(generator resource.ClientGenerator) {
// The trade-off is that the SimpleStore can only be tied to one specific Schema.
func useSimpleStore(generator resource.ClientGenerator) {
// SimpleStore can only manipulate one Custom Resource type, but allows for direct manipulation of the Spec object
simpleStore, _ := resource.NewSimpleStore[Obj2Spec](obj2Kind, generator)
simpleStore, _ := resource.NewSimpleStore[Obj2Spec](obj2Kind, generator) //nolint:staticcheck
added, err := simpleStore.Add(context.TODO(), resource.Identifier{
Namespace: "default",
Name: "example-2",
Expand Down
2 changes: 1 addition & 1 deletion health/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c CheckStatus) String() string {
b := strings.Builder{}

for _, result := range c.Results {
b.WriteString(fmt.Sprintf("%s\n", result.String())) //nolint:revive
fmt.Fprintf(&b, "%s\n", result.String()) //nolint:revive
}
return b.String()
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/apiserver/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (*SubresourceConnector) Destroy() {
}

func (r *SubresourceConnector) ConnectMethods() []string {
methods := make([]string, 0)
methods := make([]string, 0, len(r.Methods))
for method := range r.Methods {
methods = append(methods, method)
}
Expand Down
15 changes: 7 additions & 8 deletions k8s/apiserver/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"reflect"
"regexp"
"slices"
"sort"
"strings"
"sync"

Expand Down Expand Up @@ -305,14 +304,14 @@ func (r *defaultInstaller) AddToScheme(scheme *runtime.Scheme) error {
}
}

sort.Slice(groupVersions, func(i, j int) bool {
if groupVersions[i].Version == r.appConfig.ManifestData.PreferredVersion {
return true
slices.SortFunc(groupVersions, func(a, b schema.GroupVersion) int {
if a.Version == r.appConfig.ManifestData.PreferredVersion {
return -1
}
if groupVersions[j].Version == r.appConfig.ManifestData.PreferredVersion {
return false
if b.Version == r.appConfig.ManifestData.PreferredVersion {
return 1
}
return version.CompareKubeAwareVersionStrings(groupVersions[i].Version, groupVersions[j].Version) > 0
return -version.CompareKubeAwareVersionStrings(a.Version, b.Version)
})
if len(groupVersions) > 0 {
if err = scheme.SetVersionPriority(groupVersions...); err != nil {
Expand Down Expand Up @@ -798,7 +797,7 @@ func (r *defaultInstaller) App() (app.App, error) {
}

func (r *defaultInstaller) GroupVersions() []schema.GroupVersion {
groupVersions := make([]schema.GroupVersion, 0)
groupVersions := make([]schema.GroupVersion, 0, len(r.appConfig.ManifestData.Versions))
for _, gv := range r.appConfig.ManifestData.Versions {
groupVersions = append(groupVersions, schema.GroupVersion{Group: r.appConfig.ManifestData.Group, Version: gv.Name})
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/apiserver/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
}

func (o *Options) Validate() error {
errs := []error{}
errs := []error{} //nolint:prealloc
errs = append(errs, o.RecommendedOptions.Validate()...)
return utilerrors.NewAggregate(errs)
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/apiserver/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (g *genericSubresourceStrategy) NamespaceScoped() bool {
}

func (g *genericSubresourceStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
paths := make([]fieldpath.Path, 0)
paths := make([]fieldpath.Path, 0, len(g.resetFields))
for _, path := range g.resetFields {
paths = append(paths, fieldpath.MakePathOrDie(path))
}
Expand Down
6 changes: 3 additions & 3 deletions k8s/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"net/http"
"reflect"
"sort"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -109,8 +109,8 @@ func (m *ResourceManager) RegisterSchema(ctx context.Context, schema resource.Sc
existing.Spec.Versions = append(existing.Spec.Versions, toVersion(schema))
}
// Make sure the latest is the one with storage = true
sort.Slice(existing.Spec.Versions, func(i, j int) bool {
return existing.Spec.Versions[i].Name > existing.Spec.Versions[j].Name
slices.SortFunc(existing.Spec.Versions, func(a, b CustomResourceDefinitionSpecVersion) int {
return strings.Compare(b.Name, a.Name)
})
for i := 0; i < len(existing.Spec.Versions); i++ {
existing.Spec.Versions[i].Storage = false
Expand Down
2 changes: 1 addition & 1 deletion k8s/negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type KindNegotiatedSerializer struct {

// SupportedMediaTypes returns the JSON supported media type with a GenericJSONDecoder and kubernetes JSON Framer.
func (k *KindNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInfo {
supported := make([]runtime.SerializerInfo, 0)
supported := make([]runtime.SerializerInfo, 0, len(k.Kind.Codecs))
for encoding, codec := range k.Kind.Codecs {
serializer := &CodecDecoder{
SampleObject: k.Kind.ZeroValue(),
Expand Down
1 change: 1 addition & 0 deletions operator/informer_concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ConcurrentInformerOptions struct {
}

// NewConcurrentInformer creates a new ConcurrentInformer wrapping the provided Informer.
//
// Deprecated: Use NewConcurrentInformerFromOptions instead, which accepts InformerOptions.
func NewConcurrentInformer(inf Informer, opts ConcurrentInformerOptions) (
*ConcurrentInformer, error) {
Expand Down
2 changes: 1 addition & 1 deletion operator/retry_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewRetryProcessor(cfg RetryProcessorConfig, retryPolicyFn func() RetryPolic

return &defaultRetryProcessor{
workers: workers,
workerCount: uint64(cfg.WorkerPoolSize),
workerCount: uint64(cfg.WorkerPoolSize), //nolint:gosec
retryPolicyFn: retryPolicyFn,
}
}
Expand Down
3 changes: 3 additions & 0 deletions resource/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type SelectableField struct {

// SchemaGroup represents a group of Schemas. The interface does not require commonality between Schemas,
// but an implementation may require a relationship.
//
// Deprecated: Kinds are now favored over Schemas for usage.
type SchemaGroup interface {
Schemas() []Schema
Expand Down Expand Up @@ -112,6 +113,7 @@ func (s *SimpleSchema) SelectableFields() []SelectableField {
}

// SimpleSchemaGroup collects schemas with the same group and version
//
// Deprecated: Kinds are now favored over Schemas for usage. Use KindGroup instead.
type SimpleSchemaGroup struct {
group string
Expand Down Expand Up @@ -193,6 +195,7 @@ func NewSimpleSchema(group, version string, zeroVal Object, zeroList ListObject,
}

// NewSimpleSchemaGroup returns a new SimpleSchemaGroup
//
// Deprecated: Kinds are now favored over Schemas for usage. Use KindGroup instead.
func NewSimpleSchemaGroup(group, version string) *SimpleSchemaGroup {
return &SimpleSchemaGroup{
Expand Down
2 changes: 2 additions & 0 deletions resource/simplestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func WithResourceVersion(resourceVersion string) ObjectMetadataOption {
// allowing the user to work with the actual type in the Schema Object's spec,
// without casting in and out of the Object interface.
// It should be instantiated with NewSimpleStore.
//
// Deprecated: prefer using TypedStore instead
type SimpleStore[SpecType any] struct {
client Client
Expand All @@ -61,6 +62,7 @@ type SimpleStore[SpecType any] struct {
// It will error if the type of the Schema.ZeroValue().SpecObject() does not match the provided SpecType.
// It will also error if a client cannot be created from the generator, as unlike Store, the client is generated once
// and reused for all subsequent calls.
//
// Deprecated: prefer using TypedStore instead
func NewSimpleStore[SpecType any](kind Kind, generator ClientGenerator) (*SimpleStore[SpecType], error) {
if reflect.TypeOf(kind.Schema.ZeroValue().GetSpec()) != reflect.TypeOf(new(SpecType)).Elem() {
Expand Down
4 changes: 2 additions & 2 deletions simple/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (a *App) ValidateManifest(manifest app.ManifestData) error {

// ManagedKinds returns a slice of all Kinds managed by this App
func (a *App) ManagedKinds() []resource.Kind {
kinds := make([]resource.Kind, 0)
kinds := make([]resource.Kind, 0, len(a.kinds))
for _, k := range a.kinds {
kinds = append(kinds, k.Kind)
}
Expand Down Expand Up @@ -548,7 +548,7 @@ func (a *App) PrometheusCollectors() []prometheus.Collector {
}

func (a *App) HealthChecks() []health.Check {
checks := make([]health.Check, 0)
checks := make([]health.Check, 0) //nolint:prealloc

checks = append(checks, a.runner.HealthChecks()...)
checks = append(checks, a.informerController.HealthChecks()...)
Expand Down
Loading
Loading