-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add detecting higress installed by helm or not before install (#620)
- Loading branch information
1 parent
3440356
commit 7b1f538
Showing
8 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ global: | |
console: | ||
port: 8080 | ||
replicas: 1 | ||
adminPasswordValue: admin | ||
o11yEnabled: false | ||
|
||
gateway: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ global: | |
|
||
console: | ||
replicas: 1 | ||
adminPasswordValue: admin | ||
o11yEnabled: false | ||
|
||
gateway: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ global: | |
|
||
console: | ||
port: 8080 | ||
adminPasswordValue: admin | ||
|
||
gateway: | ||
httpPort: 80 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ global: | |
|
||
console: | ||
replicas: 1 | ||
adminPasswordValue: admin | ||
o11yEnabled: true | ||
|
||
gateway: | ||
|