This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addons.go
91 lines (79 loc) · 2.88 KB
/
addons.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package addons
import (
"io/ioutil"
"os"
addonassets "github.com/awesomenix/azk/addonassets"
cmdhelpers "github.com/awesomenix/azk/cmd/azk/cmd/helpers"
"github.com/spf13/cobra"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
var (
log = logf.Log.WithName("azk")
// SupportedAddons list of supported addons
SupportedAddons = []string{"prometheus"}
)
var CreateAddonsCmd = &cobra.Command{
Use: "addons",
Short: "Create Addons",
Long: `Create Addons with one command`,
}
var DeleteAddonsCmd = &cobra.Command{
Use: "addons",
Short: "Create Addons",
Long: `Create Addons with one command`,
}
var UpgradeAddonsCmd = &cobra.Command{
Use: "addons",
Short: "Upgrade Addons",
Long: `Upgrade Addons with one command`,
}
func init() {
// Create
// CreateAddonsCmd.Flags().StringVarP(&cnpo.SubscriptionID, "subscriptionid", "s", "", "SubscriptionID Required.")
// CreateAddonsCmd.MarkFlagRequired("subscriptionid")
// CreateAddonsCmd.Flags().StringVarP(&cnpo.ResourceGroup, "resourcegroup", "r", "", "Resource Group Name, in which all resources are created Required.")
// CreateAddonsCmd.MarkFlagRequired("resourcegroup")
// Delete
// DeleteAddonsCmd.Flags().StringVarP(&dnpo.SubscriptionID, "subscriptionid", "s", "", "SubscriptionID Required.")
// DeleteAddonsCmd.MarkFlagRequired("subscriptionid")
// DeleteAddonsCmd.Flags().StringVarP(&dnpo.ResourceGroup, "resourcegroup", "r", "", "Resource Group Name, in which all resources are created Required.")
// DeleteAddonsCmd.MarkFlagRequired("resourcegroup")
// Upgrade
// updateAddonsCmd.Flags().StringVarP(&dnpo.SubscriptionID, "subscriptionid", "s", "", "SubscriptionID Required.")
// updateAddonsCmd.MarkFlagRequired("subscriptionid")
// updateAddonsCmd.Flags().StringVarP(&dnpo.ResourceGroup, "resourcegroup", "r", "", "Resource Group Name, in which all resources are created Required.")
// updateAddonsCmd.MarkFlagRequired("resourcegroup")
for _, addon := range SupportedAddons {
CreateAddonsCmd.AddCommand(
&cobra.Command{
Use: addon,
Short: "Create " + addon + " Addon",
Long: `Create ` + addon + ` Addon with one command`,
Run: func(cmd *cobra.Command, args []string) {
if err := RunCreateorUpdateAddon(addon); err != nil {
log.Error(err, "Failed to create addon")
os.Exit(1)
}
},
})
UpgradeAddonsCmd.AddCommand(
&cobra.Command{
Use: addon,
Short: "Upgrade " + addon + " Addon",
Long: `Upgrade ` + addon + ` Addon with one command`,
Run: func(cmd *cobra.Command, args []string) {
if err := RunCreateorUpdateAddon(addon); err != nil {
log.Error(err, "Failed to create addon")
os.Exit(1)
}
},
})
}
}
func RunCreateorUpdateAddon(addon string) error {
kubeconfigBytes, err := ioutil.ReadFile(os.Getenv("KUBECONFIG"))
if err != nil {
return err
}
return cmdhelpers.KubectlApplyFolder(addon, string(kubeconfigBytes), addonassets.Addons)
}