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
72 changes: 40 additions & 32 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hack/generate/cli-doc/gen-cli-doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/generate/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/generate/bundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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), "_", "-"))
}
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/generate/packagemanifests/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("Running pkgmanToBundle command", func() {
var (
p pkgManToBundleCmd
pkgManDir string
outputDir string = "bundle-output"
outputDir = "bundle-output"
)

BeforeEach(func() {
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/operator-sdk/scorecard/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b ClusterServiceVersion) GetBase() (base *v1alpha1.ClusterServiceVersion,
// Auto-migrate bases with names matching "<operator name>.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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 2 additions & 4 deletions internal/helm/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/helm/release/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 3 additions & 4 deletions internal/olm/fbcutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions internal/olm/operator/bundle/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/olm/operator/bundleupgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
18 changes: 9 additions & 9 deletions internal/olm/operator/packagemanifests/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/olm/operator/registry/configmap/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -258,7 +258,7 @@ var _ = Describe("Deployment", func() {
f1(dep)

f2 := func(d *appsv1.Deployment) {
d.ObjectMeta.Namespace = "testns2"
d.Namespace = "testns2"
}
f2(dep)

Expand Down
Loading
Loading