refactor(v2): upgrade module to github.com/alibaba/higress/v2 (#2922)

Signed-off-by: Xijun Dai <daixijun1990@gmail.com>
This commit is contained in:
Xijun Dai
2025-09-21 14:29:07 +08:00
committed by GitHub
parent cd2082033c
commit 47827ad271
235 changed files with 1077 additions and 1045 deletions

View File

@@ -27,7 +27,7 @@ import (
"sigs.k8s.io/yaml"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
)
var (

View File

@@ -148,7 +148,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: BootstrapEnvoyConfigType,
expected: "out.bootstrap.yaml",
}, {
},
{
output: "json",
resourceType: ClusterEnvoyConfigType,
expected: "out.cluster.json",
@@ -157,7 +158,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: ClusterEnvoyConfigType,
expected: "out.cluster.yaml",
}, {
},
{
output: "json",
resourceType: ListenerEnvoyConfigType,
expected: "out.listener.json",
@@ -166,7 +168,8 @@ func TestExtractSubResourcesConfigDump(t *testing.T) {
output: "yaml",
resourceType: ListenerEnvoyConfigType,
expected: "out.listener.yaml",
}, {
},
{
output: "json",
resourceType: RouteEnvoyConfigType,
expected: "out.route.json",

View File

@@ -18,7 +18,7 @@ import (
"fmt"
"os"
"github.com/alibaba/higress/hgctl/pkg"
hgctl "github.com/alibaba/higress/hgctl/pkg"
)
func main() {

View File

@@ -15,9 +15,11 @@ replace github.com/docker/distribution => github.com/docker/distribution v0.0.0-
// Client-go does not handle different versions of mergo due to some breaking changes - use the matching version
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.5
replace github.com/alibaba/higress/v2 => ../
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/alibaba/higress v0.0.0
github.com/alibaba/higress/v2 v2.0.0-00010101000000-000000000000
github.com/compose-spec/compose-go v1.17.0
github.com/docker/cli v24.0.7+incompatible
github.com/docker/compose/v2 v2.23.3

View File

@@ -18,7 +18,7 @@ import (
"fmt"
"github.com/alibaba/higress/hgctl/cmd/hgctl/config"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)

View File

@@ -30,7 +30,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/docker"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
)
var (
@@ -418,7 +418,6 @@ func openBrowser(url string, writer io.Writer, browser bool) {
default:
fmt.Fprintf(writer, "Unsupported platform %q; open %s in your browser.\n", runtime.GOOS, url)
}
}
func openCommand(writer io.Writer, command string, args ...string) {

View File

@@ -137,7 +137,6 @@ func GenerateConfig(inFilenames []string, setFlags []string) (string, *Profile,
}
profileString, profile, err := GenProfile(profileName, valuesOverlay, setFlags)
if err != nil {
return "", nil, "", err
}

View File

@@ -652,14 +652,14 @@ func TestK8sObject_ResolveK8sConflict(t *testing.T) {
kind: PodDisruptionBudget
metadata:
name: istio
spec:
spec:
maxUnavailable: 3`),
o2: getK8sObject(`
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: istio
spec:
spec:
maxUnavailable: 3`),
},
{
@@ -669,7 +669,7 @@ func TestK8sObject_ResolveK8sConflict(t *testing.T) {
kind: PodDisruptionBudget
metadata:
name: istio
spec:
spec:
maxUnavailable: 50%
minAvailable: 3`),
o2: getK8sObject(`
@@ -677,7 +677,7 @@ func TestK8sObject_ResolveK8sConflict(t *testing.T) {
kind: PodDisruptionBudget
metadata:
name: istio
spec:
spec:
maxUnavailable: 50%`),
},
{
@@ -687,7 +687,7 @@ func TestK8sObject_ResolveK8sConflict(t *testing.T) {
kind: PodDisruptionBudget
metadata:
name: istio
spec:
spec:
minAvailable: 0
maxUnavailable: 0`),
o2: getK8sObject(`

View File

@@ -585,7 +585,6 @@ func locateChart(cpOpts *action.ChartPathOptions, name string, settings *cli.Env
}
func ParseLatestVersion(repoUrl string, version string, devel bool) (string, error) {
cpOpts := &action.ChartPathOptions{
RepoURL: repoUrl,
Version: version,
@@ -603,7 +602,6 @@ func ParseLatestVersion(repoUrl string, version string, devel bool) (string, err
}
client, err := getter.All(settings).ByScheme(u.Scheme)
if err != nil {
return "", fmt.Errorf("could not find protocol handler for: %s", u.Scheme)
}
@@ -615,7 +613,6 @@ func ParseLatestVersion(repoUrl string, version string, devel bool) (string, err
getter.WithBasicAuth(cpOpts.Username, cpOpts.Password),
getter.WithPassCredentialsAll(cpOpts.PassCredentialsAll),
)
if err != nil {
return "", err
}

View File

@@ -63,7 +63,6 @@ func GetPathContext(root any, path util.Path, createMissing bool) (*PathContext,
// WritePathContext writes the given value to the Node in the given PathContext.
func WritePathContext(nc *PathContext, value any, merge bool) error {
if !util.IsValueNil(value) {
return setPathContext(nc, value, merge)
}

View File

@@ -114,7 +114,7 @@ a:
desc: "ModifyListEntryMapValue",
path: `a.b.[name:n2]`,
value: `name: n2
list:
list:
- nk1: nv1
- nk2: nv2`,
wantFound: true,
@@ -503,7 +503,7 @@ a: {}
want: `
a:
list:
- v1
- v1
`,
},
{
@@ -517,7 +517,7 @@ a:
value: `v2`,
want: `
a:
list:
list:
- v1
- v2
`,

View File

@@ -22,7 +22,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/helm"
"github.com/alibaba/higress/hgctl/pkg/installer"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/spf13/cobra"
)
@@ -91,8 +91,8 @@ func newInstallCmd() *cobra.Command {
Example: ` # Apply a default higress installation
hgctl install
# Install higress on local kubernetes cluster
hgctl install --set profile=local-k8s
# Install higress on local kubernetes cluster
hgctl install --set profile=local-k8s
# Install higress on local docker environment with specific gateway port
hgctl install --set profile=local-docker --set gateway.httpPort=80 --set gateway.httpsPort=443
@@ -192,7 +192,6 @@ func promptProfileName(writer io.Writer) string {
return profileNameLocalDocker
}
}
}
func installManifests(profile *helm.Profile, writer io.Writer, devel bool) error {

View File

@@ -22,7 +22,7 @@ import (
"strings"
"github.com/alibaba/higress/hgctl/pkg/helm"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
)
type HelmRelease struct {

View File

@@ -24,7 +24,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/helm"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"k8s.io/client-go/util/homedir"
)

View File

@@ -48,7 +48,6 @@ func (d *DockerInstaller) Install() error {
}
func (d *DockerInstaller) UnInstall() error {
fmt.Fprintf(d.writer, "\n⌛ Processing uninstallation... \n\n")
if err := d.standalone.UnInstall(); err != nil {

View File

@@ -59,7 +59,7 @@ type FileDirProfileStore struct {
func (f *FileDirProfileStore) Save(profile *helm.Profile) (string, error) {
namespace := profile.Global.Namespace
install := profile.Global.Install
var profileName = ""
profileName := ""
if install == helm.InstallK8s || install == helm.InstallLocalK8s {
profileName = filepath.Join(f.profilesPath, fmt.Sprintf("%s-%s.yaml", ProfileFilePrefix, namespace))
} else {
@@ -109,7 +109,7 @@ func (f *FileDirProfileStore) List() ([]*ProfileContext, error) {
func (f *FileDirProfileStore) Delete(profile *helm.Profile) (string, error) {
namespace := profile.Global.Namespace
install := profile.Global.Install
var profileName = ""
profileName := ""
if install == helm.InstallK8s || install == helm.InstallLocalK8s {
profileName = filepath.Join(f.profilesPath, fmt.Sprintf("%s-%s.yaml", ProfileFilePrefix, namespace))
} else {

View File

@@ -22,7 +22,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/helm"
"github.com/alibaba/higress/hgctl/pkg/installer"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/spf13/cobra"
)

View File

@@ -423,13 +423,11 @@ func (b *Builder) filesHandler() error {
return nil
}
var (
optionalProducts = [][2]string{
{"README_ZH.md", MediaTypeREADME_ZH},
{"README_EN.md", MediaTypeREADME_EN},
{"icon.png", MediaTypeIcon},
}
)
var optionalProducts = [][2]string{
{"README_ZH.md", MediaTypeREADME_ZH},
{"README_EN.md", MediaTypeREADME_EN},
{"icon.png", MediaTypeIcon},
}
// TODO(WeixinX): If the image exists, no push is performed
func (b *Builder) imageHandler() error {
@@ -536,7 +534,7 @@ func (b *Builder) config(f ConfigFunc) (err error) {
if err != nil {
return errors.Wrapf(err, "failed to parse output destination %q", b.Output.Dest)
}
err = os.MkdirAll(b.Output.Dest, 0755)
err = os.MkdirAll(b.Output.Dest, 0o755)
if err != nil && !os.IsExist(err) {
return errors.Wrapf(err, "failed to create output destination %q", b.Output.Dest)
}
@@ -574,7 +572,7 @@ func (b *Builder) config(f ConfigFunc) (err error) {
if err != nil && !os.IsExist(err) {
return errors.Wrap(err, "failed to create the docker entrypoint file")
}
err = dockerEp.Chmod(0777)
err = dockerEp.Chmod(0o777)
if err != nil {
return err
}

View File

@@ -47,11 +47,11 @@ cd {{ .BuildDestDir }}
tar czf plugin.tar.gz plugin.wasm
cmd="{{ .BasicCmd }}"
products=({{ .Products }})
for ((i=0; i<${#products[*]}; i=i+2)); do
for ((i=0; i<${#products[*]}; i=i+2)); do
f=${products[i]}
typ=${products[i+1]}
if [ -e ${f} ]; then
cmd="${cmd} ./${f}:${typ}"
if [ -e ${f} ]; then
cmd="${cmd} ./${f}:${typ}"
fi
done
cmd="${cmd} ./plugin.tar.gz:{{ .MediaTypePlugin }}"
@@ -79,7 +79,7 @@ type ImageTmplFields struct {
}
func genFilesDockerEntrypoint(ft *FilesTmplFields, target string) error {
f, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY, 0777)
f, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY, 0o777)
if err != nil {
return err
}
@@ -93,7 +93,7 @@ func genFilesDockerEntrypoint(ft *FilesTmplFields, target string) error {
}
func genImageDockerEntrypoint(it *ImageTmplFields, target string) error {
f, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY, 0777)
f, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY, 0o777)
if err != nil {
return err
}

View File

@@ -49,7 +49,7 @@ func create(w io.Writer, target string) error {
if err != nil {
return errors.Wrap(err, "invalid target path")
}
if err = os.MkdirAll(target, 0755); err != nil {
if err = os.MkdirAll(target, 0o755); err != nil {
return err
}
if err = GenPluginConfYAML(configHelpTmpl, target); err != nil {

View File

@@ -22,7 +22,7 @@ import (
"os"
k8s "github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/pkg/errors"
"github.com/spf13/cobra"

View File

@@ -156,5 +156,4 @@ func (pc *PluginConf) withDefaultValue() {
if pc.Phase == "" {
pc.Phase = string(types.PhaseDefault)
}
}

View File

@@ -63,7 +63,7 @@ func runInit(w io.Writer, target string) (err error) {
return errors.Wrap(err, "invalid target directory")
}
dir := fmt.Sprintf("%s/%s", target, ans.Name)
err = os.MkdirAll(dir, 0755)
err = os.MkdirAll(dir, 0o755)
defer func() {
if err != nil {
os.RemoveAll(dir)

View File

@@ -28,7 +28,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/plugin/option"
"github.com/alibaba/higress/hgctl/pkg/plugin/types"
"github.com/alibaba/higress/hgctl/pkg/plugin/utils"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/pkg/errors"

View File

@@ -21,7 +21,7 @@ import (
"time"
k8s "github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/pkg/errors"
"github.com/spf13/cobra"

View File

@@ -51,7 +51,7 @@ func newCreateCommand() *cobra.Command {
Example: ` # If the option.yaml file exists in the current path, do the following:
hgctl plugin test create
# Explicitly specify the source of the parameters (directory of the build
# Explicitly specify the source of the parameters (directory of the build
products) and the directory where the test configuration files is stored
hgctl plugin test create -d ./out -t ./test
`,
@@ -139,9 +139,8 @@ func (c *creator) create() (err error) {
fields.Envoy = &Envoy{JSONExample: jsExample}
// 4. generate corresponding test files
if err = os.MkdirAll(target, 0755); err != nil {
if err = os.MkdirAll(target, 0o755); err != nil {
return errors.Wrap(err, "failed to create the test environment")
}
if err = c.genTestConfFiles(fields); err != nil {
return errors.Wrap(err, "failed to create the test environment")

View File

@@ -22,10 +22,12 @@ type TestExStruct struct {
three []bool
}
type ExPointerInt **int
type ExBool bool
type ExSlice []*string
type ExAlias nested.TestNestedStruct
type (
ExPointerInt **int
ExBool bool
ExSlice []*string
ExAlias nested.TestNestedStruct
)
type TestNestedStruct struct {
NestedStruct *nested.TestNestedStruct

View File

@@ -44,11 +44,13 @@ type TestAliasStruct struct {
MyStruct MyStruct
}
type MyString string
type MyPointerInt *int
type MyStruct TestBasicStruct
type NestedAlias ext.ExAlias
type NestedBasicAlias ext.ExBool
type (
MyString string
MyPointerInt *int
MyStruct TestBasicStruct
NestedAlias ext.ExAlias
NestedBasicAlias ext.ExBool
)
type TestExternalStruct struct {
InternalFloat float64
@@ -62,8 +64,7 @@ type TestNestedStruct struct {
NestedStruct *ext.TestNestedStruct
}
type MyInterface interface {
}
type MyInterface interface{}
var MyConst bool

View File

@@ -20,7 +20,7 @@ import (
"io"
k8s "github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/pkg/errors"
"github.com/spf13/cobra"

View File

@@ -61,7 +61,7 @@ func profileDump(cmd *cobra.Command, args []string, pdArgs *profileDumpArgs) err
return err
}
if len(pdArgs.output) > 0 {
err2 := os.WriteFile(pdArgs.output, []byte(yaml), 0644)
err2 := os.WriteFile(pdArgs.output, []byte(yaml), 0o644)
if err2 != nil {
return err2
}

View File

@@ -44,7 +44,6 @@ func profileListCmd(plArgs *profileListArgs) *cobra.Command {
// profileList list all the builtin profiles.
func profileList(cmd *cobra.Command, plArgs *profileListArgs) error {
profiles, err := helm.ListProfiles(plArgs.manifestsPath)
if err != nil {
return err

View File

@@ -15,9 +15,10 @@
package hgctl
import (
"os"
"github.com/alibaba/higress/hgctl/pkg/plugin"
"github.com/spf13/cobra"
"os"
)
// GetRootCommand returns the root cobra command to be executed

View File

@@ -23,7 +23,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/helm"
"github.com/alibaba/higress/hgctl/pkg/installer"
"github.com/alibaba/higress/hgctl/pkg/util"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/spf13/cobra"
)
@@ -44,9 +44,9 @@ func newUninstallCmd() *cobra.Command {
Use: "uninstall",
Short: "Uninstall higress from a cluster",
Long: "The uninstall command uninstalls higress from a cluster or local environment",
Example: `# Uninstall higress
Example: `# Uninstall higress
hgctl uninstal
# Uninstall higress, istioAPI and GatewayAPI from a cluster
hgctl uninstall --purge-resources
`,

View File

@@ -25,7 +25,7 @@ import (
"github.com/alibaba/higress/hgctl/pkg/installer"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/hgctl/pkg/util"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/spf13/cobra"
)

View File

@@ -22,8 +22,8 @@ import (
"strings"
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
"github.com/alibaba/higress/pkg/cmd/options"
"github.com/alibaba/higress/pkg/cmd/version"
"github.com/alibaba/higress/v2/pkg/cmd/options"
"github.com/alibaba/higress/v2/pkg/cmd/version"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"