Skip to content

Commit c71633e

Browse files
authored
Merge pull request #19 from tpiperatgod/main
fix: cli can install latest OpenFunction & add logo & adjust uninstallation process
2 parents 5675bac + da1694b commit c71633e

File tree

8 files changed

+96
-99
lines changed

8 files changed

+96
-99
lines changed

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latest

pkg/cmd/subcommand/demo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import (
44
"bufio"
55
"context"
66
"fmt"
7-
"github.com/OpenFunction/cli/pkg/client"
8-
"github.com/OpenFunction/cli/pkg/components/inventory"
97
"os"
108
"runtime"
119
"strings"
1210
"time"
1311

12+
"github.com/OpenFunction/cli/pkg/client"
1413
"github.com/OpenFunction/cli/pkg/cmd/util"
1514
"github.com/OpenFunction/cli/pkg/components/common"
15+
"github.com/OpenFunction/cli/pkg/components/inventory"
1616
"github.com/pkg/errors"
1717
"github.com/spf13/cobra"
1818
"golang.org/x/sync/errgroup"

pkg/cmd/subcommand/install.go

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727
)
2828

2929
var (
30-
w io.Writer
31-
availableVersions []string
30+
w io.Writer
3231
)
3332

3433
// Install is the commandline for 'init' sub command
@@ -55,7 +54,6 @@ type Install struct {
5554

5655
func init() {
5756
w = os.Stdout
58-
availableVersions = []string{"v0.3.1", "v0.4.0", "latest"}
5957
}
6058

6159
// NewInstall returns an initialized Init instance
@@ -86,7 +84,7 @@ ofn install --async
8684
ofn install --region-cn --all
8785
8886
# Install a specific version of OpenFunction (default is v0.4.0)
89-
ofn install --all --version v0.3.1
87+
ofn install --all --version v0.4.0
9088
9189
# See more at: https://github.com/OpenFunction/cli/blob/main/docs/install.md
9290
`,
@@ -116,7 +114,7 @@ ofn install --all --version v0.3.1
116114
cmd.Flags().BoolVar(&i.RegionCN, "region-cn", false, "For users who have limited access to gcr.io or github.com.")
117115
cmd.Flags().BoolVar(&i.DryRun, "dry-run", false, "Used to prompt for the components and their versions to be installed by the current command.")
118116
cmd.Flags().BoolVar(&i.WithUpgrade, "upgrade", false, "Upgrade components to target version while installing.")
119-
cmd.Flags().StringVar(&i.OpenFunctionVersion, "version", "v0.4.0", "Used to specify the version of OpenFunction to be installed. The permitted versions are: v0.3.1, v0.4.0, latest.")
117+
cmd.Flags().StringVar(&i.OpenFunctionVersion, "version", "v0.4.0", "Used to specify the version of OpenFunction to be installed.")
120118
cmd.Flags().DurationVar(&i.Timeout, "timeout", 5*time.Minute, "Set timeout time. Default is 5 minutes.")
121119
// In order to avoid too many options causing misunderstandings among users,
122120
// we have hidden the following parameters,
@@ -132,6 +130,10 @@ ofn install --all --version v0.3.1
132130
func (i *Install) ValidateArgs(cmd *cobra.Command, args []string) error {
133131
ti := util.NewTaskInformer("")
134132

133+
if i.OpenFunctionVersion == common.LatestVersion {
134+
return nil
135+
}
136+
135137
v, err := version.ParseGeneric(i.OpenFunctionVersion)
136138
if err != nil {
137139
return errors.New(ti.TaskFail(fmt.Sprintf(
@@ -245,15 +247,15 @@ func (i *Install) RunInstall(cl *k8s.Clientset, cmd *cobra.Command) error {
245247
done()
246248
}()
247249

248-
grp1, g1ctx := errgroup.WithContext(ctx)
250+
grp, gctx := errgroup.WithContext(ctx)
249251

250252
start := time.Now()
251253

252254
if i.WithDapr {
253255
// If Dapr already exists and --upgrade is not specified, skip this step.
254256
if !inventoryExist[inventory.DaprName] || i.WithUpgrade {
255-
grp1.Go(func() error {
256-
return i.installDapr(g1ctx, operator)
257+
grp.Go(func() error {
258+
return i.installDapr(gctx, operator)
257259
})
258260
} else {
259261
fmt.Fprintln(w, ti.SkipTask(inventory.DaprName))
@@ -263,8 +265,8 @@ func (i *Install) RunInstall(cl *k8s.Clientset, cmd *cobra.Command) error {
263265
if i.WithKeda {
264266
// If Keda already exists and --upgrade is not specified, skip this step.
265267
if !inventoryExist[inventory.KedaName] || i.WithUpgrade {
266-
grp1.Go(func() error {
267-
return i.installKeda(g1ctx, cl, operator)
268+
grp.Go(func() error {
269+
return i.installKeda(gctx, cl, operator)
268270
})
269271
} else {
270272
fmt.Fprintln(w, ti.SkipTask("Keda"))
@@ -274,25 +276,25 @@ func (i *Install) RunInstall(cl *k8s.Clientset, cmd *cobra.Command) error {
274276
if i.WithKnative {
275277
// If Knative Serving already exists and --upgrade is not specified, skip this step.
276278
if !inventoryExist[inventory.KnativeServingName] || i.WithUpgrade {
277-
grp1.Go(func() error {
278-
return i.installKnativeServing(g1ctx, cl, operator)
279+
grp.Go(func() error {
280+
return i.installKnativeServing(gctx, cl, operator)
279281
})
280282
} else {
281283
fmt.Fprintln(w, ti.SkipTask(inventory.KnativeServingName))
282284
}
283285
}
284286

285287
if i.WithShipWright {
286-
grp1.Go(func() error {
287-
return i.installShipwright(g1ctx, cl, operator)
288+
grp.Go(func() error {
289+
return i.installShipwright(gctx, cl, operator)
288290
})
289291
}
290292

291293
if i.WithCertManager {
292294
// If Cert Manager already exists and --upgrade is not specified, skip this step.
293295
if !inventoryExist[inventory.CertManagerName] || i.WithUpgrade {
294-
grp1.Go(func() error {
295-
return i.installCertManager(g1ctx, cl, operator)
296+
grp.Go(func() error {
297+
return i.installCertManager(gctx, cl, operator)
296298
})
297299
} else {
298300
fmt.Fprintln(w, ti.SkipTask(inventory.CertManagerName))
@@ -302,25 +304,19 @@ func (i *Install) RunInstall(cl *k8s.Clientset, cmd *cobra.Command) error {
302304
if i.WithIngress {
303305
// If Ingress Nginx already exists and --upgrade is not specified, skip this step.
304306
if !inventoryExist[inventory.IngressName] || i.WithUpgrade {
305-
grp1.Go(func() error {
306-
return i.installIngress(g1ctx, cl, operator)
307+
grp.Go(func() error {
308+
return i.installIngress(gctx, cl, operator)
307309
})
308310
} else {
309311
fmt.Fprintln(w, ti.SkipTask(inventory.IngressName))
310312
}
311313
}
312314

313-
if err := grp1.Wait(); err != nil {
315+
if err := grp.Wait(); err != nil {
314316
return errors.New(ti.TaskFail(err.Error()))
315317
}
316318

317-
grp2, g2ctx := errgroup.WithContext(ctx)
318-
319-
grp2.Go(func() error {
320-
return i.installOpenFunction(g2ctx, cl, operator)
321-
})
322-
323-
if err := grp2.Wait(); err != nil {
319+
if err := i.installOpenFunction(ctx, cl, operator); err != nil {
324320
return errors.New(ti.TaskFail(err.Error()))
325321
}
326322

@@ -330,6 +326,8 @@ func (i *Install) RunInstall(cl *k8s.Clientset, cmd *cobra.Command) error {
330326
if i.WithKnative {
331327
ti.TipsOnUsingKnative()
332328
}
329+
330+
ti.PrintOpenFunction()
333331
return nil
334332
}
335333

@@ -354,14 +352,18 @@ func (i *Install) mergeConditions() {
354352
//if i.WithSyncRuntime {
355353
//}
356354

357-
if i.openFunctionVersion.Major() == 0 && i.openFunctionVersion.Minor() == 3 {
358-
i.WithIngress = false
359-
i.WithCertManager = false
360-
}
361-
362-
if i.openFunctionVersion.Major() == 0 && i.openFunctionVersion.Minor() == 4 {
363-
i.WithIngress = false
355+
if i.OpenFunctionVersion == common.LatestVersion {
364356
i.WithCertManager = true
357+
} else {
358+
if i.openFunctionVersion.Major() == 0 && i.openFunctionVersion.Minor() == 3 {
359+
i.WithIngress = false
360+
i.WithCertManager = false
361+
}
362+
363+
if i.openFunctionVersion.Major() == 0 && i.openFunctionVersion.Minor() == 4 {
364+
i.WithIngress = false
365+
i.WithCertManager = true
366+
}
365367
}
366368
}
367369

pkg/cmd/subcommand/uninstall.go

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"k8s.io/apimachinery/pkg/util/version"
15-
1614
"github.com/OpenFunction/cli/pkg/client"
1715
"github.com/OpenFunction/cli/pkg/cmd/util"
1816
"github.com/OpenFunction/cli/pkg/components/common"
1917
"github.com/OpenFunction/cli/pkg/components/inventory"
2018
"github.com/pkg/errors"
2119
"github.com/spf13/cobra"
2220
"golang.org/x/sync/errgroup"
21+
"k8s.io/apimachinery/pkg/util/version"
2322
"k8s.io/cli-runtime/pkg/genericclioptions"
2423
k8s "k8s.io/client-go/kubernetes"
2524
)
@@ -122,6 +121,10 @@ ofn uninstall --all --version v0.4.0
122121
func (i *Uninstall) ValidateArgs(cmd *cobra.Command, args []string) error {
123122
ti := util.NewTaskInformer("")
124123

124+
if i.OpenFunctionVersion == common.LatestVersion {
125+
return nil
126+
}
127+
125128
v, err := version.ParseGeneric(i.OpenFunctionVersion)
126129
if err != nil {
127130
return errors.New(ti.TaskFail(fmt.Sprintf(
@@ -244,18 +247,6 @@ func (i *Uninstall) RunUninstall(cl *k8s.Clientset, cmd *cobra.Command) error {
244247
}
245248

246249
if i.WithKnative {
247-
if operator.Records.DefaultDomain != "" {
248-
grp.Go(func() error {
249-
return i.uninstallServingDefaultDomain(gctx, cl, operator)
250-
})
251-
}
252-
253-
if operator.Records.Kourier != "" {
254-
grp.Go(func() error {
255-
return i.uninstallKourier(gctx, cl, operator)
256-
})
257-
}
258-
259250
if operator.Records.KnativeServing != "" {
260251
grp.Go(func() error {
261252
return i.uninstallKnativeServing(gctx, cl, operator)
@@ -377,67 +368,51 @@ func (i *Uninstall) uninstallKnativeServing(ctx context.Context, cl *k8s.Clients
377368

378369
ti := util.NewTaskInformer("KNATIVE")
379370

380-
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Knative Serving..."))
381-
382-
yamls, err := operator.Inventory[inventory.KnativeServingName].GetYamlFile(operator.Records.KnativeServing)
383-
if err != nil {
384-
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to get yaml file"))
385-
}
386-
387-
if err := operator.UninstallKnativeServing(ctx, cl, yamls["CRD"], yamls["CORE"], i.WaitForCleared); err != nil {
388-
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Knative Serving"))
389-
}
390-
391-
// Reset version to null
392-
operator.Records.KnativeServing = ""
393-
394-
fmt.Fprintln(w, ti.TaskSuccess())
395-
return nil
396-
}
397-
398-
func (i *Uninstall) uninstallServingDefaultDomain(ctx context.Context, cl *k8s.Clientset, operator *common.Operator) error {
399-
ctx, done := context.WithCancel(ctx)
400-
defer done()
401-
402-
ti := util.NewTaskInformer("KNATIVE")
371+
if operator.Records.DefaultDomain != "" {
372+
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Serving Default Domain..."))
403373

404-
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Serving Default Domain..."))
374+
yamls, err := operator.Inventory[inventory.ServingDefaultDomainName].GetYamlFile(operator.Records.DefaultDomain)
375+
if err != nil {
376+
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to get yaml file"))
377+
}
405378

406-
yamls, err := operator.Inventory[inventory.ServingDefaultDomainName].GetYamlFile(operator.Records.DefaultDomain)
407-
if err != nil {
408-
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to get yaml file"))
409-
}
379+
if err := operator.Uninstall(ctx, cl, yamls["MAIN"], common.KnativeServingNamespace, false, i.WaitForCleared); err != nil {
380+
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Serving Default Domain"))
381+
}
410382

411-
if err := operator.Uninstall(ctx, cl, yamls["MAIN"], common.KnativeServingNamespace, false, i.WaitForCleared); err != nil {
412-
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Serving Default Domain"))
383+
// Reset version to null
384+
operator.Records.DefaultDomain = ""
413385
}
414386

415-
// Reset version to null
416-
operator.Records.DefaultDomain = ""
387+
if operator.Records.Kourier != "" {
388+
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Kourier..."))
417389

418-
fmt.Fprintln(w, ti.TaskSuccess())
419-
return nil
420-
}
390+
yamls, err := operator.Inventory[inventory.KourierName].GetYamlFile(operator.Records.Kourier)
391+
if err != nil {
392+
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to get yaml file"))
393+
}
421394

422-
func (i *Uninstall) uninstallKourier(ctx context.Context, cl *k8s.Clientset, operator *common.Operator) error {
423-
ctx, done := context.WithCancel(ctx)
424-
defer done()
395+
if err := operator.Uninstall(ctx, cl, yamls["MAIN"], common.KedaNamespace, false, i.WaitForCleared); err != nil {
396+
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Kourier"))
397+
}
425398

426-
ti := util.NewTaskInformer("KOURIER")
399+
// Reset version to null
400+
operator.Records.Kourier = ""
401+
}
427402

428-
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Kourier..."))
403+
fmt.Fprintln(w, ti.TaskInfo("Uninstalling Knative Serving..."))
429404

430-
yamls, err := operator.Inventory[inventory.KourierName].GetYamlFile(operator.Records.Kourier)
405+
yamls, err := operator.Inventory[inventory.KnativeServingName].GetYamlFile(operator.Records.KnativeServing)
431406
if err != nil {
432407
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to get yaml file"))
433408
}
434409

435-
if err := operator.Uninstall(ctx, cl, yamls["MAIN"], common.KedaNamespace, false, i.WaitForCleared); err != nil {
436-
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Kourier"))
410+
if err := operator.UninstallKnativeServing(ctx, cl, yamls["CRD"], yamls["CORE"], i.WaitForCleared); err != nil {
411+
return errors.Wrap(err, ti.TaskFailWithTitle("Failed to uninstall Knative Serving"))
437412
}
438413

439414
// Reset version to null
440-
operator.Records.Kourier = ""
415+
operator.Records.KnativeServing = ""
441416

442417
fmt.Fprintln(w, ti.TaskSuccess())
443418
return nil

pkg/cmd/util/print.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,21 @@ func (ti *TaskInformer) TipsOnOpenfunctionDemo(Endpoint string) {
219219
fmt.Println()
220220
fmt.Println(YellowItalic("We now use the curl command to access the address. The following information was returned:"))
221221
}
222+
223+
func (ti *TaskInformer) PrintOpenFunction() {
224+
fmt.Println(WhiteBold(`
225+
██████╗ ██████╗ ███████╗███╗ ██╗
226+
██╔═══██╗██╔══██╗██╔════╝████╗ ██║
227+
██║ ██║██████╔╝█████╗ ██╔██╗ ██║
228+
██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║
229+
╚██████╔╝██║ ███████╗██║ ╚████║
230+
╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝
231+
232+
███████╗██╗ ██╗███╗ ██╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
233+
██╔════╝██║ ██║████╗ ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
234+
█████╗ ██║ ██║██╔██╗ ██║██║ ██║ ██║██║ ██║██╔██╗ ██║
235+
██╔══╝ ██║ ██║██║╚██╗██║██║ ██║ ██║██║ ██║██║╚██╗██║
236+
██║ ╚██████╔╝██║ ╚████║╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
237+
╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
238+
`))
239+
}

pkg/components/common/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const (
3434
IngressNginxNamespace = "ingress-nginx"
3535
OpenFunctionNamespace = "openfunction"
3636

37-
BaseVersion = "v0.3.1"
37+
BaseVersion = "v0.3.1"
38+
LatestVersion = "latest"
3839
)
3940

4041
type Operator struct {
@@ -289,11 +290,11 @@ func (o *Operator) UninstallKnativeServing(
289290
waitForCleared bool,
290291
) error {
291292
var cmd string
292-
cmd = fmt.Sprintf("delete -f %s", crdYamlFile)
293+
cmd = fmt.Sprintf("delete -f %s", coreYamlFile)
293294
if err := o.executor.KubectlExec(ctx, cmd, true); util.IgnoreNotFoundErr(err) != nil {
294295
return err
295296
}
296-
cmd = fmt.Sprintf("delete -f %s", coreYamlFile)
297+
cmd = fmt.Sprintf("delete -f %s", crdYamlFile)
297298
if err := o.executor.KubectlExec(ctx, cmd, false); util.IgnoreNotFoundErr(err) != nil {
298299
return err
299300
}

pkg/components/inventory/cert-manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
const (
1111
CertManagerName = "CertManager"
12-
CertManagerRecordName = "CertManager"
12+
CertManagerRecordName = "certManager"
1313
CertManagerVersionEnv = "CERT_MANAGER_VERSION"
1414
CertManagerYamlEnv = "CERT_MANAGER_YAML"
1515
CertManagerDefaultYamlFileTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s%s/cert-manager.yaml"

0 commit comments

Comments
 (0)