Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1105 Внедрение механизмов обеспечения безопасности цепочки поставки программных проектов
Legacy
scanned-projects
helm
Commits
9763a893
Commit
9763a893
authored
9 years ago
by
Matt Butcher
Browse files
Options
Download
Patches
Plain Diff
feat(*): deploy dry-run now works
parent
063e3752
main
Release
add-codeql
dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible
dependabot/go_modules/github.com/lib/pq-1.10.9
dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0
dependabot/go_modules/golang.org/x/crypto-0.9.0
dependabot/go_modules/golang.org/x/term-0.8.0
dependabot/go_modules/k8s.io/klog/v2-2.100.1
dev-v2
feat-v3/event-emitter-lua
kube-update-test
release-2.0
release-2.1
release-2.10
release-2.11
release-2.12
release-2.13
release-2.14
release-2.15
release-2.16
release-2.17
release-2.2
release-2.3
release-2.4
release-2.5
release-2.6
release-2.7
release-2.8
release-2.9
release-3.0
release-3.1
release-3.10
release-3.11
release-3.12
release-3.2
release-3.3
release-3.4
release-3.5
release-3.6
release-3.6.1
release-3.6.2
release-3.7
release-3.8
release-3.9
release-v3.0.0-beta.4
1.999.0
v3.12.0
v3.12.0-rc.1
v3.12.0-dev.1
v3.11.3
v3.11.2
v3.11.1
v3.11.0
v3.11.0-rc.2
v3.11.0-rc.1
v3.10.3
v3.10.2
v3.10.1
v3.10.0
v3.10.0-rc.1
v3.9.4
v3.9.3
v3.9.2
v3.9.1
v3.9.0
v3.9.0-rc.1
v3.8.2
v3.8.1
v3.8.0
v3.8.0-rc.2
v3.8.0-rc.1
v3.7.2
v3.7.1
v3.7.0
v3.7.0-rc.3
v3.7.0-rc.2
v3.7.0-rc.1
v3.6.3
v3.6.2
v3.6.1
v3.6.0
v3.6.0-rc.1
v3.5.4
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.5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v2.3.0
v2.2.3
v2.2.2
v2.2.1
v2.2.0
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.0.2
v2.0.1
v2.0.0
v2.0.0-rc.2
v2.0.0-rc.1
v2.0.0-beta.2
v2.0.0-beta.1
v2.0.0-alpha.5
v2.0.0-alpha.4
v2.0.0-alpha.3
v2.0.0-alpha.2
v2.0.0-alpha.1
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
cmd/deploy.go
+19
-5
cmd/deploy.go
cmd/helm.go
+7
-1
cmd/helm.go
deploy/deploy.go
+24
-3
deploy/deploy.go
testdata/guestbook/README.md
+127
-0
testdata/guestbook/README.md
testdata/guestbook/guestbook.yaml
+12
-0
testdata/guestbook/guestbook.yaml
with
189 additions
and
9 deletions
+189
-9
cmd/deploy.go
+
19
−
5
View file @
9763a893
package
main
package
main
import
(
import
(
"encoding/json"
"errors"
"errors"
dep
"github.com/deis/helm-dm/deploy"
dep
"github.com/deis/helm-dm/deploy"
"github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/format"
)
)
func
deploy
(
cfg
*
dep
.
Deployment
,
dry
bool
)
error
{
func
deploy
(
cfg
*
dep
.
Deployment
,
host
string
,
dry
bool
)
error
{
if
dry
{
format
.
Error
(
"Not implemented: --dry-run"
)
}
if
cfg
.
Filename
==
""
{
if
cfg
.
Filename
==
""
{
return
errors
.
New
(
"A filename must be specified. For a tar archive, this is the name of the root template in the archive."
)
return
errors
.
New
(
"A filename must be specified. For a tar archive, this is the name of the root template in the archive."
)
}
}
if
err
:=
cfg
.
Commit
();
err
!=
nil
{
if
err
:=
cfg
.
Prepare
();
err
!=
nil
{
format
.
Error
(
"Failed to prepare deployment: %s"
,
err
)
return
err
}
// For a dry run, print the template and exit.
if
dry
{
format
.
Info
(
"Template prepared for %s"
,
cfg
.
Template
.
Name
)
data
,
err
:=
json
.
MarshalIndent
(
cfg
.
Template
,
""
,
"
\t
"
)
if
err
!=
nil
{
return
err
}
format
.
Msg
(
string
(
data
))
return
nil
}
if
err
:=
cfg
.
Commit
(
host
);
err
!=
nil
{
format
.
Error
(
"Failed to commit deployment: %s"
,
err
)
format
.
Error
(
"Failed to commit deployment: %s"
,
err
)
return
err
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/helm.go
+
7
−
1
View file @
9763a893
...
@@ -89,7 +89,7 @@ func commands() []cli.Command {
...
@@ -89,7 +89,7 @@ func commands() []cli.Command {
d
.
Input
=
os
.
Stdin
d
.
Input
=
os
.
Stdin
}
}
if
err
:=
deploy
(
d
,
c
.
Bool
(
"dry-run"
));
err
!=
nil
{
if
err
:=
deploy
(
d
,
c
.
String
(
"host"
),
c
.
Bool
(
"dry-run"
));
err
!=
nil
{
format
.
Error
(
"%s (Try running 'helm doctor')"
,
err
)
format
.
Error
(
"%s (Try running 'helm doctor')"
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
@@ -119,6 +119,12 @@ func commands() []cli.Command {
...
@@ -119,6 +119,12 @@ func commands() []cli.Command {
Usage
:
"The default repository"
,
Usage
:
"The default repository"
,
Value
:
"kubernetes/application-dm-templates"
,
Value
:
"kubernetes/application-dm-templates"
,
},
},
cli
.
StringFlag
{
Name
:
"host,u"
,
Usage
:
"The URL of the DM server."
,
EnvVar
:
"HELM_HOST"
,
Value
:
"https://localhost:8181/FIXME_NOT_RIGHT"
,
},
},
},
},
},
{
{
...
...
This diff is collapsed.
Click to expand it.
deploy/deploy.go
+
24
−
3
View file @
9763a893
...
@@ -13,8 +13,15 @@ import (
...
@@ -13,8 +13,15 @@ import (
"github.com/kubernetes/deployment-manager/registry"
"github.com/kubernetes/deployment-manager/registry"
)
)
// Deployer is capable of deploying an object to a back-end.
type
Deployer
interface
{
type
Deployer
interface
{
Commit
()
error
// Prepare prepares the local side of a deployment.
Prepare
()
error
// Commit pushes a deployment and checks that it is completed.
//
// This sends the data to the given host.
Commit
(
host
string
)
error
}
}
// Deployment describes a deployment of a package.
// Deployment describes a deployment of a package.
...
@@ -31,10 +38,16 @@ type Deployment struct {
...
@@ -31,10 +38,16 @@ type Deployment struct {
Input
*
os
.
File
Input
*
os
.
File
// Repository is the location of the templates.
// Repository is the location of the templates.
Repository
string
Repository
string
// The template, typically generated by the Deployment.
Template
*
common
.
Template
}
}
// Commit prepares the Deployment and then commits it to the remote processor.
// Prepare loads templates and checks for client-side errors.
func
(
d
*
Deployment
)
Commit
()
error
{
//
// This will generate the Template based on other information.
func
(
d
*
Deployment
)
Prepare
()
error
{
tpl
,
err
:=
d
.
resolveTemplate
()
tpl
,
err
:=
d
.
resolveTemplate
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -45,6 +58,13 @@ func (d *Deployment) Commit() error {
...
@@ -45,6 +58,13 @@ func (d *Deployment) Commit() error {
tpl
.
Name
=
d
.
Name
tpl
.
Name
=
d
.
Name
}
}
d
.
Template
=
tpl
return
nil
}
// Commit prepares the Deployment and then commits it to the remote processor.
func
(
d
*
Deployment
)
Commit
(
host
string
)
error
{
return
nil
return
nil
}
}
...
@@ -129,6 +149,7 @@ func buildTemplateFromType(t *registry.Type, reg string, props map[string]interf
...
@@ -129,6 +149,7 @@ func buildTemplateFromType(t *registry.Type, reg string, props map[string]interf
},
nil
},
nil
}
}
// getGitRegistry returns a registry object for a name.
func
getGitRegistry
(
reg
string
)
(
registry
.
Registry
,
error
)
{
func
getGitRegistry
(
reg
string
)
(
registry
.
Registry
,
error
)
{
s
:=
strings
.
SplitN
(
reg
,
"/"
,
3
)
s
:=
strings
.
SplitN
(
reg
,
"/"
,
3
)
if
len
(
s
)
<
2
{
if
len
(
s
)
<
2
{
...
...
This diff is collapsed.
Click to expand it.
testdata/guestbook/README.md
0 → 100644
+
127
−
0
View file @
9763a893
T
**Testing fork of the guestbook example.**
# Guestbook Example
Welcome to the Guestbook example. It shows you how to build and reuse
parameterized templates.
## Prerequisites
First, make sure DM is installed in your Kubernetes cluster and that the
Guestbook example is deployed by following the instructions in the top level
[
README.md
](
../../README.md
)
.
## Understanding the Guestbook example
Let's take a closer look at the configuration used by the Guestbook example.
### Replicated services
The typical design pattern for microservices in Kubernetes is to create a
replication controller and a service with the same selector, so that the service
exposes ports from the pods managed by the replication controller.
We have created a parameterized template for this kind of replicated service
called
[
Replicated Service
](
../../templates/replicatedservice/v1
)
, and we use it
three times in the Guestbook example.
The template is defined by a
[
Python script
](
../../templates/replicatedservice/v1/replicatedservice.py
)
. It
also has a
[
schema
](
../../templates/replicatedservice/v1/replicatedservice.py.schema
)
.
Schemas are optional. If provided, they are used to validate template invocations
that appear in configurations.
For more information about templates and schemas, see the
[
design document
](
../../docs/design/design.md#templates
)
.
### The Guestbook application
The Guestbook application consists of 2 microservices: a front end and a Redis
cluster.
#### The front end
The front end is a replicated service with 3 replicas:
```
- name: frontend
type: https://raw.githubusercontent.com/kubernetes/deployment-manager/master/templates/replicatedservice/v1/replicatedservice.py
properties:
service_port: 80
container_port: 80
external_service: true
replicas: 3
image: gcr.io/google_containers/example-guestbook-php-redis:v3
```
(Note that we use the URL for a specific version of the template replicatedservice.py,
not just the template name.)
#### The Redis cluster
The Redis cluster consists of two replicated services: a master with a single replica
and the slaves with 2 replicas. It's defined by
[
this template
](
../../templates/redis/v1/redis.jinja
)
,
which is a
[
Jinja
](
http://jinja.pocoo.org/
)
file with a
[
schema
](
../../templates/redis/v1/redis.jinja.schema
)
.
```
{% set REDIS_PORT = 6379 %}
{% set WORKERS = properties['workers'] or 2 %}
resources:
- name: redis-master
type: https://raw.githubusercontent.com/kubernetes/deployment-manager/master/templates/replicatedservice/v1/replicatedservice.py
properties:
# This has to be overwritten since service names are hard coded in the code
service_name: redis-master
service_port: {{ REDIS_PORT }}
target_port: {{ REDIS_PORT }}
container_port: {{ REDIS_PORT }}
replicas: 1
container_name: master
image: redis
- name: redis-slave
type: https://raw.githubusercontent.com/kubernetes/deployment-manager/master/templates/replicatedservice/v1/replicatedservice.py
properties:
# This has to be overwritten since service names are hard coded in the code
service_name: redis-slave
service_port: {{ REDIS_PORT }}
container_port: {{ REDIS_PORT }}
replicas: {{ WORKERS }}
container_name: worker
image: kubernetes/redis-slave:v2
# An example of how to specify env variables.
env:
- name: GET_HOSTS_FROM
value: env
- name: REDIS_MASTER_SERVICE_HOST
value: redis-master
```
### Displaying types
You can see both the both primitive types and the templates you've deployed to the
cluster using the
`deployed-types`
command:
```
dm deployed-types
["Service","ReplicationController","redis.jinja","https://raw.githubusercontent.com/kubernetes/deployment-manager/master/templates/replicatedservice/v1/replicatedservice.py"]
```
This output shows 2 primitive types (Service and ReplicationController), and 2
templates (redis.jinja and one imported from github named replicatedservice.py).
You can also see where a specific type is being used with the
`deployed-instances`
command:
```
dm deployed-instances Service
[{"name":"frontend-service","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[0].resources[0]"},{"name":"redis-master","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[1].resources[0].resources[0]"},{"name":"redis-slave","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[1].resources[1].resources[0]"}]
```
This output describes the deployment and manifest, as well as the JSON paths to
the instances of the type within the layout.
For more information about deployments, manifests and layouts, see the
[
design document
](
../../docs/design/design.md#api-model
)
.
This diff is collapsed.
Click to expand it.
testdata/guestbook/guestbook.yaml
0 → 100644
+
12
−
0
View file @
9763a893
resources
:
-
name
:
frontend
type
:
github.com/kubernetes/application-dm-templates/common/replicatedservice:v1
properties
:
service_port
:
80
container_port
:
80
external_service
:
true
replicas
:
3
image
:
gcr.io/google_containers/example-guestbook-php-redis:v3
-
name
:
redis
type
:
github.com/kubernetes/application-dm-templates/storage/redis:v1
properties
:
null
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets