Skip to content

Commit

Permalink
Merge pull request #44 from inteon/fix_linters
Browse files Browse the repository at this point in the history
Fix linters
  • Loading branch information
cert-manager-prow[bot] committed Apr 18, 2024
2 parents f3bfb31 + 4156ca3 commit cd7b918
Show file tree
Hide file tree
Showing 45 changed files with 304 additions and 236 deletions.
15 changes: 0 additions & 15 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
issues:
exclude-rules:
- linters:
- errcheck
- forbidigo
- gci
- gocritic
- gosec
- misspell
- unparam
- unused
- nilerr
- nilnil
- staticcheck
- dupword
- noctx
- predeclared
- unconvert
- usestdlibvars
- gosimple
text: ".*"
linters:
# Explicitly define all enabled linters
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"fmt"
"io"

logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/component-base/logs"

logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/cmctl/v2/pkg/build"
"github.com/cert-manager/cmctl/v2/pkg/build/commands"
)
Expand Down
39 changes: 20 additions & 19 deletions internal/versionchecker/test/testdata/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ const dummyVersion = "v99.99.99"

func main() {
ctx := context.Background()
stdOut := os.Stdout

if len(os.Args) != 3 && len(os.Args) != 4 {
fmt.Printf("Usage: %s <test_manifests.yaml> <max_version> [<force:bool>]\n", os.Args[0])
fmt.Fprintf(stdOut, "Usage: %s <test_manifests.yaml> <max_version> [<force:bool>]\n", os.Args[0])
os.Exit(1)
}

Expand All @@ -62,21 +63,21 @@ func main() {
// Read the inventory file
var inv Inventory
if err := inv.read(manifestsPath); err != nil {
fmt.Printf("Error reading inventory: %v\n", err)
fmt.Fprintf(stdOut, "Error reading inventory: %v\n", err)

inv.reset()
}

// If the passed version is identical to the latest version, we don't need to do anything
if inv.LatestVersion == maxVersion && !force {
fmt.Printf("Version %s is already the latest version\n", maxVersion)
fmt.Fprintf(stdOut, "Version %s is already the latest version\n", maxVersion)
os.Exit(0)
}

// Fetch the list of remote versions
remoteVersions, err := listVersions(ctx, maxVersion)
if err != nil {
fmt.Printf("Error listing versions: %v\n", err)
fmt.Fprintf(stdOut, "Error listing versions: %v\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -119,7 +120,7 @@ func main() {
}

if err := group.Wait(); err != nil {
fmt.Printf("Error downloading manifests: %v\n", err)
fmt.Fprintf(stdOut, "Error downloading manifests: %v\n", err)
os.Exit(1)
}

Expand All @@ -128,7 +129,7 @@ func main() {
for result := range results {
hash, err := manifestHash(result.manifest)
if err != nil {
fmt.Printf("Error hashing manifest: %v\n", err)
fmt.Fprintf(stdOut, "Error hashing manifest: %v\n", err)
os.Exit(1)
}

Expand All @@ -141,11 +142,11 @@ func main() {

// Write the inventory file
if err := inv.write(manifestsPath); err != nil {
fmt.Printf("Error writing inventory: %v\n", err)
fmt.Fprintf(stdOut, "Error writing inventory: %v\n", err)
os.Exit(1)
}

fmt.Printf("Updated inventory to version %s\n", maxVersion)
fmt.Fprintf(stdOut, "Updated inventory to version %s\n", maxVersion)
}

type Inventory struct {
Expand Down Expand Up @@ -272,7 +273,7 @@ func (inv *Inventory) write(manifestsPath string) error {

manifests = append(manifests, versionManifest{
versions: versions,
manifest: []byte(manifest),
manifest: manifest,
})
}

Expand Down Expand Up @@ -347,7 +348,7 @@ func listVersions(ctx context.Context, maxVersion string) (map[string]struct{},
func downloadManifests(ctx context.Context, version string) ([]byte, error) {
url := fmt.Sprintf(downloadURL, version)

req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -375,44 +376,44 @@ func cleanupManifests(manifests []byte, version string) ([]byte, error) {

decoder := yaml.NewDecoder(bytes.NewBuffer(manifests))
for {
var spec map[string]interface{}
var manifest map[string]interface{}

err := decoder.Decode(&spec)
err := decoder.Decode(&manifest)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return nil, fmt.Errorf("failed to decode manifest: %v", err)
}
if spec == nil {
if manifest == nil {
continue
}

kind, ok := spec["kind"].(string)
kind, ok := manifest["kind"].(string)
if !ok {
return nil, fmt.Errorf("kind is missing from manifest")
}

switch kind {
case "CustomResourceDefinition":
// remove all CRD schemas from yaml file
switch spec["spec"].(type) {
switch spec := manifest["spec"].(type) {
case map[string]interface{}:
spec["spec"].(map[string]interface{})["versions"] = []interface{}{}
spec["versions"] = []interface{}{}
case map[interface{}]interface{}:
spec["spec"].(map[interface{}]interface{})["versions"] = []interface{}{}
spec["versions"] = []interface{}{}
}

// remove status from CRD
delete(spec, "status")
delete(manifest, "status")

case "Service", "Deployment":
// keep only the CRD, Service and Deployment resources from yaml file
default:
continue
}

yamlData, err := yaml.Marshal(spec)
yamlData, err := yaml.Marshal(manifest)
if err != nil {
return nil, fmt.Errorf("failed to marshal manifest: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/versionchecker/test/versionchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package versionchecker
import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -38,6 +37,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/cert-manager/cmctl/v2/internal/versionchecker"

_ "embed"
)

const dummyVersion = "v99.99.99"
Expand Down
6 changes: 1 addition & 5 deletions internal/versionchecker/versionchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ type Version struct {
Sources map[string]string `json:"sources"`
}

func shouldReturn(err error) bool {
return (err == nil) || (!errors.Is(err, ErrVersionNotDetected))
}

// Interface is used to check what cert-manager version is installed
type Interface interface {
Version(context.Context) (*Version, error)
Expand Down Expand Up @@ -127,7 +123,7 @@ func (o *VersionChecker) Version(ctx context.Context) (*Version, error) {
// Display both.
err = fmt.Errorf("%v: %v", detectionError, err)
} else if detectionError != nil {
// An error occured while trying to reduce the found versions to 1 version
// An error occurred while trying to reduce the found versions to 1 version
err = detectionError
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"runtime"
"strings"

logf "github.com/cert-manager/cert-manager/pkg/logs"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
ctrl "sigs.k8s.io/controller-runtime"

logf "github.com/cert-manager/cert-manager/pkg/logs"
ctlcmd "github.com/cert-manager/cmctl/v2/cmd"
"github.com/cert-manager/cmctl/v2/internal/util"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/approve/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"errors"
"fmt"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/cert-manager/cmctl/v2/pkg/build"
"github.com/cert-manager/cmctl/v2/pkg/factory"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"fmt"
"time"

logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/cert-manager/pkg/util/cmapichecker"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/cert-manager/pkg/util/cmapichecker"
cmcmdutil "github.com/cert-manager/cmctl/v2/internal/util"
"github.com/cert-manager/cmctl/v2/pkg/factory"
)
Expand Down
5 changes: 2 additions & 3 deletions pkg/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"context"
"fmt"

"github.com/cert-manager/cert-manager/pkg/ctl"
logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/cmctl/v2/pkg/build"

"github.com/spf13/cobra"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -36,7 +35,7 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

"github.com/cert-manager/cert-manager/pkg/ctl"
"github.com/cert-manager/cmctl/v2/pkg/build"
)

var (
Expand Down
12 changes: 6 additions & 6 deletions pkg/create/certificaterequest/certificaterequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"os"
"time"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/cert-manager/cert-manager/pkg/ctl"
"github.com/cert-manager/cert-manager/pkg/util/pki"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -34,11 +39,6 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/cert-manager/cert-manager/pkg/ctl"
"github.com/cert-manager/cert-manager/pkg/util/pki"
"github.com/cert-manager/cmctl/v2/pkg/build"
"github.com/cert-manager/cmctl/v2/pkg/factory"
)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (o *Options) Run(ctx context.Context, args []string) error {
err = wait.PollUntilContextTimeout(ctx, time.Second, o.Timeout, false, func(ctx context.Context) (done bool, err error) {
req, err = o.CMClient.CertmanagerV1().CertificateRequests(req.Namespace).Get(ctx, req.Name, metav1.GetOptions{})
if err != nil {
return false, nil
return false, nil // nolint: nilerr // Retry and keep polling until context is cancelled
}
return apiutil.CertificateRequestHasCondition(req, cmapi.CertificateRequestCondition{
Type: cmapi.CertificateRequestConditionReady,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import (
"strconv"
"time"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
"github.com/cert-manager/cert-manager/pkg/apis/certmanager"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
experimentalapi "github.com/cert-manager/cert-manager/pkg/apis/experimental/v1alpha1"
"github.com/cert-manager/cert-manager/pkg/ctl"
"github.com/cert-manager/cert-manager/pkg/util/pki"
"github.com/spf13/cobra"
certificatesv1 "k8s.io/api/certificates/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -38,11 +43,6 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
"github.com/cert-manager/cert-manager/pkg/apis/certmanager"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
"github.com/cert-manager/cert-manager/pkg/ctl"
"github.com/cert-manager/cert-manager/pkg/util/pki"
"github.com/cert-manager/cmctl/v2/pkg/build"
"github.com/cert-manager/cmctl/v2/pkg/factory"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/deny/deny.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"errors"
"fmt"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"

apiutil "github.com/cert-manager/cert-manager/pkg/api/util"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/cert-manager/cmctl/v2/pkg/build"
"github.com/cert-manager/cmctl/v2/pkg/factory"
)
Expand Down
7 changes: 4 additions & 3 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package factory

import (
cmclient "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
Expand All @@ -25,8 +26,6 @@ import (

// Load all auth plugins
_ "k8s.io/client-go/plugin/pkg/client/auth"

cmclient "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
)

// Factory provides a set of clients and configurations to authenticate and
Expand Down Expand Up @@ -71,7 +70,9 @@ func New(cmd *cobra.Command) *Factory {
f.factory = util.NewFactory(kubeConfigFlags)

kubeConfigFlags.AddFlags(cmd.Flags())
cmd.RegisterFlagCompletionFunc("namespace", validArgsListNamespaces(f))
if err := cmd.RegisterFlagCompletionFunc("namespace", validArgsListNamespaces(f)); err != nil {
panic(err)
}

// Setup a PreRunE to populate the Factory. Catch the existing PreRunE command
// if one was defined, and execute it second.
Expand Down
Loading

0 comments on commit cd7b918

Please sign in to comment.