upgrade to istio 1.19 (#1211)

Co-authored-by: CH3CHO <ch3cho@qq.com>
Co-authored-by: rinfx <893383980@qq.com>
This commit is contained in:
澄潭
2024-08-26 09:51:47 +08:00
committed by GitHub
parent a2c2d1d521
commit f7a419770d
401 changed files with 21171 additions and 7255 deletions

View File

@@ -0,0 +1,92 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import (
"bytes"
"fmt"
"io"
"path/filepath"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
)
// GetAbsolutePath returns the absolute path, e.g.:
// - ~/foo -> /home/user/foo
// - ./foo -> /current/dir/foo
// - /foo/ -> /foo
func GetAbsolutePath(path string) (newPath string, err error) {
if strings.HasPrefix(path, "~") {
newPath, err = homedir.Expand(path)
if err != nil {
return "", errors.Wrapf(err, "failed to expand path: %q", path)
}
} else {
newPath, err = filepath.Abs(path)
if err != nil {
return "", errors.Wrapf(err, "failed to get absolute path of %q", path)
}
}
l := len(newPath)
if l > 1 && newPath[l-1] == '/' { // if l == 1, the path might be "/"
newPath = newPath[:l-1]
}
return newPath, nil
}
// AddIndent for each line of str
func AddIndent(str, indent string) string {
ret := ""
ss := strings.Split(str, "\n")
for i, s := range ss {
if i == 0 {
ret = fmt.Sprintf("%s%s", indent, s)
} else {
ret = fmt.Sprintf("%s\n%s%s", ret, indent, s)
}
}
return ret
}
// MarshalYamlWithIndent marshals v to yaml with indent, specify space width with spaces
func MarshalYamlWithIndent(v interface{}, spaces int) ([]byte, error) {
w := new(bytes.Buffer)
ec := yaml.NewEncoder(w)
defer ec.Close()
ec.SetIndent(spaces)
if err := ec.Encode(v); err != nil {
return w.Bytes(), err
}
return w.Bytes(), nil
}
// MarshalYamlWithIndentTo marshals v to yaml with indent, specify space width with spaces, and output to w
func MarshalYamlWithIndentTo(w io.Writer, v interface{}, spaces int) error {
ec := yaml.NewEncoder(w)
defer ec.Close()
ec.SetIndent(spaces)
if err := ec.Encode(v); err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,58 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import (
"fmt"
"io"
)
type Debugger interface {
Debugf(format string, a ...any) (int, error)
Debugln(a ...any) (int, error)
}
type DefaultDebugger struct {
debug bool
w io.Writer
}
func NewDefaultDebugger(debug bool, w io.Writer) *DefaultDebugger {
return &DefaultDebugger{debug: debug, w: w}
}
func (d DefaultDebugger) Debugf(format string, a ...any) (int, error) {
l := len(format)
if l > 0 && format[l-1] != '\n' {
format += "\n"
}
if d.debug {
format = "[debug] " + format
return fmt.Fprintf(d.w, format, a...)
}
return 0, nil
}
func (d DefaultDebugger) Debugln(a ...any) (int, error) {
if d.debug {
n1, err1 := fmt.Fprintf(d.w, "[debug] ")
if err1 != nil {
return n1, err1
}
n2, err2 := fmt.Fprintln(d.w, a...)
return n1 + n2, err2
}
return 0, nil
}

View File

@@ -0,0 +1,165 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import (
"fmt"
"io"
"os"
"strings"
"github.com/fatih/color"
)
type YesOrNoPrinter struct {
out io.Writer
indent *Indent
yes, no *color.Color
}
var (
DefaultOut = os.Stdout
DefaultIdent = NewIndent(strings.Repeat(" ", 2), 0)
DefaultYes = color.New(color.FgHiGreen)
DefaultNo = color.New(color.FgHiRed)
)
func NewPrinter(out io.Writer, indent *Indent, yes, no *color.Color) *YesOrNoPrinter {
return &YesOrNoPrinter{
out: out,
indent: indent,
yes: yes,
no: no,
}
}
func DefaultPrinter() *YesOrNoPrinter {
return NewPrinter(DefaultOut, DefaultIdent, DefaultYes, DefaultNo)
}
func (p *YesOrNoPrinter) Printf(format string, a ...interface{}) (int, error) {
return fmt.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) Println(a ...interface{}) (int, error) {
return fmt.Fprintln(p.out, a...)
}
func (p *YesOrNoPrinter) PrintWithIndentf(format string, a ...interface{}) (int, error) {
format = fmt.Sprintf("%s%s", p.indent, format)
return fmt.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) PrintWithIndentln(a ...interface{}) (int, error) {
n1, err := fmt.Fprintf(p.out, "%s", p.indent)
if err != nil {
return n1, err
}
n2, err := fmt.Fprintln(p.out, a...)
if err != nil {
return n1 + n2, err
}
return n1 + n2, nil
}
func (p *YesOrNoPrinter) Yesf(format string, a ...interface{}) (int, error) {
return p.yes.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) Yesln(a ...interface{}) (int, error) {
return p.yes.Fprintln(p.out, a...)
}
func (p *YesOrNoPrinter) YesWithIndentf(format string, a ...interface{}) (int, error) {
format = fmt.Sprintf("%s%s", p.indent, format)
return p.yes.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) YesWithIndentln(a ...interface{}) (int, error) {
n1, err := p.yes.Fprintf(p.out, "%s", p.indent)
if err != nil {
return n1, err
}
n2, err := p.yes.Fprintln(p.out, a...)
if err != nil {
return n1 + n2, err
}
return n1 + n2, nil
}
func (p *YesOrNoPrinter) Nof(format string, a ...interface{}) (int, error) {
return p.no.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) Noln(a ...interface{}) (int, error) {
return p.no.Fprintln(p.out, a...)
}
func (p *YesOrNoPrinter) NoWithIndentf(format string, a ...interface{}) (int, error) {
format = fmt.Sprintf("%s%s", p.indent, format)
return p.no.Fprintf(p.out, format, a...)
}
func (p *YesOrNoPrinter) NoWithIndentln(a ...interface{}) (int, error) {
n1, err := p.no.Fprintf(p.out, "%s", p.indent)
if err != nil {
return n1, err
}
n2, err := p.no.Fprintln(p.out, a...)
if err != nil {
return n1 + n2, err
}
return n1 + n2, nil
}
func (p *YesOrNoPrinter) Ident() string { return p.indent.String() }
func (p *YesOrNoPrinter) IncIdentRepeat() { p.indent.IncRepeat() }
func (p *YesOrNoPrinter) DecIndentRepeat() { p.indent.DecRepeat() }
func (p *YesOrNoPrinter) SetIdentRepeat(v int) { p.indent.SetRepeat(v) }
type Indent struct {
format string
repeat int
}
func NewIndent(format string, repeat int) *Indent {
return &Indent{
format: format,
repeat: repeat,
}
}
func (i *Indent) String() string {
return strings.Repeat(i.format, i.repeat)
}
func (i *Indent) IncRepeat() { i.repeat++ }
func (i *Indent) DecRepeat() {
i.repeat--
if i.repeat < 0 {
i.repeat = 0
}
}
func (i *Indent) SetRepeat(v int) {
if v < 0 {
v = 0
}
i.repeat = v
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import "github.com/AlecAivazis/survey/v2"
func Ask(qs []*survey.Question, response interface{}, opts ...survey.AskOpt) error {
opts = append(opts, survey.WithIcons(func(set *survey.IconSet) {
set.Error.Format = "red+hb"
}))
return survey.Ask(qs, response, opts...)
}
func AskOne(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error {
opts = append(opts, survey.WithIcons(func(set *survey.IconSet) {
set.Error.Format = "red+hb"
}))
return survey.AskOne(p, response, opts...)
}