Skip to content

Commit

Permalink
Enable forbidigo linter (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschimke95 authored Oct 18, 2024
1 parent 2ee8e70 commit 95fe533
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
7 changes: 3 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ linters:
# - errchkjson
- errname
- errorlint
- exhaustive
- fatcontext
- forbidigo


# TODO(ben): Enable those linters step by step and fix existing issues.
# - exhaustive
# - exhaustruct
# - fatcontext
# - forbidigo
# - forcetypeassert
# - funlen
# - gci
Expand Down
20 changes: 10 additions & 10 deletions src/k8s/cmd/k8sd/k8sd_cluster_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func newClusterRecoverCmd(env cmdutil.ExecutionEnvironment) *cobra.Command {
AddDirHeader: true,
})

if err := recoveryCmdPrechecks(cmd.Context()); err != nil {
if err := recoveryCmdPrechecks(cmd); err != nil {
cmd.PrintErrf("Recovery precheck failed: %v\n", err)
env.Exit(1)
}
Expand Down Expand Up @@ -179,8 +179,8 @@ func removeEmptyLines(content []byte) []byte {
return out
}

func recoveryCmdPrechecks(ctx context.Context) error {
log := log.FromContext(ctx)
func recoveryCmdPrechecks(cmd *cobra.Command) error {
log := log.FromContext(cmd.Context())

log.V(1).Info("Running prechecks.")

Expand All @@ -195,15 +195,15 @@ func recoveryCmdPrechecks(ctx context.Context) error {
return fmt.Errorf("k8sd state dir not specified")
}

fmt.Print(preRecoveryMessage)
fmt.Print("\n")
cmd.Print(preRecoveryMessage)
cmd.Print("\n")

if clusterRecoverOpts.NonInteractive {
fmt.Print(nonInteractiveMessage)
fmt.Print("\n")
cmd.Print(nonInteractiveMessage)
cmd.Print("\n")
} else {
reader := bufio.NewReader(os.Stdin)
fmt.Print(recoveryConfirmation)
cmd.Print(recoveryConfirmation)

input, err := reader.ReadString('\n')
if err != nil {
Expand All @@ -215,11 +215,11 @@ func recoveryCmdPrechecks(ctx context.Context) error {
return fmt.Errorf("cluster edit aborted; no changes made")
}

fmt.Print("\n")
cmd.Print("\n")
}

if !clusterRecoverOpts.SkipK8sDqlite {
if err := ensureK8sDqliteMembersStopped(ctx); err != nil {
if err := ensureK8sDqliteMembersStopped(cmd.Context()); err != nil {
return err
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/k8s/pkg/k8sd/api/cluster_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
apiv1 "github.com/canonical/k8s-snap-api/api/v1"
"github.com/canonical/k8s/pkg/k8sd/database"
"github.com/canonical/k8s/pkg/k8sd/types"
"github.com/canonical/k8s/pkg/log"
"github.com/canonical/k8s/pkg/utils"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/microcluster/v3/microcluster"
Expand Down Expand Up @@ -48,17 +49,19 @@ func (e *Endpoints) postClusterJoinTokens(s state.State, r *http.Request) respon
}

func getOrCreateJoinToken(ctx context.Context, m *microcluster.MicroCluster, tokenName string, ttl time.Duration) (string, error) {
log := log.FromContext(ctx)

// grab token if it exists and return it
records, err := m.ListJoinTokens(ctx)
if err != nil {
fmt.Println("Failed to get existing tokens. Trying to create a new token.")
log.V(1).Info("Failed to get existing tokens. Trying to create a new token.")
} else {
for _, record := range records {
if record.Name == tokenName {
return record.Token, nil
}
}
fmt.Println("No token exists yet. Creating a new token.")
log.V(1).Info("No token exists yet. Creating a new token.")
}

token, err := m.NewJoinToken(ctx, tokenName, ttl)
Expand Down
17 changes: 17 additions & 0 deletions src/k8s/pkg/k8sd/setup/auth-token-webhook.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Config
clusters:
- name: k8s-token-auth-service
cluster:
certificate-authority: "cluster.crt"
tls-server-name: 127.0.0.1
server: "https://auth-webhook.url"
current-context: webhook
contexts:
- context:
cluster: k8s-token-auth-service
user: k8s-apiserver
name: webhook
users:
- name: k8s-apiserver
user: {}
1 change: 1 addition & 0 deletions src/k8s/pkg/k8sd/setup/k8s-apiserver-proxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"endpoints":null}

0 comments on commit 95fe533

Please sign in to comment.