Skip to content

Commit

Permalink
Fix displaying and deleting tlsCredentials
Browse files Browse the repository at this point in the history
Stderr for warning messages
  • Loading branch information
lynnemorrison committed Dec 10, 2024
1 parent 0d87003 commit febe755
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/skupper/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func CmdListenerCreateFactory(configuredPlatform types.Platform) *cobra.Command

cmd.Flags().StringVarP(&cmdFlags.RoutingKey, common.FlagNameRoutingKey, "r", "", common.FlagDescRoutingKey)
cmd.Flags().StringVar(&cmdFlags.Host, common.FlagNameListenerHost, "", common.FlagDescListenerHost)
cmd.Flags().StringVarP(&cmdFlags.TlsCredentials, common.FlagNameTlsCredentials, "t", "", common.FlagDescTlsCredentials)
cmd.Flags().StringVar(&cmdFlags.TlsCredentials, common.FlagNameTlsCredentials, "", common.FlagDescTlsCredentials)
cmd.Flags().StringVar(&cmdFlags.ListenerType, common.FlagNameListenerType, "tcp", common.FlagDescListenerType)
cmd.Flags().DurationVar(&cmdFlags.Timeout, common.FlagNameTimeout, 60*time.Second, common.FlagDescTimeout)
cmd.Flags().StringVarP(&cmdFlags.Output, common.FlagNameOutput, "o", "", common.FlagDescOutput)
Expand All @@ -73,7 +73,7 @@ func CmdListenerUpdateFactory(configuredPlatform types.Platform) *cobra.Command
Use: "update <name>",
Short: "update a listener",
Long: `Clients at this site use the listener host and port to establish connections to the remote service.
The user can change port, host name, TLS secret, listener type and routing key`,
The user can change port, host name, TLS credentials, listener type and routing key`,
Example: "skupper listener update database --host mysql --port 3306",
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/skupper/listener/nonkube/listener_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cmd *CmdListenerCreate) ValidateInput(args []string) []error {
if cmd.Flags.Host != "" {
ip := net.ParseIP(cmd.Flags.Host)
ok, _ := hostStringValidator.Evaluate(cmd.Flags.Host)
if !ok || ip == nil {
if !ok && ip == nil {
validationErrors = append(validationErrors, fmt.Errorf("host is not valid: a valid IP address or hostname is expected"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/skupperproject/skupper/internal/nonkube/client/fs"
"github.com/spf13/cobra"

"gotest.tools/assert"
"gotest.tools/v3/assert"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"
"gotest.tools/assert"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/skupper/listener/nonkube/listener_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ func (cmd *CmdListenerStatus) Run() error {
}
} else {
tw := tabwriter.NewWriter(os.Stdout, 8, 8, 1, '\t', tabwriter.TabIndent)
_, _ = fmt.Fprintln(tw, fmt.Sprintf("%s\t%s\t%s\t%s\t%s",
"NAME", "STATUS", "ROUTING-KEY", "HOST", "PORT"))
_, _ = fmt.Fprintln(tw, fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s",
"NAME", "STATUS", "ROUTING-KEY", "HOST", "PORT", "TLS-CREDENTIALS"))
for _, listener := range listeners {
status := "Not Ready"
if listener.IsConfigured() {
status = "Ok"
}
fmt.Fprintln(tw, fmt.Sprintf("%s\t%s\t%s\t%s\t%d",
listener.Name, status, listener.Spec.RoutingKey, listener.Spec.Host, listener.Spec.Port))
fmt.Fprintln(tw, fmt.Sprintf("%s\t%s\t%s\t%s\t%d\t%s",
listener.Name, status, listener.Spec.RoutingKey, listener.Spec.Host, listener.Spec.Port, listener.Spec.TlsCredentials))
}
_ = tw.Flush()
}
Expand All @@ -122,8 +122,8 @@ func (cmd *CmdListenerStatus) Run() error {
status = "Ok"
}
tw := tabwriter.NewWriter(os.Stdout, 8, 8, 1, '\t', tabwriter.TabIndent)
fmt.Fprintln(tw, fmt.Sprintf("Name:\t%s\nStatus:\t%s\nRouting key:\t%s\nHost:\t%s\nPort:\t%d\n",
listener.Name, status, listener.Spec.RoutingKey, listener.Spec.Host, listener.Spec.Port))
fmt.Fprintln(tw, fmt.Sprintf("Name:\t%s\nStatus:\t%s\nRouting key:\t%s\nHost:\t%s\nPort:\t%d\nTlsCredentials:\t%s\n",
listener.Name, status, listener.Spec.RoutingKey, listener.Spec.Host, listener.Spec.Port, listener.Spec.TlsCredentials))
_ = tw.Flush()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/skupperproject/skupper/internal/nonkube/client/fs"
"github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"gotest.tools/assert"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down
6 changes: 5 additions & 1 deletion internal/cmd/skupper/listener/nonkube/listener_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cmd *CmdListenerUpdate) ValidateInput(args []string) []error {
if cmd.Flags.Host != "" {
ip := net.ParseIP(cmd.Flags.Host)
ok, _ := hostStringValidator.Evaluate(cmd.Flags.Host)
if !ok || ip == nil {
if !ok && ip == nil {
validationErrors = append(validationErrors, fmt.Errorf("host is not valid: a valid IP address or hostname is expected"))
} else {
cmd.newSettings.host = cmd.Flags.Host
Expand Down Expand Up @@ -148,6 +148,10 @@ func (cmd *CmdListenerUpdate) InputToOptions() {
if cmd.namespace == "" {
cmd.namespace = "default"
}
// user wants to clear TlsCredentials
if cmd.CobraCmd.Flags().Changed(common.FlagNameTlsCredentials) && cmd.Flags.TlsCredentials == "" {
cmd.newSettings.tlsCredentials = ""
}
}

func (cmd *CmdListenerUpdate) Run() error {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/skupper/listener/nonkube/listener_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"
"gotest.tools/assert"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestCmdListenerUpdate_Run(t *testing.T) {

for _, test := range testTable {
command := &CmdListenerUpdate{}

command.CobraCmd = &cobra.Command{Use: "test"}
command.listenerName = test.listenerName
command.newSettings.output = test.output
command.newSettings.port = test.port
Expand Down
6 changes: 3 additions & 3 deletions internal/nonkube/client/fs/connector_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package fs

import (
"errors"
"fmt"
"io/fs"
"os"

"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *ConnectorHandler) Get(name string, opt GetOptions) (*v2alpha1.Connector
err, file := s.ReadFile(s.pathProvider.GetRuntimeNamespace(), fileName, common.Connectors)
if err != nil {
if opt.LogWarning {
fmt.Println("Site not initialized yet")
os.Stderr.WriteString("Site not initialized yet")
}
err, file = s.ReadFile(s.pathProvider.GetNamespace(), fileName, common.Connectors)
if err != nil {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *ConnectorHandler) List() ([]*v2alpha1.Connector, error) {
path := s.pathProvider.GetRuntimeNamespace()
err, files := s.ReadDir(path, common.Connectors)
if err != nil {
fmt.Println("Site not initialized yet")
os.Stderr.WriteString("Site not initialized yet")
path = s.pathProvider.GetNamespace()
err, files = s.ReadDir(path, common.Connectors)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/nonkube/client/fs/listener_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package fs

import (
"errors"
"fmt"
"io/fs"
"os"

"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/pkg/apis/skupper/v2alpha1"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *ListenerHandler) Get(name string, opts GetOptions) (*v2alpha1.Listener,
err, file := s.ReadFile(s.pathProvider.GetRuntimeNamespace(), fileName, common.Listeners)
if err != nil {
if opts.LogWarning {
fmt.Println("Site not initialized yet")
os.Stderr.WriteString("Site not initialized yet")
}
err, file = s.ReadFile(s.pathProvider.GetNamespace(), fileName, common.Listeners)
if err != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (s *ListenerHandler) List() ([]*v2alpha1.Listener, error) {
path := s.pathProvider.GetRuntimeNamespace()
err, files := s.ReadDir(path, common.Listeners)
if err != nil {
fmt.Println("Site not initialized yet")
os.Stderr.WriteString("Site not initialized yet")
path = s.pathProvider.GetNamespace()
err, files = s.ReadDir(path, common.Listeners)
if err != nil {
Expand Down

0 comments on commit febe755

Please sign in to comment.