mirror of
https://github.com/alibaba/higress.git
synced 2026-06-26 02:35:02 +08:00
Add detecting higress installed by helm or not before install (#620)
This commit is contained in:
@@ -85,7 +85,6 @@ func (p ProfileGlobal) Validate(install InstallMode) []error {
|
|||||||
type ProfileConsole struct {
|
type ProfileConsole struct {
|
||||||
Port uint32 `json:"port,omitempty"`
|
Port uint32 `json:"port,omitempty"`
|
||||||
Replicas uint32 `json:"replicas,omitempty"`
|
Replicas uint32 `json:"replicas,omitempty"`
|
||||||
AdminPasswordValue string `json:"adminPasswordValue,omitempty"`
|
|
||||||
O11yEnabled bool `json:"o11YEnabled,omitempty"`
|
O11yEnabled bool `json:"o11YEnabled,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +92,6 @@ func (p ProfileConsole) SetFlags(install InstallMode) ([]string, error) {
|
|||||||
sets := make([]string, 0)
|
sets := make([]string, 0)
|
||||||
if install == InstallK8s || install == InstallLocalK8s {
|
if install == InstallK8s || install == InstallLocalK8s {
|
||||||
sets = append(sets, fmt.Sprintf("higress-console.replicaCount=%d", p.Replicas))
|
sets = append(sets, fmt.Sprintf("higress-console.replicaCount=%d", p.Replicas))
|
||||||
sets = append(sets, fmt.Sprintf("higress-console.admin.password.value=%s", p.AdminPasswordValue))
|
|
||||||
sets = append(sets, fmt.Sprintf("higress-console.o11y.enabled=%t", p.O11yEnabled))
|
sets = append(sets, fmt.Sprintf("higress-console.o11y.enabled=%t", p.O11yEnabled))
|
||||||
}
|
}
|
||||||
return sets, nil
|
return sets, nil
|
||||||
|
|||||||
93
pkg/cmd/hgctl/installer/helm_agent.go
Normal file
93
pkg/cmd/hgctl/installer/helm_agent.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
// 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 installer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alibaba/higress/pkg/cmd/hgctl/helm"
|
||||||
|
"github.com/alibaba/higress/pkg/cmd/options"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmRelease struct {
|
||||||
|
appVersion string `json:"app_version,omitempty"`
|
||||||
|
chart string `json:"chart,omitempty"`
|
||||||
|
name string `json:"name,omitempty"`
|
||||||
|
namespace string `json:"namespace,omitempty"`
|
||||||
|
revision string `json:"revision,omitempty"`
|
||||||
|
status string `json:"status,omitempty"`
|
||||||
|
updated string `json:"updated,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HelmAgent struct {
|
||||||
|
profile *helm.Profile
|
||||||
|
writer io.Writer
|
||||||
|
helmBinaryName string
|
||||||
|
quiet bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHelmAgent(profile *helm.Profile, writer io.Writer, quiet bool) *HelmAgent {
|
||||||
|
return &HelmAgent{
|
||||||
|
profile: profile,
|
||||||
|
writer: writer,
|
||||||
|
helmBinaryName: "helm",
|
||||||
|
quiet: quiet,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HelmAgent) IsHigressInstalled() (bool, error) {
|
||||||
|
args := []string{"list", "-n", h.profile.Global.Namespace, "-f", "higress"}
|
||||||
|
if len(*options.DefaultConfigFlags.KubeConfig) > 0 {
|
||||||
|
args = append(args, fmt.Sprintf("--kubeconfig=%s", *options.DefaultConfigFlags.KubeConfig))
|
||||||
|
}
|
||||||
|
if len(*options.DefaultConfigFlags.Context) > 0 {
|
||||||
|
args = append(args, fmt.Sprintf("--kube-context=%s", *options.DefaultConfigFlags.Context))
|
||||||
|
}
|
||||||
|
if !h.quiet {
|
||||||
|
fmt.Fprintf(h.writer, "\n📦 Running command: %s %s\n\n", h.helmBinaryName, strings.Join(args, " "))
|
||||||
|
}
|
||||||
|
cmd := exec.Command(h.helmBinaryName, args...)
|
||||||
|
var out bytes.Buffer
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
done <- cmd.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case err := <-done:
|
||||||
|
if err == nil {
|
||||||
|
content := out.String()
|
||||||
|
if !h.quiet {
|
||||||
|
fmt.Fprintf(h.writer, "\n%s\n", content)
|
||||||
|
}
|
||||||
|
if strings.Contains(content, "deployed") {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
@@ -35,6 +35,14 @@ type K8sInstaller struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *K8sInstaller) Install() error {
|
func (o *K8sInstaller) Install() error {
|
||||||
|
// check if higress is installed by helm
|
||||||
|
fmt.Fprintf(o.writer, "\n⌛️ Detecting higress installed by helm or not... \n\n")
|
||||||
|
helmAgent := NewHelmAgent(o.profile, o.writer, false)
|
||||||
|
if helmInstalled, _ := helmAgent.IsHigressInstalled(); helmInstalled {
|
||||||
|
fmt.Fprintf(o.writer, "\n🧐 You have already installed higress by helm, please use \"helm upgrade\" to upgrade higress!\n")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := GetProfileInstalledPath(); err != nil {
|
if _, err := GetProfileInstalledPath(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ func (a *Agent) profileArgs() []string {
|
|||||||
fmt.Sprintf("--nacos-password=%s", a.profile.Storage.Password),
|
fmt.Sprintf("--nacos-password=%s", a.profile.Storage.Password),
|
||||||
fmt.Sprintf("--nacos-username=%s", a.profile.Storage.Username),
|
fmt.Sprintf("--nacos-username=%s", a.profile.Storage.Username),
|
||||||
fmt.Sprintf("--data-enc-key=%s", a.profile.Storage.DataEncKey),
|
fmt.Sprintf("--data-enc-key=%s", a.profile.Storage.DataEncKey),
|
||||||
fmt.Sprintf("--console-password=%s", a.profile.Console.AdminPasswordValue),
|
|
||||||
fmt.Sprintf("--console-port=%d", a.profile.Console.Port),
|
fmt.Sprintf("--console-port=%d", a.profile.Console.Port),
|
||||||
fmt.Sprintf("--gateway-http-port=%d", a.profile.Gateway.HttpPort),
|
fmt.Sprintf("--gateway-http-port=%d", a.profile.Gateway.HttpPort),
|
||||||
fmt.Sprintf("--gateway-https-port=%d", a.profile.Gateway.HttpsPort),
|
fmt.Sprintf("--gateway-https-port=%d", a.profile.Gateway.HttpsPort),
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ global:
|
|||||||
console:
|
console:
|
||||||
port: 8080
|
port: 8080
|
||||||
replicas: 1
|
replicas: 1
|
||||||
adminPasswordValue: admin
|
|
||||||
o11yEnabled: false
|
o11yEnabled: false
|
||||||
|
|
||||||
gateway:
|
gateway:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ global:
|
|||||||
|
|
||||||
console:
|
console:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
adminPasswordValue: admin
|
|
||||||
o11yEnabled: false
|
o11yEnabled: false
|
||||||
|
|
||||||
gateway:
|
gateway:
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ global:
|
|||||||
|
|
||||||
console:
|
console:
|
||||||
port: 8080
|
port: 8080
|
||||||
adminPasswordValue: admin
|
|
||||||
|
|
||||||
gateway:
|
gateway:
|
||||||
httpPort: 80
|
httpPort: 80
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ global:
|
|||||||
|
|
||||||
console:
|
console:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
adminPasswordValue: admin
|
|
||||||
o11yEnabled: true
|
o11yEnabled: true
|
||||||
|
|
||||||
gateway:
|
gateway:
|
||||||
|
|||||||
Reference in New Issue
Block a user