-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
sync_minikube.go
69 lines (57 loc) · 1.56 KB
/
sync_minikube.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
package actions
import (
"github.com/spf13/cobra"
"github.com/guumaster/hostctl/pkg/file"
"github.com/guumaster/hostctl/pkg/k8s/minikube"
"github.com/guumaster/hostctl/pkg/profile"
"github.com/guumaster/hostctl/pkg/types"
)
func newSyncMinikubeCmd(removeCmd *cobra.Command) *cobra.Command {
return &cobra.Command{
Use: "minikube [profile] [flags]",
Short: "Sync a minikube profile with a hostctl profile.",
Long: `
Reads from Minikube the list of ingresses and add names and IPs to a profile in your hosts file.
`,
Args: commonCheckArgs,
PreRunE: func(cmd *cobra.Command, _ []string) error {
ns, _ := cmd.Flags().GetString("namespace")
allNs, _ := cmd.Flags().GetBool("all-namespaces")
if ns == "" && !allNs {
return types.ErrKubernetesNamespace
}
return nil
},
RunE: func(cmd *cobra.Command, profiles []string) error {
src, _ := cmd.Flags().GetString("host-file")
ns, _ := cmd.Flags().GetString("namespace")
allNs, _ := cmd.Flags().GetBool("all-namespace")
if allNs {
ns = ""
}
profileName := profiles[0]
mini, err := minikube.GetProfile(profileName)
if err != nil {
return err
}
p, err := profile.NewProfileFromMinikube(mini, ns)
if err != nil {
return err
}
h, err := file.NewFile(src)
if err != nil {
return err
}
p.Name = mini.Name
p.Status = types.Enabled
err = h.ReplaceProfile(p)
if err != nil {
return err
}
return h.Flush()
},
PostRunE: func(cmd *cobra.Command, args []string) error {
return postActionCmd(cmd, args, removeCmd, true)
},
}
}