/
upgrade.go
58 lines (48 loc) · 1.49 KB
/
upgrade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* *******************************************************************************
* * Copyright (c) 2023 Datasance Teknoloji A.S.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/
package cmd
import (
"fmt"
"strings"
"github.com/datasance/potctl/internal/upgrade"
"github.com/datasance/potctl/pkg/util"
"github.com/spf13/cobra"
)
func newUpgradeCommand() *cobra.Command {
// Instantiate options
var opt upgrade.Options
cmd := &cobra.Command{
Use: "upgrade RESOURCE NAME",
Short: "Upgrade ioFog resources",
Long: `Upgrade ioFog resources to latest versions available.`,
Example: `potctl upgrade agent NAME`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
// Get resource type and name
opt.ResourceType = args[0]
opt.Name = args[1]
var err error
// Get namespace option
opt.Namespace, err = cmd.Flags().GetString("namespace")
util.Check(err)
// Get executor for upgrade command
exe, err := upgrade.NewExecutor(opt)
util.Check(err)
// Execute the command
err = exe.Execute()
util.Check(err)
util.PrintSuccess(fmt.Sprintf("Succesfully scheduled upgrade for %s %s", strings.Title(opt.ResourceType), opt.Name))
},
}
return cmd
}