/
nginx_inc_app.go
131 lines (105 loc) · 4.52 KB
/
nginx_inc_app.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package apps
import (
"fmt"
"github.com/alexellis/arkade/pkg/config"
"strconv"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/k8s"
"github.com/alexellis/arkade/pkg/types"
"github.com/alexellis/arkade/pkg"
"github.com/spf13/cobra"
)
func MakeInstallNginxIncIngress() *cobra.Command {
var command = &cobra.Command{
Use: "nginx-inc",
Short: "Install nginx-inc for OpenFaaS",
Long: `Install nginx-inc for OpenFaaS`,
Example: `arkade install nginx-inc`,
SilenceUsage: true,
}
command.Flags().StringP("namespace", "n", "default", "The namespace used for installation")
command.Flags().Bool("update-repo", true, "Update the helm repo")
command.Flags().StringArray("set", []string{},
"Use custom flags or override existing flags \n(example --set key=value)")
command.Flags().String("controller-image", "", "Controller Image for NGINX Plus: (assuming you have pushed the Ingress controller image nginx-ingress to your private registry myregistry.example.com)")
command.Flags().Bool("plus", false, "Install Nginx Plus")
command.Flags().Int("replicas", 1, "The number of replicas of the Ingress controller deployment")
command.Flags().Bool("prometheus", false, "Install Nginx Plus")
command.Flags().Int64("prometheus-port", 9113, "Configures the prometheus port to scrape the metrics.")
command.Flags().String("kind", "deployment", "The kind of the Ingress controller installation - deployment or daemonset")
command.RunE = func(command *cobra.Command, args []string) error {
wait, _ := command.Flags().GetBool("wait")
updateRepo, _ := command.Flags().GetBool("update-repo")
namespace, _ := command.Flags().GetString("namespace")
overrides := map[string]string{}
nginxPlus, err := command.Flags().GetBool("plus")
if err != nil {
return fmt.Errorf("error with --plus usage: %s", err)
}
overrides["controller.nginxplus"] = strconv.FormatBool(nginxPlus)
if command.Flags().Changed("controller-image") {
controllerImage, err := command.Flags().GetString("controller-image")
if err != nil {
return fmt.Errorf("error with --controller-image usage: %s", err)
}
overrides["controller.image.repository"] = controllerImage
}
replicaCount, err := command.Flags().GetInt("replicas")
if err != nil {
return fmt.Errorf("error with --replicas usage: %s", err)
}
overrides["controller.replicaCount"] = fmt.Sprintf("%d", replicaCount)
prometheusCreate, err := command.Flags().GetBool("prometheus")
if err != nil {
return fmt.Errorf("error with --prometheus usage: %s", err)
}
overrides["prometheus.create"] = strconv.FormatBool(prometheusCreate)
if prometheusCreate {
prometheusPort, err := command.Flags().GetInt64("prometheus-port")
if err != nil {
return fmt.Errorf("error with --prometheus-port usage: %s", err)
}
overrides["prometheus.port"] = fmt.Sprintf("%d", prometheusPort)
}
kindName, err := command.Flags().GetString("kind")
if err != nil {
return fmt.Errorf("error with --kind usage: %s", err)
}
overrides["controller.kind"] = kindName
customFlags, err := command.Flags().GetStringArray("set")
if err != nil {
return fmt.Errorf("error with --set usage: %s", err)
}
if err := config.MergeFlags(overrides, customFlags); err != nil {
return err
}
arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)
nginxIncIngressAppOptions := types.DefaultInstallOptions().
WithNamespace(namespace).
WithHelmRepo("nginx-stable/nginx-ingress").
WithHelmURL("https://helm.nginx.com/stable").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithWait(wait)
if command.Flags().Changed("kubeconfig") {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
nginxIncIngressAppOptions.WithKubeconfigPath(kubeConfigPath)
}
_, err = apps.MakeInstallChart(nginxIncIngressAppOptions)
if err != nil {
return err
}
fmt.Println(NginxIncIngressInstallMsg)
return nil
}
return command
}
const NginxIncIngressInfoMsg = `# If you're using a local environment such as "minikube" or "KinD",
# then try the inlets operator with "arkade install inlets-operator"
# Find out more on the project homepage:
# https://github.com/nginxinc/kubernetes-ingress`
const NginxIncIngressInstallMsg = `=======================================================================
= nginx-inc has been installed. =
=======================================================================` +
"\n\n" + NginxIncIngressInfoMsg + "\n\n" + pkg.SupportMessageShort