mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-26 15:54:08 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea0508a634 | ||
|
|
23e29aa62a | ||
|
|
ed2cb80219 | ||
|
|
1a3d5debd5 | ||
|
|
d4a82fe292 | ||
|
|
963ae400fa |
@@ -33,7 +33,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
initAdminPassword = "VelaUX12345"
|
||||
// InitAdminPassword the password of first admin user
|
||||
InitAdminPassword = "VelaUX12345"
|
||||
)
|
||||
|
||||
// UserService User manage api
|
||||
@@ -70,7 +71,7 @@ func (u *userServiceImpl) Init(ctx context.Context) error {
|
||||
Name: admin,
|
||||
}); err != nil {
|
||||
if errors.Is(err, datastore.ErrRecordNotExist) {
|
||||
encrypted, err := GeneratePasswordHash(initAdminPassword)
|
||||
encrypted, err := GeneratePasswordHash(InitAdminPassword)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -83,7 +84,7 @@ func (u *userServiceImpl) Init(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
// print default password of admin user in log
|
||||
log.Logger.Infof("initialized admin username and password: admin / %s", initAdminPassword)
|
||||
log.Logger.Infof("initialized admin username and password: admin / %s", InitAdminPassword)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -99,3 +99,40 @@ func NewDefaultFactory(cfg *rest.Config) Factory {
|
||||
copiedCfg.Wrap(multicluster.NewSecretModeMultiClusterRoundTripper)
|
||||
return &defaultFactory{cfg: &copiedCfg}
|
||||
}
|
||||
|
||||
type deferredFactory struct {
|
||||
sync.Mutex
|
||||
Factory
|
||||
ConfigGetter
|
||||
}
|
||||
|
||||
// NewDeferredFactory create a factory that will only get KubeConfig until it is needed for the first time
|
||||
func NewDeferredFactory(getter ConfigGetter) Factory {
|
||||
return &deferredFactory{ConfigGetter: getter}
|
||||
}
|
||||
|
||||
func (f *deferredFactory) init() {
|
||||
cfg, err := f.ConfigGetter()
|
||||
cmdutil.CheckErr(err)
|
||||
f.Factory = NewDefaultFactory(cfg)
|
||||
}
|
||||
|
||||
// Config return the kubeConfig
|
||||
func (f *deferredFactory) Config() *rest.Config {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
if f.Factory == nil {
|
||||
f.init()
|
||||
}
|
||||
return f.Factory.Config()
|
||||
}
|
||||
|
||||
// Client return the kubeClient
|
||||
func (f *deferredFactory) Client() client.Client {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
if f.Factory == nil {
|
||||
f.init()
|
||||
}
|
||||
return f.Factory.Client()
|
||||
}
|
||||
|
||||
@@ -140,20 +140,16 @@ func (h *Helper) UpgradeChart(ch *chart.Chart, releaseName, namespace string, va
|
||||
r.Info.Status == release.StatusPendingRollback {
|
||||
return nil, fmt.Errorf("previous installation (e.g., using vela install or helm upgrade) is still in progress. Please try again in %d minutes", timeoutInMinutes)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// merge un-existing values into the values as user-input, because the helm chart upgrade didn't handle the new default values in the chart.
|
||||
// the new default values <= the old custom values <= the new custom values
|
||||
if config.ReuseValues {
|
||||
// sort will sort the release by revision from old to new
|
||||
relutil.SortByRevision(releases)
|
||||
rel := releases[len(releases)-1]
|
||||
// merge new chart values into old values, the values of old chart has the high priority
|
||||
mergedWithNewValues := chartutil.CoalesceTables(rel.Chart.Values, ch.Values)
|
||||
// merge the chart with the released chart config but follow the old config
|
||||
mergeWithConfigs := chartutil.CoalesceTables(rel.Config, mergedWithNewValues)
|
||||
// merge new values as the user input, follow the new user input for --set
|
||||
values = chartutil.CoalesceTables(values, mergeWithConfigs)
|
||||
values = chartutil.CoalesceTables(values, rel.Config)
|
||||
}
|
||||
|
||||
// overwrite existing installation
|
||||
@@ -161,7 +157,8 @@ func (h *Helper) UpgradeChart(ch *chart.Chart, releaseName, namespace string, va
|
||||
install.Namespace = namespace
|
||||
install.Wait = config.Wait
|
||||
install.Timeout = time.Duration(timeoutInMinutes) * time.Minute
|
||||
install.ReuseValues = config.ReuseValues
|
||||
// use the new default value set.
|
||||
install.ReuseValues = false
|
||||
newRelease, err = install.Run(releaseName, ch, values)
|
||||
}
|
||||
// check if install/upgrade worked
|
||||
|
||||
@@ -49,7 +49,10 @@ var _ = Describe("Test helm helper", func() {
|
||||
helper := NewHelper()
|
||||
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz", nil)
|
||||
Expect(err).Should(BeNil())
|
||||
release, err := helper.UpgradeChart(chart, "autoscalertrait", "default", nil, UpgradeChartOptions{
|
||||
release, err := helper.UpgradeChart(chart, "autoscalertrait", "default", map[string]interface{}{
|
||||
"replicaCount": 2,
|
||||
"image.tag": "0.1.0",
|
||||
}, UpgradeChartOptions{
|
||||
Config: cfg,
|
||||
Detail: false,
|
||||
Logging: util.IOStreams{Out: os.Stdout, ErrOut: os.Stderr},
|
||||
@@ -58,6 +61,42 @@ var _ = Describe("Test helm helper", func() {
|
||||
crds := GetCRDFromChart(release.Chart)
|
||||
Expect(cmp.Diff(len(crds), 1)).Should(BeEmpty())
|
||||
Expect(err).Should(BeNil())
|
||||
deployments := GetDeploymentsFromManifest(release.Manifest)
|
||||
Expect(cmp.Diff(len(deployments), 1)).Should(BeEmpty())
|
||||
Expect(cmp.Diff(*deployments[0].Spec.Replicas, int32(2))).Should(BeEmpty())
|
||||
containers := deployments[0].Spec.Template.Spec.Containers
|
||||
Expect(cmp.Diff(len(containers), 1)).Should(BeEmpty())
|
||||
|
||||
// add new default value
|
||||
Expect(cmp.Diff(containers[0].Image, "ghcr.io/oam-dev/catalog/autoscalertrait:0.1.0")).Should(BeEmpty())
|
||||
|
||||
chartNew, err := helper.LoadCharts("./testdata/autoscalertrait-0.2.0.tgz", nil)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
// the new custom values should override the last release custom values
|
||||
releaseNew, err := helper.UpgradeChart(chartNew, "autoscalertrait", "default", map[string]interface{}{
|
||||
"image.tag": "0.2.0",
|
||||
}, UpgradeChartOptions{
|
||||
Config: cfg,
|
||||
Detail: false,
|
||||
ReuseValues: true,
|
||||
Logging: util.IOStreams{Out: os.Stdout, ErrOut: os.Stderr},
|
||||
Wait: false,
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
deployments = GetDeploymentsFromManifest(releaseNew.Manifest)
|
||||
Expect(cmp.Diff(len(deployments), 1)).Should(BeEmpty())
|
||||
// keep the custom values
|
||||
Expect(cmp.Diff(*deployments[0].Spec.Replicas, int32(2))).Should(BeEmpty())
|
||||
containers = deployments[0].Spec.Template.Spec.Containers
|
||||
Expect(cmp.Diff(len(containers), 1)).Should(BeEmpty())
|
||||
|
||||
// change the default value
|
||||
Expect(cmp.Diff(containers[0].Image, "ghcr.io/oam-dev/catalog/autoscalertrait:0.2.0")).Should(BeEmpty())
|
||||
|
||||
// add new default value
|
||||
Expect(cmp.Diff(len(containers[0].Env), 1)).Should(BeEmpty())
|
||||
Expect(cmp.Diff(containers[0].Env[0].Name, "env1")).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test UninstallRelease", func() {
|
||||
|
||||
BIN
pkg/utils/helm/testdata/autoscalertrait-0.1.0.tgz
vendored
BIN
pkg/utils/helm/testdata/autoscalertrait-0.1.0.tgz
vendored
Binary file not shown.
BIN
pkg/utils/helm/testdata/autoscalertrait-0.2.0.tgz
vendored
Normal file
BIN
pkg/utils/helm/testdata/autoscalertrait-0.2.0.tgz
vendored
Normal file
Binary file not shown.
@@ -30,6 +30,7 @@ import (
|
||||
|
||||
"helm.sh/helm/v3/pkg/strvals"
|
||||
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
@@ -201,8 +202,7 @@ func AdditionalEndpointPrinter(ctx context.Context, c common.Args, k8sClient cli
|
||||
}
|
||||
if name == "velaux" {
|
||||
if !isUpgrade {
|
||||
fmt.Println(`To check the initialized admin user name and password by:`)
|
||||
fmt.Println(` vela logs -n vela-system --name apiserver addon-velaux | grep "initialized admin username"`)
|
||||
fmt.Printf("Initialized admin username and password: admin / %s \n", service.InitAdminPassword)
|
||||
}
|
||||
fmt.Println(`To open the dashboard directly by port-forward:`)
|
||||
fmt.Println(` vela port-forward -n vela-system addon-velaux 9082:80`)
|
||||
|
||||
@@ -71,7 +71,7 @@ func NewCommandWithIOStreams(ioStream util.IOStreams) *cobra.Command {
|
||||
commandArgs := common.Args{
|
||||
Schema: common.Scheme,
|
||||
}
|
||||
f := velacmd.NewDefaultFactory(config.GetConfigOrDie())
|
||||
f := velacmd.NewDeferredFactory(config.GetConfig)
|
||||
|
||||
if err := system.InitDirs(); err != nil {
|
||||
fmt.Println("InitDir err", err)
|
||||
|
||||
@@ -20,7 +20,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gosuri/uitable"
|
||||
tcv1beta1 "github.com/oam-dev/terraform-controller/api/v1beta1"
|
||||
@@ -56,19 +58,11 @@ func NewProviderCommand(c common.Args, order string, ioStreams cmdutil.IOStreams
|
||||
types.TagCommandType: types.TypeExtension,
|
||||
},
|
||||
}
|
||||
add, err := prepareProviderAddCommand(c, ioStreams)
|
||||
if err == nil {
|
||||
cmd.AddCommand(add)
|
||||
}
|
||||
|
||||
delete, err := prepareProviderDeleteCommand(c, ioStreams)
|
||||
if err == nil {
|
||||
cmd.AddCommand(delete)
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
NewProviderListCommand(c, ioStreams),
|
||||
)
|
||||
cmd.AddCommand(prepareProviderAddCommand(c, ioStreams))
|
||||
cmd.AddCommand(prepareProviderDeleteCommand(c, ioStreams))
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -93,13 +87,7 @@ func NewProviderListCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.C
|
||||
}
|
||||
}
|
||||
|
||||
func prepareProviderAddCommand(c common.Args, ioStreams cmdutil.IOStreams) (*cobra.Command, error) {
|
||||
ctx := context.Background()
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func prepareProviderAddCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Authenticate Terraform Cloud Provider",
|
||||
@@ -107,13 +95,13 @@ func prepareProviderAddCommand(c common.Args, ioStreams cmdutil.IOStreams) (*cob
|
||||
Example: "vela provider add <provider-type>",
|
||||
}
|
||||
|
||||
addSubCommands, err := prepareProviderAddSubCommand(c, ioStreams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.AddCommand(addSubCommands...)
|
||||
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1)
|
||||
defer cancel()
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defs, err := getTerraformProviderTypes(ctx, k8sClient)
|
||||
if len(args) < 1 {
|
||||
errMsg := "must specify a Terraform Cloud Provider type"
|
||||
@@ -143,11 +131,21 @@ func prepareProviderAddCommand(c common.Args, ioStreams cmdutil.IOStreams) (*cob
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return cmd, nil
|
||||
|
||||
addSubCommands, err := prepareProviderAddSubCommand(c, ioStreams)
|
||||
if err != nil {
|
||||
ioStreams.Errorf("Fail to prepare the sub commands for the add command:%s \n", err.Error())
|
||||
}
|
||||
cmd.AddCommand(addSubCommands...)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func prepareProviderAddSubCommand(c common.Args, ioStreams cmdutil.IOStreams) ([]*cobra.Command, error) {
|
||||
ctx := context.Background()
|
||||
if len(os.Args) < 2 || os.Args[1] != "provider" {
|
||||
return nil, nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1)
|
||||
defer cancel()
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -315,28 +313,28 @@ func getTerraformProviderType(ctx context.Context, k8sClient client.Client, name
|
||||
return def, nil
|
||||
}
|
||||
|
||||
func prepareProviderDeleteCommand(c common.Args, ioStreams cmdutil.IOStreams) (*cobra.Command, error) {
|
||||
ctx := context.Background()
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func prepareProviderDeleteCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{"rm", "del"},
|
||||
Short: "Delete Terraform Cloud Provider",
|
||||
Long: "Delete Terraform Cloud Provider",
|
||||
Example: "vela provider delete <provider-type> -name <provider-name>",
|
||||
Example: "vela provider delete <provider-type> --name <provider-name>",
|
||||
}
|
||||
|
||||
deleteSubCommands, err := prepareProviderDeleteSubCommand(c, ioStreams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
ioStreams.Errorf("Fail to prepare the sub commands for the delete command:%s \n", err.Error())
|
||||
}
|
||||
cmd.AddCommand(deleteSubCommands...)
|
||||
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1)
|
||||
defer cancel()
|
||||
defs, err := getTerraformProviderTypes(ctx, k8sClient)
|
||||
if len(args) < 1 {
|
||||
errMsg := "must specify a Terraform Cloud Provider type"
|
||||
@@ -366,11 +364,15 @@ func prepareProviderDeleteCommand(c common.Args, ioStreams cmdutil.IOStreams) (*
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return cmd, nil
|
||||
return cmd
|
||||
}
|
||||
|
||||
func prepareProviderDeleteSubCommand(c common.Args, ioStreams cmdutil.IOStreams) ([]*cobra.Command, error) {
|
||||
ctx := context.Background()
|
||||
if len(os.Args) < 2 || os.Args[1] != "provider" {
|
||||
return nil, nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1)
|
||||
defer cancel()
|
||||
k8sClient, err := c.GetClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -209,6 +209,21 @@ func forceDisableAddon(ctx context.Context, kubeClient client.Client, config *re
|
||||
if err := pkgaddon.DisableAddon(ctx, kubeClient, "fluxcd", config, true); err != nil {
|
||||
return err
|
||||
}
|
||||
timeConsumed = time.Now()
|
||||
for {
|
||||
if time.Now().After(timeConsumed.Add(5 * time.Minute)) {
|
||||
return errors.New("timeout disable fluxcd addon, please disable the addon manually")
|
||||
}
|
||||
addons, err := checkInstallAddon(kubeClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(addons) == 0 {
|
||||
break
|
||||
}
|
||||
fmt.Printf("Waiting delete the fluxcd addon, timeout left %s . \r\n", 5*time.Minute-time.Since(timeConsumed))
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user