Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keystore generation output #6059

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/controller/integrationplatform/kamelets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const (
kamelVersionAnnotation = "camel.apache.org/version"
)

// installKameletCatalog installs the version Apache Kamelet Catalog into the specified namespace. It returns the number of Kamelets installed and errored
// if successful.
// installKameletCatalog installs the version Apache Kamelet Catalog into the specified namespace.
// It returns the number of Kamelets installed and errored if successful.
func installKameletCatalog(ctx context.Context, c client.Client, platform *v1.IntegrationPlatform, version string) (int, int, error) {
// Prepare proper privileges for Kamelets installed globally
if err := prepareKameletsPermissions(ctx, c, platform.Namespace); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/jvm/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const (
var (
logger = log.WithName("keytool")

loggerInfo = func(s string) string { logger.Info(s); return "" }
loggerError = func(s string) string { logger.Error(nil, s); return "" }
loggerInfo = func(s string) string { logger.Info(s); return s }
loggerError = func(s string) string { logger.Error(nil, s); return s }
)

func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePass string, data [][]byte) error {
Expand All @@ -49,7 +49,7 @@ func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePa
cmd.Stdin = bytes.NewReader(data)
// keytool logs info messages to stderr, as stdout is used to output results,
// otherwise it logs error messages to stdout.
err := util.RunAndLog(ctx, cmd, loggerError, loggerInfo)
err := util.RunAndLog(ctx, cmd, loggerInfo, loggerError)
if err != nil {
return err
}
Expand All @@ -66,7 +66,7 @@ func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePa
cmd.Dir = keystoreDir
// keytool logs info messages to stderr, as stdout is used to output results,
// otherwise it logs error messages to stdout.
err := util.RunAndLog(ctx, cmd, loggerError, loggerInfo)
err := util.RunAndLog(ctx, cmd, loggerInfo, loggerError)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/jvm/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/apache/camel-k/v2/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -38,10 +39,12 @@ func TestGenerateKeystore(t *testing.T) {
data = [][]byte{{0}, {1}}
err = GenerateKeystore(ctx, "", "/tmp/keystore", NewKeystorePassword(), data)
require.Error(t, err)
assert.Equal(t, "keytool error: java.io.IOException: keystore password was incorrect: exit status 1", err.Error())

// Incorrect password format
err = GenerateKeystore(ctx, "", "/tmp/keystore", "", data)
require.Error(t, err)
assert.Equal(t, "Illegal option: /tmp/keystore: exit status 1", err.Error())

testFileExists, _ := util.FileExists("/tmp/keystore")
if testFileExists {
Expand Down