From dc91ff264b580458d869f38a8cb7f7f0040f7d9a Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 08:37:27 -0700 Subject: [PATCH 1/9] Move service lookup to pkg/util --- cmd/manager/deployments.go | 43 +++------------------------------- pkg/util/kubernetes.go | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/cmd/manager/deployments.go b/cmd/manager/deployments.go index 52e215020..e2702fb7a 100644 --- a/cmd/manager/deployments.go +++ b/cmd/manager/deployments.go @@ -20,9 +20,7 @@ import ( "errors" "fmt" "log" - "net" "net/http" - "os" "strings" "github.com/kubernetes/helm/cmd/manager/manager" @@ -93,9 +91,9 @@ func newManager(c *router.Context) manager.Manager { service := repo.NewInmemRepoService() cp := c.CredentialProvider rp := repo.NewRepoProvider(service, repo.NewGCSRepoProvider(cp), cp) - expander := manager.NewExpander(getServiceURL(cfg.ExpanderURL, cfg.ExpanderName, expanderPort), rp) - deployer := manager.NewDeployer(getServiceURL(cfg.DeployerURL, cfg.DeployerName, deployerPort)) - address := strings.TrimPrefix(getServiceURL(cfg.MongoAddress, cfg.MongoName, cfg.MongoPort), "http://") + expander := manager.NewExpander(util.GetServiceURL(cfg.ExpanderURL, cfg.ExpanderName, expanderPort), rp) + deployer := manager.NewDeployer(util.GetServiceURL(cfg.DeployerURL, cfg.DeployerName, deployerPort)) + address := strings.TrimPrefix(util.GetServiceURL(cfg.MongoAddress, cfg.MongoName, cfg.MongoPort), "http://") repository := createRepository(address) return manager.NewManager(expander, deployer, repository, rp, service, c.CredentialProvider) } @@ -109,41 +107,6 @@ func createRepository(address string) repository.Repository { return r } -func getServiceURL(serviceURL, serviceName, servicePort string) string { - if serviceURL == "" { - serviceURL = makeEnvVariableURL(serviceName) - if serviceURL == "" { - addrs, err := net.LookupHost(serviceName) - if err != nil || len(addrs) < 1 { - log.Fatalf("cannot resolve service:%v. environment:%v\n", serviceName, os.Environ()) - } - - serviceURL = fmt.Sprintf("http://%s:%s", addrs[0], servicePort) - } - } - - return serviceURL -} - -// makeEnvVariableURL takes a service name and returns the value of the -// environment variable that identifies its URL, if it exists, or the empty -// string, if it doesn't. -func makeEnvVariableURL(str string) string { - prefix := makeEnvVariableName(str) - url := os.Getenv(prefix + "_PORT") - return strings.Replace(url, "tcp", "http", 1) -} - -// makeEnvVariableName is copied from the Kubernetes source, -// which is referenced by the documentation for service environment variables. -func makeEnvVariableName(str string) string { - // TODO: If we simplify to "all names are DNS1123Subdomains" this - // will need two tweaks: - // 1) Handle leading digits - // 2) Handle dots - return strings.ToUpper(strings.Replace(str, "-", "_", -1)) -} - func listDeploymentsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error { handler := "manager: list deployments" util.LogHandlerEntry(handler, r) diff --git a/pkg/util/kubernetes.go b/pkg/util/kubernetes.go index 81bc3aa23..8a444e9d3 100644 --- a/pkg/util/kubernetes.go +++ b/pkg/util/kubernetes.go @@ -16,6 +16,14 @@ limitations under the License. package util +import ( + "fmt" + "log" + "net" + "os" + "strings" +) + // KubernetesConfig defines the configuration options for talking to Kubernetes master type KubernetesConfig struct { KubePath string // The path to kubectl binary @@ -56,3 +64,43 @@ type KubernetesSecret struct { Metadata map[string]string `json:"metadata"` Data map[string]string `json:"data,omitempty"` } + +// GetServiceURL takes a default service URL, a service name and a service port, +// and returns a URL for accessing the service. It first looks for an environment +// variable set by Kubernetes by transposing the service name. If it can't find +// one, it looks up the service name in DNS. If that fails, it returns the default +// service URL. +func GetServiceURL(serviceURL, serviceName, servicePort string) string { + if serviceURL == "" { + serviceURL = MakeEnvVariableURL(serviceName) + if serviceURL == "" { + addrs, err := net.LookupHost(serviceName) + if err != nil || len(addrs) < 1 { + log.Fatalf("cannot resolve service:%v. environment:%v\n", serviceName, os.Environ()) + } + + serviceURL = fmt.Sprintf("http://%s:%s", addrs[0], servicePort) + } + } + + return serviceURL +} + +// MakeEnvVariableURL takes a service name and returns the value of the +// environment variable that identifies its URL, if it exists, or the empty +// string, if it doesn't. +func MakeEnvVariableURL(str string) string { + prefix := MakeEnvVariableName(str) + url := os.Getenv(prefix + "_PORT") + return strings.Replace(url, "tcp", "http", 1) +} + +// MakeEnvVariableName is copied from the Kubernetes source, +// which is referenced by the documentation for service environment variables. +func MakeEnvVariableName(str string) string { + // TODO: If we simplify to "all names are DNS1123Subdomains" this + // will need two tweaks: + // 1) Handle leading digits + // 2) Handle dots + return strings.ToUpper(strings.Replace(str, "-", "_", -1)) +} From 8e8bbb3f56965eec5576b645248aa196f6ac0c9f Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 13:35:12 -0700 Subject: [PATCH 2/9] Remove expandbird address and URL command line flags --- cmd/manager/deployments.go | 10 +++++++--- cmd/manager/main.go | 4 ---- cmd/manager/router/context.go | 4 ---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/manager/deployments.go b/cmd/manager/deployments.go index e2702fb7a..318faec77 100644 --- a/cmd/manager/deployments.go +++ b/cmd/manager/deployments.go @@ -83,15 +83,19 @@ func setupDependencies(c *router.Context) error { return nil } -const expanderPort = "8080" -const deployerPort = "8080" +const ( + expanderName = "expander-service" + expanderPort = "8080" + expanderURL = "http://localhost:8081" + deployerPort = "8080" +) func newManager(c *router.Context) manager.Manager { cfg := c.Config service := repo.NewInmemRepoService() cp := c.CredentialProvider rp := repo.NewRepoProvider(service, repo.NewGCSRepoProvider(cp), cp) - expander := manager.NewExpander(util.GetServiceURL(cfg.ExpanderURL, cfg.ExpanderName, expanderPort), rp) + expander := manager.NewExpander(util.GetServiceURL(expanderURL, expanderName, expanderPort), rp) deployer := manager.NewDeployer(util.GetServiceURL(cfg.DeployerURL, cfg.DeployerName, deployerPort)) address := strings.TrimPrefix(util.GetServiceURL(cfg.MongoAddress, cfg.MongoName, cfg.MongoPort), "http://") repository := createRepository(address) diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 7005b888c..d79c91996 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -31,8 +31,6 @@ import ( var ( port = flag.Int("port", 8080, "The port to listen on") maxLength = flag.Int64("maxLength", 1024, "The maximum length (KB) of a template.") - expanderName = flag.String("expander", "expandybird-service", "The DNS name of the expander service.") - expanderURL = flag.String("expanderURL", "", "The URL for the expander service.") deployerName = flag.String("deployer", "resourcifier-service", "The DNS name of the deployer service.") deployerURL = flag.String("deployerURL", "", "The URL for the deployer service.") credentialFile = flag.String("credentialFile", "", "Local file to use for credentials.") @@ -73,8 +71,6 @@ func parseFlags() *router.Config { return &router.Config{ Address: fmt.Sprintf(":%d", *port), MaxTemplateLength: *maxLength, - ExpanderName: *expanderName, - ExpanderURL: *expanderURL, DeployerName: *deployerName, DeployerURL: *deployerURL, CredentialFile: *credentialFile, diff --git a/cmd/manager/router/context.go b/cmd/manager/router/context.go index e7c6408d6..9a4ebe49f 100644 --- a/cmd/manager/router/context.go +++ b/cmd/manager/router/context.go @@ -31,10 +31,6 @@ type Config struct { Address string // MaxTemplateLength is the maximum length of a template. MaxTemplateLength int64 - // ExpanderName is the DNS name of the expansion service. - ExpanderName string - // ExpanderURL is the expander service's URL. - ExpanderURL string // DeployerName is the deployer's DNS name DeployerName string // DeployerURL is the deployer's URL From edcf783f6525f35fd00b9f074af6bc9e4572ebac Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:17:46 -0700 Subject: [PATCH 3/9] Make pkg/repo use testdata from pkg/chart --- pkg/repo/gcs_repo_test.go | 2 +- pkg/repo/testdata/README.md | 6 -- pkg/repo/testdata/frobnitz-0.0.1.tgz | Bin 2327 -> 0 bytes pkg/repo/testdata/frobnitz/Chart.yaml | 33 -------- pkg/repo/testdata/frobnitz/LICENSE | 1 - pkg/repo/testdata/frobnitz/README.md | 11 --- pkg/repo/testdata/frobnitz/docs/README.md | 1 - .../testdata/frobnitz/hooks/pre-install.py | 1 - pkg/repo/testdata/frobnitz/icon.svg | 8 -- .../templates/wordpress-resources.yaml | 12 --- .../frobnitz/templates/wordpress.jinja | 72 ------------------ .../frobnitz/templates/wordpress.jinja.schema | 69 ----------------- .../frobnitz/templates/wordpress.yaml | 6 -- 13 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 pkg/repo/testdata/README.md delete mode 100644 pkg/repo/testdata/frobnitz-0.0.1.tgz delete mode 100644 pkg/repo/testdata/frobnitz/Chart.yaml delete mode 100644 pkg/repo/testdata/frobnitz/LICENSE delete mode 100644 pkg/repo/testdata/frobnitz/README.md delete mode 100644 pkg/repo/testdata/frobnitz/docs/README.md delete mode 100644 pkg/repo/testdata/frobnitz/hooks/pre-install.py delete mode 100644 pkg/repo/testdata/frobnitz/icon.svg delete mode 100644 pkg/repo/testdata/frobnitz/templates/wordpress-resources.yaml delete mode 100644 pkg/repo/testdata/frobnitz/templates/wordpress.jinja delete mode 100644 pkg/repo/testdata/frobnitz/templates/wordpress.jinja.schema delete mode 100644 pkg/repo/testdata/frobnitz/templates/wordpress.yaml diff --git a/pkg/repo/gcs_repo_test.go b/pkg/repo/gcs_repo_test.go index e71719947..fab4aea9d 100644 --- a/pkg/repo/gcs_repo_test.go +++ b/pkg/repo/gcs_repo_test.go @@ -30,7 +30,7 @@ var ( TestChartName = "frobnitz" TestChartVersion = "0.0.1" TestArchiveName = TestChartName + "-" + TestChartVersion + ".tgz" - TestChartFile = "testdata/frobnitz/Chart.yaml" + TestChartFile = "../chart/testdata/frobnitz/Chart.yaml" TestShouldFindRegex = regexp.MustCompile(TestArchiveName) TestShouldNotFindRegex = regexp.MustCompile("foobar") TestName = "bucket-name" diff --git a/pkg/repo/testdata/README.md b/pkg/repo/testdata/README.md deleted file mode 100644 index 2f58d9774..000000000 --- a/pkg/repo/testdata/README.md +++ /dev/null @@ -1,6 +0,0 @@ -The testdata directory here holds charts that match the specification. - -The `fromnitz/` directory contains a chart that matches the chart -specification. - -The `frobnitz-0.0.1.tgz` file is an archive of the `frobnitz` directory. diff --git a/pkg/repo/testdata/frobnitz-0.0.1.tgz b/pkg/repo/testdata/frobnitz-0.0.1.tgz deleted file mode 100644 index 322f463969025c897ec52b7f94fc44f98d37093d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2327 zcmV+y3F!78iwFR`*Rxgt1MM4YbK5pDpYaiR(-KM&@}C+(?RmH z8+~d8BNQC3Dp%o zzm?SKME}=p;9%)e68Jdad3irBCYT18V^*a2U03vI4sJLOM4MDoKr7d#F7*lKmi|DO zYFpTcXK6Krtk8W+$s)|LGpRj*fvg(Oy|ioC0@CNT|7-j29#Z?eQxYg_Ip2Yd4f&te>2}NcpLW!)^S^z-$qzTamm~_O zkiu!rA6_<2U?CvrfHVRAJ8i}(&-L}Sa&0Pv&Q${jsX|{fLVFNJrUntW8_x}{s*v^L z<6~9!HuI@Vq!GGyZSI^ljZU`-DW5xcc>Lhnr%lLqc=IJtorqNRWj{)(kXXNCpScw9(G75DqLus`vu|q|_b&WDb3O008Cc6zQ!Vmf7?|6ViQbW1+8ek~YzrnQ zVnSYiMX6Eh|396-?td8dcOhew|7%94RR4F{hF1IkJ|H$b3O#Fz9pc%TDqqp^tYOEH z`v0*1>g;`A@$ILVvC01pQ!nR#-EMvUvllo(Z;~UKMtZmtp!i$@$ukM1(Kt9j|6{^HY@E5b`0b>JplVFn`z!W8 zZx;fdd)B`mc*y^iPj2wZ`f?c?{J*1hIwk+t+ui#7XD?8C|7ZJ`slR{z22wPR2E&U% ze>gtxkI-q(*$`xOpYPB&cR9R&^k0twDWmv!2n3(-lpp>_;2+w4>*{;f5+^opFh9&u ze|R&x9QB7k_lG40BE&FEmzYL83NkaQ%ku#cX3rlF-7praYl@~A9aAydN7W)P2N%O} zi994U*4oh8$JJzK=c6A>WFjcVa+Bb=My4RXd@~yVI_Q^p%$SIEF&BKp+XW79&p-UT zJV$dkxT%^Rftw8Od+lD&us?wM|CKPTZ1{Kx8Mx<8Ef$YFNAb(W@N6*bk4Be+cY~7r zEMo|rutJXlZC+}jV{7Tjh)UF%#g2ssX2kD*9sTpClFD*xsZdqoCIaL`p0R0a-TTO| zMkAq0j=*9}%t>s*Xd6o#?=gs%QB0g$LD~LSO_VL4n6`T5tl7EKJ$3GKXEBlQps&&w z$f^}eV~F?FE%4iHe_&9cL1v%=i{4VN*n!=!hdzHUIp^J->=ScY?v=A0_lv=n`{n$^ z{m}>o#u`@wymXAhE&k{z0naCa8ZSwXZ4rdrDef(eiXq3Hm)Y<#*NZiulK5uBLr94S z~X zeXHI7$Z-MjjlE4wm+-wogov6uV zMlhe^L28vV;XFBWgmz?$RASzfBABsp>`xVOCFe_p5WinjRx40p>WWQby~)=jXQnsu zrcV{<%|d^j`7^F(e}DV}Si|St#b{jS5p50e6zt2NpF3Ht;mKih{iiUfiTp1q12@!v zW>+tr{~5-Sxc^(%f4c{96fZoUyWA6TC$T*=6)t}MCZoa`oh0<}d z0t)Dc!Vb+K-9%ZKPeL_>R4WjfUDEKKc$S$-uB902^Qbm-zF&!CK5kSRQY~>kw7^B; zigydYRIx%6!X30=SgOJaVva?zcu|iTa4haaaRD1e#c0=KoWdZZbQRC6g$FxIv9gW( za`QKc*rZoLg;7d3aE{gUB_)#J-vc%l17f zq^y8g8Z6NwE;zQ-L)2XBb&xA;1%iDkQp&zR{#1OFvTwTr(zInO!#pri3m-B$p;y8Y z+?h%x3qB?^EO_eIq-kXcdGzuX=Lj2??^Kw8%O2yf77V*zrBF#i#Q<<2BS)`l>Jv89$x3N#K=j?RL?!E8n%Se{eQ4w%MDJk-xT1~>HPlc;4K>tILk%_5P(uwh)bJ;U{{u*v{-FR+001N6iq`-D diff --git a/pkg/repo/testdata/frobnitz/Chart.yaml b/pkg/repo/testdata/frobnitz/Chart.yaml deleted file mode 100644 index b1e67a038..000000000 --- a/pkg/repo/testdata/frobnitz/Chart.yaml +++ /dev/null @@ -1,33 +0,0 @@ -#helm:generate foo -name: frobnitz -description: This is a frobniz. -version: "1.2.3-alpha.1+12345" -keywords: - - frobnitz - - sprocket - - dodad -maintainers: - - name: The Helm Team - email: helm@example.com - - name: Someone Else - email: nobody@example.com -source: - - https://example.com/foo/bar -home: http://example.com -dependencies: - - name: thingerbob - location: https://example.com/charts/thingerbob-3.2.1.tgz - version: ^3 -environment: - - name: Kubernetes - version: ~1.1 - extensions: - - extensions/v1beta1 - - extensions/v1beta1/daemonset - apiGroups: - - 3rdParty -expander: - name: Expandybird - entrypoint: templates/wordpress.jinja -schema: wordpress.jinja.schema - \ No newline at end of file diff --git a/pkg/repo/testdata/frobnitz/LICENSE b/pkg/repo/testdata/frobnitz/LICENSE deleted file mode 100644 index 6121943b1..000000000 --- a/pkg/repo/testdata/frobnitz/LICENSE +++ /dev/null @@ -1 +0,0 @@ -LICENSE placeholder. diff --git a/pkg/repo/testdata/frobnitz/README.md b/pkg/repo/testdata/frobnitz/README.md deleted file mode 100644 index 8cf4cc3d7..000000000 --- a/pkg/repo/testdata/frobnitz/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Frobnitz - -This is an example chart. - -## Usage - -This is an example. It has no usage. - -## Development - -For developer info, see the top-level repository. diff --git a/pkg/repo/testdata/frobnitz/docs/README.md b/pkg/repo/testdata/frobnitz/docs/README.md deleted file mode 100644 index d40747caf..000000000 --- a/pkg/repo/testdata/frobnitz/docs/README.md +++ /dev/null @@ -1 +0,0 @@ -This is a placeholder for documentation. diff --git a/pkg/repo/testdata/frobnitz/hooks/pre-install.py b/pkg/repo/testdata/frobnitz/hooks/pre-install.py deleted file mode 100644 index c9b0d0a92..000000000 --- a/pkg/repo/testdata/frobnitz/hooks/pre-install.py +++ /dev/null @@ -1 +0,0 @@ -# Placeholder. diff --git a/pkg/repo/testdata/frobnitz/icon.svg b/pkg/repo/testdata/frobnitz/icon.svg deleted file mode 100644 index 892130606..000000000 --- a/pkg/repo/testdata/frobnitz/icon.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - Example icon - - - diff --git a/pkg/repo/testdata/frobnitz/templates/wordpress-resources.yaml b/pkg/repo/testdata/frobnitz/templates/wordpress-resources.yaml deleted file mode 100644 index 00f709de0..000000000 --- a/pkg/repo/testdata/frobnitz/templates/wordpress-resources.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# Google Cloud Deployment Manager template -resources: -- name: nfs-disk - type: compute.v1.disk - properties: - zone: us-central1-b - sizeGb: 200 -- name: mysql-disk - type: compute.v1.disk - properties: - zone: us-central1-b - sizeGb: 200 diff --git a/pkg/repo/testdata/frobnitz/templates/wordpress.jinja b/pkg/repo/testdata/frobnitz/templates/wordpress.jinja deleted file mode 100644 index f34e4fec9..000000000 --- a/pkg/repo/testdata/frobnitz/templates/wordpress.jinja +++ /dev/null @@ -1,72 +0,0 @@ -#helm:generate dm_template -{% set PROPERTIES = properties or {} %} -{% set PROJECT = PROPERTIES['project'] or 'dm-k8s-testing' %} -{% set NFS_SERVER = PROPERTIES['nfs-server'] or {} %} -{% set NFS_SERVER_IP = NFS_SERVER['ip'] or '10.0.253.247' %} -{% set NFS_SERVER_PORT = NFS_SERVER['port'] or 2049 %} -{% set NFS_SERVER_DISK = NFS_SERVER['disk'] or 'nfs-disk' %} -{% set NFS_SERVER_DISK_FSTYPE = NFS_SERVER['fstype'] or 'ext4' %} -{% set NGINX = PROPERTIES['nginx'] or {} %} -{% set NGINX_PORT = 80 %} -{% set NGINX_REPLICAS = NGINX['replicas'] or 2 %} -{% set WORDPRESS_PHP = PROPERTIES['wordpress-php'] or {} %} -{% set WORDPRESS_PHP_REPLICAS = WORDPRESS_PHP['replicas'] or 2 %} -{% set WORDPRESS_PHP_PORT = WORDPRESS_PHP['port'] or 9000 %} -{% set MYSQL = PROPERTIES['mysql'] or {} %} -{% set MYSQL_PORT = MYSQL['port'] or 3306 %} -{% set MYSQL_PASSWORD = MYSQL['password'] or 'mysql-password' %} -{% set MYSQL_DISK = MYSQL['disk'] or 'mysql-disk' %} -{% set MYSQL_DISK_FSTYPE = MYSQL['fstype'] or 'ext4' %} - -resources: -- name: nfs - type: github.com/kubernetes/application-dm-templates/storage/nfs:v1 - properties: - ip: {{ NFS_SERVER_IP }} - port: {{ NFS_SERVER_PORT }} - disk: {{ NFS_SERVER_DISK }} - fstype: {{NFS_SERVER_DISK_FSTYPE }} -- name: nginx - type: github.com/kubernetes/application-dm-templates/common/replicatedservice:v2 - properties: - service_port: {{ NGINX_PORT }} - container_port: {{ NGINX_PORT }} - replicas: {{ NGINX_REPLICAS }} - external_service: true - image: gcr.io/{{ PROJECT }}/nginx:latest - volumes: - - mount_path: /var/www/html - persistentVolumeClaim: - claimName: nfs -- name: mysql - type: github.com/kubernetes/application-dm-templates/common/replicatedservice:v2 - properties: - service_port: {{ MYSQL_PORT }} - container_port: {{ MYSQL_PORT }} - replicas: 1 - image: mysql:5.6 - env: - - name: MYSQL_ROOT_PASSWORD - value: {{ MYSQL_PASSWORD }} - volumes: - - mount_path: /var/lib/mysql - gcePersistentDisk: - pdName: {{ MYSQL_DISK }} - fsType: {{ MYSQL_DISK_FSTYPE }} -- name: wordpress-php - type: github.com/kubernetes/application-dm-templates/common/replicatedservice:v2 - properties: - service_name: wordpress-php - service_port: {{ WORDPRESS_PHP_PORT }} - container_port: {{ WORDPRESS_PHP_PORT }} - replicas: 2 - image: wordpress:fpm - env: - - name: WORDPRESS_DB_PASSWORD - value: {{ MYSQL_PASSWORD }} - - name: WORDPRESS_DB_HOST - value: mysql-service - volumes: - - mount_path: /var/www/html - persistentVolumeClaim: - claimName: nfs diff --git a/pkg/repo/testdata/frobnitz/templates/wordpress.jinja.schema b/pkg/repo/testdata/frobnitz/templates/wordpress.jinja.schema deleted file mode 100644 index 215b47e1e..000000000 --- a/pkg/repo/testdata/frobnitz/templates/wordpress.jinja.schema +++ /dev/null @@ -1,69 +0,0 @@ -info: - title: Wordpress - description: | - Defines a Wordpress website by defining four replicated services: an NFS service, an nginx service, a wordpress-php service, and a MySQL service. - - The nginx service and the Wordpress-php service both use NFS to share files. - -properties: - project: - type: string - default: dm-k8s-testing - description: Project location to load the images from. - nfs-service: - type: object - properties: - ip: - type: string - default: 10.0.253.247 - description: The IP of the NFS service. - port: - type: int - default: 2049 - description: The port of the NFS service. - disk: - type: string - default: nfs-disk - description: The name of the persistent disk the NFS service uses. - fstype: - type: string - default: ext4 - description: The filesystem the disk of the NFS service uses. - nginx: - type: object - properties: - replicas: - type: int - default: 2 - description: The number of replicas for the nginx service. - wordpress-php: - type: object - properties: - replicas: - type: int - default: 2 - description: The number of replicas for the wordpress-php service. - port: - type: int - default: 9000 - description: The port the wordpress-php service runs on. - mysql: - type: object - properties: - port: - type: int - default: 3306 - description: The port the MySQL service runs on. - password: - type: string - default: mysql-password - description: The root password of the MySQL service. - disk: - type: string - default: mysql-disk - description: The name of the persistent disk the MySQL service uses. - fstype: - type: string - default: ext4 - description: The filesystem the disk of the MySQL service uses. - diff --git a/pkg/repo/testdata/frobnitz/templates/wordpress.yaml b/pkg/repo/testdata/frobnitz/templates/wordpress.yaml deleted file mode 100644 index b401897ab..000000000 --- a/pkg/repo/testdata/frobnitz/templates/wordpress.yaml +++ /dev/null @@ -1,6 +0,0 @@ -imports: -- path: wordpress.jinja - -resources: -- name: wordpress - type: wordpress.jinja From a3fefbb0b745a0d99ffe414160373716933fcb28 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:19:20 -0700 Subject: [PATCH 4/9] Make pkg/chart use expandybird-service --- pkg/chart/chartfile.go | 2 +- pkg/chart/chartfile_test.go | 4 ++-- pkg/chart/testdata/frobnitz-0.0.1.tgz | Bin 2363 -> 2382 bytes pkg/chart/testdata/frobnitz/Chart.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/chart/chartfile.go b/pkg/chart/chartfile.go index 1332ef805..93a54940d 100644 --- a/pkg/chart/chartfile.go +++ b/pkg/chart/chartfile.go @@ -61,7 +61,7 @@ type EnvConstraint struct { // Expander controls how template/ is evaluated. type Expander struct { - // Currently just Expandybird or GoTemplate + // Kubernetes service name to look up in DNS. Name string `json:"name"` // During evaluation, which file to start from. Entrypoint string `json:"entrypoint"` diff --git a/pkg/chart/chartfile_test.go b/pkg/chart/chartfile_test.go index 3c4042db7..ac4237f83 100644 --- a/pkg/chart/chartfile_test.go +++ b/pkg/chart/chartfile_test.go @@ -55,8 +55,8 @@ func TestLoadChartfile(t *testing.T) { if expander == nil { t.Errorf("No expander found in %s", testfile) } else { - if expander.Name != "Expandybird" { - t.Errorf("Expected expander name Expandybird, got %s", expander.Name) + if expander.Name != "expandybird-service" { + t.Errorf("Expected expander name expandybird-service, got %s", expander.Name) } if expander.Entrypoint != "templates/wordpress.jinja" { diff --git a/pkg/chart/testdata/frobnitz-0.0.1.tgz b/pkg/chart/testdata/frobnitz-0.0.1.tgz index fae67e01141c91d380b367764a5b634ea7731792..3c3a7cf010057a05819e46a9525225f00231cdc8 100644 GIT binary patch literal 2382 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 diff --git a/pkg/chart/testdata/frobnitz/Chart.yaml b/pkg/chart/testdata/frobnitz/Chart.yaml index b1e67a038..fd5754b56 100644 --- a/pkg/chart/testdata/frobnitz/Chart.yaml +++ b/pkg/chart/testdata/frobnitz/Chart.yaml @@ -27,7 +27,7 @@ environment: apiGroups: - 3rdParty expander: - name: Expandybird + name: expandybird-service entrypoint: templates/wordpress.jinja schema: wordpress.jinja.schema \ No newline at end of file From 30f8db7fbf3f7dc3cef6c20c311166a905d42716 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:19:50 -0700 Subject: [PATCH 5/9] Make example charts use expandybird-service --- examples/charts/redis/Chart.yaml | 2 +- examples/charts/replicatedservice/Chart.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/charts/redis/Chart.yaml b/examples/charts/redis/Chart.yaml index 836bd9c4b..773e52af3 100644 --- a/examples/charts/redis/Chart.yaml +++ b/examples/charts/redis/Chart.yaml @@ -3,5 +3,5 @@ description: Port of the replicatedservice template from kubernetes/charts version: "2" home: "" expander: - name: Expandybird + name: expandybird-service entrypoint: templates/redis.jinja diff --git a/examples/charts/replicatedservice/Chart.yaml b/examples/charts/replicatedservice/Chart.yaml index 2790b9c9d..e106d60ab 100644 --- a/examples/charts/replicatedservice/Chart.yaml +++ b/examples/charts/replicatedservice/Chart.yaml @@ -3,5 +3,5 @@ description: Port of the replicatedservice template from kubernetes/charts version: "3" home: "" expander: - name: Expandybird + name: expandybird-service entrypoint: templates/replicatedservice.py From 378a27e8b37b0f76878ccc99f50aae551be73588 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:21:02 -0700 Subject: [PATCH 6/9] Streamline service lookup --- pkg/util/kubernetes.go | 62 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/pkg/util/kubernetes.go b/pkg/util/kubernetes.go index 8a444e9d3..df3f5785c 100644 --- a/pkg/util/kubernetes.go +++ b/pkg/util/kubernetes.go @@ -65,42 +65,48 @@ type KubernetesSecret struct { Data map[string]string `json:"data,omitempty"` } -// GetServiceURL takes a default service URL, a service name and a service port, +// GetServiceURL takes a service name, a service port, and a default service URL, // and returns a URL for accessing the service. It first looks for an environment // variable set by Kubernetes by transposing the service name. If it can't find -// one, it looks up the service name in DNS. If that fails, it returns the default -// service URL. -func GetServiceURL(serviceURL, serviceName, servicePort string) string { - if serviceURL == "" { - serviceURL = MakeEnvVariableURL(serviceName) - if serviceURL == "" { +// one, it looks up the service name in DNS. If that doesn't work, it returns the +// default service URL. If that's empty, it returns an HTTP localhost URL for the +// service port. If service port is empty, it panics. +func GetServiceURL(serviceName, servicePort, serviceURL string) (string, error) { + if serviceName != "" { + varBase := strings.Replace(serviceName, "-", "_", -1) + varName := strings.ToUpper(varBase) + "_PORT" + serviceURL := os.Getenv(varName) + if serviceURL != "" { + return strings.Replace(serviceURL, "tcp", "http", 1), nil + } + + if servicePort != "" { addrs, err := net.LookupHost(serviceName) - if err != nil || len(addrs) < 1 { - log.Fatalf("cannot resolve service:%v. environment:%v\n", serviceName, os.Environ()) + if err == nil && len(addrs) > 0 { + return fmt.Sprintf("http://%s:%s", addrs[0], servicePort), nil } - - serviceURL = fmt.Sprintf("http://%s:%s", addrs[0], servicePort) } } - return serviceURL -} + if serviceURL != "" { + return serviceURL, nil + } -// MakeEnvVariableURL takes a service name and returns the value of the -// environment variable that identifies its URL, if it exists, or the empty -// string, if it doesn't. -func MakeEnvVariableURL(str string) string { - prefix := MakeEnvVariableName(str) - url := os.Getenv(prefix + "_PORT") - return strings.Replace(url, "tcp", "http", 1) + if servicePort != "" { + serviceURL = fmt.Sprintf("http://localhost:%s", servicePort) + return serviceURL, nil + } + + err := fmt.Errorf("cannot resolve service:%v in environment:%v\n", serviceName, os.Environ()) + return "", err } -// MakeEnvVariableName is copied from the Kubernetes source, -// which is referenced by the documentation for service environment variables. -func MakeEnvVariableName(str string) string { - // TODO: If we simplify to "all names are DNS1123Subdomains" this - // will need two tweaks: - // 1) Handle leading digits - // 2) Handle dots - return strings.ToUpper(strings.Replace(str, "-", "_", -1)) +// GetServiceURLOrDie calls GetServiceURL and exits if it returns an error. +func GetServiceURLOrDie(serviceName, servicePort, serviceURL string) string { + URL, err := GetServiceURL(serviceName, servicePort, serviceURL) + if err != nil { + log.Fatal(err) + } + + return URL } From 2c20a3185fd3be48a27142e082e7ccf8c3c4f2e9 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:21:33 -0700 Subject: [PATCH 7/9] Make expander use dynamic service name --- cmd/manager/manager/expander.go | 140 +++++++++++++++------------ cmd/manager/manager/expander_test.go | 18 +--- 2 files changed, 77 insertions(+), 81 deletions(-) diff --git a/cmd/manager/manager/expander.go b/cmd/manager/manager/expander.go index 988ab7d60..5f76618e1 100644 --- a/cmd/manager/manager/expander.go +++ b/cmd/manager/manager/expander.go @@ -20,21 +20,17 @@ import ( "github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/expansion" "github.com/kubernetes/helm/pkg/repo" + "github.com/kubernetes/helm/pkg/util" "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" + "net/url" + "strings" ) -/* -const ( - // TODO (iantw): Align this with a character not allowed to show up in resource names. - layoutNodeKeySeparator = "#" -) -*/ - // ExpandedConfiguration is the structure returned by the expansion service. type ExpandedConfiguration struct { Config *common.Configuration `json:"config"` @@ -47,23 +43,20 @@ type Expander interface { } // NewExpander returns a new initialized Expander. -func NewExpander(URL string, rp repo.IRepoProvider) Expander { +func NewExpander(port, URL string, rp repo.IRepoProvider) Expander { if rp == nil { rp = repo.NewRepoProvider(nil, nil, nil) } - return &expander{expanderURL: URL, repoProvider: rp} + return &expander{expanderPort: port, expanderURL: URL, repoProvider: rp} } type expander struct { repoProvider repo.IRepoProvider + expanderPort string expanderURL string } -func (e *expander) getBaseURL() string { - return fmt.Sprintf("%s/expand", e.expanderURL) -} - // ExpandConfiguration expands the supplied configuration and returns // an expanded configuration. func (e *expander) ExpandConfiguration(conf *common.Configuration) (*ExpandedConfiguration, error) { @@ -81,80 +74,81 @@ func (e *expander) expandConfiguration(conf *common.Configuration) (*ExpandedCon // Iterate over all of the resources in the unexpanded configuration for _, resource := range conf.Resources { - // A primitive layout resource captures only the name and type + additions := []*common.Resource{resource} layout := &common.LayoutResource{ Resource: common.Resource{ Name: resource.Name, Type: resource.Type, }, } - // If the type is not a chart reference, then it must be primitive - if !repo.IsChartReference(resource.Type) { - // Add it to the flat list of exapnded resources - resources = append(resources, resource) - - // Add its layout to the list of layouts at this level - layouts = append(layouts, layout) - continue - } - - // It is a chart, so go fetch it, decompress it and unpack it - cbr, _, err := e.repoProvider.GetChartByReference(resource.Type) - if err != nil { - return nil, err - } - - defer cbr.Close() - - // Now, load the charts contents into strings that we can pass to exapnsion - content, err := cbr.LoadContent() - if err != nil { - return nil, err - } - - // Build a request to the expansion service and call it to do the expansion - svcReq := &expansion.ServiceRequest{ - ChartInvocation: resource, - Chart: content, - } - - svcResp, err := e.callService(svcReq) - if err != nil { - return nil, err + // If the type is a chart reference + if repo.IsChartReference(resource.Type) { + // Fetch, decompress and unpack + cbr, _, err := e.repoProvider.GetChartByReference(resource.Type) + if err != nil { + return nil, err + } + + defer cbr.Close() + expander := cbr.Chartfile().Expander + if expander != nil && expander.Name != "" { + // Load the charts contents into strings that we can pass to exapnsion + content, err := cbr.LoadContent() + if err != nil { + return nil, err + } + + // Build a request to the expansion service and call it to do the expansion + svcReq := &expansion.ServiceRequest{ + ChartInvocation: resource, + Chart: content, + } + + svcResp, err := e.callService(expander.Name, svcReq) + if err != nil { + return nil, err + } + + // Call ourselves recursively with the list of resources returned by expansion + expConf, err := e.expandConfiguration(svcResp) + if err != nil { + return nil, err + } + + // Append the reources returned by the recursion to the flat list of resources + additions = expConf.Config.Resources + + // This was not a primitive resource, so add its properties to the layout + // Then add the all of the layout resources returned by the recursion to the layout + layout.Properties = resource.Properties + layout.Resources = expConf.Layout.Resources + } } - // Call ourselves recursively with the list of resources returned by expansion - expConf, err := e.expandConfiguration(svcResp) - if err != nil { - return nil, err - } - - // Append the reources returned by the recursion to the flat list of resources - resources = append(resources, expConf.Config.Resources...) - - // This was not a primitive resource, so add its properties to the layout - layout.Properties = resource.Properties - - // Now add the all of the layout resources returned by the recursion to the layout - layout.Resources = expConf.Layout.Resources + resources = append(resources, additions...) layouts = append(layouts, layout) } - // All done with this level, so return the espanded configuration + // All done with this level, so return the expanded configuration return &ExpandedConfiguration{ Config: &common.Configuration{Resources: resources}, Layout: &common.Layout{Resources: layouts}, }, nil } -func (e *expander) callService(svcReq *expansion.ServiceRequest) (*common.Configuration, error) { +func (e *expander) callService(svcName string, svcReq *expansion.ServiceRequest) (*common.Configuration, error) { + svcURL, err := e.getServiceURL(svcName) + if err != nil { + return nil, err + } + j, err := json.Marshal(svcReq) if err != nil { return nil, err } reader := ioutil.NopCloser(bytes.NewReader(j)) - request, err := http.NewRequest("POST", e.getBaseURL(), reader) + request, err := http.NewRequest("POST", svcURL, reader) if err != nil { return nil, err } @@ -188,3 +182,21 @@ func (e *expander) callService(svcReq *expansion.ServiceRequest) (*common.Config return svcResp, nil } + +func (e *expander) getServiceURL(svcName string) (string, error) { + if !strings.HasPrefix(svcName, "http:") && !strings.HasPrefix(svcName, "https:") { + var err error + svcName, err = util.GetServiceURL(svcName, e.expanderPort, e.expanderURL) + if err != nil { + return "", err + } + } + + u, err := url.Parse(svcName) + if err != nil { + return "", err + } + + u.Path = fmt.Sprintf("%s/expand", u.Path) + return u.String(), nil +} diff --git a/cmd/manager/manager/expander_test.go b/cmd/manager/manager/expander_test.go index 4dd9dacae..8ab757581 100644 --- a/cmd/manager/manager/expander_test.go +++ b/cmd/manager/manager/expander_test.go @@ -27,7 +27,6 @@ import ( "testing" "github.com/ghodss/yaml" - "github.com/kubernetes/helm/pkg/chart" "github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/expansion" "github.com/kubernetes/helm/pkg/repo" @@ -219,21 +218,6 @@ var roundTripResponses = []*ExpandedConfiguration{ } */ -type mockRepoProvider struct { -} - -func (m *mockRepoProvider) GetChartByReference(reference string) (*chart.Chart, repo.IChartRepo, error) { - return &chart.Chart{}, nil, nil -} - -func (m *mockRepoProvider) GetRepoByChartURL(URL string) (repo.IChartRepo, error) { - return nil, nil -} - -func (m *mockRepoProvider) GetRepoByURL(URL string) (repo.IChartRepo, error) { - return nil, nil -} - type ExpanderTestCase struct { Description string Error string @@ -266,7 +250,7 @@ func TestExpandTemplate(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(etc.Handler)) defer ts.Close() - expander := NewExpander(ts.URL, getTestRepoProvider(t)) + expander := NewExpander("8081", ts.URL, getTestRepoProvider(t)) resource := &common.Resource{ Name: "test_invocation", Type: TestResourceType, From 4bf9ac6e9b054720cc7ffe5c79d7abeb005571c6 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:22:27 -0700 Subject: [PATCH 8/9] Make manager initialization use dynamic services --- cmd/manager/deployments.go | 13 +++---------- cmd/manager/main.go | 6 ++++++ cmd/manager/router/context.go | 6 ++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cmd/manager/deployments.go b/cmd/manager/deployments.go index 318faec77..7948d17f3 100644 --- a/cmd/manager/deployments.go +++ b/cmd/manager/deployments.go @@ -83,21 +83,14 @@ func setupDependencies(c *router.Context) error { return nil } -const ( - expanderName = "expander-service" - expanderPort = "8080" - expanderURL = "http://localhost:8081" - deployerPort = "8080" -) - func newManager(c *router.Context) manager.Manager { cfg := c.Config service := repo.NewInmemRepoService() cp := c.CredentialProvider rp := repo.NewRepoProvider(service, repo.NewGCSRepoProvider(cp), cp) - expander := manager.NewExpander(util.GetServiceURL(expanderURL, expanderName, expanderPort), rp) - deployer := manager.NewDeployer(util.GetServiceURL(cfg.DeployerURL, cfg.DeployerName, deployerPort)) - address := strings.TrimPrefix(util.GetServiceURL(cfg.MongoAddress, cfg.MongoName, cfg.MongoPort), "http://") + expander := manager.NewExpander(cfg.ExpanderPort, cfg.ExpanderURL, rp) + deployer := manager.NewDeployer(util.GetServiceURLOrDie(cfg.DeployerName, cfg.DeployerPort, cfg.DeployerURL)) + address := strings.TrimPrefix(util.GetServiceURLOrDie(cfg.MongoName, cfg.MongoPort, cfg.MongoAddress), "http://") repository := createRepository(address) return manager.NewManager(expander, deployer, repository, rp, service, c.CredentialProvider) } diff --git a/cmd/manager/main.go b/cmd/manager/main.go index d79c91996..c6747d05d 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -31,7 +31,10 @@ import ( var ( port = flag.Int("port", 8080, "The port to listen on") maxLength = flag.Int64("maxLength", 1024, "The maximum length (KB) of a template.") + expanderPort = flag.String("expanderPort", "8081", "The IP port of the default expander service.") + expanderURL = flag.String("expanderURL", "", "The URL for the default expander service.") deployerName = flag.String("deployer", "resourcifier-service", "The DNS name of the deployer service.") + deployerPort = flag.String("deployerPort", "8082", "The IP port of the deployer service.") deployerURL = flag.String("deployerURL", "", "The URL for the deployer service.") credentialFile = flag.String("credentialFile", "", "Local file to use for credentials.") credentialSecrets = flag.Bool("credentialSecrets", true, "Use secrets for credentials.") @@ -71,7 +74,10 @@ func parseFlags() *router.Config { return &router.Config{ Address: fmt.Sprintf(":%d", *port), MaxTemplateLength: *maxLength, + ExpanderPort: *expanderPort, + ExpanderURL: *expanderURL, DeployerName: *deployerName, + DeployerPort: *deployerPort, DeployerURL: *deployerURL, CredentialFile: *credentialFile, CredentialSecrets: *credentialSecrets, diff --git a/cmd/manager/router/context.go b/cmd/manager/router/context.go index 9a4ebe49f..6e878c762 100644 --- a/cmd/manager/router/context.go +++ b/cmd/manager/router/context.go @@ -31,8 +31,14 @@ type Config struct { Address string // MaxTemplateLength is the maximum length of a template. MaxTemplateLength int64 + // ExpanderPort is the default expander's IP port + ExpanderPort string + // ExpanderURL is the default expander's URL + ExpanderURL string // DeployerName is the deployer's DNS name DeployerName string + // DeployerPort is the deployer's IP port + DeployerPort string // DeployerURL is the deployer's URL DeployerURL string // CredentialFile is the file to the credentials. From 1a64a499eed6c0fbb3ba19788f1d73763cae23e3 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 5 Apr 2016 20:22:49 -0700 Subject: [PATCH 9/9] Make startup script use dynamic services --- scripts/start-local.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start-local.sh b/scripts/start-local.sh index 678833467..e533af611 100755 --- a/scripts/start-local.sh +++ b/scripts/start-local.sh @@ -44,7 +44,7 @@ echo "Starting expandybird..." nohup $EXPANDYBIRD > $LOGDIR/expandybird.log 2>&1 --port=8081 --expansion_binary=expansion/expansion.py & echo "Starting deployment manager..." -nohup $MANAGER > $LOGDIR/manager.log 2>&1 --port="${MANAGER_PORT}" --kubectl="${KUBECTL}" --expanderURL=http://localhost:8081 --deployerURL=http://localhost:8082 & +nohup $MANAGER > $LOGDIR/manager.log 2>&1 --port="${MANAGER_PORT}" --kubectl="${KUBECTL}" --expanderPort=8081 --deployerPort=8082 & if [[ "$KUBE_PROXY" ]]; then echo "Starting kubectl proxy..."