Skip to content

Commit

Permalink
Fix linter rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Sep 21, 2024
1 parent a66002b commit 3d4b9e6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func Run() error {
rootCmd.AddCommand(getInitCommand())
rootCmd.AddCommand(getUnsealCommand())

return rootCmd.Execute()
return rootCmd.Execute() //nolint:wrapcheck // it's our errors returned
}
2 changes: 1 addition & 1 deletion cmd/unseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func getUnsealCommand() *cobra.Command {
unsealCmd := &cobra.Command{
Use: "unseal",
Short: "Unseal a vault instance",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
kube, err := kubernetes.New(true)
if err != nil {
return fmt.Errorf("error creating kubernetes client: %s", err)

Check failure on line 24 in cmd/unseal.go

View workflow job for this annotation

GitHub Actions / run-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
Expand Down
7 changes: 4 additions & 3 deletions internal/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ func New(inCluster bool) (*Kubernetes, error) {
kubeconfigLocation = remoteKubernetes()

if _, err := os.Stat(kubeconfigLocation); err != nil {
return nil, fmt.Errorf("error reading kubeconfig: %s", err)
return nil, fmt.Errorf("error reading kubeconfig: %w", err)
}
}

// From the docs: If neither masterUrl or kubeconfigPath are passed in we
// fallback to inClusterConfig
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigLocation)
if err != nil {
return nil, fmt.Errorf("error building kubeconfig: %s", err)
return nil, fmt.Errorf("error building kubeconfig: %w", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("error creating clientset: %s", err)
return nil, fmt.Errorf("error creating clientset: %w", err)
}

kube.clientset = clientset
Expand All @@ -58,6 +58,7 @@ func remoteKubernetes() string {
return filepath.Join(homedir.HomeDir(), ".kube", "config")
}

//nolint:ireturn // okay to return the Kubernetes interface
func (k *Kubernetes) GetClientSet() kubernetes.Interface {
return k.clientset
}
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k *Kubernetes) ReadConfigMap(name, namespace string) (map[string]string, e

parsedSecretData := make(map[string]string)
for key, value := range configMap.Data {
parsedSecretData[key] = string(value)
parsedSecretData[key] = value
}

return parsedSecretData, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (k *Kubernetes) GetPodWhenReady(ctx context.Context, timeoutSeconds int, ma
if err := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
pods, err := k.clientset.CoreV1().Pods(namespace).List(ctx, podListOptions)
if err != nil {
return false, err
return false, fmt.Errorf("error listing pods: %w", err)
}

for _, pod := range pods.Items {
Expand Down
15 changes: 8 additions & 7 deletions internal/vault/autounseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net"
"time"

vaultapi "github.com/hashicorp/vault/api"
Expand All @@ -18,7 +19,7 @@ func (conf *Configuration) getVaultClientForNode(node string) (*vaultapi.Client,
}

configCopy := conf.Config
configCopy.Address = fmt.Sprintf("http://%s:8200", pod.Status.PodIP)
configCopy.Address = "http://" + net.JoinHostPort(pod.Status.PodIP, "8200")
client, err := vaultapi.NewClient(configCopy)
if err != nil {
return nil, fmt.Errorf("error creating vault client: %w", err)
Expand Down Expand Up @@ -48,14 +49,14 @@ func unsealVault(client *vaultapi.Client, keys []string) error {
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
continue
} else {
cancel()
return fmt.Errorf("error unsealing shard %v: %w", i+1, err)
}
} else {
unsealed = true
break

cancel()
return fmt.Errorf("error unsealing shard %v: %w", i+1, err)
}

unsealed = true
break
}

cancel()
Expand Down
8 changes: 4 additions & 4 deletions internal/vault/vault.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vault

import (
"fmt"
"strings"

vaultapi "github.com/hashicorp/vault/api"
Expand All @@ -12,7 +13,7 @@ func (conf *Configuration) parseExistingVaultInitSecret() (*vaultapi.InitRespons
// of the initialization secret
secret, err := conf.Kubernetes.ReadSecret(VaultSecretName, VaultNamespace)
if err != nil {
return &vaultapi.InitResponse{}, err
return nil, fmt.Errorf("error reading secret %q: %w", VaultSecretName, err)
}

// Add root-unseal-key entries to slice
Expand All @@ -23,9 +24,8 @@ func (conf *Configuration) parseExistingVaultInitSecret() (*vaultapi.InitRespons
}
}

existingInitResponse := &vaultapi.InitResponse{
return &vaultapi.InitResponse{
Keys: rkSlice,
RootToken: secret["root-token"],
}
return existingInitResponse, nil
}, nil
}

0 comments on commit 3d4b9e6

Please sign in to comment.