diff --git a/builtin/roles/addons/cni/tasks/kubeovn.yaml b/builtin/roles/addons/cni/tasks/kubeovn.yaml index 456b45a04..7b9e42e0e 100644 --- a/builtin/roles/addons/cni/tasks/kubeovn.yaml +++ b/builtin/roles/addons/cni/tasks/kubeovn.yaml @@ -16,7 +16,7 @@ - name: Install kubeovn command: | helm install kubeovn /etc/kubernetes/cni/kubeovn-{{ .kubeovn_version }}.tgz --set replicaCount={{ .cni.kubeovn.replica }} \ - {{- $ips := list -}} + {{ $ips := list }} {{- range .groups.kube_control_plane -}} {{- $ips = append $ips (index $.inventory_hosts . "internal_ipv4") -}} {{- end -}} diff --git a/builtin/roles/install/etcd/templates/backup.script b/builtin/roles/install/etcd/templates/backup.sh similarity index 100% rename from builtin/roles/install/etcd/templates/backup.script rename to builtin/roles/install/etcd/templates/backup.sh diff --git a/builtin/roles/install/etcd/templates/etcd.env b/builtin/roles/install/etcd/templates/etcd.env index 7510a2215..3800edd48 100644 --- a/builtin/roles/install/etcd/templates/etcd.env +++ b/builtin/roles/install/etcd/templates/etcd.env @@ -8,7 +8,7 @@ ETCD_LISTEN_PEER_URLS={{ printf "https://%s:2380" .internal_ipv4 }} ETCD_NAME={{ .inventory_name }} ETCD_PROXY=off ETCD_ENABLE_V2=true -{{- $ips := list -}} +{{ $ips := list }} {{- range .groups.etcd -}} {{- $ips = append $ips (printf "%s=https://%s:2380" (index $.inventory_hosts . "inventory_name") (index $.inventory_hosts . "internal_ipv4")) -}} {{- end -}} diff --git a/builtin/roles/install/image-registry/tasks/install_docker.yaml b/builtin/roles/install/image-registry/tasks/install_docker.yaml index aedb6ba86..0d27a5a8c 100644 --- a/builtin/roles/install/image-registry/tasks/install_docker.yaml +++ b/builtin/roles/install/image-registry/tasks/install_docker.yaml @@ -5,7 +5,7 @@ register: docker_install_version - name: Install docker - when: or (.docker_install_version.stderr | ne "") (not .docker_install_version.stdout | hasPrefix (printf "Docker version %s," .docker_version)) + when: or (.docker_install_version.stderr | ne "") (.docker_install_version.stdout | hasPrefix (printf "Docker version %s," .docker_version) | not) block: - name: Sync docker binary to remote copy: diff --git a/builtin/roles/install/image-registry/tasks/main.yaml b/builtin/roles/install/image-registry/tasks/main.yaml index 49b5dfe7b..339fcbab7 100644 --- a/builtin/roles/install/image-registry/tasks/main.yaml +++ b/builtin/roles/install/image-registry/tasks/main.yaml @@ -13,7 +13,7 @@ ignore_errors: true command: systemctl status harbor.service register: image_registry_service - - include_tasks: install_registry.yaml + - include_tasks: install_harbor.yaml when: .image_registry_service.stderr | ne "" - name: Install registry diff --git a/builtin/roles/install/image-registry/templates/docker.config b/builtin/roles/install/image-registry/templates/docker.config index 3f57da580..23767c217 100644 --- a/builtin/roles/install/image-registry/templates/docker.config +++ b/builtin/roles/install/image-registry/templates/docker.config @@ -15,5 +15,5 @@ {{- if and .cri.docker.bridge_ip (ne .cri.docker.bridge_ip "") }} "bip": "{{ .cri.docker.bridge_ip }}", {{- end }} - "exec-opts": ["native.cgroupdriver={{ .cri.cgroup_driver }}"] + "exec-opts": ["native.cgroupdriver={{ .cri.cgroup_driver | default "systemd" }}"] } diff --git a/builtin/roles/install/kubernetes/templates/kubevip/kubevip.BGP b/builtin/roles/install/kubernetes/templates/kubevip/kubevip.BGP index 206f5e976..cd106b4ce 100644 --- a/builtin/roles/install/kubernetes/templates/kubevip/kubevip.BGP +++ b/builtin/roles/install/kubernetes/templates/kubevip/kubevip.BGP @@ -30,7 +30,7 @@ spec: value: "true" - name: bgp_routerid value: | - {{- $ips := list -}} + {{ $ips := list }} {{- range .groups.kube_control_plane -}} {{- $ips = append $ips (index $.inventory_hosts . "internal_ipv4") -}} {{- end -}} @@ -43,7 +43,7 @@ spec: value: "65000" - name: bgp_peers value: | - {{- $ips := list -}} + {{ $ips := list }} {{- range .groups.kube_control_plane -}} {{- $ips = append $ips (printf "%s:65000::false" (index $.inventory_hosts . "internal_ipv4")) -}} {{- end -}} diff --git a/go.mod b/go.mod index ec2722871..9b4545696 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/opencontainers/image-spec v1.1.0 github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.13.6 - github.com/schollz/progressbar/v3 v3.14.3 + github.com/schollz/progressbar/v3 v3.14.5 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 @@ -115,8 +115,8 @@ require ( golang.org/x/net v0.20.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/term v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/term v0.22.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.17.0 // indirect diff --git a/go.sum b/go.sum index f4da7fb9e..b7d8786d3 100644 --- a/go.sum +++ b/go.sum @@ -204,8 +204,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/schollz/progressbar/v3 v3.14.3 h1:oOuWW19ka12wxYU1XblR4n16wF/2Y1dBLMarMo6p4xU= -github.com/schollz/progressbar/v3 v3.14.3/go.mod h1:aT3UQ7yGm+2ZjeXPqsjTenwL3ddUiuZ0kfQ/2tHlyNI= +github.com/schollz/progressbar/v3 v3.14.5 h1:97RrSxbBASxQuZN9yemnyGrFZ/swnG6IrEe2R0BseX8= +github.com/schollz/progressbar/v3 v3.14.5/go.mod h1:Nrzpuw3Nl0srLY0VlTvC4V6RL50pcEymjy6qyJAaLa0= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= @@ -341,18 +341,16 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 6a1f69bf3..a3256c084 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -20,7 +20,10 @@ import ( "context" "errors" "fmt" + "io" "os" + "strings" + "time" "github.com/schollz/progressbar/v3" "k8s.io/apimachinery/pkg/runtime" @@ -56,9 +59,10 @@ func NewTaskExecutor(client ctrlclient.Client, pipeline *kubekeyv1.Pipeline) Tas } return &executor{ - client: client, - pipeline: pipeline, - variable: v, + client: client, + pipeline: pipeline, + variable: v, + logOutput: os.Stdout, } } @@ -67,6 +71,8 @@ type executor struct { pipeline *kubekeyv1.Pipeline variable variable.Variable + + logOutput io.Writer } type execBlockOptions struct { @@ -234,6 +240,7 @@ func (e executor) getGatherFact(ctx context.Context, hostname string, vars varia return nil, nil } +// execBlock loop block and generate task. func (e executor) execBlock(ctx context.Context, options execBlockOptions) error { for _, at := range options.blocks { if !kkcorev1.JoinTag(at.Taggable, options.tags).IsEnabled(e.pipeline.Spec.Tags, e.pipeline.Spec.SkipTags) { @@ -343,7 +350,7 @@ func (e executor) execBlock(ctx context.Context, options execBlockOptions) error } for { - klog.Infof("[Task %s] task exec \"%s\" begin for %v times", ctrlclient.ObjectKeyFromObject(task), task.Spec.Name, task.Status.RestartCount+1) + fmt.Fprintf(e.logOutput, "%s [Task %s] \"%s\":\"%s\" exec:%v times\n", time.Now().Format(time.RFC3339), ctrlclient.ObjectKeyFromObject(task), task.Annotations[kubekeyv1alpha1.TaskAnnotationRole], task.Spec.Name, task.Status.RestartCount+1) // exec task task.Status.Phase = kubekeyv1alpha1.TaskPhaseRunning if err := e.client.Status().Update(ctx, task); err != nil { @@ -362,7 +369,6 @@ func (e executor) execBlock(ctx context.Context, options execBlockOptions) error break } } - klog.Infof("[Task %s] task exec \"%s\" end status is %s", ctrlclient.ObjectKeyFromObject(task), task.Spec.Name, task.Status.Phase) e.pipeline.Status.TaskResult.Total++ switch task.Status.Phase { case kubekeyv1alpha1.TaskPhaseSuccess: @@ -395,26 +401,16 @@ func (e executor) execBlock(ctx context.Context, options execBlockOptions) error return nil } +// executeTask parallel in each host. func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, options execBlockOptions) error { // check task host results wg := &wait.Group{} task.Status.HostResults = make([]kubekeyv1alpha1.TaskHostResult, len(task.Spec.Hosts)) + for i, h := range task.Spec.Hosts { wg.StartWithContext(ctx, func(ctx context.Context) { + // task result var stdout, stderr string - - // progress bar for task - var bar = progressbar.NewOptions(1, - progressbar.OptionEnableColorCodes(true), - progressbar.OptionSetDescription(fmt.Sprintf("[%s] running...", h)), - progressbar.OptionOnCompletion(func() { - if _, err := os.Stdout.WriteString("\n"); err != nil { - klog.ErrorS(err, "failed to write output", "host", h) - } - }), - progressbar.OptionShowElapsedTimeOnFinish(), - progressbar.OptionSetPredictTime(false), - ) defer func() { if task.Spec.Register != "" { var stdoutResult any = stdout @@ -434,26 +430,11 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o return } } - - switch { - case stderr != "": // failed - bar.Describe(fmt.Sprintf("[%s] failed", h)) - if err := bar.Finish(); err != nil { - klog.ErrorS(err, "fail to finish bar") - } - klog.Errorf("[Task %s] run failed: %s", ctrlclient.ObjectKeyFromObject(task), stderr) - case stdout == "skip": // skip - bar.Describe(fmt.Sprintf("[%s] skip", h)) - if err := bar.Finish(); err != nil { - klog.ErrorS(err, "fail to finish bar") - } - default: //success - bar.Describe(fmt.Sprintf("[%s] success", h)) - if err := bar.Finish(); err != nil { - klog.ErrorS(err, "fail to finish bar") - } + if stderr != "" && task.Spec.IgnoreError != nil && *task.Spec.IgnoreError { + klog.V(4).ErrorS(fmt.Errorf("%s", stderr), "task run failed", "task", ctrlclient.ObjectKeyFromObject(task)) + } else if stderr != "" { + klog.ErrorS(fmt.Errorf("%s", stderr), "task run failed", "task", ctrlclient.ObjectKeyFromObject(task)) } - // fill result task.Status.HostResults[i] = kubekeyv1alpha1.TaskHostResult{ Host: h, @@ -461,20 +442,63 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o StdErr: stderr, } }() - + // task log + // placeholder format task log + var placeholder string + if hostNameMaxLen, err := e.variable.Get(variable.GetHostMaxLength()); err == nil { + placeholder = strings.Repeat(" ", hostNameMaxLen.(int)-len(h)) + } + // progress bar for task + var bar = progressbar.NewOptions(-1, + progressbar.OptionSetWriter(e.logOutput), + progressbar.OptionSpinnerType(59), + progressbar.OptionEnableColorCodes(true), + progressbar.OptionSetDescription(fmt.Sprintf("[\033[36m%s\033[0m]%s \033[36mrunning\033[0m", h, placeholder)), + progressbar.OptionOnCompletion(func() { + if _, err := os.Stdout.WriteString("\n"); err != nil { + klog.ErrorS(err, "failed to write output", "host", h) + } + }), + progressbar.OptionShowElapsedTimeOnFinish(), + progressbar.OptionSetPredictTime(false), + ) + go func() { + for !bar.IsFinished() { + if err := bar.Add(1); err != nil { + return + } + time.Sleep(100 * time.Millisecond) + } + }() + defer func() { + switch { + case stderr != "": + if task.Spec.IgnoreError != nil && *task.Spec.IgnoreError { // ignore + bar.Describe(fmt.Sprintf("[\033[36m%s\033[0m]%s \033[34mignore \033[0m ", h, placeholder)) + } else { // failed + bar.Describe(fmt.Sprintf("[\033[36m%s\033[0m]%s \033[31mfailed \033[0m ", h, placeholder)) + } + case stdout == "skip": // skip + bar.Describe(fmt.Sprintf("[\033[36m%s\033[0m]%s \033[34mskip \033[0m", h, placeholder)) + default: //success + bar.Describe(fmt.Sprintf("[\033[36m%s\033[0m]%s \033[34msuccess\033[0m", h, placeholder)) + } + if err := bar.Finish(); err != nil { + klog.ErrorS(err, "finish bar error") + } + }() + // task execute ha, err := e.variable.Get(variable.GetAllVariable(h)) if err != nil { stderr = fmt.Sprintf("get variable error: %v", err) return } // execute module with loop - loop, err := e.execLoop(ctx, ha.(map[string]any), task) + loop, err := e.parseLoop(ctx, ha.(map[string]any), task) if err != nil { stderr = fmt.Sprintf("parse loop vars error: %v", err) return } - bar.ChangeMax(len(loop)*3 + 1) - // check when condition if len(task.Spec.When) > 0 { ok, err := tmpl.ParseBool(ha.(map[string]any), task.Spec.When) @@ -487,7 +511,7 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o return } } - + // if loop is empty. execute once, and the item is null for _, item := range loop { // set item to runtime variable if err := e.variable.Merge(variable.MergeRuntimeVariable(h, map[string]any{ @@ -496,9 +520,6 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o stderr = fmt.Sprintf("set loop item to variable error: %v", err) return } - if err := bar.Add(1); err != nil { - klog.ErrorS(err, "fail to add bar") - } stdout, stderr = e.executeModule(ctx, task, modules.ExecOptions{ Args: task.Spec.Module.Args, Host: h, @@ -506,9 +527,6 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o Task: *task, Pipeline: *e.pipeline, }) - if err := bar.Add(1); err != nil { - klog.ErrorS(err, "fail to add bar") - } // delete item if err := e.variable.Merge(variable.MergeRuntimeVariable(h, map[string]any{ _const.VariableItem: nil, @@ -516,14 +534,11 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o stderr = fmt.Sprintf("clean loop item to variable error: %v", err) return } - if err := bar.Add(1); err != nil { - klog.ErrorS(err, "fail to add bar") - } } }) } wg.Wait() - + // host result for task task.Status.Phase = kubekeyv1alpha1.TaskPhaseSuccess for _, data := range task.Status.HostResults { if data.StdErr != "" { @@ -539,7 +554,11 @@ func (e executor) executeTask(ctx context.Context, task *kubekeyv1alpha1.Task, o return nil } -func (e executor) execLoop(ctx context.Context, ha map[string]any, task *kubekeyv1alpha1.Task) ([]any, error) { +// parseLoop parse loop to slice. if loop contains template string. convert it. +// loop is json string. try convertor to string slice by json. +// loop is normal string. set it to empty slice and return. +// loop is string slice. return it. +func (e executor) parseLoop(ctx context.Context, ha map[string]any, task *kubekeyv1alpha1.Task) ([]any, error) { switch { case task.Spec.Loop.Raw == nil: // loop is not set. add one element to execute once module. @@ -549,13 +568,14 @@ func (e executor) execLoop(ctx context.Context, ha map[string]any, task *kubekey } } +// executeModule find register module and execute it. func (e executor) executeModule(ctx context.Context, task *kubekeyv1alpha1.Task, opts modules.ExecOptions) (string, string) { + // get all variable. which contains item. lg, err := opts.Variable.Get(variable.GetAllVariable(opts.Host)) if err != nil { klog.V(5).ErrorS(err, "get location variable error", "task", ctrlclient.ObjectKeyFromObject(task)) return "", err.Error() } - // check failed when condition if len(task.Spec.FailedWhen) > 0 { ok, err := tmpl.ParseBool(lg.(map[string]any), task.Spec.FailedWhen) @@ -571,7 +591,7 @@ func (e executor) executeModule(ctx context.Context, task *kubekeyv1alpha1.Task, return modules.FindModule(task.Spec.Module.Name)(ctx, opts) } -// merge defined variable to host variable +// mergeVariable to runtime variable func (e executor) mergeVariable(ctx context.Context, v variable.Variable, vd map[string]any, hosts ...string) error { if len(vd) == 0 { // skip diff --git a/pkg/modules/template_test.go b/pkg/modules/template_test.go index fd9421dff..9b7d1d320 100644 --- a/pkg/modules/template_test.go +++ b/pkg/modules/template_test.go @@ -56,10 +56,16 @@ func TestTemplate(t *testing.T) { name: "dest is empty", opt: ExecOptions{ Args: runtime.RawExtension{ - Raw: []byte(fmt.Sprintf(`{"src": "%s"}`, absPath)), + Raw: []byte(`{ +"src": "{{ .absPath }}" +}`), + }, + Host: "local", + Variable: &testVariable{ + value: map[string]any{ + "absPath": absPath, + }, }, - Host: "local", - Variable: &testVariable{}, }, ctxFunc: context.Background, exceptStderr: "\"dest\" should be string", diff --git a/pkg/variable/internal.go b/pkg/variable/internal.go index 645c87e82..76c6c3c1d 100644 --- a/pkg/variable/internal.go +++ b/pkg/variable/internal.go @@ -317,6 +317,7 @@ var MergeAllRuntimeVariable = func(hostName string, vd map[string]any) MergeFunc } } +// GetAllVariable get all variable for a given host var GetAllVariable = func(hostName string) GetFunc { return func(v Variable) (any, error) { if _, ok := v.(*variable); !ok { @@ -336,3 +337,18 @@ var GetAllVariable = func(hostName string) GetFunc { return result, nil } } + +// GetHostMaxLength get the max length for all hosts +var GetHostMaxLength = func() GetFunc { + return func(v Variable) (any, error) { + if _, ok := v.(*variable); !ok { + return nil, fmt.Errorf("variable type error") + } + data := v.(*variable).value + var hostNameMaxLen int + for k := range data.Hosts { + hostNameMaxLen = max(len(k), hostNameMaxLen) + } + return hostNameMaxLen, nil + } +} diff --git a/vendor/github.com/schollz/progressbar/v3/.golangci.yml b/vendor/github.com/schollz/progressbar/v3/.golangci.yml new file mode 100644 index 000000000..8c45095d2 --- /dev/null +++ b/vendor/github.com/schollz/progressbar/v3/.golangci.yml @@ -0,0 +1,21 @@ +run: + timeout: 5m + exclude-dirs: + - vendor + - examples + +linters: + enable: + - errcheck + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - staticcheck + - unused + +linters-settings: + gocyclo: + min-complexity: 20 \ No newline at end of file diff --git a/vendor/github.com/schollz/progressbar/v3/progressbar.go b/vendor/github.com/schollz/progressbar/v3/progressbar.go index cef46294d..e3bd67b31 100644 --- a/vendor/github.com/schollz/progressbar/v3/progressbar.go +++ b/vendor/github.com/schollz/progressbar/v3/progressbar.go @@ -494,7 +494,13 @@ func (p *ProgressBar) Reset() { // Finish will fill the bar to full func (p *ProgressBar) Finish() error { - return p.Set64(p.config.max) + p.lock.Lock() + p.state.currentNum = p.config.max + if !p.config.ignoreLength { + p.state.currentBytes = float64(p.config.max) + } + p.lock.Unlock() + return p.Add(0) } // Exit will exit the bar to keep current state diff --git a/vendor/golang.org/x/sys/unix/mremap.go b/vendor/golang.org/x/sys/unix/mremap.go index fd45fe529..3a5e776f8 100644 --- a/vendor/golang.org/x/sys/unix/mremap.go +++ b/vendor/golang.org/x/sys/unix/mremap.go @@ -50,3 +50,8 @@ func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data [ func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { return mapper.Mremap(oldData, newLength, flags) } + +func MremapPtr(oldAddr unsafe.Pointer, oldSize uintptr, newAddr unsafe.Pointer, newSize uintptr, flags int) (ret unsafe.Pointer, err error) { + xaddr, err := mapper.mremap(uintptr(oldAddr), oldSize, newSize, flags, uintptr(newAddr)) + return unsafe.Pointer(xaddr), err +} diff --git a/vendor/golang.org/x/sys/unix/syscall_darwin.go b/vendor/golang.org/x/sys/unix/syscall_darwin.go index 59542a897..4cc7b0059 100644 --- a/vendor/golang.org/x/sys/unix/syscall_darwin.go +++ b/vendor/golang.org/x/sys/unix/syscall_darwin.go @@ -542,6 +542,18 @@ func SysctlKinfoProcSlice(name string, args ...int) ([]KinfoProc, error) { } } +//sys pthread_chdir_np(path string) (err error) + +func PthreadChdir(path string) (err error) { + return pthread_chdir_np(path) +} + +//sys pthread_fchdir_np(fd int) (err error) + +func PthreadFchdir(fd int) (err error) { + return pthread_fchdir_np(fd) +} + //sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) //sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_unix.go b/vendor/golang.org/x/sys/unix/syscall_unix.go index 77081de8c..4e92e5aa4 100644 --- a/vendor/golang.org/x/sys/unix/syscall_unix.go +++ b/vendor/golang.org/x/sys/unix/syscall_unix.go @@ -154,6 +154,15 @@ func Munmap(b []byte) (err error) { return mapper.Munmap(b) } +func MmapPtr(fd int, offset int64, addr unsafe.Pointer, length uintptr, prot int, flags int) (ret unsafe.Pointer, err error) { + xaddr, err := mapper.mmap(uintptr(addr), length, prot, flags, fd, offset) + return unsafe.Pointer(xaddr), err +} + +func MunmapPtr(addr unsafe.Pointer, length uintptr) (err error) { + return mapper.munmap(uintptr(addr), length) +} + func Read(fd int, p []byte) (n int, err error) { n, err = read(fd, p) if raceenabled { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go index ccb02f240..07642c308 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go @@ -760,6 +760,39 @@ var libc_sysctl_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pthread_chdir_np(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := syscall_syscall(libc_pthread_chdir_np_trampoline_addr, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_chdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_chdir_np pthread_chdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pthread_fchdir_np(fd int) (err error) { + _, _, e1 := syscall_syscall(libc_pthread_fchdir_np_trampoline_addr, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_fchdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_fchdir_np pthread_fchdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s index 8b8bb2840..923e08cb7 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s @@ -228,6 +228,16 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) +TEXT libc_pthread_chdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_chdir_np(SB) +GLOBL ·libc_pthread_chdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_chdir_np_trampoline_addr(SB)/8, $libc_pthread_chdir_np_trampoline<>(SB) + +TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_fchdir_np(SB) +GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go index 1b40b997b..7d73dda64 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go @@ -760,6 +760,39 @@ var libc_sysctl_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pthread_chdir_np(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := syscall_syscall(libc_pthread_chdir_np_trampoline_addr, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_chdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_chdir_np pthread_chdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pthread_fchdir_np(fd int) (err error) { + _, _, e1 := syscall_syscall(libc_pthread_fchdir_np_trampoline_addr, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_fchdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_fchdir_np pthread_fchdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s index 08362c1ab..057700111 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s @@ -228,6 +228,16 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) +TEXT libc_pthread_chdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_chdir_np(SB) +GLOBL ·libc_pthread_chdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_chdir_np_trampoline_addr(SB)/8, $libc_pthread_chdir_np_trampoline<>(SB) + +TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_fchdir_np(SB) +GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/vendor/golang.org/x/sys/windows/security_windows.go b/vendor/golang.org/x/sys/windows/security_windows.go index 6f7d2ac70..97651b5bd 100644 --- a/vendor/golang.org/x/sys/windows/security_windows.go +++ b/vendor/golang.org/x/sys/windows/security_windows.go @@ -894,7 +894,7 @@ type ACL struct { aclRevision byte sbz1 byte aclSize uint16 - aceCount uint16 + AceCount uint16 sbz2 uint16 } @@ -1087,6 +1087,27 @@ type EXPLICIT_ACCESS struct { Trustee TRUSTEE } +// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-ace_header +type ACE_HEADER struct { + AceType uint8 + AceFlags uint8 + AceSize uint16 +} + +// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-access_allowed_ace +type ACCESS_ALLOWED_ACE struct { + Header ACE_HEADER + Mask ACCESS_MASK + SidStart uint32 +} + +const ( + // Constants for AceType + // https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-ace_header + ACCESS_ALLOWED_ACE_TYPE = 0 + ACCESS_DENIED_ACE_TYPE = 1 +) + // This type is the union inside of TRUSTEE and must be created using one of the TrusteeValueFrom* functions. type TrusteeValue uintptr @@ -1158,6 +1179,7 @@ type OBJECTS_AND_NAME struct { //sys makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURITY_DESCRIPTOR, selfRelativeSDSize *uint32) (err error) = advapi32.MakeSelfRelativeSD //sys setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) = advapi32.SetEntriesInAclW +//sys GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (ret error) = advapi32.GetAce // Control returns the security descriptor control bits. func (sd *SECURITY_DESCRIPTOR) Control() (control SECURITY_DESCRIPTOR_CONTROL, revision uint32, err error) { diff --git a/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 9f73df75b..eba761018 100644 --- a/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -91,6 +91,7 @@ var ( procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW") procEqualSid = modadvapi32.NewProc("EqualSid") procFreeSid = modadvapi32.NewProc("FreeSid") + procGetAce = modadvapi32.NewProc("GetAce") procGetLengthSid = modadvapi32.NewProc("GetLengthSid") procGetNamedSecurityInfoW = modadvapi32.NewProc("GetNamedSecurityInfoW") procGetSecurityDescriptorControl = modadvapi32.NewProc("GetSecurityDescriptorControl") @@ -1224,6 +1225,14 @@ func setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCE return } +func GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (ret error) { + r0, _, _ := syscall.Syscall(procGetAce.Addr(), 3, uintptr(unsafe.Pointer(acl)), uintptr(aceIndex), uintptr(unsafe.Pointer(pAce))) + if r0 == 0 { + ret = GetLastError() + } + return +} + func SetKernelObjectSecurity(handle Handle, securityInformation SECURITY_INFORMATION, securityDescriptor *SECURITY_DESCRIPTOR) (err error) { r1, _, e1 := syscall.Syscall(procSetKernelObjectSecurity.Addr(), 3, uintptr(handle), uintptr(securityInformation), uintptr(unsafe.Pointer(securityDescriptor))) if r1 == 0 { diff --git a/vendor/modules.txt b/vendor/modules.txt index 5d3433d44..56c008a69 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -351,7 +351,7 @@ github.com/prometheus/procfs/internal/util # github.com/rivo/uniseg v0.4.7 ## explicit; go 1.18 github.com/rivo/uniseg -# github.com/schollz/progressbar/v3 v3.14.3 +# github.com/schollz/progressbar/v3 v3.14.5 ## explicit; go 1.13 github.com/schollz/progressbar/v3 # github.com/sergi/go-diff v1.3.1 @@ -523,7 +523,7 @@ golang.org/x/oauth2/internal golang.org/x/sync/errgroup golang.org/x/sync/semaphore golang.org/x/sync/singleflight -# golang.org/x/sys v0.21.0 +# golang.org/x/sys v0.22.0 ## explicit; go 1.18 golang.org/x/sys/cpu golang.org/x/sys/execabs @@ -531,7 +531,7 @@ golang.org/x/sys/plan9 golang.org/x/sys/unix golang.org/x/sys/windows golang.org/x/sys/windows/registry -# golang.org/x/term v0.21.0 +# golang.org/x/term v0.22.0 ## explicit; go 1.18 golang.org/x/term # golang.org/x/text v0.14.0