diff --git a/.golangci.yaml b/.golangci.yaml index 6c26724cd..695bb714d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -36,14 +36,16 @@ linters-settings: local-prefixes: github.com/vmware-tanzu govet: check-shadowing: true - misspell: locale: US nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) allow-unused: false # report any unused nolint directives require-explanation: false # don't require an explanation for nolint directives require-specific: false # don't require nolint directives to be specific about which linter is being skipped + revive: + rules: + - name: unused-parameter + disabled: true whitespace: multi-func: true @@ -144,8 +146,3 @@ run: skip-dirs: - fakes/ timeout: 15m - -# golangci.com configuration -# https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.46.0 # use the fixed version to not introduce new linters unexpectedly diff --git a/cmd/plugin/builder/command/cli_compile.go b/cmd/plugin/builder/command/cli_compile.go index 76bae9a30..48a35405a 100644 --- a/cmd/plugin/builder/command/cli_compile.go +++ b/cmd/plugin/builder/command/cli_compile.go @@ -160,7 +160,7 @@ func Compile(compileArgs *PluginCompileArgs) error { guard := make(chan struct{}, maxConcurrent) // Mix up IDs so we don't always get the same set. - randSkew := rand.Intn(len(identifiers)) // nolint:gosec + randSkew := rand.Intn(len(identifiers)) //nolint:gosec var wg sync.WaitGroup plugins := make(chan cli.Plugin, len(files)) fatalErrors := make(chan errInfo, len(files)) diff --git a/cmd/plugin/builder/command/publish/helper_test.go b/cmd/plugin/builder/command/publish/helper_test.go index 37ef915a3..e15eae393 100644 --- a/cmd/plugin/builder/command/publish/helper_test.go +++ b/cmd/plugin/builder/command/publish/helper_test.go @@ -66,6 +66,7 @@ func convertVersionToStringArray(arrOsArchInfo []osArch) []string { return oa } +//nolint:unparam func createDummyArtifactDir(directoryBasePath, pluginName, recommendedVersion, description string, versions []string) { var err error diff --git a/cmd/plugin/builder/inventory/inventory_plugin_group_test.go b/cmd/plugin/builder/inventory/inventory_plugin_group_test.go index b7d924ef2..aee697fc1 100644 --- a/cmd/plugin/builder/inventory/inventory_plugin_group_test.go +++ b/cmd/plugin/builder/inventory/inventory_plugin_group_test.go @@ -26,7 +26,7 @@ var _ = Describe("Unit tests for inventory plugin-group add", func() { fakeImgpkgWrapper := &fakes.ImgpkgWrapper{} // pullDBImageStub create new empty database with the table schemas created - pullDBImageStub := func(image, path string) error { + pullDBImageStub := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteDBFileName) db := plugininventory.NewSQLiteInventory(dbFile, "") err := db.CreateSchema() diff --git a/cmd/plugin/builder/inventory/inventory_plugin_test.go b/cmd/plugin/builder/inventory/inventory_plugin_test.go index 554dc48f3..0f731d9c9 100644 --- a/cmd/plugin/builder/inventory/inventory_plugin_test.go +++ b/cmd/plugin/builder/inventory/inventory_plugin_test.go @@ -36,7 +36,7 @@ var _ = Describe("Unit tests for inventory plugin add", func() { } // pullDBImageStub create new empty database with the table schemas created - pullDBImageStub := func(image, path string) error { + pullDBImageStub := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteDBFileName) db := plugininventory.NewSQLiteInventory(dbFile, "") err := db.CreateSchema() @@ -46,7 +46,7 @@ var _ = Describe("Unit tests for inventory plugin add", func() { } // pullDBImageStubWithPlugins create new database with the table schemas and foo plugin - pullDBImageStubWithPlugins := func(image, path string) error { + pullDBImageStubWithPlugins := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteDBFileName) db := plugininventory.NewSQLiteInventory(dbFile, "") err := db.CreateSchema() diff --git a/cmd/plugin/builder/inventory_plugin.go b/cmd/plugin/builder/inventory_plugin.go index 8a576518b..9df74b882 100644 --- a/cmd/plugin/builder/inventory_plugin.go +++ b/cmd/plugin/builder/inventory_plugin.go @@ -88,7 +88,7 @@ type inventoryPluginActivateDeactivateFlags struct { func newInventoryPluginActivateCmd() *cobra.Command { pluginActivateCmd, flags := getActivateDeactivateBaseCmd() - pluginActivateCmd.Use = "activate" // nolint:goconst + pluginActivateCmd.Use = "activate" //nolint:goconst pluginActivateCmd.Short = "Activate the existing plugin in the inventory database available on the remote repository" pluginActivateCmd.Example = "" pluginActivateCmd.RunE = func(cmd *cobra.Command, args []string) error { @@ -108,7 +108,7 @@ func newInventoryPluginActivateCmd() *cobra.Command { func newInventoryPluginDeactivateCmd() *cobra.Command { pluginDeactivateCmd, flags := getActivateDeactivateBaseCmd() - pluginDeactivateCmd.Use = "deactivate" // nolint:goconst + pluginDeactivateCmd.Use = "deactivate" //nolint:goconst pluginDeactivateCmd.Short = "Deactivate the existing plugin in the inventory database available on the remote repository" pluginDeactivateCmd.Example = "" pluginDeactivateCmd.RunE = func(cmd *cobra.Command, args []string) error { @@ -126,7 +126,7 @@ func newInventoryPluginDeactivateCmd() *cobra.Command { return pluginDeactivateCmd } -func getActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginActivateDeactivateFlags) { // nolint:dupl +func getActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginActivateDeactivateFlags) { //nolint:dupl var flags = &inventoryPluginActivateDeactivateFlags{} var activateDeactivateCmd = &cobra.Command{} diff --git a/cmd/plugin/builder/inventory_plugin_group.go b/cmd/plugin/builder/inventory_plugin_group.go index 78855e6b6..06c86cef1 100644 --- a/cmd/plugin/builder/inventory_plugin_group.go +++ b/cmd/plugin/builder/inventory_plugin_group.go @@ -131,7 +131,7 @@ func newInventoryPluginGroupDeactivateCmd() *cobra.Command { return pluginGroupDeactivateCmd } -func getPluginGroupActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginGroupActivateDeactivateFlags) { // nolint:dupl +func getPluginGroupActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginGroupActivateDeactivateFlags) { //nolint:dupl var flags = &inventoryPluginGroupActivateDeactivateFlags{} var activateDeactivateCmd = &cobra.Command{} diff --git a/hack/tools/Makefile b/hack/tools/Makefile index 4b03871e4..a069c68c6 100644 --- a/hack/tools/Makefile +++ b/hack/tools/Makefile @@ -21,7 +21,7 @@ BIN_DIR := bin GOIMPORTS_VERSION=0.1.12 VALE_VERSION=2.20.1 -GOLANGCI_LINT_VERSION=1.46.0 +GOLANGCI_LINT_VERSION=1.52.2 MISSPELL_VERSION=0.3.4 CONTROLLER_TOOLS_VERSION=0.9.2 IMGPKG_VERSION=v0.35.0 diff --git a/pkg/airgapped/plugin_bundle_test.go b/pkg/airgapped/plugin_bundle_test.go index e59a1cad2..41a202547 100644 --- a/pkg/airgapped/plugin_bundle_test.go +++ b/pkg/airgapped/plugin_bundle_test.go @@ -155,7 +155,7 @@ imagesToCopy: // downloadInventoryImageAndSaveFilesToDirStub fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryImageAndSaveFilesToDirStub := func(image, path string) error { + downloadInventoryImageAndSaveFilesToDirStub := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -175,7 +175,7 @@ imagesToCopy: // downloadInventoryMetadataImageWithNoExistingPlugins fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryMetadataImageWithNoExistingPlugins := func(image, path string) error { + downloadInventoryMetadataImageWithNoExistingPlugins := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -189,7 +189,7 @@ imagesToCopy: // downloadInventoryMetadataImageWithExistingPlugins fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryMetadataImageWithExistingPlugins := func(image, path string) error { + downloadInventoryMetadataImageWithExistingPlugins := func(image, path string) error { //nolint:unparam dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -208,7 +208,7 @@ imagesToCopy: } // copyImageToTarStub fakes the image downloads and creates a fake tar.gz file for images - copyImageToTarStub := func(image, tarfile string) error { + copyImageToTarStub := func(image, tarfile string) error { //nolint:unparam _, err := os.Create(tarfile) Expect(err).ToNot(HaveOccurred()) return nil diff --git a/pkg/auth/csp/grpc.go b/pkg/auth/csp/grpc.go index 6fc359159..e2dae17ef 100644 --- a/pkg/auth/csp/grpc.go +++ b/pkg/auth/csp/grpc.go @@ -62,11 +62,11 @@ type configSource struct { // Token fetches the token. func (c *configSource) Token() (*oauth2.Token, error) { - g, err := c.GetCurrentServer() // nolint:staticcheck // Deprecated + g, err := c.GetCurrentServer() //nolint:staticcheck // Deprecated if err != nil { return nil, err } - if !g.IsGlobal() { // nolint:staticcheck // Deprecated + if !g.IsGlobal() { //nolint:staticcheck // Deprecated return nil, fmt.Errorf("trying to fetch token for non global server") } if !IsExpired(g.GlobalOpts.Auth.Expiration) { diff --git a/pkg/auth/csp/selfmanaged.go b/pkg/auth/csp/selfmanaged.go index 394439601..09619fb8b 100644 --- a/pkg/auth/csp/selfmanaged.go +++ b/pkg/auth/csp/selfmanaged.go @@ -95,6 +95,7 @@ func runLocalListener() error { mux := http.NewServeMux() mux.HandleFunc("/callback", callbackHandler) tokenExchange, tokenExchangeComplete = context.WithCancel(context.TODO()) + //nolint:gosec l := http.Server{ Addr: "", Handler: mux, diff --git a/pkg/auth/tkg/cluster_pinniped_info.go b/pkg/auth/tkg/cluster_pinniped_info.go index 38947cd33..1824ef039 100644 --- a/pkg/auth/tkg/cluster_pinniped_info.go +++ b/pkg/auth/tkg/cluster_pinniped_info.go @@ -4,6 +4,7 @@ package tkgauth import ( + "context" "crypto/tls" "crypto/x509" "encoding/json" @@ -59,7 +60,7 @@ func GetClusterInfoFromCluster(clusterAPIServerURL, configmapName string) (*clie clusterAPIServerURL = strings.TrimRight(clusterAPIServerURL, " /") clusterInfoURL := clusterAPIServerURL + fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", KubePublicNamespace, configmapName) - req, _ := http.NewRequest("GET", clusterInfoURL, http.NoBody) + req, _ := http.NewRequestWithContext(context.Background(), "GET", clusterInfoURL, http.NoBody) // To get the cluster ca certificate first time, we need to use skip verify the server certificate, // all the later communications to cluster would be using CA after this call clusterClient := &http.Client{ @@ -124,7 +125,7 @@ func GetPinnipedInfoFromCluster(clusterInfo *clientcmdapi.Cluster, discoveryPort } } pinnipedInfoURL := endpoint + fmt.Sprintf("/api/v1/namespaces/%s/configmaps/pinniped-info", KubePublicNamespace) - req, _ := http.NewRequest("GET", pinnipedInfoURL, http.NoBody) + req, _ := http.NewRequestWithContext(context.Background(), "GET", pinnipedInfoURL, http.NoBody) pool := x509.NewCertPool() pool.AppendCertsFromPEM(clusterInfo.CertificateAuthorityData) clusterClient := &http.Client{ diff --git a/pkg/auth/tkg/kube_config.go b/pkg/auth/tkg/kube_config.go index de7c20952..936ed7d08 100644 --- a/pkg/auth/tkg/kube_config.go +++ b/pkg/auth/tkg/kube_config.go @@ -91,7 +91,6 @@ func KubeconfigWithPinnipedAuthLoginPlugin(endpoint string, options *KubeConfigO return } - mergeFilePath = "" if options != nil && options.MergeFilePath != "" { mergeFilePath = options.MergeFilePath } else { diff --git a/pkg/auth/wcp/discovery.go b/pkg/auth/wcp/discovery.go index 4aa4e9420..4a270f5f0 100644 --- a/pkg/auth/wcp/discovery.go +++ b/pkg/auth/wcp/discovery.go @@ -5,6 +5,7 @@ package wcp import ( + "context" "fmt" "net/http" @@ -22,7 +23,7 @@ const ( func IsVSphereSupervisor(endpoint string, httpClient *http.Client) (bool, error) { loginBannerURL := fmt.Sprintf("%s/wcp/loginbanner", endpoint) - req, _ := http.NewRequest("GET", loginBannerURL, http.NoBody) + req, _ := http.NewRequestWithContext(context.Background(), "GET", loginBannerURL, http.NoBody) resp, err := httpClient.Do(req) if err != nil { diff --git a/pkg/command/config.go b/pkg/command/config.go index e601a35e1..439a81b41 100644 --- a/pkg/command/config.go +++ b/pkg/command/config.go @@ -182,7 +182,7 @@ func setUnstableVersions(cfg *configtypes.ClientConfig, value string) error { configtypes.AlphaUnstableVersions, configtypes.ExperimentalUnstableVersions, configtypes.NoUnstableVersions: - cfg.SetUnstableVersionSelector(optionKey) // nolint:staticcheck // Deprecated + cfg.SetUnstableVersionSelector(optionKey) //nolint:staticcheck // Deprecated default: return fmt.Errorf("unknown unstable-versions setting: %s; should be one of [all, none, alpha, experimental]", optionKey) } @@ -194,7 +194,7 @@ func setEdition(cfg *configtypes.ClientConfig, edition string) error { switch editionOption { case configtypes.EditionCommunity, configtypes.EditionStandard: - cfg.SetEditionSelector(editionOption) // nolint:staticcheck // Deprecated + cfg.SetEditionSelector(editionOption) //nolint:staticcheck // Deprecated default: return fmt.Errorf("unknown edition: %s; should be one of [%s, %s]", editionOption, configtypes.EditionStandard, configtypes.EditionCommunity) } @@ -260,9 +260,9 @@ var listServersCmd = &cobra.Command{ } output := component.NewOutputWriter(cmd.OutOrStdout(), outputFormat, "Name", "Type", "Endpoint", "Path", "Context") - for _, server := range cfg.KnownServers { // nolint:staticcheck // Deprecated + for _, server := range cfg.KnownServers { //nolint:staticcheck // Deprecated var endpoint, path, context string - if server.IsGlobal() { // nolint:staticcheck // Deprecated + if server.IsGlobal() { //nolint:staticcheck // Deprecated endpoint = server.GlobalOpts.Endpoint } else { endpoint = server.ManagementClusterOpts.Endpoint @@ -294,13 +294,13 @@ var deleteServersCmd = &cobra.Command{ if isAborted == nil { log.Infof("Deleting entry for cluster %s", args[0]) - serverExists, err := configlib.ServerExists(args[0]) // nolint:staticcheck // Deprecated + serverExists, err := configlib.ServerExists(args[0]) //nolint:staticcheck // Deprecated if err != nil { return err } if serverExists { - err := configlib.RemoveServer(args[0]) // nolint:staticcheck // Deprecated + err := configlib.RemoveServer(args[0]) //nolint:staticcheck // Deprecated if err != nil { return err } diff --git a/pkg/command/discovery_source.go b/pkg/command/discovery_source.go index aa675b1f1..30310b4b2 100644 --- a/pkg/command/discovery_source.go +++ b/pkg/command/discovery_source.go @@ -108,7 +108,7 @@ func newListDiscoverySourceCmd() *cobra.Command { } } } else { - server, err := configlib.GetCurrentServer() // nolint:staticcheck // Deprecated + server, err := configlib.GetCurrentServer() //nolint:staticcheck // Deprecated if err == nil && server != nil { outputFromDiscoverySources(server.DiscoverySources, common.PluginScopeContext, output) } @@ -300,8 +300,8 @@ func createRESTDiscoverySource(discoveryName, uri string) *configtypes.GenericRE func discoverySourceNameAndType(ds configtypes.PluginDiscovery) (string, string) { switch { - case ds.GCP != nil: // nolint:staticcheck // Deprecated - return ds.GCP.Name, common.DiscoveryTypeGCP // nolint:staticcheck // Deprecated + case ds.GCP != nil: //nolint:staticcheck // Deprecated + return ds.GCP.Name, common.DiscoveryTypeGCP //nolint:staticcheck // Deprecated case ds.Kubernetes != nil: return ds.Kubernetes.Name, common.DiscoveryTypeKubernetes case ds.Local != nil: diff --git a/pkg/command/login.go b/pkg/command/login.go index 9d0e54c7b..978d2bd6a 100644 --- a/pkg/command/login.go +++ b/pkg/command/login.go @@ -51,9 +51,9 @@ func init() { loginCmd.Flags().BoolVar(&stderrOnly, "stderr-only", false, "send all output to stderr rather than stdout") loginCmd.Flags().BoolVar(&forceCSP, "force-csp", false, "force the endpoint to be logged in as a csp server") loginCmd.Flags().BoolVar(&staging, "staging", false, "use CSP staging issuer") - loginCmd.Flags().MarkHidden("stderr-only") // nolint - loginCmd.Flags().MarkHidden("force-csp") // nolint - loginCmd.Flags().MarkHidden("staging") // nolint + loginCmd.Flags().MarkHidden("stderr-only") //nolint + loginCmd.Flags().MarkHidden("force-csp") //nolint + loginCmd.Flags().MarkHidden("staging") //nolint loginCmd.SetUsageFunc(cli.SubCmdUsageFunc) command.DeprecateCommandWithAlternative(loginCmd, "1.2.0", "context") @@ -85,7 +85,7 @@ func login(cmd *cobra.Command, args []string) (err error) { } newServerSelector := "+ new server" - var serverTarget *configtypes.Server // nolint:staticcheck // Deprecated + var serverTarget *configtypes.Server //nolint:staticcheck // Deprecated if name != "" { serverTarget, err = createNewServer() if err != nil { @@ -97,7 +97,7 @@ func login(cmd *cobra.Command, args []string) (err error) { return err } } else { - serverTarget, err = config.GetServer(server) // nolint:staticcheck // Deprecated + serverTarget, err = config.GetServer(server) //nolint:staticcheck // Deprecated if err != nil { return err } @@ -110,7 +110,7 @@ func login(cmd *cobra.Command, args []string) (err error) { } } - if serverTarget.Type == configtypes.GlobalServerType { // nolint:staticcheck // Deprecated + if serverTarget.Type == configtypes.GlobalServerType { //nolint:staticcheck // Deprecated err = globalLoginUsingServer(serverTarget) } else { err = managementClusterLogin(serverTarget) @@ -128,11 +128,11 @@ func login(cmd *cobra.Command, args []string) (err error) { return nil } -func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (*configtypes.Server, error) { // nolint:staticcheck // Deprecated +func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (*configtypes.Server, error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() - servers := map[string]*configtypes.Server{} // nolint:staticcheck // Deprecated - for _, server := range cfg.KnownServers { // nolint:staticcheck // Deprecated - ep, err := config.EndpointFromServer(server) // nolint:staticcheck // Deprecated + servers := map[string]*configtypes.Server{} //nolint:staticcheck // Deprecated + for _, server := range cfg.KnownServers { //nolint:staticcheck // Deprecated + ep, err := config.EndpointFromServer(server) //nolint:staticcheck // Deprecated if err != nil { return nil, err } @@ -150,7 +150,7 @@ func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (* } serverKeys := getKeysFromServerMap(servers) serverKeys = append(serverKeys, newServerSelector) - servers[newServerSelector] = &configtypes.Server{} // nolint:staticcheck // Deprecated + servers[newServerSelector] = &configtypes.Server{} //nolint:staticcheck // Deprecated err := component.Prompt( &component.PromptConfig{ Message: "Select a server", @@ -166,7 +166,7 @@ func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (* return servers[server], nil } -func getKeysFromServerMap(m map[string]*configtypes.Server) []string { // nolint:staticcheck // Deprecated +func getKeysFromServerMap(m map[string]*configtypes.Server) []string { //nolint:staticcheck // Deprecated keys := make([]string, 0, len(m)) for key := range m { keys = append(keys, key) @@ -185,7 +185,7 @@ func isGlobalServer(endpoint string) bool { return false } -func createNewServer() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createNewServer() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated // user provided command line options to create a server using kubeconfig[optional] and context if kubeContext != "" { return createServerWithKubeconfig() @@ -218,7 +218,7 @@ func createNewServer() (server *configtypes.Server, err error) { // nolint:stati return createServerWithKubeconfig() } -func createServerWithKubeconfig() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createServerWithKubeconfig() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() if kubeConfig == "" && kubeContext == "" { err = component.Prompt( @@ -263,7 +263,7 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n } } name = strings.TrimSpace(name) - nameExists, err := config.ServerExists(name) // nolint:staticcheck // Deprecated + nameExists, err := config.ServerExists(name) //nolint:staticcheck // Deprecated if err != nil { return server, err } @@ -272,12 +272,12 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n return } - endpointType := configtypes.ManagementClusterServerType // nolint:staticcheck // Deprecated + endpointType := configtypes.ManagementClusterServerType //nolint:staticcheck // Deprecated - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, Type: endpointType, - ManagementClusterOpts: &configtypes.ManagementClusterServer{ // nolint:staticcheck // Deprecated + ManagementClusterOpts: &configtypes.ManagementClusterServer{ //nolint:staticcheck // Deprecated Path: kubeConfig, Context: kubeContext, Endpoint: endpoint}, @@ -285,7 +285,7 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n return server, err } -func createServerWithEndpoint() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createServerWithEndpoint() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() if endpoint == "" { err = component.Prompt( @@ -313,7 +313,7 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol } } name = strings.TrimSpace(name) - nameExists, err := config.ServerExists(name) // nolint:staticcheck // Deprecated + nameExists, err := config.ServerExists(name) //nolint:staticcheck // Deprecated if err != nil { return server, err } @@ -322,9 +322,9 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol return } if isGlobalServer(endpoint) { - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, - Type: configtypes.GlobalServerType, // nolint:staticcheck // Deprecated + Type: configtypes.GlobalServerType, //nolint:staticcheck // Deprecated GlobalOpts: &configtypes.GlobalServer{Endpoint: sanitizeEndpoint(endpoint)}, } } else { @@ -354,10 +354,10 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol } } - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, - Type: configtypes.ManagementClusterServerType, // nolint:staticcheck // Deprecated - ManagementClusterOpts: &configtypes.ManagementClusterServer{ // nolint:staticcheck // Deprecated + Type: configtypes.ManagementClusterServerType, //nolint:staticcheck // Deprecated + ManagementClusterOpts: &configtypes.ManagementClusterServer{ //nolint:staticcheck // Deprecated Path: kubeConfig, Context: kubeContext, Endpoint: endpoint}, @@ -366,7 +366,7 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol return server, err } -func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:staticcheck // Deprecated +func globalLoginUsingServer(s *configtypes.Server) (err error) { //nolint:staticcheck // Deprecated a := configtypes.GlobalServerAuth{} apiTokenValue, apiTokenExists := os.LookupEnv(config.EnvAPITokenKey) @@ -405,7 +405,7 @@ func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:stati s.GlobalOpts.Auth = a - err = config.PutServer(s, true) // nolint:staticcheck // Deprecated + err = config.PutServer(s, true) //nolint:staticcheck // Deprecated if err != nil { return err } @@ -415,7 +415,7 @@ func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:stati return nil } -func managementClusterLogin(s *configtypes.Server) error { // nolint:staticcheck // Deprecated +func managementClusterLogin(s *configtypes.Server) error { //nolint:staticcheck // Deprecated if s.ManagementClusterOpts.Path != "" && s.ManagementClusterOpts.Context != "" { _, err := tkgauth.GetServerKubernetesVersion(s.ManagementClusterOpts.Path, s.ManagementClusterOpts.Context) if err != nil { @@ -423,7 +423,7 @@ func managementClusterLogin(s *configtypes.Server) error { // nolint:staticcheck log.Error(err, "") return err } - err = config.PutServer(s, true) // nolint:staticcheck // Deprecated + err = config.PutServer(s, true) //nolint:staticcheck // Deprecated if err != nil { return err } diff --git a/pkg/command/plugin.go b/pkg/command/plugin.go index 59f7e5bfc..30f49d5ee 100644 --- a/pkg/command/plugin.go +++ b/pkg/command/plugin.go @@ -233,7 +233,7 @@ func newInstallPluginCmd() *cobra.Command { } if config.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { - return legacyPluginInstall(cmd, args) + return legacyPluginInstall(args) } if group != "" { @@ -300,7 +300,7 @@ func newInstallPluginCmd() *cobra.Command { return installCmd } -func legacyPluginInstall(cmd *cobra.Command, args []string) error { +func legacyPluginInstall(args []string) error { var err error if len(args) == 0 { return fmt.Errorf("missing plugin name or '%s' as an argument", cli.AllPlugins) diff --git a/pkg/command/plugin_test.go b/pkg/command/plugin_test.go index 0cb6e5177..bf58f46b4 100644 --- a/pkg/command/plugin_test.go +++ b/pkg/command/plugin_test.go @@ -167,7 +167,7 @@ func TestPluginList(t *testing.T) { cc, err := catalog.NewContextCatalog("") assert.Nil(err) for i, pluginName := range spec.plugins { - err = setupFakePlugin(dir, pluginName, spec.versions[i], plugin.SystemCmdGroup, completionType, spec.targets[i], 1, false, []string{pluginName[:2]}) + err = setupFakePlugin(dir, pluginName, plugin.SystemCmdGroup, completionType, spec.targets[i], 1, false, []string{pluginName[:2]}) assert.Nil(err) pi := &cli.PluginInfo{ Name: pluginName, @@ -254,7 +254,7 @@ func TestDeletePlugin(t *testing.T) { assert.Nil(err) for i, pluginName := range spec.plugins { - err = setupFakePlugin(dir, pluginName, spec.versions[i], plugin.SystemCmdGroup, completionType, spec.targets[i], 1, false, []string{pluginName[:2]}) + err = setupFakePlugin(dir, pluginName, plugin.SystemCmdGroup, completionType, spec.targets[i], 1, false, []string{pluginName[:2]}) assert.Nil(err) pi := &cli.PluginInfo{ Name: pluginName, diff --git a/pkg/command/root_test.go b/pkg/command/root_test.go index cb2c2c255..d44f8cb48 100644 --- a/pkg/command/root_test.go +++ b/pkg/command/root_test.go @@ -271,7 +271,7 @@ func TestSubcommands(t *testing.T) { os.Stdout = w os.Stderr = w - err = setupFakePlugin(dir, spec.plugin, spec.version, spec.cmdGroup, completionType, spec.target, spec.postInstallResult, spec.hidden, spec.aliases) + err = setupFakePlugin(dir, spec.plugin, spec.cmdGroup, completionType, spec.target, spec.postInstallResult, spec.hidden, spec.aliases) assert.Nil(err) pi := &cli.PluginInfo{ @@ -358,7 +358,7 @@ func TestEnvVarsSet(t *testing.T) { os.Unsetenv(envVarName) } -func setupFakePlugin(dir, pluginName, version string, commandGroup plugin.CmdGroup, completionType uint8, target configtypes.Target, postInstallResult uint8, hidden bool, aliases []string) error { +func setupFakePlugin(dir, pluginName string, commandGroup plugin.CmdGroup, completionType uint8, target configtypes.Target, postInstallResult uint8, hidden bool, aliases []string) error { filePath := filepath.Join(dir, pluginName) f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0755) diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index eb75ad7f5..4beb7e964 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -47,7 +47,7 @@ const DefaultVersionSelector = configtypes.NoUnstableVersions const DefaultEdition = "tkg" // CoreGCPBucketRepository is the default GCP bucket repository. -var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticcheck // Deprecated +var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ //nolint:staticcheck // Deprecated BucketName: CoreBucketName, Name: CoreRepositoryName, } @@ -56,7 +56,7 @@ var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticc const AdvancedRepositoryName = "advanced" // AdvancedGCPBucketRepository is the GCP bucket repository for advanced plugins. -var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticcheck // Deprecated +var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ //nolint:staticcheck // Deprecated BucketName: "tanzu-cli-advanced-plugins", Name: AdvancedRepositoryName, } @@ -65,7 +65,7 @@ var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:sta const DefaultTMCPluginsArtifactRepository = "https://tmc-cli.s3-us-west-2.amazonaws.com/plugins/artifacts" // DefaultRepositories are the default repositories for the CLI. -var DefaultRepositories = []configtypes.PluginRepository{ // nolint:staticcheck // Deprecated +var DefaultRepositories = []configtypes.PluginRepository{ //nolint:staticcheck // Deprecated { GCPPluginRepository: &CoreGCPBucketRepository, }, @@ -170,7 +170,7 @@ func GetAdditionalTestDiscoveryImages() []string { return additionalImages } -func getHTTPURIForGCPPluginRepository(repo configtypes.GCPPluginRepository) string { // nolint:staticcheck // Deprecated +func getHTTPURIForGCPPluginRepository(repo configtypes.GCPPluginRepository) string { //nolint:staticcheck // Deprecated return fmt.Sprintf("https://storage.googleapis.com/%s/", repo.BucketName) } diff --git a/pkg/discovery/oci_dbbacked_test.go b/pkg/discovery/oci_dbbacked_test.go index 23cd0ba13..97948fb26 100644 --- a/pkg/discovery/oci_dbbacked_test.go +++ b/pkg/discovery/oci_dbbacked_test.go @@ -130,11 +130,11 @@ var _ = Describe("Unit tests for DB-backed OCI discovery", func() { }) Context("With a criteria", func() { It("should have a filter that matches the criteria and ignore hidden plugins", func() { - filteredName := "cluster" // nolint:goconst + filteredName := "cluster" //nolint:goconst filteredTarget := configtypes.TargetK8s - filteredVersion := "v0.26.0" // nolint:goconst - filteredOS := "darwin" // nolint:goconst - filteredArch := "amd64" // nolint:goconst + filteredVersion := "v0.26.0" //nolint:goconst + filteredOS := "darwin" //nolint:goconst + filteredArch := "amd64" //nolint:goconst discovery = NewOCIDiscovery("test-discovery", "test-image:latest", &PluginDiscoveryCriteria{ Name: filteredName, diff --git a/pkg/discovery/utils.go b/pkg/discovery/utils.go index d7b8ac784..d970bd708 100644 --- a/pkg/discovery/utils.go +++ b/pkg/discovery/utils.go @@ -10,7 +10,7 @@ import ( // CheckDiscoveryName returns true if discovery name exists else return false func CheckDiscoveryName(ds configtypes.PluginDiscovery, dn string) bool { - return (ds.GCP != nil && ds.GCP.Name == dn) || // nolint:staticcheck // Deprecated + return (ds.GCP != nil && ds.GCP.Name == dn) || //nolint:staticcheck // Deprecated (ds.Kubernetes != nil && ds.Kubernetes.Name == dn) || (ds.Local != nil && ds.Local.Name == dn) || (ds.REST != nil && ds.REST.Name == dn) || @@ -39,10 +39,10 @@ func CompareDiscoverySource(ds1, ds2 configtypes.PluginDiscovery, dsType string) } func compareGCPDiscoverySources(ds1, ds2 configtypes.PluginDiscovery) bool { - return ds1.GCP != nil && ds2.GCP != nil && // nolint:staticcheck // Deprecated - ds1.GCP.Name == ds2.GCP.Name && // nolint:staticcheck // Deprecated - ds1.GCP.Bucket == ds2.GCP.Bucket && // nolint:staticcheck // Deprecated - ds1.GCP.ManifestPath == ds2.GCP.ManifestPath // nolint:staticcheck // Deprecated + return ds1.GCP != nil && ds2.GCP != nil && //nolint:staticcheck // Deprecated + ds1.GCP.Name == ds2.GCP.Name && //nolint:staticcheck // Deprecated + ds1.GCP.Bucket == ds2.GCP.Bucket && //nolint:staticcheck // Deprecated + ds1.GCP.ManifestPath == ds2.GCP.ManifestPath //nolint:staticcheck // Deprecated } func compareLocalDiscoverySources(ds1, ds2 configtypes.PluginDiscovery) bool { diff --git a/pkg/plugininventory/sqlite_inventory.go b/pkg/plugininventory/sqlite_inventory.go index ea878ac6c..cfbbb6d13 100644 --- a/pkg/plugininventory/sqlite_inventory.go +++ b/pkg/plugininventory/sqlite_inventory.go @@ -144,10 +144,7 @@ func (b *SQLiteInventory) getPluginsFromDB(filter *PluginInventoryFilter) ([]*Pl } defer db.Close() - whereClause, err := createPluginWhereClause(filter) - if err != nil { - return nil, err - } + whereClause := createPluginWhereClause(filter) // Build the final query with the SELECT, WHERE and ORDER clauses. // The ORDER clause is essential because the parsing algorithm of extractPluginsFromRows() @@ -163,7 +160,7 @@ func (b *SQLiteInventory) getPluginsFromDB(filter *PluginInventoryFilter) ([]*Pl } // createPluginWhereClause parses the filter and creates the WHERE clause for the DB query. -func createPluginWhereClause(filter *PluginInventoryFilter) (string, error) { +func createPluginWhereClause(filter *PluginInventoryFilter) string { var whereClause string // If there is a filter, create a WHERE clause for the query. @@ -214,7 +211,7 @@ func createPluginWhereClause(filter *PluginInventoryFilter) (string, error) { whereClause = fmt.Sprintf("WHERE %s", whereClause) } } - return whereClause, nil + return whereClause } // extractPluginsFromRows loops through all DB rows and builds an array @@ -304,10 +301,7 @@ func (b *SQLiteInventory) getGroupsFromDB(filter PluginGroupFilter) ([]*PluginGr } defer db.Close() - whereClause, err := createGroupWhereClause(filter) - if err != nil { - return nil, err - } + whereClause := createGroupWhereClause(filter) // Build the final query with the SELECT, WHERE and ORDER clauses. // The ORDER clause is essential because the parsing algorithm of extractGroupsFromRows() @@ -323,7 +317,7 @@ func (b *SQLiteInventory) getGroupsFromDB(filter PluginGroupFilter) ([]*PluginGr } // createGroupWhereClause parses the filter and creates the WHERE clause for the DB query for groups. -func createGroupWhereClause(filter PluginGroupFilter) (string, error) { +func createGroupWhereClause(filter PluginGroupFilter) string { var whereClause string // If there is a filter, create a WHERE clause for the query. @@ -348,7 +342,7 @@ func createGroupWhereClause(filter PluginGroupFilter) (string, error) { whereClause = fmt.Sprintf("WHERE %s", whereClause) } - return whereClause, nil + return whereClause } // extractGroupsFromRows loops through all DB rows and builds an array diff --git a/pkg/plugininventory/sqlite_inventory_test.go b/pkg/plugininventory/sqlite_inventory_test.go index 9f5245634..9807bca1c 100644 --- a/pkg/plugininventory/sqlite_inventory_test.go +++ b/pkg/plugininventory/sqlite_inventory_test.go @@ -464,7 +464,7 @@ var _ = Describe("Unit tests for plugin inventory", func() { Expect(len(plugins)).To(Equal(2)) for _, p := range plugins { - if p.Name == "management-cluster" { // nolint: goconst + if p.Name == "management-cluster" { //nolint:goconst Expect(p.RecommendedVersion).To(Equal("v0.28.0")) Expect(string(p.Target)).To(Equal("kubernetes")) Expect(p.Description).To(Equal("Kubernetes management cluster operations")) @@ -475,7 +475,7 @@ var _ = Describe("Unit tests for plugin inventory", func() { artifactList := p.Artifacts["v0.28.0"] Expect(len(artifactList)).To(Equal(2)) for _, a := range artifactList { - if a.OS == "linux" { // nolint: goconst + if a.OS == "linux" { //nolint:goconst Expect(a.Arch).To(Equal("amd64")) Expect(a.Digest).To(Equal("0000000000")) Expect(a.Image).To(Equal(tmpDir + "/vmware/tkg/linux/amd64/k8s/management-cluster:v0.28.0")) diff --git a/pkg/pluginmanager/default_discoveries.go b/pkg/pluginmanager/default_discoveries.go index 368236722..b7170c428 100644 --- a/pkg/pluginmanager/default_discoveries.go +++ b/pkg/pluginmanager/default_discoveries.go @@ -10,12 +10,12 @@ import ( configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" ) -func defaultDiscoverySourceBasedOnServer(server *configtypes.Server) []configtypes.PluginDiscovery { // nolint:staticcheck // Deprecated +func defaultDiscoverySourceBasedOnServer(server *configtypes.Server) []configtypes.PluginDiscovery { //nolint:staticcheck // Deprecated var defaultDiscoveries []configtypes.PluginDiscovery // If current server type is management-cluster, then add // the default kubernetes discovery endpoint pointing to the // management-cluster kubeconfig - if server.Type == configtypes.ManagementClusterServerType && server.ManagementClusterOpts != nil { // nolint:staticcheck // Deprecated + if server.Type == configtypes.ManagementClusterServerType && server.ManagementClusterOpts != nil { //nolint:staticcheck // Deprecated defaultDiscoveries = append(defaultDiscoveries, defaultDiscoverySourceForK8sTargetedContext(server.Name, server.ManagementClusterOpts.Path, server.ManagementClusterOpts.Context)) } return defaultDiscoveries diff --git a/pkg/pluginmanager/manager.go b/pkg/pluginmanager/manager.go index dc6725caf..d71e86353 100644 --- a/pkg/pluginmanager/manager.go +++ b/pkg/pluginmanager/manager.go @@ -270,7 +270,7 @@ func discoverServerPluginsBasedOnAllCurrentContexts() ([]discovery.Discovered, e func discoverServerPluginsBasedOnCurrentServer() ([]discovery.Discovered, error) { var plugins []discovery.Discovered - server, err := configlib.GetCurrentServer() // nolint:staticcheck // Deprecated + server, err := configlib.GetCurrentServer() //nolint:staticcheck // Deprecated if err != nil || server == nil { // If servername is not specified than returning empty list // as there are no server plugins that can be discovered @@ -665,7 +665,8 @@ func InstallPluginFromContext(pluginName, version string, target configtypes.Tar // installs a plugin by name, version and target. // If the contextName is not empty, it implies the plugin is a context-scope plugin, otherwise // we are installing a standalone plugin. -// nolint: gocyclo +// +//nolint:gocyclo func installPlugin(pluginName, version string, target configtypes.Target, contextName string) error { if configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { // The legacy installation can figure out if the plugin is from a context @@ -1130,7 +1131,8 @@ func SyncPlugins() error { } // InstallPluginsFromLocalSource installs plugin from local source directory -// nolint: gocyclo +// +//nolint:gocyclo func InstallPluginsFromLocalSource(pluginName, version string, target configtypes.Target, localPath string, installTestPlugin bool) error { // Set default local plugin distro to local-path as while installing the plugin // from local source we should take t @@ -1484,6 +1486,10 @@ func getPluginDiscoveries() ([]configtypes.PluginDiscovery, error) { // For example, if the staging central repo is added as a test discovery, it // may contain older versions of a plugin that is now published to the production // central repo; we therefore need to search the test discoveries last. - discoverySources, _ := configlib.GetCLIDiscoverySources() + discoverySources, err := configlib.GetCLIDiscoverySources() + if err != nil { + return testDiscoveries, err + } + return append(discoverySources, testDiscoveries...), nil } diff --git a/pkg/registry/client.go b/pkg/registry/client.go index 31e10cf33..2e3cdc5ab 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -104,7 +104,7 @@ func getFilesFromLayer(imgLayer regv1.Layer) (map[string][]byte, error) { } return files, err } - if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA { + if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA { //nolint:staticcheck,nolintlint buf, err := io.ReadAll(tarReader) if err != nil { return files, err