Skip to content

Commit

Permalink
updating project to use go 1.23
Browse files Browse the repository at this point in the history
Signed-off-by: Adam D. Cornett <[email protected]>
  • Loading branch information
acornett21 committed Jan 3, 2025
1 parent d0e10c2 commit e9868db
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fix: ## Fixup files in the repo.

.PHONY: setup-lint
setup-lint: ## Setup the lint
$(SCRIPTS_DIR)/fetch golangci-lint 1.54.0
$(SCRIPTS_DIR)/fetch golangci-lint 1.62.2

.PHONY: lint
lint: setup-lint ## Run the lint check
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/operator-framework/operator-sdk

go 1.22.5
go 1.23.4

require (
github.com/blang/semver/v4 v4.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GenerateSample(binaryPath, samplesPath string) {
errorInfo += monitoringString
}

log.Infof(logInfo)
log.Info(logInfo)
ctx, err := pkg.NewSampleContext(binaryPath, filepath.Join(samplesPath, "memcached-operator"), "GO111MODULE=on")
pkg.CheckError(errorInfo, err)

Expand All @@ -71,7 +71,7 @@ func (mh *Memcached) Prepare() {
logInfo += monitoringString
}

log.Infof(logInfo)
log.Info(logInfo)
mh.ctx.Destroy()

log.Infof("creating directory")
Expand Down
4 changes: 2 additions & 2 deletions images/custom-scorecard-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the custom-scorecard-tests binary
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand All @@ -17,7 +17,7 @@ COPY . .
RUN GOOS=linux GOARCH=$TARGETARCH make build/custom-scorecard-tests

# Final image.
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4-1227.1726694542
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5

ENV HOME=/opt/custom-scorecard-tests \
USER_NAME=custom-scorecard-tests \
Expand Down
4 changes: 2 additions & 2 deletions images/helm-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand All @@ -17,7 +17,7 @@ COPY . .
RUN GOOS=linux GOARCH=$TARGETARCH make build/helm-operator

# Final image.
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4-1227.1726694542
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5

ENV HOME=/opt/helm \
USER_NAME=helm \
Expand Down
6 changes: 3 additions & 3 deletions images/operator-sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the operator-sdk binary
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand All @@ -17,10 +17,10 @@ COPY . .
RUN GOOS=linux GOARCH=$TARGETARCH make build/operator-sdk

# Final image.
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4-1227.1726694542
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5

# TODO: Figure out how to take the go binary from the builder image so this doesn't have to be maintained.
ENV GO_VERSION=1.22.5
ENV GO_VERSION=1.23.4

ARG TARGETARCH
RUN microdnf install -y make gcc which tar gzip
Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-test-kuttl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test-kuttl binary
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG TARGETARCH
ARG BUILDPLATFORM

Expand Down
4 changes: 2 additions & 2 deletions images/scorecard-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test binary
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand All @@ -17,7 +17,7 @@ COPY . .
RUN GOOS=linux GOARCH=$TARGETARCH make build/scorecard-test

# Final image.
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4-1227.1726694542
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5

ENV HOME=/opt/scorecard-test \
USER_NAME=scorecard-test \
Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-untar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi9/ubi:9.4-1214.1726694543
FROM registry.access.redhat.com/ubi9/ubi:9.5

## Create a new non-root user to run as
ENV HOME=/opt/scorecard-untar \
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/helm-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Run the operator",
Args: func(cmd *cobra.Command, args []string) error {
Args: func(cmd *cobra.Command, _ []string) error {
if cmd.Flag("metrics-require-rbac").Value.String() == "true" && cmd.Flag("metrics-secure").Value.String() == "false" {
return errors.New("--metrics-secure flag is required when --metrics-require-rbac is present")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/helm-operator/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Prints the version of operator-sdk",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
run()
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/operator-sdk/alpha/config3alphato3/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The 3-alpha version has recently become stable (3), and therefore is no longer
supported by operator-sdk v1.5+. This command is intended to migrate 3-alpha PROJECT files
to 3 with as few manual modifications required as possible.
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
RunE: func(_ *cobra.Command, _ []string) (err error) {
cfgBytes, err := os.ReadFile("PROJECT")
if err != nil {
return fmt.Errorf("%v (config-3alpha-to-3 must be run from project root)", err)
Expand Down Expand Up @@ -64,7 +64,7 @@ to 3 with as few manual modifications required as possible.
// RootPersistentPreRun prints a helpful message on any exit caused by kubebuilder's
// config unmarshal step finding "3-alpha", since the CLI will not recognize this version.
// Add this to the root command (`operator-sdk`).
var RootPersistentPreRun = func(cmd *cobra.Command, args []string) {
var RootPersistentPreRun = func(_ *cobra.Command, _ []string) {
if cfgBytes, err := os.ReadFile("PROJECT"); err == nil {
if ver, err := getConfigVersion(cfgBytes); err == nil && ver == v3alpha {
log.Warn("Config version 3-alpha has been stabilized as 3, and 3-alpha is no longer supported. " +
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/bundle/validate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewCmd() *cobra.Command {
Short: "Validate an operator bundle",
Long: longHelp,
Example: examples,
RunE: func(cmd *cobra.Command, args []string) (err error) {
RunE: func(_ *cobra.Command, args []string) (err error) {
// Always print non-output logs to stderr as to not pollute actual command output.
// Note that it allows the JSON result be redirected to the Stdout. E.g
// if we run the command with `| jq . > result.json` the command will print just the logs
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/olm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newInstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install",
Short: "Install Operator Lifecycle Manager in your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if err := mgr.Install(); err != nil {
log.Fatalf("Failed to install OLM version %q: %s", mgr.Version, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/olm/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newStatusCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "status",
Short: "Get the status of the Operator Lifecycle Manager installation in your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if err := mgr.Status(); err != nil {
log.Fatalf("Failed to get OLM status: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator-sdk/olm/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newUninstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "uninstall",
Short: "Uninstall Operator Lifecycle Manager from your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if err := mgr.Uninstall(); err != nil {
log.Fatalf("Failed to uninstall OLM: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/operator-sdk/pkgmantobundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func NewCmd() *cobra.Command {
Short: "Migrates packagemanifests to bundles",
Long: longHelp,
Example: examples,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
PreRunE: func(_ *cobra.Command, args []string) (err error) {
return p.validate(args)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
RunE: func(_ *cobra.Command, args []string) (err error) {
p.pkgmanifestDir = args[0]
return p.run()
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/operator-sdk/scorecard/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func NewCmd() *cobra.Command {
Long: `Has flags to configure dsl, bundle, and selector. This command takes
one argument, either a bundle image or directory containing manifests and metadata.
If the argument holds an image tag, it must be present remotely.`,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
PreRunE: func(_ *cobra.Command, args []string) (err error) {
return c.validate(args)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
RunE: func(_ *cobra.Command, args []string) (err error) {
c.bundle = args[0]
return c.run()
},
Expand Down
30 changes: 15 additions & 15 deletions internal/generate/packagemanifest/packagemanifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/operator-framework/operator-sdk/internal/generate/packagemanifest"
"github.com/operator-framework/operator-sdk/internal/generate/packagemanifest"
)

var _ = Describe("A package manifest generator", func() {
Expand All @@ -32,8 +32,8 @@ var _ = Describe("A package manifest generator", func() {
})
Describe("Generate", func() {
var (
g Generator
blankOpts Options
g packagemanifest.Generator
blankOpts packagemanifest.Options
operatorName string
outputDir string
pkgManFilename string
Expand All @@ -44,9 +44,9 @@ var _ = Describe("A package manifest generator", func() {
pkgManUpdatedSecondChannelNewDefault string
)
BeforeEach(func() {
g = NewGenerator()
g = packagemanifest.NewGenerator()
operatorName = "memcached-operator"
blankOpts = Options{}
blankOpts = packagemanifest.Options{}
pkgManFilename = operatorName + ".package.yaml"
outputDir = os.TempDir()
pkgManDefault = `channels:
Expand Down Expand Up @@ -93,7 +93,7 @@ packageName: memcached-operator
Expect(string(file)).To(Equal(pkgManDefault))
})
It("writes a package manifest with a non-default channel", func() {
opts := Options{
opts := packagemanifest.Options{
ChannelName: "stable",
}

Expand All @@ -106,7 +106,7 @@ packageName: memcached-operator
})
Context("when updating an existing package manifest", func() {
It("creates a new package manifest if provided an existing packagemanifest that doesn't exist", func() {
opts := Options{
opts := packagemanifest.Options{
BaseDir: "testpotato",
ChannelName: "stable",
}
Expand All @@ -118,7 +118,7 @@ packageName: memcached-operator
Expect(string(file)).To(Equal(pkgManOneChannel))
})
It("updates an existing package manifest with a updated channel", func() {
opts := Options{
opts := packagemanifest.Options{
BaseDir: testDataDir,
ChannelName: "alpha",
}
Expand All @@ -130,7 +130,7 @@ packageName: memcached-operator
Expect(string(file)).To(Equal(pkgManUpdatedOneChannel))
})
It("updates an existing package manifest with a new channel", func() {
opts := Options{
opts := packagemanifest.Options{
BaseDir: testDataDir,
ChannelName: "stable",
}
Expand All @@ -142,7 +142,7 @@ packageName: memcached-operator
Expect(string(file)).To(Equal(pkgManUpdatedSecondChannel))
})
It("updates an existing package manifest with a new channel and an updated default channel", func() {
opts := Options{
opts := packagemanifest.Options{
BaseDir: testDataDir,
ChannelName: "stable",
IsDefaultChannel: true,
Expand All @@ -159,26 +159,26 @@ packageName: memcached-operator
It("fails if no operator name is specified", func() {
err := g.Generate("", "", "", blankOpts)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(ErrNoOpName.Error()))
Expect(err.Error()).To(ContainSubstring(packagemanifest.ErrNoOpName.Error()))
})
It("fails if no version is specified", func() {
err := g.Generate(operatorName, "", "", blankOpts)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(ErrNoVersion.Error()))
Expect(err.Error()).To(ContainSubstring(packagemanifest.ErrNoVersion.Error()))
})
It("fails if no output directory is set", func() {
err := g.Generate(operatorName, "0.0.1", "", blankOpts)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(ErrNoOutputDir.Error()))
Expect(err.Error()).To(ContainSubstring(packagemanifest.ErrNoOutputDir.Error()))
})
})
})
Describe("GetBase", func() {
var (
b PackageManifest
b packagemanifest.PackageManifest
)
BeforeEach(func() {
b = PackageManifest{}
b = packagemanifest.PackageManifest{}
})
It("returns a new blank packagemanifest", func() {
b.PackageName = "sweetsop"
Expand Down
2 changes: 1 addition & 1 deletion internal/helm/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func readBoolAnnotationWithDefault(obj *unstructured.Unstructured, annotation st
r, err := strconv.ParseBool(val)
if err != nil {
log.Error(
fmt.Errorf(strings.ToLower(err.Error())), "error parsing annotation", "annotation", annotation)
fmt.Errorf("%s", strings.ToLower(err.Error())), "error parsing annotation", "annotation", annotation)
return fallback
}

Expand Down
3 changes: 2 additions & 1 deletion internal/helm/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func (f *Flags) ToManagerOptions(options manager.Options) manager.Options {
return f.flagSet.Changed(flagName)
}
if f.flagSet == nil {
changed = func(flagName string) bool { return false }
//nolint:golint
changed = func(_ string) bool { return false }
}

// TODO(2.0.0): remove metrics-addr
Expand Down
2 changes: 1 addition & 1 deletion internal/olm/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s Status) HasInstalledResources() (bool, error) {
}
// Sort resources by whether they're installed or not to get consistent
// return values.
sort.Slice(s.Resources, func(i int, j int) bool {
sort.Slice(s.Resources, func(i int, _ int) bool {
return s.Resources[i].Resource != nil
})
for _, r := range s.Resources {
Expand Down
4 changes: 2 additions & 2 deletions internal/scorecard/kubeclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestGetKubeNamespace(t *testing.T) {
// create temp kubeconfig file
file, err := os.CreateTemp("/tmp", "")
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
defer os.Remove(file.Name())

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestGetKubeNamespaceEnvVar(t *testing.T) {
// create temp kubeconfig file
file, err := os.CreateTemp("/tmp", "")
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
defer os.Remove(file.Name())

Expand Down
2 changes: 1 addition & 1 deletion internal/scorecard/tests/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func CRDsHaveResourcesTest(bundle *apimanifests.Bundle) scapiv1alpha3.TestStatus
func CheckResources(crd operatorsv1alpha1.CustomResourceDefinitions,
r scapiv1alpha3.TestResult) scapiv1alpha3.TestResult {
for _, description := range crd.Owned {
if description.Resources == nil || len(description.Resources) == 0 {
if len(description.Resources) == 0 {
r.State = scapiv1alpha3.FailState
r.Errors = append(r.Errors, "Owned CRDs do not have resources specified")
return r
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (tc TestContext) UninstallOLM() {

// ReplaceInFile replaces all instances of old with new in the file at path.
// todo(camilamacedo86): this func can be pushed to upstream/kb
func ReplaceInFile(path, old, new string) error {
func ReplaceInFile(path, o, n string) error {
info, err := os.Stat(path)
if err != nil {
return err
Expand All @@ -116,10 +116,10 @@ func ReplaceInFile(path, old, new string) error {
if err != nil {
return err
}
if !strings.Contains(string(b), old) {
if !strings.Contains(string(b), o) {
return errors.New("unable to find the content to be replaced")
}
s := strings.Replace(string(b), old, new, -1)
s := strings.Replace(string(b), o, n, -1)
err = os.WriteFile(path, []byte(s), info.Mode())
if err != nil {
return err
Expand Down
Loading

0 comments on commit e9868db

Please sign in to comment.