Changes due to DTadrzak review
This commit is contained in:
parent
af0672d339
commit
273433cdba
14
dependencies/config/config.go
vendored
14
dependencies/config/config.go
vendored
@ -8,7 +8,6 @@ import (
|
||||
"text/template"
|
||||
|
||||
entry "github.com/stackanetes/kubernetes-entrypoint/entrypoint"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/logger"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/util"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/util/env"
|
||||
)
|
||||
@ -36,14 +35,12 @@ func init() {
|
||||
func NewConfig(name string) Config {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
logger.Error.Printf("Cannot determine hostname: %v", err)
|
||||
os.Exit(1)
|
||||
panic(fmt.Sprintf("Cannot determine hostname: %v", err))
|
||||
}
|
||||
|
||||
ip, err := util.GetIp()
|
||||
if err != nil {
|
||||
logger.Error.Printf("Cannot get ip address: %v", err)
|
||||
os.Exit(1)
|
||||
panic(fmt.Sprintf("Cannot get ip address: %v", err))
|
||||
}
|
||||
|
||||
return Config{
|
||||
@ -56,13 +53,12 @@ func NewConfig(name string) Config {
|
||||
}
|
||||
|
||||
func (c Config) IsResolved(entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
var err error
|
||||
//Create directory to ensure it exists
|
||||
err := createDirectory(c.GetName())
|
||||
if err != nil {
|
||||
if err = createDirectory(c.GetName()); err != nil {
|
||||
return false, fmt.Errorf("Couldn't create directory: %v", err)
|
||||
}
|
||||
err = createAndTemplateConfig(c.GetName(), c.params)
|
||||
if err != nil {
|
||||
if err = createAndTemplateConfig(c.GetName(), c.params); err != nil {
|
||||
return false, fmt.Errorf("Cannot template %s: %v", c.GetName(), err)
|
||||
}
|
||||
return true, nil
|
||||
|
17
dependencies/daemonset/daemonset.go
vendored
17
dependencies/daemonset/daemonset.go
vendored
@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
|
||||
entry "github.com/stackanetes/kubernetes-entrypoint/entrypoint"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/logger"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/util/env"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
@ -19,36 +18,34 @@ func init() {
|
||||
daemonsetEnv := fmt.Sprintf("%sDAEMONSET", entry.DependencyPrefix)
|
||||
if daemonsetsDeps := env.SplitEnvToList(daemonsetEnv); daemonsetsDeps != nil {
|
||||
for _, dep := range daemonsetsDeps {
|
||||
entry.Register(NewDaemonSet(dep))
|
||||
entry.Register(NewDaemonset(dep))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewDaemonSet(name string) Daemonset {
|
||||
func NewDaemonset(name string) Daemonset {
|
||||
return Daemonset{name: name}
|
||||
}
|
||||
|
||||
func (d Daemonset) IsResolved(entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
var myPodName string
|
||||
daemonset, err := entrypoint.Client().DaemonSets(entrypoint.GetNamespace()).Get(d.GetName())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
label := labels.SelectorFromSet(daemonset.Spec.Selector.MatchLabels)
|
||||
opts := api.ListOptions{LabelSelector: label}
|
||||
pods, err := entrypoint.Client().Pods(entrypoint.GetNamespace()).List(opts)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
myPodName := os.Getenv("POD_NAME")
|
||||
if myPodName == "" {
|
||||
logger.Error.Print("Environment variable POD_NAME not set")
|
||||
os.Exit(1)
|
||||
|
||||
if myPodName := os.Getenv("POD_NAME"); myPodName == "" {
|
||||
panic("Environment variable POD_NAME not set")
|
||||
}
|
||||
myPod, err := entrypoint.Client().Pods(entrypoint.GetNamespace()).Get(myPodName)
|
||||
if err != nil {
|
||||
logger.Error.Printf("Getting POD: %v failed : %v", myPodName, err)
|
||||
os.Exit(1)
|
||||
panic(fmt.Sprintf("Getting POD: %v failed : %v", myPodName, err))
|
||||
}
|
||||
myHost := myPod.Status.HostIP
|
||||
|
||||
|
@ -22,7 +22,7 @@ type EntrypointInterface interface {
|
||||
GetNamespace() string
|
||||
}
|
||||
|
||||
// Entrypoint is a main struct which check dependencies
|
||||
// Entrypoint is a main struct which checks dependencies
|
||||
type Entrypoint struct {
|
||||
client cli.ClientInterface
|
||||
namespace string
|
||||
@ -51,7 +51,7 @@ func (e Entrypoint) GetNamespace() string {
|
||||
return e.namespace
|
||||
}
|
||||
|
||||
//Resolve is a main loop whic iterates through all dependencies and resolves them
|
||||
//Resolve is a main loop which iterates through all dependencies and resolves them
|
||||
func (e Entrypoint) Resolve() {
|
||||
var wg sync.WaitGroup
|
||||
for _, dep := range dependencies {
|
||||
@ -81,7 +81,7 @@ type Resolver interface {
|
||||
GetName() string
|
||||
}
|
||||
|
||||
//Register is a function which register new dependencies
|
||||
//Register is a function which registers new dependencies
|
||||
func Register(res Resolver) {
|
||||
if res == nil {
|
||||
panic("Entrypoint: could not register nil Resolver")
|
||||
|
@ -34,8 +34,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
err = command.Execute(comm)
|
||||
if err != nil {
|
||||
if err = command.Execute(comm); err != nil {
|
||||
logger.Error.Printf("Cannot execute command: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func GetIp() (ip string, err error) {
|
||||
iface := os.Getenv("INTERFACE_NAME")
|
||||
if iface == "" {
|
||||
var iface string
|
||||
if iface = os.Getenv("INTERFACE_NAME"); iface == "" {
|
||||
return "", fmt.Errorf("Environment variable INTERFACE_NAME not set")
|
||||
}
|
||||
i, err := net.InterfaceByName(iface)
|
||||
|
Loading…
Reference in New Issue
Block a user