diff --git a/go.mod b/go.mod index 7cb3ef8c9..675f7e3d5 100644 --- a/go.mod +++ b/go.mod @@ -90,7 +90,7 @@ require ( github.com/google/uuid v1.1.2 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/loft-sh/vcluster v0.10.2 + github.com/loft-sh/vcluster v0.11.0-alpha.0 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/go.sum b/go.sum index 2b38b868c..3d603c2ee 100644 --- a/go.sum +++ b/go.sum @@ -387,6 +387,8 @@ github.com/loft-sh/vcluster v0.10.1 h1:+WVq0FmPQosrBjbzgeUpsdH5xiQvE7/jDKWz+O5+9 github.com/loft-sh/vcluster v0.10.1/go.mod h1:L/3nvFQnztTksBy6irGGdaaFoh/XmfkCcRk/1TKLht8= github.com/loft-sh/vcluster v0.10.2 h1:YKa3fyCdoUijlfxSy+/J0g+ws5lSRhnVbFDtQU5mop8= github.com/loft-sh/vcluster v0.10.2/go.mod h1:YErYq6bA2e1BKrqobiZhqDPFR3u+Xet7R6G9SRqey0c= +github.com/loft-sh/vcluster v0.11.0-alpha.0 h1:+sJFAUPUwBeiibjk7Q0LXjeQM/cPqTrDT9L6KuRJvNE= +github.com/loft-sh/vcluster v0.11.0-alpha.0/go.mod h1:WjgBXz8MiTqptx5EHkJr691/FslxZsI3oEjoXW9Fwj4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/vendor/github.com/loft-sh/vcluster/pkg/helm/helm.go b/vendor/github.com/loft-sh/vcluster/pkg/helm/helm.go index 5b811fe8b..66d0c5a13 100644 --- a/vendor/github.com/loft-sh/vcluster/pkg/helm/helm.go +++ b/vendor/github.com/loft-sh/vcluster/pkg/helm/helm.go @@ -1,6 +1,7 @@ package helm import ( + "context" "fmt" "io/ioutil" "os" @@ -28,8 +29,11 @@ type UpgradeOptions struct { SetValues map[string]string SetStringValues map[string]string + CreateNamespace bool + Username string Password string + WorkDir string Atomic bool Force bool @@ -37,10 +41,13 @@ type UpgradeOptions struct { // Client defines the interface how to interact with helm type Client interface { - Install(name, namespace string, options UpgradeOptions) error - Upgrade(name, namespace string, options UpgradeOptions) error + Install(ctx context.Context, name, namespace string, options UpgradeOptions) error + Upgrade(ctx context.Context, name, namespace string, options UpgradeOptions) error + Pull(ctx context.Context, name string, options UpgradeOptions) error Delete(name, namespace string) error Exists(name, namespace string) (bool, error) + Rollback(ctx context.Context, name, namespace string) error + Status(ctx context.Context, name, namespace string) ([]byte, error) } type client struct { @@ -58,15 +65,23 @@ func NewClient(config *clientcmdapi.Config, log log.Logger) Client { } } -func (c *client) Install(name, namespace string, options UpgradeOptions) error { - return c.run(name, namespace, options, "install", []string{"--repository-config=''"}) +func (c *client) Install(ctx context.Context, name, namespace string, options UpgradeOptions) error { + return c.run(ctx, name, namespace, options, "install", []string{"--repository-config=''"}) +} + +func (c *client) Upgrade(ctx context.Context, name, namespace string, options UpgradeOptions) error { + return c.run(ctx, name, namespace, options, "upgrade", []string{"--install", "--repository-config=''"}) } -func (c *client) Upgrade(name, namespace string, options UpgradeOptions) error { - return c.run(name, namespace, options, "upgrade", []string{"--install", "--repository-config=''"}) +func (c *client) Pull(ctx context.Context, name string, options UpgradeOptions) error { + return c.run(ctx, name, "", options, "pull", []string{}) } -func (c *client) run(name, namespace string, options UpgradeOptions, command string, extraArgs []string) error { +func (c *client) Rollback(ctx context.Context, name, namespace string) error { + return c.run(ctx, name, namespace, UpgradeOptions{}, "rollback", []string{}) +} + +func (c *client) run(ctx context.Context, name, namespace string, options UpgradeOptions, command string, extraArgs []string) error { kubeConfig, err := WriteKubeConfig(c.config) if err != nil { return err @@ -94,6 +109,10 @@ func (c *client) run(name, namespace string, options UpgradeOptions, command str } } + if options.CreateNamespace { + args = append(args, "--create-namespace") + } + args = append(args, "--kubeconfig", kubeConfig, "--namespace", namespace) args = append(args, extraArgs...) @@ -168,8 +187,19 @@ func (c *client) run(name, namespace string, options UpgradeOptions, command str args = append(args, "--atomic") } - c.log.Debug("execute command: helm " + strings.Join(args, " ")) - output, err := exec.Command(c.helmPath, args...).CombinedOutput() + cmd := exec.CommandContext(ctx, c.helmPath, args...) + + if options.WorkDir != "" { + cmd.Dir = options.WorkDir + } + + c.log.Info("execute command: helm " + strings.Join(args, " ")) + output, err := cmd.CombinedOutput() + + if ctx.Err() == context.DeadlineExceeded { + return fmt.Errorf("error executing helm %s: operation timedout", command) + } + if err != nil { return fmt.Errorf("error executing helm %s: %s", strings.Join(args, " "), string(output)) } @@ -219,6 +249,17 @@ func (c *client) Exists(name, namespace string) (bool, error) { return true, nil } +func (c *client) Status(ctx context.Context, name, namespace string) ([]byte, error) { + kubeConfig, err := WriteKubeConfig(c.config) + if err != nil { + return nil, err + } + defer os.Remove(kubeConfig) + + args := []string{"status", name, "--namespace", namespace, "--kubeconfig", kubeConfig} + return exec.CommandContext(ctx, c.helmPath, args...).CombinedOutput() +} + // WriteKubeConfig writes the kubeconfig to a file and returns the filename func WriteKubeConfig(configRaw *clientcmdapi.Config) (string, error) { data, err := clientcmd.Write(*configRaw) diff --git a/vendor/github.com/loft-sh/vcluster/pkg/helm/values/k3s.go b/vendor/github.com/loft-sh/vcluster/pkg/helm/values/k3s.go index 7a4dc8499..877668416 100644 --- a/vendor/github.com/loft-sh/vcluster/pkg/helm/values/k3s.go +++ b/vendor/github.com/loft-sh/vcluster/pkg/helm/values/k3s.go @@ -92,8 +92,11 @@ securityContext: } func addCommonReleaseValues(values string, chartOptions *helm.ChartOptions) (string, error) { - values += ` + if chartOptions.CIDR != "" { + values += ` serviceCIDR: ##CIDR##` + values = strings.ReplaceAll(values, "##CIDR##", chartOptions.CIDR) + } if chartOptions.DisableIngressSync { values += ` @@ -131,7 +134,6 @@ isolation: enabled: true` } - values = strings.ReplaceAll(values, "##CIDR##", chartOptions.CIDR) values = strings.TrimSpace(values) return values, nil } diff --git a/vendor/github.com/loft-sh/vcluster/pkg/util/translate/translate.go b/vendor/github.com/loft-sh/vcluster/pkg/util/translate/translate.go index 0a089e4eb..7bb1f76bc 100644 --- a/vendor/github.com/loft-sh/vcluster/pkg/util/translate/translate.go +++ b/vendor/github.com/loft-sh/vcluster/pkg/util/translate/translate.go @@ -29,7 +29,7 @@ func SafeConcatGenerateName(name ...string) string { fullPath := strings.Join(name, "-") if len(fullPath) > 53 { digest := sha256.Sum256([]byte(fullPath)) - return strings.Replace(fullPath[0:42]+"-"+hex.EncodeToString(digest[0:])[0:10], ".-", "-", -1) + return strings.ReplaceAll(fullPath[0:42]+"-"+hex.EncodeToString(digest[0:])[0:10], ".-", "-") } return fullPath } @@ -38,7 +38,7 @@ func SafeConcatName(name ...string) string { fullPath := strings.Join(name, "-") if len(fullPath) > 63 { digest := sha256.Sum256([]byte(fullPath)) - return strings.Replace(fullPath[0:52]+"-"+hex.EncodeToString(digest[0:])[0:10], ".-", "-", -1) + return strings.ReplaceAll(fullPath[0:52]+"-"+hex.EncodeToString(digest[0:])[0:10], ".-", "-") } return fullPath } diff --git a/vendor/modules.txt b/vendor/modules.txt index 14144dcc4..d7460fdc0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -167,7 +167,7 @@ github.com/kballard/go-shellquote # github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de ## explicit github.com/liggitt/tabwriter -# github.com/loft-sh/vcluster v0.10.2 +# github.com/loft-sh/vcluster v0.11.0-alpha.0 ## explicit; go 1.18 github.com/loft-sh/vcluster/cmd/vclusterctl/log github.com/loft-sh/vcluster/cmd/vclusterctl/log/survey