Compare commits

...

6 Commits

Author SHA1 Message Date
github-actions[bot]
ea0508a634 [Backport release-1.4] Fix: hold the force uninstalling process untill the last addon been deleted (#4103)
* hold the force uninstalling process untill the last addon been deleted

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix lint

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 1d4266432c)

* fix comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix lint

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit cecd8c28d0)

* add period

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 62e4dac538)

Co-authored-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
2022-06-02 16:29:02 +08:00
github-actions[bot]
23e29aa62a Fix: vela provider delete command's example is wrong (#4099)
Signed-off-by: StevenLeiZhang <zhangleiic@163.com>
(cherry picked from commit 9b66f90100)

Co-authored-by: StevenLeiZhang <zhangleiic@163.com>
2022-06-02 11:04:34 +08:00
github-actions[bot]
ed2cb80219 Fix: the new default values do not take effect when upgrading the vela core (#4097)
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 0ccbbb2636)

Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
2022-06-02 10:23:30 +08:00
github-actions[bot]
1a3d5debd5 Fix: show the default password (#4095)
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit c3cfc4729e)

Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
2022-06-02 10:14:43 +08:00
github-actions[bot]
d4a82fe292 Fix: load the provider subcommands on demand (#4090)
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 52bbf937bb)

Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
2022-06-01 16:32:53 +08:00
github-actions[bot]
963ae400fa Feat: use deferred config in CLI (#4085)
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
(cherry picked from commit 478434003b)

Co-authored-by: Somefive <yd219913@alibaba-inc.com>
2022-06-01 10:24:57 +08:00
10 changed files with 141 additions and 50 deletions

View File

@@ -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
}

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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() {

Binary file not shown.

Binary file not shown.

View File

@@ -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`)

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}