diff --git a/.golangci.yml b/.golangci.yml index 53c9dc6c40d..a09c7614081 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,38 +1,46 @@ -run: - timeout: 5m +version: "2" linters: enable: - - nakedret - - misspell - - ineffassign + - dupl - ginkgolinter - goconst - - goimports - - errcheck - - dupl - - unparam - - revive - - staticcheck - - unused - - gosimple - - unconvert - gocyclo - gosec -issues: - exclude-rules: - # Allow dot imports for ginkgo and gomega - - source: ginkgo|gomega - linters: - - revive - text: "should not use dot imports" - - - linters: - - gosec - # these exclusion rules are for current failures in the code base for gosec which are - # excluded for future PRs which include: - # G110: Potential DoS vulnerability via decompression bomb - # G204: Audit use of command execution - # G306: Poor file permissions used when writing to a new file - # G404: Insecure random number source (rand) - # G601: Implicit memory aliasing of items from a range statement - text: "G110|G601|G404|G204|G306" + - misspell + - nakedret + - revive + - unconvert + - unparam + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - revive + text: should not use dot imports + source: ginkgo|gomega + - linters: + - gosec + text: G110|G601|G404|G204|G306 + paths: + - third_party$ + - builtin$ + - examples$ + settings: + revive: + rules: + - name: var-naming + disabled: true +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 14a60909207..c3928ed8e45 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ fix: ## Fixup files in the repo. .PHONY: setup-lint setup-lint: ## Setup the lint - $(SCRIPTS_DIR)/fetch golangci-lint 1.64.8 + $(SCRIPTS_DIR)/fetch golangci-lint 2.6.2 .PHONY: lint lint: setup-lint ## Run the lint check diff --git a/hack/generate/cli-doc/gen-cli-doc.go b/hack/generate/cli-doc/gen-cli-doc.go index 00ba114f410..6d1d0f75d9d 100644 --- a/hack/generate/cli-doc/gen-cli-doc.go +++ b/hack/generate/cli-doc/gen-cli-doc.go @@ -82,7 +82,7 @@ func recreateDocDir(rootCmd *cobra.Command, docPath string) { filePrepender := func(filename string) string { name := filepath.Base(filename) base := strings.TrimSuffix(name, path.Ext(name)) - return fmt.Sprintf(fmTemplate, strings.Replace(base, "_", " ", -1)) + return fmt.Sprintf(fmTemplate, strings.ReplaceAll(base, "_", " ")) } linkHandler := func(name string) string { base := strings.TrimSuffix(name, path.Ext(name)) diff --git a/hack/generate/samples/internal/go/memcached-with-customization/e2e_test_code.go b/hack/generate/samples/internal/go/memcached-with-customization/e2e_test_code.go index ab61b70c178..912ce203176 100644 --- a/hack/generate/samples/internal/go/memcached-with-customization/e2e_test_code.go +++ b/hack/generate/samples/internal/go/memcached-with-customization/e2e_test_code.go @@ -23,7 +23,7 @@ func (mh *Memcached) implementingE2ETests() { testUtilsDir := filepath.Join(testDir, "utils") // Following we will create the directories - // Create the golang files with a string replace inside onlu + // Create the golang files with a string replace inside only // Then, replace the string replace by the template contents mh.createDirs(testDir, testE2eDir, testUtilsDir) mh.createGoFiles(testE2eDir, testUtilsDir) diff --git a/internal/cmd/operator-sdk/generate/bundle/bundle.go b/internal/cmd/operator-sdk/generate/bundle/bundle.go index cd772f25bae..36e2ca54760 100644 --- a/internal/cmd/operator-sdk/generate/bundle/bundle.go +++ b/internal/cmd/operator-sdk/generate/bundle/bundle.go @@ -134,7 +134,7 @@ func (c bundleCmd) validateManifests() (err error) { isInputDir := c.inputDir != "" isLegacyDirs := c.deployDir != "" || c.crdsDir != "" switch { - case !(isPipeReader || isInputDir || isLegacyDirs): + case !isPipeReader && !isInputDir && !isLegacyDirs: return errors.New("one of stdin, --input-dir, or --deploy-dir (and optionally --crds-dir) must be set") case isPipeReader && (isInputDir || isLegacyDirs): return errors.New("none of --input-dir, --deploy-dir, or --crds-dir may be set if reading from stdin") diff --git a/internal/cmd/operator-sdk/generate/bundle/cmd.go b/internal/cmd/operator-sdk/generate/bundle/cmd.go index e4803a962b5..0638de6c6d7 100644 --- a/internal/cmd/operator-sdk/generate/bundle/cmd.go +++ b/internal/cmd/operator-sdk/generate/bundle/cmd.go @@ -147,7 +147,7 @@ func (c *bundleCmd) addFlagsTo(fs *pflag.FlagSet) { } func (c bundleCmd) println(a ...interface{}) { - if !(c.quiet || c.stdout) { + if !c.quiet && !c.stdout { fmt.Println(a...) } } diff --git a/internal/cmd/operator-sdk/generate/internal/relatedimages.go b/internal/cmd/operator-sdk/generate/internal/relatedimages.go index 4cea2a88b26..12468f803c6 100644 --- a/internal/cmd/operator-sdk/generate/internal/relatedimages.go +++ b/internal/cmd/operator-sdk/generate/internal/relatedimages.go @@ -147,5 +147,5 @@ func (c *relatedImageCollector) collectedRelatedImages() []operatorsv1alpha1.Rel // formatName transforms RELATED_IMAGE_This_IS_a_cool_image to this-is-a-cool-image func (c *relatedImageCollector) formatName(name string) string { - return strings.ToLower(strings.Replace(strings.TrimPrefix(name, relatedImagePrefix), "_", "-", -1)) + return strings.ToLower(strings.ReplaceAll(strings.TrimPrefix(name, relatedImagePrefix), "_", "-")) } diff --git a/internal/cmd/operator-sdk/generate/packagemanifests/cmd.go b/internal/cmd/operator-sdk/generate/packagemanifests/cmd.go index 78c2534c32a..3f0d3a96a83 100644 --- a/internal/cmd/operator-sdk/generate/packagemanifests/cmd.go +++ b/internal/cmd/operator-sdk/generate/packagemanifests/cmd.go @@ -112,7 +112,7 @@ func (c *packagemanifestsCmd) addFlagsTo(fs *pflag.FlagSet) { } func (c packagemanifestsCmd) println(a ...interface{}) { - if !(c.quiet || c.stdout) { + if !c.quiet && !c.stdout { fmt.Println(a...) } } diff --git a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go b/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go index de684c661f2..9434b23ad0d 100644 --- a/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go +++ b/internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go @@ -33,7 +33,7 @@ var _ = Describe("Running pkgmanToBundle command", func() { var ( p pkgManToBundleCmd pkgManDir string - outputDir string = "bundle-output" + outputDir = "bundle-output" ) BeforeEach(func() { diff --git a/internal/cmd/operator-sdk/scorecard/cmd.go b/internal/cmd/operator-sdk/scorecard/cmd.go index a654c9a69dd..fa44d8e6293 100644 --- a/internal/cmd/operator-sdk/scorecard/cmd.go +++ b/internal/cmd/operator-sdk/scorecard/cmd.go @@ -194,9 +194,10 @@ func (c *scorecardCmd) run() (err error) { } podSecFlag := true - if c.podSecurity == "restricted" { + switch c.podSecurity { + case "restricted": podSecFlag = true - } else if c.podSecurity == "legacy" { + case "legacy": podSecFlag = false } diff --git a/internal/generate/clusterserviceversion/bases/clusterserviceversion.go b/internal/generate/clusterserviceversion/bases/clusterserviceversion.go index c5f201bbc13..8d4554e32f1 100644 --- a/internal/generate/clusterserviceversion/bases/clusterserviceversion.go +++ b/internal/generate/clusterserviceversion/bases/clusterserviceversion.go @@ -69,7 +69,7 @@ func (b ClusterServiceVersion) GetBase() (base *v1alpha1.ClusterServiceVersion, // Auto-migrate bases with names matching ".vX.Y.Z", which // may cause problems with the CSV validator. if base.GetName() == b.OperatorName+".vX.Y.Z" { - base.SetName(fmt.Sprintf("%s.v%s", b.OperatorName, base.Spec.Version.Version.String())) + base.SetName(fmt.Sprintf("%s.v%s", b.OperatorName, base.Spec.Version.String())) } } else { b.setDefaults() diff --git a/internal/generate/clusterserviceversion/clusterserviceversion.go b/internal/generate/clusterserviceversion/clusterserviceversion.go index 6e66aaa0f8c..17ec47bb76b 100644 --- a/internal/generate/clusterserviceversion/clusterserviceversion.go +++ b/internal/generate/clusterserviceversion/clusterserviceversion.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/blang/semver/v4" - "github.com/operator-framework/api/pkg/operators/v1alpha1" operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/operator-framework/operator-registry/pkg/lib/bundle" @@ -128,7 +127,7 @@ func (g *Generator) Generate(opts ...Option) (err error) { } // setSDKAnnotations adds SDK metric labels to the base if they do not exist. -func (g Generator) setAnnotations(csv *v1alpha1.ClusterServiceVersion) { +func (g Generator) setAnnotations(csv *operatorsv1alpha1.ClusterServiceVersion) { annotations := csv.GetAnnotations() if annotations == nil { annotations = make(map[string]string) diff --git a/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go b/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go index 98d7540705d..e0a33571eca 100644 --- a/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go +++ b/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go @@ -64,7 +64,7 @@ func apply(c *collector.Manifests, csv *operatorsv1alpha1.ClusterServiceVersion, csv.Spec.InstallStrategy = strategy // Update createdAt timestamp annotation since the CSV has been updated. - csv.ObjectMeta.Annotations["createdAt"] = time.Now().UTC().Format(time.RFC3339) + csv.Annotations["createdAt"] = time.Now().UTC().Format(time.RFC3339) applyCustomResourceDefinitions(c, csv) if err := applyCustomResources(c, csv); err != nil { diff --git a/internal/generate/clusterserviceversion/clusterserviceversion_updaters_test.go b/internal/generate/clusterserviceversion/clusterserviceversion_updaters_test.go index 212e32a6e0d..773ba5bffb4 100644 --- a/internal/generate/clusterserviceversion/clusterserviceversion_updaters_test.go +++ b/internal/generate/clusterserviceversion/clusterserviceversion_updaters_test.go @@ -467,7 +467,7 @@ func newDeploymentWithServiceAccount(name, saName string) (d appsv1.Deployment) // newDeploymentWithLabels returns a deployment with the given labels func newDeploymentWithLabels(name string, labels labels.Set) appsv1.Deployment { d := newDeployment(name, nil) - d.ObjectMeta.Labels = labels + d.Labels = labels return d } diff --git a/internal/helm/controller/reconcile.go b/internal/helm/controller/reconcile.go index 300e72ee33a..c8122899aa5 100644 --- a/internal/helm/controller/reconcile.go +++ b/internal/helm/controller/reconcile.go @@ -121,8 +121,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile reconcileResult.RequeueAfter = finalReconcilePeriod if o.GetDeletionTimestamp() != nil { - if !(controllerutil.ContainsFinalizer(o, uninstallFinalizer) || - controllerutil.ContainsFinalizer(o, uninstallFinalizerLegacy)) { + if !controllerutil.ContainsFinalizer(o, uninstallFinalizer) && !controllerutil.ContainsFinalizer(o, uninstallFinalizerLegacy) { log.Info("Resource is terminated, skipping reconciliation") return reconcile.Result{}, nil @@ -296,8 +295,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile return reconcileResult, err } - if !(controllerutil.ContainsFinalizer(o, uninstallFinalizer) || - controllerutil.ContainsFinalizer(o, uninstallFinalizerLegacy)) { + if !controllerutil.ContainsFinalizer(o, uninstallFinalizer) && !controllerutil.ContainsFinalizer(o, uninstallFinalizerLegacy) { log.V(1).Info("Adding finalizer", "finalizer", uninstallFinalizer) controllerutil.AddFinalizer(o, uninstallFinalizer) diff --git a/internal/helm/release/manager.go b/internal/helm/release/manager.go index cc893dfe6da..d5926632924 100644 --- a/internal/helm/release/manager.go +++ b/internal/helm/release/manager.go @@ -374,7 +374,7 @@ func createJSONMergePatch(existingJSON, expectedJSON []byte) ([]byte, error) { // All "add" operations without a value (null) can be ignored patchOps := make([]jsonpatch.JsonPatchOperation, 0) for _, op := range ops { - if op.Operation != "remove" && !(op.Operation == "add" && op.Value == nil) { + if op.Operation != "remove" && (op.Operation != "add" || op.Value != nil) { patchOps = append(patchOps, op) } } diff --git a/internal/olm/fbcutil/util.go b/internal/olm/fbcutil/util.go index 7e4a0ca42ea..7579940b85a 100644 --- a/internal/olm/fbcutil/util.go +++ b/internal/olm/fbcutil/util.go @@ -25,7 +25,6 @@ import ( "strings" "github.com/operator-framework/operator-registry/alpha/action" - "github.com/operator-framework/operator-registry/alpha/declcfg" declarativeconfig "github.com/operator-framework/operator-registry/alpha/declcfg" "github.com/operator-framework/operator-registry/pkg/containertools" "github.com/operator-framework/operator-registry/pkg/image/containerdregistry" @@ -55,9 +54,9 @@ const ( // This struct only consists of one Package, Bundle, and Channel blob. It is used to // represent the bundle image in the File-Based Catalog format. type BundleDeclcfg struct { - Package declcfg.Package - Channel declcfg.Channel - Bundle declcfg.Bundle + Package declarativeconfig.Package + Channel declarativeconfig.Channel + Bundle declarativeconfig.Bundle } // FBCContext is a struct that stores all the required information while constructing diff --git a/internal/olm/operator/bundle/install.go b/internal/olm/operator/bundle/install.go index bee9ce98c60..7b66f063e33 100644 --- a/internal/olm/operator/bundle/install.go +++ b/internal/olm/operator/bundle/install.go @@ -95,15 +95,15 @@ func (i *Install) setup(ctx context.Context) error { } // check if index image adopts File-Based Catalog or SQLite index image format - isFBCImage, err := fbcutil.IsFBC(ctx, i.IndexImageCatalogCreator.IndexImage) + isFBCImage, err := fbcutil.IsFBC(ctx, i.IndexImage) if err != nil { - return fmt.Errorf("error determining whether index %q is FBC or SQLite based: %v", i.IndexImageCatalogCreator.IndexImage, err) + return fmt.Errorf("error determining whether index %q is FBC or SQLite based: %v", i.IndexImage, err) } - i.IndexImageCatalogCreator.HasFBCLabel = isFBCImage + i.HasFBCLabel = isFBCImage // set the field to true if FBC label is on the image or for a default index image. - if i.IndexImageCatalogCreator.HasFBCLabel { - if i.IndexImageCatalogCreator.BundleAddMode != "" { + if i.HasFBCLabel { + if i.BundleAddMode != "" { return fmt.Errorf("specifying the bundle add mode is not supported for File-Based Catalog bundles and index images") } @@ -122,26 +122,26 @@ func (i *Install) setup(ctx context.Context) error { f.ChannelName = fbcutil.DefaultChannel // generate an fbc if an fbc specific label is found on the image or for a default index image. - content, err := generateFBCContent(ctx, f, i.BundleImage, i.IndexImageCatalogCreator.IndexImage) + content, err := generateFBCContent(ctx, f, i.BundleImage, i.IndexImage) if err != nil { return fmt.Errorf("error generating File-Based Catalog with bundle %q: %v", i.BundleImage, err) } - i.IndexImageCatalogCreator.FBCContent = content - i.OperatorInstaller.Channel = fbcutil.DefaultChannel + i.FBCContent = content + i.Channel = fbcutil.DefaultChannel } else { // index image is of the SQLite index format. - deprecationMsg := fmt.Sprintf("%s is a SQLite index image. SQLite based index images are being deprecated and will be removed in a future release, please migrate your catalogs to the new File-Based Catalog format", i.IndexImageCatalogCreator.IndexImage) + deprecationMsg := fmt.Sprintf("%s is a SQLite index image. SQLite based index images are being deprecated and will be removed in a future release, please migrate your catalogs to the new File-Based Catalog format", i.IndexImage) log.Warn(deprecationMsg) // set the channel the old way - i.OperatorInstaller.Channel = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0] + i.Channel = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0] } i.OperatorInstaller.PackageName = labels[registrybundle.PackageLabel] - i.OperatorInstaller.CatalogSourceName = operator.CatalogNameForPackage(i.OperatorInstaller.PackageName) - i.OperatorInstaller.StartingCSV = csv.Name - i.OperatorInstaller.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes) + i.CatalogSourceName = operator.CatalogNameForPackage(i.OperatorInstaller.PackageName) + i.StartingCSV = csv.Name + i.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes) i.IndexImageCatalogCreator.PackageName = i.OperatorInstaller.PackageName i.IndexImageCatalogCreator.BundleImage = i.BundleImage diff --git a/internal/olm/operator/bundleupgrade/upgrade.go b/internal/olm/operator/bundleupgrade/upgrade.go index 9896048fc31..afd9c871863 100644 --- a/internal/olm/operator/bundleupgrade/upgrade.go +++ b/internal/olm/operator/bundleupgrade/upgrade.go @@ -75,15 +75,15 @@ func (u *Upgrade) setup(ctx context.Context) error { csv := bundle.CSV u.OperatorInstaller.PackageName = labels[registrybundle.PackageLabel] - u.OperatorInstaller.CatalogSourceName = operator.CatalogNameForPackage(u.OperatorInstaller.PackageName) - u.OperatorInstaller.StartingCSV = csv.Name - u.OperatorInstaller.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes) + u.CatalogSourceName = operator.CatalogNameForPackage(u.OperatorInstaller.PackageName) + u.StartingCSV = csv.Name + u.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes) // Since an existing CatalogSource will have an annotation containing the existing index image, // defer defaulting the bundle add mode to after the existing CatalogSource is retrieved. u.IndexImageCatalogCreator.PackageName = u.OperatorInstaller.PackageName u.IndexImageCatalogCreator.BundleImage = u.BundleImage - u.IndexImageCatalogCreator.IndexImage = fbcutil.DefaultIndexImage + u.IndexImage = fbcutil.DefaultIndexImage return nil } diff --git a/internal/olm/operator/packagemanifests/install.go b/internal/olm/operator/packagemanifests/install.go index e4fd513337a..18ae836fd29 100644 --- a/internal/olm/operator/packagemanifests/install.go +++ b/internal/olm/operator/packagemanifests/install.go @@ -43,7 +43,7 @@ func NewInstall(cfg *operator.Configuration) Install { OperatorInstaller: registry.NewOperatorInstaller(cfg), cfg: cfg, } - i.OperatorInstaller.CatalogCreator = i.ConfigMapCatalogCreator + i.CatalogCreator = i.ConfigMapCatalogCreator return i } @@ -73,22 +73,22 @@ func (i *Install) setup() error { return err } - i.OperatorInstaller.PackageName = pkg.PackageName - i.OperatorInstaller.CatalogSourceName = operator.CatalogNameForPackage(i.OperatorInstaller.PackageName) - i.OperatorInstaller.StartingCSV = bundle.CSV.GetName() - i.OperatorInstaller.SupportedInstallModes = operator.GetSupportedInstallModes(bundle.CSV.Spec.InstallModes) + i.PackageName = pkg.PackageName + i.CatalogSourceName = operator.CatalogNameForPackage(i.PackageName) + i.StartingCSV = bundle.CSV.GetName() + i.SupportedInstallModes = operator.GetSupportedInstallModes(bundle.CSV.Spec.InstallModes) - if i.OperatorInstaller.SupportedInstallModes.Len() == 0 { + if i.SupportedInstallModes.Len() == 0 { return fmt.Errorf("operator %q is not installable: no supported install modes", bundle.CSV.GetName()) } - i.OperatorInstaller.Channel, err = getChannelForCSVName(pkg, i.OperatorInstaller.StartingCSV) + i.Channel, err = getChannelForCSVName(pkg, i.StartingCSV) if err != nil { return err } - i.ConfigMapCatalogCreator.Package = pkg - i.ConfigMapCatalogCreator.Bundles = bundles + i.Package = pkg + i.Bundles = bundles return nil } diff --git a/internal/olm/operator/registry/configmap/deployment_test.go b/internal/olm/operator/registry/configmap/deployment_test.go index 31dade87135..276f7e479db 100644 --- a/internal/olm/operator/registry/configmap/deployment_test.go +++ b/internal/olm/operator/registry/configmap/deployment_test.go @@ -247,7 +247,7 @@ var _ = Describe("Deployment", func() { }) It("should return a dployment for a custom made function", func() { f := func(d *appsv1.Deployment) { - d.ObjectMeta.Namespace = "testns2" + d.Namespace = "testns2" } f(dep) @@ -258,7 +258,7 @@ var _ = Describe("Deployment", func() { f1(dep) f2 := func(d *appsv1.Deployment) { - d.ObjectMeta.Namespace = "testns2" + d.Namespace = "testns2" } f2(dep) diff --git a/internal/olm/operator/registry/configmap/registry_test.go b/internal/olm/operator/registry/configmap/registry_test.go index d2ba484dfae..ff314fe8c90 100644 --- a/internal/olm/operator/registry/configmap/registry_test.go +++ b/internal/olm/operator/registry/configmap/registry_test.go @@ -22,7 +22,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/operator-framework/api/pkg/lib/version" - "github.com/operator-framework/api/pkg/manifests" apimanifests "github.com/operator-framework/api/pkg/manifests" "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/operator-framework/operator-sdk/internal/olm/client" @@ -72,10 +71,10 @@ var _ = Describe("Registry", func() { newRegistryService("pkgName", "testns"), ).Build() rr := RegistryResources{ - Pkg: &manifests.PackageManifest{ + Pkg: &apimanifests.PackageManifest{ PackageName: "pkgName", - Channels: []manifests.PackageChannel{ - manifests.PackageChannel{ + Channels: []apimanifests.PackageChannel{ + apimanifests.PackageChannel{ Name: "pkgChannelTest", }, }, @@ -133,10 +132,10 @@ var _ = Describe("Registry", func() { newRegistryService("pkgName", testns), ).Build() rr = RegistryResources{ - Pkg: &manifests.PackageManifest{ + Pkg: &apimanifests.PackageManifest{ PackageName: "pkgName", - Channels: []manifests.PackageChannel{ - manifests.PackageChannel{ + Channels: []apimanifests.PackageChannel{ + apimanifests.PackageChannel{ Name: "pkgChannelTest", }, }, @@ -213,10 +212,10 @@ var _ = Describe("Registry", func() { newRegistryService("pkgName", testns), ).Build() rr = RegistryResources{ - Pkg: &manifests.PackageManifest{ + Pkg: &apimanifests.PackageManifest{ PackageName: "pkgName", - Channels: []manifests.PackageChannel{ - manifests.PackageChannel{ + Channels: []apimanifests.PackageChannel{ + apimanifests.PackageChannel{ Name: "pkgChannelTest", }, }, @@ -322,10 +321,10 @@ var _ = Describe("Registry", func() { }) It("should return true if it fails in the next iteration", func() { - binarydata, _ := makeObjectBinaryData(&manifests.PackageManifest{ + binarydata, _ := makeObjectBinaryData(&apimanifests.PackageManifest{ PackageName: "pkgName", - Channels: []manifests.PackageChannel{ - manifests.PackageChannel{ + Channels: []apimanifests.PackageChannel{ + apimanifests.PackageChannel{ Name: "pkgChannelTest", }, }, diff --git a/internal/olm/operator/registry/index/registry_pod_test.go b/internal/olm/operator/registry/index/registry_pod_test.go index 40cd21baf40..1f6a81b53df 100644 --- a/internal/olm/operator/registry/index/registry_pod_test.go +++ b/internal/olm/operator/registry/index/registry_pod_test.go @@ -288,7 +288,7 @@ func containerCommandFor(dbPath string, items []BundleItem, hasCA, skipTLSVerify } additions := &strings.Builder{} for _, item := range items { - additions.WriteString(fmt.Sprintf("opm registry add -d /tmp/tmp.db -b %s --mode=%s%s --skip-tls-verify=%v --use-http=%v && \\\n", item.ImageTag, item.AddMode, caFlag, skipTLSVerify, useHTTP)) + fmt.Fprintf(additions, "opm registry add -d /tmp/tmp.db -b %s --mode=%s%s --skip-tls-verify=%v --use-http=%v && \\\n", item.ImageTag, item.AddMode, caFlag, skipTLSVerify, useHTTP) } return fmt.Sprintf("[[ -f %s ]] && cp %s /tmp/tmp.db; \\\n%sopm registry serve -d /tmp/tmp.db -p 50051\n", dbPath, dbPath, additions.String()) diff --git a/internal/plugins/helm/v1/api.go b/internal/plugins/helm/v1/api.go index d38f795ec89..b7c3930de25 100644 --- a/internal/plugins/helm/v1/api.go +++ b/internal/plugins/helm/v1/api.go @@ -235,5 +235,5 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error { // hasDifferentCRDVersion returns true if any other CRD version is tracked in the project configuration. func hasDifferentAPIVersion(versions []string, version string) bool { - return !(len(versions) == 0 || (len(versions) == 1 && versions[0] == version)) + return len(versions) != 0 && (len(versions) != 1 || versions[0] != version) } diff --git a/internal/plugins/helm/v1/scaffolds/internal/templates/config/samples/custom_resource.go b/internal/plugins/helm/v1/scaffolds/internal/templates/config/samples/custom_resource.go index 7aed0f6761c..f002e69eaed 100644 --- a/internal/plugins/helm/v1/scaffolds/internal/templates/config/samples/custom_resource.go +++ b/internal/plugins/helm/v1/scaffolds/internal/templates/config/samples/custom_resource.go @@ -73,7 +73,7 @@ func (f *CustomResource) SetTemplateDefaults() error { func indent(spaces int, v string) string { pad := strings.Repeat(" ", spaces) - return pad + strings.Replace(v, "\n", "\n"+pad, -1) + return pad + strings.ReplaceAll(v, "\n", "\n"+pad) } // GetFuncMap implements machinery.UseCustomFuncMap diff --git a/internal/plugins/manifests/v2/utils.go b/internal/plugins/manifests/v2/utils.go index e4d49cfd15a..c20589601d7 100644 --- a/internal/plugins/manifests/v2/utils.go +++ b/internal/plugins/manifests/v2/utils.go @@ -37,10 +37,10 @@ func HasSupportForKustomizeV4(c config.Config) bool { // we have data only into the pluginChain for _, pluginKey := range c.GetPluginChain() { if strings.HasPrefix(pluginKey, "go") { - switch { - case pluginKey == kubebuilderGoV3: + switch pluginKey { + case kubebuilderGoV3: return false - case pluginKey == kubebuilderGoV2: + case kubebuilderGoV2: return false } } diff --git a/internal/testutils/utils.go b/internal/testutils/utils.go index dd6796de664..75604649476 100644 --- a/internal/testutils/utils.go +++ b/internal/testutils/utils.go @@ -23,8 +23,8 @@ import ( "strings" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck kbutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util" kbtestutils "sigs.k8s.io/kubebuilder/v4/test/e2e/utils" ) @@ -119,7 +119,7 @@ func ReplaceInFile(path, o, n string) error { if !strings.Contains(string(b), o) { return errors.New("unable to find the content to be replaced") } - s := strings.Replace(string(b), o, n, -1) + s := strings.ReplaceAll(string(b), o, n) err = os.WriteFile(path, []byte(s), info.Mode()) if err != nil { return err diff --git a/internal/util/k8sutil/api.go b/internal/util/k8sutil/api.go index 92a31344e91..1badee20ac7 100644 --- a/internal/util/k8sutil/api.go +++ b/internal/util/k8sutil/api.go @@ -196,8 +196,8 @@ func Convertv1beta1Tov1CustomResourceDefinition(in *apiextv1beta1.CustomResource } var out apiextv1.CustomResourceDefinition - out.TypeMeta.APIVersion = apiextv1.SchemeGroupVersion.String() - out.TypeMeta.Kind = "CustomResourceDefinition" + out.APIVersion = apiextv1.SchemeGroupVersion.String() + out.Kind = "CustomResourceDefinition" if err := apiextv1.Convert_apiextensions_CustomResourceDefinition_To_v1_CustomResourceDefinition(&unversioned, &out, nil); err != nil { return nil, err } diff --git a/test/common/scorecard.go b/test/common/scorecard.go index 8aeeb71d6d0..c0b7d982dd6 100644 --- a/test/common/scorecard.go +++ b/test/common/scorecard.go @@ -20,8 +20,8 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck "github.com/operator-framework/api/pkg/apis/scorecard/v1alpha3" "github.com/operator-framework/operator-sdk/internal/testutils" diff --git a/test/e2e/go/local_test.go b/test/e2e/go/local_test.go index c5c83f94ee5..9adbc1325b1 100644 --- a/test/e2e/go/local_test.go +++ b/test/e2e/go/local_test.go @@ -20,8 +20,8 @@ package e2e_go_test import ( "os/exec" - . "github.com/onsi/ginkgo/v2" //nolint:golint - . "github.com/onsi/gomega" //nolint:golint + . "github.com/onsi/ginkgo/v2" //nolint:golint,staticcheck + . "github.com/onsi/gomega" //nolint:golint,staticcheck ) var _ = Describe("Running Go projects", func() {