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
1058fb9c
Commit
1058fb9c
authored
9 years ago
by
Matt Butcher
Browse files
Options
Download
Patches
Plain Diff
feat(deploy): Create dm.Client from cli.Context
Also, remove a whole bunch of unused functions.
parent
bbb3229d
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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0
v2.4.2
v2.4.1
v2.4.0
v2.3.1
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
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/helm/deploy.go
+4
-5
cmd/helm/deploy.go
deploy/deploy.go
+0
-177
deploy/deploy.go
dm/client.go
+7
-4
dm/client.go
with
11 additions
and
186 deletions
+11
-186
cmd/helm/deploy.go
+
4
−
5
View file @
1058fb9c
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"github.com/aokoli/goutils"
"github.com/aokoli/goutils"
"github.com/codegangsta/cli"
"github.com/codegangsta/cli"
dep
"github.com/deis/helm-dm/deploy"
dep
"github.com/deis/helm-dm/deploy"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/format"
"github.com/kubernetes/deployment-manager/chart"
"github.com/kubernetes/deployment-manager/chart"
)
)
...
@@ -79,10 +78,10 @@ func deploy(c *cli.Context) error {
...
@@ -79,10 +78,10 @@ func deploy(c *cli.Context) error {
d
.
Input
=
os
.
Stdin
d
.
Input
=
os
.
Stdin
}
}
return
doDeploy
(
d
,
c
.
GlobalString
(
"host"
),
c
.
Bool
(
"dry-run"
)
)
return
doDeploy
(
d
,
c
)
}
}
func
doDeploy
(
cfg
*
dep
.
Deployment
,
host
string
,
dry
bool
)
error
{
func
doDeploy
(
cfg
*
dep
.
Deployment
,
cxt
*
cli
.
Context
)
error
{
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."
)
}
}
...
@@ -125,12 +124,12 @@ func doDeploy(cfg *dep.Deployment, host string, dry bool) error {
...
@@ -125,12 +124,12 @@ func doDeploy(cfg *dep.Deployment, host string, dry bool) error {
cfg
.
Name
=
n
cfg
.
Name
=
n
}
}
if
dry
{
if
cxt
.
Bool
(
"dry-run"
)
{
format
.
Info
(
"Prepared deploy %q using file %q"
,
cfg
.
Name
,
cfg
.
Filename
)
format
.
Info
(
"Prepared deploy %q using file %q"
,
cfg
.
Name
,
cfg
.
Filename
)
return
nil
return
nil
}
}
c
:=
dm
.
NewC
lient
(
hos
t
)
c
:=
c
lient
(
cx
t
)
return
c
.
DeployChart
(
cfg
.
Filename
,
cfg
.
Name
)
return
c
.
DeployChart
(
cfg
.
Filename
,
cfg
.
Name
)
}
}
...
...
This diff is collapsed.
Click to expand it.
deploy/deploy.go
+
0
−
177
View file @
1058fb9c
package
deploy
package
deploy
import
(
import
(
//"archive/tar"
//"errors"
//"fmt"
"os"
"os"
//"strings"
//"github.com/ghodss/yaml"
"github.com/kubernetes/deployment-manager/chart"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/common"
//"github.com/kubernetes/deployment-manager/expandybird/expander"
//"github.com/kubernetes/deployment-manager/registry"
)
)
// Deployer is capable of deploying an object to a back-end.
type
Deployer
interface
{
// 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.
type
Deployment
struct
{
type
Deployment
struct
{
// Name is the Deployment name. Autogenerated if empty.
// Name is the Deployment name. Autogenerated if empty.
...
@@ -42,162 +23,4 @@ type Deployment struct {
...
@@ -42,162 +23,4 @@ type Deployment struct {
// The template, typically generated by the Deployment.
// The template, typically generated by the Deployment.
Template
*
common
.
Template
Template
*
common
.
Template
lchart
*
chart
.
Chart
}
// Prepare loads templates and checks for client-side errors.
//
// This will generate the Template based on other information.
func
(
d
*
Deployment
)
Prepare
()
error
{
// Is Filename a local dir, a local file, or a remote URL?
fi
,
err
:=
os
.
Stat
(
d
.
Filename
)
if
err
!=
nil
{
return
err
}
var
c
*
chart
.
Chart
if
fi
.
IsDir
()
{
c
,
err
=
chart
.
LoadDir
(
d
.
Filename
)
if
err
!=
nil
{
return
err
}
}
else
{
c
,
err
=
chart
.
Load
(
d
.
Filename
)
if
err
!=
nil
{
return
err
}
}
// Override name if we need to
// Properties
d
.
lchart
=
c
return
nil
}
// Chart retrieves the chart from teh deployment.
func
(
d
*
Deployment
)
Chart
()
*
chart
.
Chart
{
return
d
.
lchart
}
// Commit prepares the Deployment and then commits it to the remote processor.
func
(
d
*
Deployment
)
Commit
(
host
string
)
error
{
return
nil
}
/*
// resolveTemplate resolves what kind of template is being loaded, and then returns the template.
func (d *Deployment) resolveTemplate() (*common.Template, error) {
// If some input has been specified, read it.
if d.Input != nil {
// Assume this is a tar archive.
tpl, err := expander.NewTemplateFromArchive(d.Filename, d.Input, d.Imports)
if err == nil {
return tpl, err
} else if err != tar.ErrHeader {
return nil, err
}
// If we get here, the file is not a tar archive.
if _, err := os.Stdin.Seek(0, 0); err != nil {
return nil, err
}
return expander.NewTemplateFromReader(d.Filename, d.Input, d.Imports)
}
// Non-Stdin case
if len(d.Imports) > 0 {
if t, err := registryType(d.Filename); err != nil {
return expander.NewTemplateFromRootTemplate(d.Filename)
} else {
return buildTemplateFromType(t, d.Repository, d.Properties)
}
}
return expander.NewTemplateFromFileNames(d.Filename, d.Imports)
}
// registryType is a placeholder until registry.ParseType() is merged.
func registryType(name string) (*registry.Type, error) {
tList := strings.Split(name, ":")
if len(tList) != 2 {
return nil, errors.New("No version")
}
semver, err := registry.ParseSemVer(tList[1])
if err != nil {
return nil, err
}
tt := registry.Type{Version: semver}
cList := strings.Split(tList[0], "/")
if len(cList) == 1 {
tt.Name = tList[0]
} else {
tt.Collection = cList[0]
tt.Name = cList[1]
}
return &tt, nil
}
// buildTemplateFromType is a straight lift-n-shift from dm.go.
func buildTemplateFromType(t *registry.Type, reg string, props map[string]interface{}) (*common.Template, error) {
// Name the deployment after the type name.
name := fmt.Sprintf("%s:%s", t.Name, t.Version)
git, err := getGitRegistry(reg)
if err != nil {
return nil, err
}
gurls, err := git.GetDownloadURLs(*t)
if err != nil {
return nil, err
}
config := common.Configuration{Resources: []*common.Resource{&common.Resource{
Name: name,
Type: gurls[0].Host,
Properties: props,
}}}
y, err := yaml.Marshal(config)
if err != nil {
return nil, fmt.Errorf("error: %s\ncannot create configuration for deployment: %v\n", err, config)
}
return &common.Template{
Name: name,
Content: string(y),
// No imports, as this is a single type from repository.
}, nil
}
// getGitRegistry returns a registry object for a name.
func getGitRegistry(reg string) (registry.Registry, error) {
s := strings.SplitN(reg, "/", 3)
if len(s) < 2 {
return nil, fmt.Errorf("invalid template registry: %s", reg)
}
//path := ""
//if len(s) > 2 {
//path = s[3]
//}
if s[0] == "helm" {
r, err := registry.NewGithubPackageRegistry(s[0], s[1], nil, nil)
if err != nil {
return nil, err
}
return r, nil
} else {
r, err := registry.NewGithubTemplateRegistry(s[0], s[1], nil, nil)
if err != nil {
return nil, err
}
return r, nil
}
}
}
*/
This diff is collapsed.
Click to expand it.
dm/client.go
+
7
−
4
View file @
1058fb9c
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"os"
"path"
fancypath
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
"time"
"time"
...
@@ -177,10 +177,13 @@ func (c *Client) DeployChart(filename, deployname string) error {
...
@@ -177,10 +177,13 @@ func (c *Client) DeployChart(filename, deployname string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
f
.
Close
()
u
,
err
:=
c
.
url
(
"/v2/deployments"
)
u
,
err
:=
c
.
url
(
"/v2/deployments"
)
request
,
err
:=
http
.
NewRequest
(
"POST"
,
u
,
f
)
request
,
err
:=
http
.
NewRequest
(
"POST"
,
u
,
f
)
if
err
!=
nil
{
f
.
Close
()
return
err
}
// There is an argument to be made for using the legacy x-octet-stream for
// There is an argument to be made for using the legacy x-octet-stream for
// this. But since we control both sides, we should use the standard one.
// this. But since we control both sides, we should use the standard one.
...
@@ -209,7 +212,7 @@ func (c *Client) DeployChart(filename, deployname string) error {
...
@@ -209,7 +212,7 @@ func (c *Client) DeployChart(filename, deployname string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
fmt
.
Errorf
(
"
F
ailed to post: %d %s - %s"
,
response
.
StatusCode
,
response
.
Status
,
body
)
return
fmt
.
Errorf
(
"
f
ailed to post: %d %s - %s"
,
response
.
StatusCode
,
response
.
Status
,
body
)
}
}
return
nil
return
nil
...
@@ -218,7 +221,7 @@ func (c *Client) DeployChart(filename, deployname string) error {
...
@@ -218,7 +221,7 @@ func (c *Client) DeployChart(filename, deployname string) error {
// GetDeployment retrieves the supplied deployment
// GetDeployment retrieves the supplied deployment
func
(
c
*
Client
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
func
(
c
*
Client
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
var
deployment
*
common
.
Deployment
var
deployment
*
common
.
Deployment
if
err
:=
c
.
CallService
(
path
.
Join
(
"deployments"
,
name
),
"GET"
,
"get deployment"
,
&
deployment
,
nil
);
err
!=
nil
{
if
err
:=
c
.
CallService
(
fancy
path
.
Join
(
"deployments"
,
name
),
"GET"
,
"get deployment"
,
&
deployment
,
nil
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
deployment
,
nil
return
deployment
,
nil
...
...
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