Browse Source

Merge pull request #2287 from 2opremio/fluxctl-setup

Add `fluxctl install` command
Alfonso Acosta 3 months ago
parent
commit
077060ee53
No account linked to committer's email address

+ 12
- 8
Makefile View File

@@ -1,5 +1,5 @@
1 1
 .DEFAULT: all
2
-.PHONY: all release-bins clean realclean test integration-test check-generated
2
+.PHONY: all release-bins clean realclean test integration-test generate-deploy check-generated
3 3
 
4 4
 SUDO := $(shell docker info > /dev/null 2> /dev/null || echo "sudo")
5 5
 
@@ -18,11 +18,7 @@ endif
18 18
 CURRENT_OS_ARCH=$(shell echo `go env GOOS`-`go env GOARCH`)
19 19
 GOBIN?=$(shell echo `go env GOPATH`/bin)
20 20
 
21
-# NB because this outputs absolute file names, you have to be careful
22
-# if you're testing out the Makefile with `-W` (pretend a file is
23
-# new); use the full path to the pretend-new file, e.g.,
24
-#  `make -W $PWD/registry/registry.go`
25
-godeps=$(shell go list -deps -f '{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}' $(1))
21
+godeps=$(shell go list -deps -f '{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}' $(1) | sed "s%${PWD}/%%g")
26 22
 
27 23
 FLUXD_DEPS:=$(call godeps,./cmd/fluxd/...)
28 24
 FLUXCTL_DEPS:=$(call godeps,./cmd/fluxctl/...)
@@ -124,7 +120,15 @@ $(GOBIN)/helm-operator: $(HELM_OPERATOR_DEPS)
124 120
 integration-test: all
125 121
 	test/bin/test-flux
126 122
 
127
-check-generated:
123
+
124
+
125
+generate-deploy: install/generated_templates.gogen.go
126
+	cd deploy && go run ../install/generate.go deploy
127
+
128
+install/generated_templates.gogen.go: install/templates/*
129
+	cd install && go run generate.go embedded-templates
130
+
131
+check-generated: generate-deploy install/generated_templates.gogen.go
128 132
 	./bin/helm/update_codegen.sh
129
-	git diff --exit-code -- integrations/apis intergrations/client
133
+	git diff --exit-code -- integrations/apis intergrations/client install/generated_templates.gogen.go
130 134
 

+ 1
- 1
bin/helm/update_codegen.sh View File

@@ -8,7 +8,7 @@ SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/../..
8 8
 CODEGEN_PKG=${CODEGEN_PKG:-$(echo `go env GOPATH`'/pkg/mod/k8s.io/code-generator@v0.0.0-20190511023357-639c964206c2')}
9 9
 
10 10
 go mod download # make sure the code-generator is downloaded
11
-bash ${CODEGEN_PKG}/generate-groups.sh all github.com/weaveworks/flux/integrations/client \
11
+env GOPATH=`go env GOPATH` bash ${CODEGEN_PKG}/generate-groups.sh all github.com/weaveworks/flux/integrations/client \
12 12
               github.com/weaveworks/flux/integrations/apis \
13 13
               "flux.weave.works:v1beta1 helm.integrations.flux.weave.works:v1alpha2" \
14 14
   --go-header-file "${SCRIPT_ROOT}/bin/helm/custom-boilerplate.go.txt"

+ 62
- 0
cmd/fluxctl/install_cmd.go View File

@@ -0,0 +1,62 @@
1
+package main
2
+
3
+import (
4
+	"fmt"
5
+	"os"
6
+
7
+	"github.com/spf13/cobra"
8
+
9
+	"github.com/weaveworks/flux/install"
10
+)
11
+
12
+type installOpts install.TemplateParameters
13
+
14
+func newInstall() *installOpts {
15
+	return &installOpts{}
16
+}
17
+
18
+func (opts *installOpts) Command() *cobra.Command {
19
+	cmd := &cobra.Command{
20
+		Use:   "install",
21
+		Short: "Print and tweak Kubernetes manifests needed to install Flux in a Cluster",
22
+		Example: `# Install Flux and make it use Git repository git@github.com:<your username>/flux-get-started
23
+fluxctl install --git-url 'git@github.com:<your username>/flux-get-started' | kubectl -f -`,
24
+		RunE: opts.RunE,
25
+	}
26
+	cmd.Flags().StringVarP(&opts.GitURL, "git-url", "", "",
27
+		"URL of the Git repository to be used by Flux, e.g. git@github.com:<your username>/flux-get-started")
28
+	cmd.Flags().StringVarP(&opts.GitBranch, "git-branch", "", "master",
29
+		"Git branch to be used by Flux")
30
+	cmd.Flags().StringSliceVarP(&opts.GitPaths, "git-paths", "", []string{},
31
+		"Relative paths within the Git repo for Flux to locate Kubernetes manifests")
32
+	cmd.Flags().StringVarP(&opts.GitLabel, "git-label", "", "flux",
33
+		"Git label to keep track of Flux's sync progress; overrides both --git-sync-tag and --git-notes-ref")
34
+	cmd.Flags().StringVarP(&opts.GitUser, "git-user", "", "Flux",
35
+		"Username to use as git committer")
36
+	cmd.Flags().StringVarP(&opts.GitEmail, "git-email", "", "",
37
+		"Email to use as git committer")
38
+	cmd.Flags().StringVarP(&opts.Namespace, "namespace", "", getKubeConfigContextNamespace("default"),
39
+		"Cluster namespace where to install flux")
40
+	return cmd
41
+}
42
+
43
+func (opts *installOpts) RunE(cmd *cobra.Command, args []string) error {
44
+	if opts.GitURL == "" {
45
+		return fmt.Errorf("please supply a valid --git-url argument")
46
+	}
47
+	if opts.GitEmail == "" {
48
+		return fmt.Errorf("please supply a valid --git-email argument")
49
+	}
50
+	manifests, err := install.FillInTemplates(install.TemplateParameters(*opts))
51
+	if err != nil {
52
+		return err
53
+	}
54
+	for fileName, content := range manifests {
55
+		if _, err := os.Stdout.Write(content); err != nil {
56
+			return fmt.Errorf("cannot output manifest file %s: %s", fileName, err)
57
+		}
58
+
59
+	}
60
+
61
+	return nil
62
+}

+ 4
- 1
cmd/fluxctl/root_cmd.go View File

@@ -89,15 +89,18 @@ func (opts *rootOpts) Command() *cobra.Command {
89 89
 		newSave(opts).Command(),
90 90
 		newIdentity(opts).Command(),
91 91
 		newSync(opts).Command(),
92
+		newInstall().Command(),
92 93
 	)
93 94
 
94 95
 	return cmd
95 96
 }
96 97
 
97 98
 func (opts *rootOpts) PersistentPreRunE(cmd *cobra.Command, _ []string) error {
98
-	// skip port forward for version command
99
+	// skip port forward for certain commands
99 100
 	switch cmd.Use {
100 101
 	case "version":
102
+		fallthrough
103
+	case "install":
101 104
 		return nil
102 105
 	}
103 106
 

+ 1
- 1
deploy/flux-deployment.yaml View File

@@ -117,7 +117,7 @@ spec:
117 117
         # mounted above, for K8s >= 1.10
118 118
         - --ssh-keygen-dir=/var/fluxd/keygen
119 119
 
120
-        # Replace or remove the following URL.
120
+        # Replace the following URL to change the Git repository used by Flux.
121 121
         - --git-url=git@github.com:weaveworks/flux-get-started
122 122
         - --git-branch=master
123 123
         # include this if you want to restrict the manifests considered by flux

+ 1
- 1
deploy/memcache-svc.yaml View File

@@ -8,4 +8,4 @@ spec:
8 8
     - name: memcached
9 9
       port: 11211
10 10
   selector:
11
-    name: memcached
11
+    name: memcached

+ 3
- 1
go.mod View File

@@ -36,7 +36,7 @@ require (
36 36
 	github.com/hashicorp/golang-lru v0.5.1 // indirect
37 37
 	github.com/huandu/xstrings v1.2.0 // indirect
38 38
 	github.com/imdario/mergo v0.3.7
39
-	github.com/inconshreveable/mousetrap v1.0.0 // indirect
39
+	github.com/instrumenta/kubeval v0.0.0-20190720105720-70e32d660927
40 40
 	github.com/justinbarrick/go-k8s-portforward v1.0.4-0.20190722134107-d79fe1b9d79d
41 41
 	github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
42 42
 	github.com/ncabatoff/go-seq v0.0.0-20180805175032-b08ef85ed833
@@ -51,6 +51,8 @@ require (
51 51
 	github.com/prometheus/common v0.3.0 // indirect
52 52
 	github.com/prometheus/procfs v0.0.0-20190412120340-e22ddced7142 // indirect
53 53
 	github.com/ryanuber/go-glob v1.0.0
54
+	github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
55
+	github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
54 56
 	github.com/sirupsen/logrus v1.4.1 // indirect
55 57
 	github.com/spf13/cobra v0.0.3
56 58
 	github.com/spf13/pflag v1.0.3

+ 42
- 0
go.sum View File

@@ -59,6 +59,8 @@ github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f/go.mod h1:gNh8
59 59
 github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
60 60
 github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=
61 61
 github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
62
+github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
63
+github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
62 64
 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
63 65
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
64 66
 github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
@@ -119,11 +121,17 @@ github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH
119 121
 github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
120 122
 github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE=
121 123
 github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
124
+github.com/hashicorp/errwrap v0.0.0-20180715044906-d6c0cd880357 h1:Rem2+U35z1QtPQc6r+WolF7yXiefXqDKyk+lN2pE164=
125
+github.com/hashicorp/errwrap v0.0.0-20180715044906-d6c0cd880357/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
122 126
 github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
123 127
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
128
+github.com/hashicorp/go-multierror v0.0.0-20180717150148-3d5d8f294aa0 h1:j30noezaCfvNLcdMYSvHLv81DxYRSt1grlpseG67vhU=
129
+github.com/hashicorp/go-multierror v0.0.0-20180717150148-3d5d8f294aa0/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
124 130
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
125 131
 github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
126 132
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
133
+github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce h1:xdsDDbiBDQTKASoGEZ+pEmF1OnWuu8AQ9I8iNbHNeno=
134
+github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
127 135
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
128 136
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
129 137
 github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
@@ -133,6 +141,8 @@ github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
133 141
 github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
134 142
 github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
135 143
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
144
+github.com/instrumenta/kubeval v0.0.0-20190720105720-70e32d660927 h1:r1cvxQYvoKyFHUbPpDRAJw4QRvfyWyR55cp3mS1fklc=
145
+github.com/instrumenta/kubeval v0.0.0-20190720105720-70e32d660927/go.mod h1:HeTbS2psckzaIy3V3lGbcCvSGP9f9MvrQV6s9IWGy0w=
136 146
 github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
137 147
 github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
138 148
 github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be h1:AHimNtVIpiBjPUhEF5KNCkrUyqTSA5zWUl8sQ2bfGBE=
@@ -155,8 +165,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
155 165
 github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
156 166
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
157 167
 github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
168
+github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
169
+github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
170
+github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
171
+github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
172
+github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
173
+github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
158 174
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
159 175
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
176
+github.com/mitchellh/mapstructure v0.0.0-20180715050151-f15292f7a699 h1:KXZJFdun9knAVAR8tg/aHJEr5DgtcbqyvzacK+CDCaI=
177
+github.com/mitchellh/mapstructure v0.0.0-20180715050151-f15292f7a699/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
160 178
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
161 179
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
162 180
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
@@ -178,6 +196,8 @@ github.com/opentracing-contrib/go-stdlib v0.0.0-20190324214902-3020fec0e66b/go.m
178 196
 github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
179 197
 github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
180 198
 github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
199
+github.com/pelletier/go-toml v0.0.0-20180724185102-c2dbbc24a979 h1:Uh8pTMDzw+nuDTW7lyxcpmYqQJFE8SnO93F3lyY4XzY=
200
+github.com/pelletier/go-toml v0.0.0-20180724185102-c2dbbc24a979/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
181 201
 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
182 202
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
183 203
 github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
@@ -206,14 +226,28 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
206 226
 github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
207 227
 github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
208 228
 github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
229
+github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
230
+github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
231
+github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
232
+github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
209 233
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
210 234
 github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
211 235
 github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
236
+github.com/spf13/afero v1.1.1 h1:Lt3ihYMlE+lreX1GS4Qw4ZsNpYQLxIXKBTEOXm3nt6I=
237
+github.com/spf13/afero v1.1.1/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
238
+github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
239
+github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
240
+github.com/spf13/cobra v0.0.0-20180820174524-ff0d02e85550/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
212 241
 github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
213 242
 github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
243
+github.com/spf13/jwalterweatherman v0.0.0-20180814060501-14d3d4c51834 h1:kJI9pPzfsULT/72wy7mxkRQZPtKWgFdCA2RTGZ4v8/E=
244
+github.com/spf13/jwalterweatherman v0.0.0-20180814060501-14d3d4c51834/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
245
+github.com/spf13/pflag v0.0.0-20180821114517-d929dcbb1086/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
214 246
 github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
215 247
 github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
216 248
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
249
+github.com/spf13/viper v1.1.0 h1:V7OZpY8i3C1x/pDmU0zNNlfVoDz112fSYvtWMjjS3f4=
250
+github.com/spf13/viper v1.1.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
217 251
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
218 252
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
219 253
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -231,6 +265,12 @@ github.com/weaveworks/promrus v1.2.0 h1:jOLf6pe6/vss4qGHjXmGz4oDJQA+AOCqEL3FvvZG
231 265
 github.com/weaveworks/promrus v1.2.0/go.mod h1:SaE82+OJ91yqjrE1rsvBWVzNZKcHYFtMUyS1+Ogs/KA=
232 266
 github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa h1:rW+Lu6281ed/4XGuVIa4/YebTRNvoUJlfJ44ktEVwZk=
233 267
 github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa/go.mod h1:2rx5KE5FLD0HRfkkpyn8JwbVLBdhgeiOb2D2D9LLKM4=
268
+github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
269
+github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
270
+github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
271
+github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
272
+github.com/xeipuuv/gojsonschema v0.0.0-20180816142147-da425ebb7609 h1:BcMExZAULPkihVZ7UJXK7t8rwGqisXFw75tILnafhBY=
273
+github.com/xeipuuv/gojsonschema v0.0.0-20180816142147-da425ebb7609/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
234 274
 go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
235 275
 go.opencensus.io v0.20.2 h1:NAfh7zF0/3/HqtMvJNZ/RFrSlCE6ZTlHmKfhL/Dm1Jk=
236 276
 go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
@@ -269,6 +309,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
269 309
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
270 310
 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
271 311
 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
312
+golang.org/x/sys v0.0.0-20180821044426-4ea2f632f6e9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
272 313
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
273 314
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
274 315
 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -281,6 +322,7 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w
281 322
 golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
282 323
 golang.org/x/sys v0.0.0-20190411185658-b44545bcd369 h1:aBlRBZoCuZNRDClvfkDoklQqdLzBaA3uViASg2z2p24=
283 324
 golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
325
+golang.org/x/text v0.0.0-20180810153555-6e3c4e7365dd/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
284 326
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
285 327
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To=
286 328
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

+ 56
- 0
install/generate.go View File

@@ -0,0 +1,56 @@
1
+// +build ignore
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+	"io/ioutil"
8
+	"log"
9
+	"net/http"
10
+	"os"
11
+
12
+	"github.com/shurcooL/vfsgen"
13
+
14
+	"github.com/weaveworks/flux/install"
15
+)
16
+
17
+func main() {
18
+	usage := func() {
19
+		fmt.Fprintf(os.Stderr, "usage: %s {embedded-templates,deploy}\n", os.Args[0])
20
+		os.Exit(1)
21
+	}
22
+	if len(os.Args) != 2 {
23
+		usage()
24
+	}
25
+	switch os.Args[1] {
26
+	case "embedded-templates":
27
+		var fs http.FileSystem = http.Dir("templates/")
28
+		err := vfsgen.Generate(fs, vfsgen.Options{
29
+			Filename:     "generated_templates.gogen.go",
30
+			PackageName:  "install",
31
+			VariableName: "templates",
32
+		})
33
+		if err != nil {
34
+			log.Fatalln(err)
35
+		}
36
+	case "deploy":
37
+		params := install.TemplateParameters{
38
+			GitURL:    "git@github.com:weaveworks/flux-get-started",
39
+			GitBranch: "master",
40
+		}
41
+		manifests, err := install.FillInTemplates(params)
42
+		if err != nil {
43
+			fmt.Fprintf(os.Stderr, "error: failed to fill in templates: %s\n", err)
44
+			os.Exit(1)
45
+		}
46
+		for fileName, contents := range manifests {
47
+			if err := ioutil.WriteFile(fileName, contents, 0600); err != nil {
48
+				fmt.Fprintf(os.Stderr, "error: failed to write deploy file %s: %s\n", fileName, err)
49
+				os.Exit(1)
50
+			}
51
+		}
52
+
53
+	default:
54
+		usage()
55
+	}
56
+}

+ 216
- 0
install/generated_templates.gogen.go
File diff suppressed because it is too large
View File


+ 56
- 0
install/install.go View File

@@ -0,0 +1,56 @@
1
+package install
2
+
3
+import (
4
+	"bytes"
5
+	"fmt"
6
+	"io"
7
+	"io/ioutil"
8
+	"os"
9
+	"strings"
10
+	"text/template"
11
+
12
+	"github.com/shurcooL/httpfs/vfsutil"
13
+)
14
+
15
+type TemplateParameters struct {
16
+	GitURL             string
17
+	GitBranch          string
18
+	GitPaths           []string
19
+	GitLabel           string
20
+	GitUser            string
21
+	GitEmail           string
22
+	Namespace          string
23
+	AdditionalFluxArgs []string
24
+}
25
+
26
+func FillInTemplates(params TemplateParameters) (map[string][]byte, error) {
27
+	result := map[string][]byte{}
28
+	err := vfsutil.WalkFiles(templates, "/", func(path string, info os.FileInfo, rs io.ReadSeeker, err error) error {
29
+		if err != nil {
30
+			return fmt.Errorf("cannot walk embedded files: %s", err)
31
+		}
32
+		if info.IsDir() {
33
+			return nil
34
+		}
35
+		manifestTemplateBytes, err := ioutil.ReadAll(rs)
36
+		if err != nil {
37
+			return fmt.Errorf("cannot read embedded file %q: %s", info.Name(), err)
38
+		}
39
+		manifestTemplate, err := template.New(info.Name()).
40
+			Funcs(template.FuncMap{"StringsJoin": strings.Join}).
41
+			Parse(string(manifestTemplateBytes))
42
+		if err != nil {
43
+			return fmt.Errorf("cannot parse embedded file %q: %s", info.Name(), err)
44
+		}
45
+		out := bytes.NewBuffer(nil)
46
+		if err := manifestTemplate.Execute(out, params); err != nil {
47
+			return fmt.Errorf("cannot execute template for embedded file %q: %s", info.Name(), err)
48
+		}
49
+		result[strings.TrimSuffix(info.Name(), ".tmpl")] = out.Bytes()
50
+		return nil
51
+	})
52
+	if err != nil {
53
+		return nil, fmt.Errorf("internal error filling embedded installation templates: %s", err)
54
+	}
55
+	return result, nil
56
+}

+ 50
- 0
install/install_test.go View File

@@ -0,0 +1,50 @@
1
+package install
2
+
3
+import (
4
+	"testing"
5
+
6
+	"github.com/instrumenta/kubeval/kubeval"
7
+	"github.com/stretchr/testify/assert"
8
+)
9
+
10
+func testFillInTemplates(t *testing.T, params TemplateParameters) {
11
+	manifests, err := FillInTemplates(params)
12
+	assert.NoError(t, err)
13
+	assert.Len(t, manifests, 5)
14
+	for fileName, contents := range manifests {
15
+		validationResults, err := kubeval.Validate(contents, fileName)
16
+		assert.NoError(t, err)
17
+		for _, result := range validationResults {
18
+			if len(result.Errors) > 0 {
19
+				t.Errorf("found problems with manifest %s (Kind %s):\ncontent:\n%s\nerrors: %s",
20
+					fileName,
21
+					result.Kind,
22
+					string(contents),
23
+					result.Errors)
24
+			}
25
+		}
26
+	}
27
+}
28
+
29
+func TestFillInTemplatesAllParameters(t *testing.T) {
30
+	testFillInTemplates(t, TemplateParameters{
31
+		GitURL:             "git@github.com:fluxcd/flux-get-started",
32
+		GitBranch:          "branch",
33
+		GitPaths:           []string{"dir1", "dir2"},
34
+		GitLabel:           "label",
35
+		GitUser:            "User",
36
+		GitEmail:           "this.is@anemail.com",
37
+		Namespace:          "flux",
38
+		AdditionalFluxArgs: []string{"arg1=foo", "arg2=bar"},
39
+	})
40
+
41
+}
42
+
43
+func TestFillInTemplatesMissingValues(t *testing.T) {
44
+	testFillInTemplates(t, TemplateParameters{
45
+		GitURL:    "git@github.com:fluxcd/flux-get-started",
46
+		GitBranch: "branch",
47
+		GitPaths:  []string{},
48
+		GitLabel:  "label",
49
+	})
50
+}

+ 38
- 0
install/templates/flux-account.yaml.tmpl View File

@@ -0,0 +1,38 @@
1
+---
2
+# The service account, cluster roles, and cluster role binding are
3
+# only needed for Kubernetes with role-based access control (RBAC).
4
+apiVersion: v1
5
+kind: ServiceAccount
6
+metadata:
7
+  labels:
8
+    name: flux
9
+  name: flux{{ if .Namespace }}
10
+  namespace: {{ .Namespace }}{{ end}}
11
+---
12
+apiVersion: rbac.authorization.k8s.io/v1beta1
13
+kind: ClusterRole
14
+metadata:
15
+  labels:
16
+    name: flux
17
+  name: flux
18
+rules:
19
+  - apiGroups: ['*']
20
+    resources: ['*']
21
+    verbs: ['*']
22
+  - nonResourceURLs: ['*']
23
+    verbs: ['*']
24
+---
25
+apiVersion: rbac.authorization.k8s.io/v1beta1
26
+kind: ClusterRoleBinding
27
+metadata:
28
+  labels:
29
+    name: flux
30
+  name: flux
31
+roleRef:
32
+  apiGroup: rbac.authorization.k8s.io
33
+  kind: ClusterRole
34
+  name: flux
35
+subjects:
36
+  - kind: ServiceAccount
37
+    name: flux
38
+    namespace: {{ if .Namespace }}{{ .Namespace }}{{ else }}default{{ end }}

+ 157
- 0
install/templates/flux-deployment.yaml.tmpl View File

@@ -0,0 +1,157 @@
1
+---
2
+apiVersion: apps/v1
3
+kind: Deployment
4
+metadata:
5
+  name: flux{{ if .Namespace }}
6
+  namespace: {{ .Namespace }}{{ end }}
7
+spec:
8
+  replicas: 1
9
+  selector:
10
+    matchLabels:
11
+      name: flux
12
+  strategy:
13
+    type: Recreate
14
+  template:
15
+    metadata:
16
+      annotations:
17
+        prometheus.io/port: "3031" # tell prometheus to scrape /metrics endpoint's port.
18
+      labels:
19
+        name: flux
20
+    spec:
21
+      serviceAccountName: flux
22
+      volumes:
23
+      - name: git-key
24
+        secret:
25
+          secretName: flux-git-deploy
26
+          defaultMode: 0400 # when mounted read-only, we won't be able to chmod
27
+
28
+      # This is a tmpfs used for generating SSH keys. In K8s >= 1.10,
29
+      # mounted secrets are read-only, so we need a separate volume we
30
+      # can write to.
31
+      - name: git-keygen
32
+        emptyDir:
33
+          medium: Memory
34
+
35
+      # The following volume is for using a customised known_hosts
36
+      # file, which you will need to do if you host your own git
37
+      # repo rather than using github or the like. You'll also need to
38
+      # mount it into the container, below. See
39
+      # https://github.com/weaveworks/flux/blob/master/site/standalone-setup.md#using-a-private-git-host
40
+      # - name: ssh-config
41
+      #   configMap:
42
+      #     name: flux-ssh-config
43
+
44
+      # The following volume is for using a customised .kube/config,
45
+      # which you will need to do if you wish to have a different
46
+      # default namespace. You will also need to provide the configmap
47
+      # with an entry for `config`, and uncomment the volumeMount and
48
+      # env entries below.
49
+      # - name: kubeconfig
50
+      #   configMap:
51
+      #     name: flux-kubeconfig
52
+
53
+      # The following volume is used to import GPG keys (for signing
54
+      # and verification purposes). You will also need to provide the
55
+      # secret with the keys, and uncomment the volumeMount and args
56
+      # below.
57
+      # - name: gpg-keys
58
+      #   secret:
59
+      #     secretName: flux-gpg-keys
60
+      #     defaultMode: 0400
61
+
62
+      containers:
63
+      - name: flux
64
+        # There are no ":latest" images for flux. Find the most recent
65
+        # release or image version at https://hub.docker.com/r/weaveworks/flux/tags
66
+        # and replace the tag here.
67
+        image: docker.io/fluxcd/flux:1.13.3
68
+        imagePullPolicy: IfNotPresent
69
+        resources:
70
+          requests:
71
+            cpu: 50m
72
+            memory: 64Mi
73
+        ports:
74
+        - containerPort: 3030 # informational
75
+        volumeMounts:
76
+        - name: git-key
77
+          mountPath: /etc/fluxd/ssh # to match location given in image's /etc/ssh/config
78
+          readOnly: true # this will be the case perforce in K8s >=1.10
79
+        - name: git-keygen
80
+          mountPath: /var/fluxd/keygen # to match location given in image's /etc/ssh/config
81
+
82
+        # Include this if you need to mount a customised known_hosts
83
+        # file; you'll also need the volume declared above.
84
+        # - name: ssh-config
85
+        #   mountPath: /root/.ssh
86
+
87
+        # Include this and the volume "kubeconfig" above, and the
88
+        # environment entry "KUBECONFIG" below, to override the config
89
+        # used by kubectl.
90
+        # - name: kubeconfig
91
+        #   mountPath: /etc/fluxd/kube
92
+
93
+        # Include this to point kubectl at a different config; you
94
+        # will need to do this if you have mounted an alternate config
95
+        # from a configmap, as in commented blocks above.
96
+        # env:
97
+        # - name: KUBECONFIG
98
+        #   value: /etc/fluxd/kube/config
99
+
100
+        # Include this and the volume "gpg-keys" above, and the
101
+        # args below.
102
+        # - name: gpg-keys
103
+        #   mountPath: /root/gpg-import
104
+        #   readOnly: true
105
+
106
+        args:
107
+
108
+        # If you deployed memcached in a different namespace to flux,
109
+        # or with a different service name, you can supply these
110
+        # following two arguments to tell fluxd how to connect to it.
111
+        # - --memcached-hostname=memcached.default.svc.cluster.local
112
+
113
+        # Use the memcached ClusterIP service name by setting the
114
+        # memcached-service to string empty
115
+        - --memcached-service=
116
+
117
+        # This must be supplied, and be in the tmpfs (emptyDir)
118
+        # mounted above, for K8s >= 1.10
119
+        - --ssh-keygen-dir=/var/fluxd/keygen
120
+
121
+        # Replace the following URL to change the Git repository used by Flux.
122
+        - --git-url={{ .GitURL }}
123
+        - --git-branch={{ .GitBranch }}{{ if .GitPaths }}
124
+        - --git-path={{ StringsJoin .GitPaths "," }}{{ else }}
125
+        # include this if you want to restrict the manifests considered by flux
126
+        # to those under the following relative paths in the git repository
127
+        # - --git-path=subdir1,subdir2{{ end }}{{ if .GitLabel }}
128
+        - --git-label={{ .GitLabel }}{{ end }}{{ if .GitUser }}
129
+        - --git-user={{ .GitUser   }}{{ end }}{{ if .GitEmail }}
130
+        - --git-email={{ .GitEmail }}{{ end }}
131
+
132
+        # Include these two to enable git commit signing
133
+        # - --git-gpg-key-import=/root/gpg-import
134
+        # - --git-signing-key=<key id>
135
+        
136
+        # Include this to enable git signature verification
137
+        # - --git-verify-signatures
138
+
139
+        # Include these next two to connect to an "upstream" service
140
+        # (e.g., Weave Cloud). The token is particular to the service.
141
+        # - --connect=wss://cloud.weave.works/api/flux
142
+        # - --token=abc123abc123abc123abc123
143
+
144
+        # Serve /metrics endpoint at different port;
145
+        # make sure to set prometheus' annotation to scrape the port value.
146
+        - --listen-metrics=:3031
147
+{{ if .AdditionalFluxArgs }}
148
+        # Additional arguments{{ range .AdditionalFluxArgs }}
149
+        - {{ . }}{{ end }}
150
+{{ end }}
151
+      # Optional DNS settings, configuring the ndots option may resolve
152
+      # nslookup issues on some Kubernetes setups.
153
+      # dnsPolicy: "None"
154
+      # dnsConfig:
155
+      #   options:
156
+      #     - name: ndots
157
+      #       value: "1"

+ 7
- 0
install/templates/flux-secret.yaml.tmpl View File

@@ -0,0 +1,7 @@
1
+---
2
+apiVersion: v1
3
+kind: Secret
4
+metadata:
5
+  name: flux-git-deploy{{ if .Namespace }}
6
+  namespace: {{ .Namespace }}{{ end }}
7
+type: Opaque

+ 34
- 0
install/templates/memcache-dep.yaml.tmpl View File

@@ -0,0 +1,34 @@
1
+---
2
+# memcached deployment used by Flux to cache
3
+# container image metadata.
4
+apiVersion: apps/v1
5
+kind: Deployment
6
+metadata:
7
+  name: memcached{{ if .Namespace }}
8
+  namespace: {{ .Namespace }}{{ end }}
9
+spec:
10
+  replicas: 1
11
+  selector:
12
+    matchLabels:
13
+      name: memcached
14
+  template:
15
+    metadata:
16
+      labels:
17
+        name: memcached
18
+    spec:
19
+      containers:
20
+      - name: memcached
21
+        image: memcached:1.5.15
22
+        imagePullPolicy: IfNotPresent
23
+        args:
24
+        - -m 512   # Maximum memory to use, in megabytes
25
+        - -I 5m    # Maximum size for one item
26
+        - -p 11211 # Default port
27
+        # - -vv    # Uncomment to get logs of each request and response.
28
+        ports:
29
+        - name: clients
30
+          containerPort: 11211
31
+        securityContext:
32
+          runAsUser: 11211
33
+          runAsGroup: 11211
34
+          allowPrivilegeEscalation: false

+ 12
- 0
install/templates/memcache-svc.yaml.tmpl View File

@@ -0,0 +1,12 @@
1
+---
2
+apiVersion: v1
3
+kind: Service
4
+metadata:
5
+  name: memcached{{ if .Namespace }}
6
+  namespace: {{ .Namespace }}{{ end }}
7
+spec:
8
+  ports:
9
+    - name: memcached
10
+      port: 11211
11
+  selector:
12
+    name: memcached

+ 1
- 0
tools.go View File

@@ -6,5 +6,6 @@
6 6
 package flux
7 7
 
8 8
 import (
9
+	_ "github.com/shurcooL/vfsgen"
9 10
 	_ "k8s.io/code-generator"
10 11
 )

Loading…
Cancel
Save