Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
dc91ff26
Commit
dc91ff26
authored
Apr 05, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move service lookup to pkg/util
parent
105348bd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
40 deletions
+51
-40
deployments.go
cmd/manager/deployments.go
+3
-40
kubernetes.go
pkg/util/kubernetes.go
+48
-0
No files found.
cmd/manager/deployments.go
View file @
dc91ff26
...
@@ -20,9 +20,7 @@ import (
...
@@ -20,9 +20,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"log"
"log"
"net"
"net/http"
"net/http"
"os"
"strings"
"strings"
"github.com/kubernetes/helm/cmd/manager/manager"
"github.com/kubernetes/helm/cmd/manager/manager"
...
@@ -93,9 +91,9 @@ func newManager(c *router.Context) manager.Manager {
...
@@ -93,9 +91,9 @@ func newManager(c *router.Context) manager.Manager {
service
:=
repo
.
NewInmemRepoService
()
service
:=
repo
.
NewInmemRepoService
()
cp
:=
c
.
CredentialProvider
cp
:=
c
.
CredentialProvider
rp
:=
repo
.
NewRepoProvider
(
service
,
repo
.
NewGCSRepoProvider
(
cp
),
cp
)
rp
:=
repo
.
NewRepoProvider
(
service
,
repo
.
NewGCSRepoProvider
(
cp
),
cp
)
expander
:=
manager
.
NewExpander
(
g
etServiceURL
(
cfg
.
ExpanderURL
,
cfg
.
ExpanderName
,
expanderPort
),
rp
)
expander
:=
manager
.
NewExpander
(
util
.
G
etServiceURL
(
cfg
.
ExpanderURL
,
cfg
.
ExpanderName
,
expanderPort
),
rp
)
deployer
:=
manager
.
NewDeployer
(
g
etServiceURL
(
cfg
.
DeployerURL
,
cfg
.
DeployerName
,
deployerPort
))
deployer
:=
manager
.
NewDeployer
(
util
.
G
etServiceURL
(
cfg
.
DeployerURL
,
cfg
.
DeployerName
,
deployerPort
))
address
:=
strings
.
TrimPrefix
(
g
etServiceURL
(
cfg
.
MongoAddress
,
cfg
.
MongoName
,
cfg
.
MongoPort
),
"http://"
)
address
:=
strings
.
TrimPrefix
(
util
.
G
etServiceURL
(
cfg
.
MongoAddress
,
cfg
.
MongoName
,
cfg
.
MongoPort
),
"http://"
)
repository
:=
createRepository
(
address
)
repository
:=
createRepository
(
address
)
return
manager
.
NewManager
(
expander
,
deployer
,
repository
,
rp
,
service
,
c
.
CredentialProvider
)
return
manager
.
NewManager
(
expander
,
deployer
,
repository
,
rp
,
service
,
c
.
CredentialProvider
)
}
}
...
@@ -109,41 +107,6 @@ func createRepository(address string) repository.Repository {
...
@@ -109,41 +107,6 @@ func createRepository(address string) repository.Repository {
return
r
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
{
func
listDeploymentsHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list deployments"
handler
:=
"manager: list deployments"
util
.
LogHandlerEntry
(
handler
,
r
)
util
.
LogHandlerEntry
(
handler
,
r
)
...
...
pkg/util/kubernetes.go
View file @
dc91ff26
...
@@ -16,6 +16,14 @@ limitations under the License.
...
@@ -16,6 +16,14 @@ limitations under the License.
package
util
package
util
import
(
"fmt"
"log"
"net"
"os"
"strings"
)
// KubernetesConfig defines the configuration options for talking to Kubernetes master
// KubernetesConfig defines the configuration options for talking to Kubernetes master
type
KubernetesConfig
struct
{
type
KubernetesConfig
struct
{
KubePath
string
// The path to kubectl binary
KubePath
string
// The path to kubectl binary
...
@@ -56,3 +64,43 @@ type KubernetesSecret struct {
...
@@ -56,3 +64,43 @@ type KubernetesSecret struct {
Metadata
map
[
string
]
string
`json:"metadata"`
Metadata
map
[
string
]
string
`json:"metadata"`
Data
map
[
string
]
string
`json:"data,omitempty"`
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
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment