diff --git a/cmd/tk/check.go b/cmd/tk/check.go index a3db5d61..735656e8 100644 --- a/cmd/tk/check.go +++ b/cmd/tk/check.go @@ -122,35 +122,35 @@ func kubectlCheck(ctx context.Context, version string) bool { func kubernetesCheck(version string) bool { cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { - logFailure("kubernetes client initialization failed: %s", err.Error()) + logFailure("Kubernetes client initialization failed: %s", err.Error()) return false } client, err := kubernetes.NewForConfig(cfg) if err != nil { - logFailure("kubernetes client initialization failed: %s", err.Error()) + logFailure("Kubernetes client initialization failed: %s", err.Error()) return false } ver, err := client.Discovery().ServerVersion() if err != nil { - logFailure("kubernetes API call failed %s", err.Error()) + logFailure("Kubernetes API call failed: %s", err.Error()) return false } v, err := semver.ParseTolerant(ver.String()) if err != nil { - logFailure("kubernetes version can't be determined") + logFailure("Kubernetes version can't be determined") return false } rng, _ := semver.ParseRange(version) if !rng(v) { - logFailure("kubernetes version must be %s", version) + logFailure("Kubernetes version must be %s", version) return false } - logSuccess("kubernetes %s %s", v.String(), version) + logSuccess("Kubernetes %s %s", v.String(), version) return true } diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go index a6db3617..501cbf70 100644 --- a/cmd/tk/create_source_git.go +++ b/cmd/tk/create_source_git.go @@ -258,7 +258,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { } if gitRepository.Status.Artifact != nil { - logSuccess("fetched revision %s", gitRepository.Status.Artifact.Revision) + logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision) } else { return fmt.Errorf("git sync failed, artifact not found") } @@ -268,7 +268,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { func generateKeyPair(ctx context.Context) (*ssh.KeyPair, error) { var keyGen ssh.KeyPairGenerator - switch sourceGitKeyAlgorithm.String() { + switch algorithm := sourceGitKeyAlgorithm.String(); algorithm { case "rsa": keyGen = ssh.NewRSAGenerator(int(sourceGitRSABits)) case "ecdsa": @@ -276,11 +276,11 @@ func generateKeyPair(ctx context.Context) (*ssh.KeyPair, error) { case "ed25519": keyGen = ssh.NewEd25519Generator() default: - return nil, fmt.Errorf("unsupported public key algorithm '%s'", sourceGitKeyAlgorithm.String()) + return nil, fmt.Errorf("unsupported public key algorithm: %s", algorithm) } pair, err := keyGen.Generate() if err != nil { - return nil, fmt.Errorf("key pair generation failed: %w", err) + return nil, fmt.Errorf("key pair generation failed, error: %w", err) } return pair, nil } @@ -292,7 +292,7 @@ func scanHostKey(ctx context.Context, url *url.URL) ([]byte, error) { } hostKey, err := ssh.ScanHostKey(host, 30*time.Second) if err != nil { - return nil, fmt.Errorf("SSH key scan for host '%s' failed: %w", host, err) + return nil, fmt.Errorf("SSH key scan for host %s failed, error: %w", host, err) } return hostKey, nil } diff --git a/cmd/tk/export_source_git.go b/cmd/tk/export_source_git.go index e9fd7f26..b8d38e99 100644 --- a/cmd/tk/export_source_git.go +++ b/cmd/tk/export_source_git.go @@ -125,16 +125,16 @@ func exportGit(source sourcev1.GitRepository) error { return nil } -func exportGitCredentials(ctx context.Context, kubeClinet client.Client, source sourcev1.GitRepository) error { +func exportGitCredentials(ctx context.Context, kubeClient client.Client, source sourcev1.GitRepository) error { if source.Spec.SecretRef != nil { namespacedName := types.NamespacedName{ Namespace: source.Namespace, Name: source.Spec.SecretRef.Name, } var cred corev1.Secret - err := kubeClinet.Get(ctx, namespacedName, &cred) + err := kubeClient.Get(ctx, namespacedName, &cred) if err != nil { - return fmt.Errorf("get secret failed: %w", err) + return fmt.Errorf("failed to retrieve secret %s, error: %w", namespacedName.Name, err) } exported := corev1.Secret{ diff --git a/cmd/tk/get_source_git.go b/cmd/tk/get_source_git.go index 9de4236d..b3a04fcc 100644 --- a/cmd/tk/get_source_git.go +++ b/cmd/tk/get_source_git.go @@ -62,7 +62,7 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error { for _, condition := range source.Status.Conditions { if condition.Type == sourcev1.ReadyCondition { if condition.Status != corev1.ConditionFalse { - logSuccess("%s last fetched revision %s", source.GetName(), source.Status.Artifact.Revision) + logSuccess("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision) } else { logFailure("%s %s", source.GetName(), condition.Message) } diff --git a/cmd/tk/sync_source_git.go b/cmd/tk/sync_source_git.go index 4950699b..efa0678a 100644 --- a/cmd/tk/sync_source_git.go +++ b/cmd/tk/sync_source_git.go @@ -93,7 +93,7 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error { } if gitRepository.Status.Artifact != nil { - logSuccess("fetched revision %s", gitRepository.Status.Artifact.Revision) + logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision) } else { return fmt.Errorf("git sync failed, artifact not found") } diff --git a/cmd/tk/utils.go b/cmd/tk/utils.go index 0183a456..433bcbac 100644 --- a/cmd/tk/utils.go +++ b/cmd/tk/utils.go @@ -111,7 +111,7 @@ func (*Utils) execTemplate(obj interface{}, tmpl, filename string) error { func (*Utils) kubeClient(config string) (client.Client, error) { cfg, err := clientcmd.BuildConfigFromFlags("", config) if err != nil { - return nil, fmt.Errorf("kubernetes client initialization failed: %w", err) + return nil, fmt.Errorf("Kubernetes client initialization failed: %w", err) } scheme := runtime.NewScheme() @@ -123,7 +123,7 @@ func (*Utils) kubeClient(config string) (client.Client, error) { Scheme: scheme, }) if err != nil { - return nil, fmt.Errorf("kubernetes client initialization failed: %w", err) + return nil, fmt.Errorf("Kubernetes client initialization failed: %w", err) } return kubeClient, nil diff --git a/pkg/git/provider_github.go b/pkg/git/provider_github.go index 27b67bb5..a2340478 100644 --- a/pkg/git/provider_github.go +++ b/pkg/git/provider_github.go @@ -77,7 +77,7 @@ func (p *GithubProvider) CreateRepository(ctx context.Context, r *Repository) (b }) if err != nil { if !strings.Contains(err.Error(), "name already exists on this account") { - return false, fmt.Errorf("create repository error: %w", err) + return false, fmt.Errorf("failed to create repository, error: %w", err) } } else { return true, nil @@ -95,13 +95,13 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi // check team exists _, _, err = gh.Teams.GetTeamBySlug(ctx, r.Owner, name) if err != nil { - return false, fmt.Errorf("get team %s error: %w", name, err) + return false, fmt.Errorf("failed to retrieve team '%s', error: %w", name, err) } // check if team is assigned to the repo _, resp, err := gh.Teams.IsTeamRepoBySlug(ctx, r.Owner, name, r.Owner, r.Name) if resp == nil && err != nil { - return false, fmt.Errorf("is team %s error: %w", name, err) + return false, fmt.Errorf("failed to determine if team '%s' is assigned to the repository, error: %w", name, err) } // add team to the repo @@ -110,7 +110,7 @@ func (p *GithubProvider) AddTeam(ctx context.Context, r *Repository, name, permi Permission: permission, }) if err != nil { - return false, fmt.Errorf("add team %s error: %w", name, err) + return false, fmt.Errorf("failed to add team '%s' to the repository, error: %w", name, err) } return true, nil } @@ -128,10 +128,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k // list deploy keys keys, resp, err := gh.Repositories.ListKeys(ctx, r.Owner, r.Name, nil) if err != nil { - return false, fmt.Errorf("list deploy keys error: %w", err) + return false, fmt.Errorf("failed to list deploy keys, error: %w", err) } if resp.StatusCode >= 300 { - return false, fmt.Errorf("list deploy keys failed with status code: %s", resp.Status) + return false, fmt.Errorf("failed to list deploy keys (status code: %s)", resp.Status) } // check if the key exists @@ -152,10 +152,10 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k if existingKey != nil { resp, err := gh.Repositories.DeleteKey(ctx, r.Owner, r.Name, *existingKey.ID) if err != nil { - return false, fmt.Errorf("delete deploy key error: %w", err) + return false, fmt.Errorf("failed to delete deploy key '%s', error: %w", keyName, err) } if resp.StatusCode >= 300 { - return false, fmt.Errorf("delete deploy key failed with status code: %s", resp.Status) + return false, fmt.Errorf("failed to delete deploy key '%s' (status code: %s)", keyName, resp.Status) } } @@ -168,7 +168,7 @@ func (p *GithubProvider) AddDeployKey(ctx context.Context, r *Repository, key, k ReadOnly: &isReadOnly, }) if err != nil { - return false, fmt.Errorf("create deploy key error: %w", err) + return false, fmt.Errorf("failed to create deploy key '%s', error: %w", keyName, err) } return true, nil } diff --git a/pkg/git/provider_gitlab.go b/pkg/git/provider_gitlab.go index 1b71987f..c3012435 100644 --- a/pkg/git/provider_gitlab.go +++ b/pkg/git/provider_gitlab.go @@ -59,7 +59,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b if !p.IsPersonal { groups, _, err := gl.Groups.ListGroups(&gitlab.ListGroupsOptions{Search: gitlab.String(r.Owner)}, gitlab.WithContext(ctx)) if err != nil { - return false, fmt.Errorf("list groups error: %w", err) + return false, fmt.Errorf("failed to list groups, error: %w", err) } if len(groups) > 0 { @@ -74,7 +74,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx)) if err != nil { - return false, fmt.Errorf("list projects error: %w", err) + return false, fmt.Errorf("failed to list projects, error: %w", err) } if len(projects) == 0 { @@ -87,7 +87,7 @@ func (p *GitLabProvider) CreateRepository(ctx context.Context, r *Repository) (b _, _, err := gl.Projects.CreateProject(p) if err != nil { - return false, fmt.Errorf("create project error: %w", err) + return false, fmt.Errorf("failed to create project, error: %w", err) } return true, nil } @@ -111,7 +111,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k var projId int projects, _, err := gl.Projects.ListProjects(&gitlab.ListProjectsOptions{Search: gitlab.String(r.Name)}, gitlab.WithContext(ctx)) if err != nil { - return false, fmt.Errorf("list projects error: %w", err) + return false, fmt.Errorf("failed to list projects, error: %w", err) } if len(projects) > 0 { projId = projects[0].ID @@ -122,7 +122,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k // check if the key exists keys, _, err := gl.DeployKeys.ListProjectDeployKeys(projId, &gitlab.ListProjectDeployKeysOptions{}) if err != nil { - return false, fmt.Errorf("list keys error: %w", err) + return false, fmt.Errorf("failed to list deploy keys, error: %w", err) } shouldCreateKey := true @@ -142,7 +142,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k if existingKey != nil { _, err := gl.DeployKeys.DeleteDeployKey(projId, existingKey.ID, gitlab.WithContext(ctx)) if err != nil { - return false, fmt.Errorf("delete key error: %w", err) + return false, fmt.Errorf("failed to delete deploy key '%s', error: %w", keyName, err) } } @@ -154,7 +154,7 @@ func (p *GitLabProvider) AddDeployKey(ctx context.Context, r *Repository, key, k CanPush: gitlab.Bool(false), }, gitlab.WithContext(ctx)) if err != nil { - return false, fmt.Errorf("add key error: %w", err) + return false, fmt.Errorf("failed to create deploy key '%s', error: %w", keyName, err) } return true, nil }