This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
forked from istio/istio
/
cmd.go
179 lines (154 loc) · 5.45 KB
/
cmd.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright 2017 Istio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gendeployment
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/spf13/cobra"
)
const (
defaultTag = "0.8.latest"
defaultHyperkubeTag = "v1.7.6_coreos.0"
)
// Command returns the "gen-deploy" subcommand for istioctl.
func Command(istioNamespaceFlag *string) *cobra.Command {
var (
helmChartLocation string
valuesPath string
)
install := defaultInstall()
cmd := &cobra.Command{
Use: "gen-deploy",
Short: "Generates the configuration for Istio's control plane.",
Long: "istioctl gen-deploy produces deployment files to run the Istio.",
Example: `istioctl gen-deploy --values myvalues.yaml`,
RunE: func(c *cobra.Command, args []string) error {
install.Namespace = *istioNamespaceFlag
// TODO: this is NOT merged with the values.yaml from helm directory.
values, err := getValues(valuesPath, install)
if err != nil {
return err
}
rendered, err := yamlFromInstallation(values, *istioNamespaceFlag, helmChartLocation)
if err != nil {
return err
}
_, err = fmt.Fprint(os.Stdout, rendered)
return err
},
}
cmd.PersistentFlags().StringVar(&valuesPath, "values", "", "Path to the Helm values.yaml file used to render YAML "+
"deployments locally when --out=yaml. Flag values are ignored in favor of using the file directly.")
cmd.PersistentFlags().StringVar(&install.Hub, "hub", install.Hub, "The container registry to pull Istio images from")
cmd.PersistentFlags().StringVar(&install.MixerTag, "mixer-tag", install.MixerTag, "The tag to use to pull the `mixer` container")
cmd.PersistentFlags().StringVar(&install.PilotTag, "pilot-tag", install.PilotTag, "The tag to use to pull the `pilot-discovery` container")
cmd.PersistentFlags().StringVar(&install.CaTag, "ca-tag", install.CaTag, "The tag to use to pull the `ca` container")
cmd.PersistentFlags().StringVar(&install.ProxyTag, "proxy-tag", install.ProxyTag, "The tag to use to pull the `proxy` container")
cmd.PersistentFlags().BoolVar(&install.Debug, "debug", install.Debug, "If true, uses debug images instead of release images")
cmd.PersistentFlags().Uint16Var(&install.NodePort, "ingress-node-port", install.NodePort,
"If provided, Istio ingress proxies will run as a NodePort service mapped to the port provided by this flag. "+
"Note that this flag is ignored unless the \"ingress\" feature flag is provided too.")
// TODO: figure out how we want to package up the charts with the binary to make this easy
cmd.PersistentFlags().StringVar(&helmChartLocation, "helm-chart-dir", ".",
"The directory to find the helm charts used to render Istio deployments. -o yaml uses these to render the helm chart locally.")
cmd.PersistentFlags().StringVar(&install.HyperkubeHub, "hyperkube-hub", install.HyperkubeHub, "The container registry to pull Hyperkube images from")
cmd.PersistentFlags().StringVar(&install.HyperkubeTag, "hyperkube-tag", install.HyperkubeTag, "The tag to use to pull the `Hyperkube` container")
_ = cmd.PersistentFlags().MarkHidden("hub")
_ = cmd.PersistentFlags().MarkHidden("mixer-tag")
_ = cmd.PersistentFlags().MarkHidden("pilot-tag")
_ = cmd.PersistentFlags().MarkHidden("ca-tag")
_ = cmd.PersistentFlags().MarkHidden("proxy-tag")
return cmd
}
func getValues(path string, i *installation) (string, error) {
if path == "" {
return "", nil
}
out, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
return string(out), nil
}
type installation struct {
Namespace string
// todo: support hub per component
Hub string // hub to pull images from
MixerTag string
PilotTag string
CaTag string
ProxyTag string
HyperkubeHub string
HyperkubeTag string
NodePort uint16
Debug bool
Mixer bool
Pilot bool
CA bool
Ingress bool
SidecarInjector bool
}
func defaultInstall() *installation {
return &installation{
Mixer: true,
Pilot: true,
CA: true,
Ingress: true,
SidecarInjector: false,
Namespace: "istio-system",
Debug: false,
NodePort: 0,
Hub: "gcr.io/istio-testing",
MixerTag: defaultTag,
PilotTag: defaultTag,
CaTag: defaultTag,
ProxyTag: defaultTag,
HyperkubeHub: "quay.io/coreos/hyperkube",
HyperkubeTag: defaultHyperkubeTag,
}
}
func (i *installation) setFeatures(features []string) error {
if len(features) == 0 {
return nil
} else if len(features) == 1 {
features = strings.Split(features[0], ",")
}
i.Mixer = false
i.Pilot = false
i.CA = false
i.Ingress = false
i.SidecarInjector = false
for _, f := range features {
switch strings.ToLower(f) {
case "telemetry", "policy":
i.Mixer = true
i.Pilot = true
case "routing":
i.Pilot = true
case "mtls":
i.CA = true
i.Pilot = true
case "ingress":
i.Ingress = true
i.Pilot = true
case "sidecar-injector":
i.SidecarInjector = true
default:
return fmt.Errorf("invalid feature name %q", f)
}
}
return nil
}