Skip to content

Commit 2626603

Browse files
aleoliadamjensenbot
authored andcommitted
fix liqoctl output
1 parent e2022e0 commit 2626603

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

cmd/liqoctl/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
4343
rootCmd.PersistentFlags().AddGoFlag(f)
4444
}
4545
})
46+
4647
rateFlagset := flag.NewFlagSet("rate-limiting", flag.PanicOnError)
4748
restcfg.InitFlags(rateFlagset)
4849
rootCmd.PersistentFlags().AddGoFlagSet(rateFlagset)

pkg/liqoctl/install/handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ import (
1919
"fmt"
2020

2121
"github.com/spf13/cobra"
22+
"k8s.io/klog/v2"
2223

2324
"github.com/liqotech/liqo/pkg/liqoctl/common"
2425
"github.com/liqotech/liqo/pkg/liqoctl/generate"
2526
installprovider "github.com/liqotech/liqo/pkg/liqoctl/install/provider"
2627
installutils "github.com/liqotech/liqo/pkg/liqoctl/install/utils"
28+
logsutils "github.com/liqotech/liqo/pkg/utils/logs"
2729
)
2830

2931
// HandleInstallCommand implements the "install" command. It detects which provider has to be used, generates the chart
3032
// with provider-specific values. Finally, it performs the installation on the target cluster.
3133
func HandleInstallCommand(ctx context.Context, cmd *cobra.Command, baseCommand, providerName string) error {
34+
if !klog.V(4).Enabled() {
35+
klog.SetLogFilter(logsutils.LogFilter{})
36+
}
37+
3238
config := common.GetLiqoctlRestConfOrDie()
3339
providerInstance := getProviderInstance(providerName)
3440

pkg/liqoctl/install/k3s/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (k *k3sProvider) validateAPIServer() error {
230230
hostname := apiServerURL.Hostname()
231231
for i := range localhostValues {
232232
if hostname == localhostValues[i] {
233-
return fmt.Errorf("cannot use localhost (%v) as API Server address", hostname)
233+
return fmt.Errorf("cannot use localhost (%v) as API Server address, set an external address in your kubeconfig", hostname)
234234
}
235235
}
236236

pkg/utils/logs/doc.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package logs contains shared utility methods for logging.
16+
package logs

pkg/utils/logs/logfilter.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package logs
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
)
21+
22+
// LogFilter implements the klog LogFilter interface, to filter log messages in the liqoctl install command.
23+
type LogFilter struct{}
24+
25+
// Filter filters the helm CRDs installation errors.
26+
func (l LogFilter) Filter(args []interface{}) []interface{} {
27+
if len(args) == 0 {
28+
return args
29+
}
30+
31+
err, ok := args[0].(error)
32+
if !ok {
33+
return args
34+
}
35+
36+
if strings.
37+
Contains(err.Error(), "couldn't get resource list for") && strings.
38+
Contains(err.Error(), "the server could not find the requested resource") {
39+
// since we cannot cancel the log, we change the error message to "continuing"
40+
return []interface{}{
41+
fmt.Errorf("continuing"),
42+
}
43+
}
44+
return args
45+
}
46+
47+
// FilterF does nothing (i.e, only passes through the arguments), as not used in this context.
48+
func (l LogFilter) FilterF(format string, args []interface{}) (f string, a []interface{}) {
49+
return format, args
50+
}
51+
52+
// FilterS does nothing (i.e, only passes through the arguments), as not used in this context.
53+
func (l LogFilter) FilterS(msg string, keysAndValues []interface{}) (m string, a []interface{}) {
54+
return msg, keysAndValues
55+
}

0 commit comments

Comments
 (0)