Improve cmd messages

pull/58/head
Hidde Beydals 5 years ago
parent 98cf176c81
commit dbfa2f9944

@ -122,35 +122,35 @@ func kubectlCheck(ctx context.Context, version string) bool {
func kubernetesCheck(version string) bool { func kubernetesCheck(version string) bool {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig) cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil { if err != nil {
logFailure("kubernetes client initialization failed: %s", err.Error()) logFailure("Kubernetes client initialization failed: %s", err.Error())
return false return false
} }
client, err := kubernetes.NewForConfig(cfg) client, err := kubernetes.NewForConfig(cfg)
if err != nil { if err != nil {
logFailure("kubernetes client initialization failed: %s", err.Error()) logFailure("Kubernetes client initialization failed: %s", err.Error())
return false return false
} }
ver, err := client.Discovery().ServerVersion() ver, err := client.Discovery().ServerVersion()
if err != nil { if err != nil {
logFailure("kubernetes API call failed %s", err.Error()) logFailure("Kubernetes API call failed: %s", err.Error())
return false return false
} }
v, err := semver.ParseTolerant(ver.String()) v, err := semver.ParseTolerant(ver.String())
if err != nil { if err != nil {
logFailure("kubernetes version can't be determined") logFailure("Kubernetes version can't be determined")
return false return false
} }
rng, _ := semver.ParseRange(version) rng, _ := semver.ParseRange(version)
if !rng(v) { if !rng(v) {
logFailure("kubernetes version must be %s", version) logFailure("Kubernetes version must be %s", version)
return false return false
} }
logSuccess("kubernetes %s %s", v.String(), version) logSuccess("Kubernetes %s %s", v.String(), version)
return true return true
} }

@ -258,7 +258,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
} }
if gitRepository.Status.Artifact != nil { if gitRepository.Status.Artifact != nil {
logSuccess("fetched revision %s", gitRepository.Status.Artifact.Revision) logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision)
} else { } else {
return fmt.Errorf("git sync failed, artifact not found") 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) { func generateKeyPair(ctx context.Context) (*ssh.KeyPair, error) {
var keyGen ssh.KeyPairGenerator var keyGen ssh.KeyPairGenerator
switch sourceGitKeyAlgorithm.String() { switch algorithm := sourceGitKeyAlgorithm.String(); algorithm {
case "rsa": case "rsa":
keyGen = ssh.NewRSAGenerator(int(sourceGitRSABits)) keyGen = ssh.NewRSAGenerator(int(sourceGitRSABits))
case "ecdsa": case "ecdsa":
@ -276,11 +276,11 @@ func generateKeyPair(ctx context.Context) (*ssh.KeyPair, error) {
case "ed25519": case "ed25519":
keyGen = ssh.NewEd25519Generator() keyGen = ssh.NewEd25519Generator()
default: 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() pair, err := keyGen.Generate()
if err != nil { 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 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) hostKey, err := ssh.ScanHostKey(host, 30*time.Second)
if err != nil { 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 return hostKey, nil
} }

@ -125,16 +125,16 @@ func exportGit(source sourcev1.GitRepository) error {
return nil 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 { if source.Spec.SecretRef != nil {
namespacedName := types.NamespacedName{ namespacedName := types.NamespacedName{
Namespace: source.Namespace, Namespace: source.Namespace,
Name: source.Spec.SecretRef.Name, Name: source.Spec.SecretRef.Name,
} }
var cred corev1.Secret var cred corev1.Secret
err := kubeClinet.Get(ctx, namespacedName, &cred) err := kubeClient.Get(ctx, namespacedName, &cred)
if err != nil { 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{ exported := corev1.Secret{

@ -62,7 +62,7 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
for _, condition := range source.Status.Conditions { for _, condition := range source.Status.Conditions {
if condition.Type == sourcev1.ReadyCondition { if condition.Type == sourcev1.ReadyCondition {
if condition.Status != corev1.ConditionFalse { 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 { } else {
logFailure("%s %s", source.GetName(), condition.Message) logFailure("%s %s", source.GetName(), condition.Message)
} }

@ -93,7 +93,7 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
} }
if gitRepository.Status.Artifact != nil { if gitRepository.Status.Artifact != nil {
logSuccess("fetched revision %s", gitRepository.Status.Artifact.Revision) logSuccess("fetched revision: %s", gitRepository.Status.Artifact.Revision)
} else { } else {
return fmt.Errorf("git sync failed, artifact not found") return fmt.Errorf("git sync failed, artifact not found")
} }

@ -111,7 +111,7 @@ func (*Utils) execTemplate(obj interface{}, tmpl, filename string) error {
func (*Utils) kubeClient(config string) (client.Client, error) { func (*Utils) kubeClient(config string) (client.Client, error) {
cfg, err := clientcmd.BuildConfigFromFlags("", config) cfg, err := clientcmd.BuildConfigFromFlags("", config)
if err != nil { 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() scheme := runtime.NewScheme()
@ -123,7 +123,7 @@ func (*Utils) kubeClient(config string) (client.Client, error) {
Scheme: scheme, Scheme: scheme,
}) })
if err != nil { 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 return kubeClient, nil

Loading…
Cancel
Save