Skip to content

Commit

Permalink
Merge branch 'main' into bufix-openBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcsjc123 authored Dec 5, 2023
2 parents 267f246 + bd4109e commit 1b26102
Show file tree
Hide file tree
Showing 11 changed files with 461 additions and 51 deletions.
40 changes: 39 additions & 1 deletion pkg/cmd/hgctl/helm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,45 @@ func GenProfile(profileOrPath, fileOverlayYAML string, setFlags []string) (strin
return "", nil, err
}

finalProfile.InstallPackagePath = installPackagePath
if len(installPackagePath) > 0 {
finalProfile.InstallPackagePath = installPackagePath
}

if finalProfile.Profile == "" {
finalProfile.Profile = DefaultProfileName
}
return util.ToYAML(finalProfile), finalProfile, nil
}

func GenProfileFromProfileContent(profileContent, fileOverlayYAML string, setFlags []string) (string, *Profile, error) {
installPackagePath, err := getInstallPackagePath(fileOverlayYAML)
if err != nil {
return "", nil, err
}
if sfp := GetValueForSetFlag(setFlags, "installPackagePath"); sfp != "" {
// set flag installPackagePath has the highest precedence, if set.
installPackagePath = sfp
}

// Combine file and --set overlays and translate any K8s settings in values to Profile format
overlayYAML, err := overlaySetFlagValues(fileOverlayYAML, setFlags)
if err != nil {
return "", nil, err
}
// Merge user file and --set flags.
outYAML, err := util.OverlayYAML(profileContent, overlayYAML)
if err != nil {
return "", nil, fmt.Errorf("could not overlay user config over base: %s", err)
}

finalProfile, err := UnmarshalProfile(outYAML)
if err != nil {
return "", nil, err
}

if len(installPackagePath) > 0 {
finalProfile.InstallPackagePath = installPackagePath
}

if finalProfile.Profile == "" {
finalProfile.Profile = DefaultProfileName
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/hgctl/helm/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
type Profile struct {
Profile string `json:"profile,omitempty"`
InstallPackagePath string `json:"installPackagePath,omitempty"`
HigressVersion string `json:"higressVersion,omitempty"`
Global ProfileGlobal `json:"global,omitempty"`
Console ProfileConsole `json:"console,omitempty"`
Gateway ProfileGateway `json:"gateway,omitempty"`
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/hgctl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hgctl
import (
"fmt"
"io"
"os"
"strings"

"github.com/alibaba/higress/pkg/cmd/hgctl/helm"
Expand Down Expand Up @@ -134,7 +135,7 @@ func install(writer io.Writer, iArgs *InstallArgs) error {
return fmt.Errorf("generate config: %v", err)
}

fmt.Fprintf(writer, "🧐 Validating Profile: \"%s\" \n", profileName)
fmt.Fprintf(writer, "\n🧐 Validating Profile: \"%s\" \n", profileName)
err = profile.Validate()
if err != nil {
return err
Expand All @@ -144,6 +145,12 @@ func install(writer io.Writer, iArgs *InstallArgs) error {
if err != nil {
return fmt.Errorf("failed to install manifests: %v", err)
}

// Remove "~/.hgctl/profiles/install.yaml"
if oldProfileName, isExisted := installer.GetInstalledYamlPath(); isExisted {
_ = os.Remove(oldProfileName)
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/hgctl/installer/higress.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (h *HigressComponent) Run() error {
if err := h.renderer.Init(); err != nil {
return err
}
h.profile.HigressVersion = h.opts.Version
h.started = true
return nil
}
Expand Down
43 changes: 27 additions & 16 deletions pkg/cmd/hgctl/installer/installer_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ package installer
import (
"errors"
"fmt"
"github.com/alibaba/higress/pkg/cmd/hgctl/helm"
"github.com/alibaba/higress/pkg/cmd/hgctl/util"
"io"
"os"

"github.com/alibaba/higress/pkg/cmd/hgctl/helm"
)

type DockerInstaller struct {
started bool
standalone *StandaloneComponent
profile *helm.Profile
writer io.Writer
started bool
standalone *StandaloneComponent
profile *helm.Profile
writer io.Writer
profileStore ProfileStore
}

func (d *DockerInstaller) Install() error {
Expand All @@ -37,11 +37,11 @@ func (d *DockerInstaller) Install() error {
return err
}

profileName, _ := GetInstalledYamlPath()
fmt.Fprintf(d.writer, "\n✔️ Wrote Profile: \"%s\" \n", profileName)
if err := util.WriteFileString(profileName, util.ToYAML(d.profile), 0o644); err != nil {
return err
profileName, err1 := d.profileStore.Save(d.profile)
if err1 != nil {
return err1
}
fmt.Fprintf(d.writer, "\n✔️ Wrote Profile: \"%s\" \n", profileName)

fmt.Fprintf(d.writer, "\n🎊 Install All Resources Complete!\n")
return nil
Expand All @@ -55,9 +55,11 @@ func (d *DockerInstaller) UnInstall() error {
return err
}

profileName, _ := GetInstalledYamlPath()
profileName, err1 := d.profileStore.Delete(d.profile)
if err1 != nil {
return err1
}
fmt.Fprintf(d.writer, "\n✔️ Removed Profile: \"%s\" \n", profileName)
os.Remove(profileName)

fmt.Fprintf(d.writer, "\n🎊 Uninstall All Resources Complete!\n")
return nil
Expand Down Expand Up @@ -92,10 +94,19 @@ func NewDockerInstaller(profile *helm.Profile, writer io.Writer, quiet bool) (*D
return nil, fmt.Errorf("NewStandaloneComponent failed, err: %s", err)
}

profileInstalledPath, err1 := GetProfileInstalledPath()
if err1 != nil {
return nil, err1
}
profileStore, err2 := NewFileDirProfileStore(profileInstalledPath)
if err2 != nil {
return nil, err2
}
op := &DockerInstaller{
profile: profile,
standalone: standaloneComponent,
writer: writer,
profile: profile,
standalone: standaloneComponent,
writer: writer,
profileStore: profileStore,
}
return op, nil
}
49 changes: 30 additions & 19 deletions pkg/cmd/hgctl/installer/installer_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/alibaba/higress/pkg/cmd/hgctl/helm"
"github.com/alibaba/higress/pkg/cmd/hgctl/helm/object"
Expand All @@ -28,11 +29,12 @@ import (
)

type K8sInstaller struct {
started bool
components map[ComponentName]Component
kubeCli kubernetes.CLIClient
profile *helm.Profile
writer io.Writer
started bool
components map[ComponentName]Component
kubeCli kubernetes.CLIClient
profile *helm.Profile
writer io.Writer
profileStore ProfileStore
}

func (o *K8sInstaller) Install() error {
Expand All @@ -44,10 +46,6 @@ func (o *K8sInstaller) Install() error {
return nil
}

if _, err := GetProfileInstalledPath(); err != nil {
return err
}

if err := o.Run(); err != nil {
return err
}
Expand All @@ -62,11 +60,16 @@ func (o *K8sInstaller) Install() error {
return err
}

profileName, _ := GetInstalledYamlPath()
fmt.Fprintf(o.writer, "\n✔️ Wrote Profile: \"%s\" \n", profileName)
if err := util.WriteFileString(profileName, util.ToYAML(o.profile), 0o644); err != nil {
return err
profileName, err1 := o.profileStore.Save(o.profile)
if err1 != nil {
return err1
}
fmt.Fprintf(o.writer, "\n✔️ Wrote Profile in kubernetes configmap: \"%s\" \n", profileName)
fmt.Fprintf(o.writer, "\n Use bellow kubectl command to edit profile for upgrade. \n")
fmt.Fprintf(o.writer, " ================================================================================== \n")
names := strings.Split(profileName, "/")
fmt.Fprintf(o.writer, " kubectl edit configmap %s -n %s \n", names[1], names[0])
fmt.Fprintf(o.writer, " ================================================================================== \n")

fmt.Fprintf(o.writer, "\n🎊 Install All Resources Complete!\n")

Expand All @@ -92,9 +95,11 @@ func (o *K8sInstaller) UnInstall() error {
return err
}

profileName, _ := GetInstalledYamlPath()
profileName, err1 := o.profileStore.Delete(o.profile)
if err1 != nil {
return err1
}
fmt.Fprintf(o.writer, "\n✔️ Removed Profile: \"%s\" \n", profileName)
os.Remove(profileName)

fmt.Fprintf(o.writer, "\n🎊 Uninstall All Resources Complete!\n")

Expand Down Expand Up @@ -322,11 +327,17 @@ func NewK8sInstaller(profile *helm.Profile, cli kubernetes.CLIClient, writer io.
components[GatewayAPI] = gatewayAPIComponent
}

profileStore, err := NewConfigmapProfileStore(cli)
if err != nil {
return nil, err
}

op := &K8sInstaller{
profile: profile,
components: components,
kubeCli: cli,
writer: writer,
profile: profile,
components: components,
kubeCli: cli,
writer: writer,
profileStore: profileStore,
}
return op, nil
}
Loading

0 comments on commit 1b26102

Please sign in to comment.