|
| 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