Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ Example:
The Kubernetes-entrypoint will look for the configuration file `/configmaps/nova.conf/nova.conf`, template
`{{ .IP }} and {{ .HOSTNAME }}` tags and save the file as `/etc/nova/nova.conf`.

### Socket
### File
Checks whether a given file exists and container has rights to read it.
Example:

`DEPENDENCY_SOCKET=/var/run/openvswitch/ovs.socket`
`DEPENDENCY_FILE=/var/run/openvswitch/ovs.socket`

## Image

Expand Down
44 changes: 44 additions & 0 deletions dependencies/file/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package file

import (
"fmt"
"os"

entry "github.com/stackanetes/kubernetes-entrypoint/entrypoint"
"github.com/stackanetes/kubernetes-entrypoint/util/env"
)

type File struct {
name string
}

func init() {
fileEnv := fmt.Sprintf("%sFILE", entry.DependencyPrefix)
if fileDeps := env.SplitEnvToList(fileEnv); len(fileDeps) > 0 {
for _, dep := range fileDeps {
entry.Register(NewFile(dep))
}
}
}

func NewFile(name string) File {
return File{name: name}
}

func (s File) GetName() string {
return s.name
}

func (s File) IsResolved(entrypoint entry.EntrypointInterface) (bool, error) {
_, err := os.Stat(s.GetName())
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, fmt.Errorf("File %v doesn't exists", s.GetName())
}
if os.IsPermission(err) {
return false, fmt.Errorf("I have no permission to %v", s.GetName())
}
return false, err
}
5 changes: 4 additions & 1 deletion dependencies/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package socket

import (
"fmt"
"os"

entry "github.com/stackanetes/kubernetes-entrypoint/entrypoint"
"github.com/stackanetes/kubernetes-entrypoint/logger"
"github.com/stackanetes/kubernetes-entrypoint/util/env"
"os"
)

type Socket struct {
Expand All @@ -14,6 +16,7 @@ type Socket struct {
func init() {
socketEnv := fmt.Sprintf("%sSOCKET", entry.DependencyPrefix)
if socketDeps := env.SplitEnvToList(socketEnv); len(socketDeps) > 0 {
logger.Info.Printf("%sSOCKET is deprecated and will be removed in next release", entry.DependencyPrefix)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use file dependency instead of that.

for _, dep := range socketDeps {
entry.Register(NewSocket(dep))
}
Expand Down
Binary file added kubernetes-entrypoint
Binary file not shown.
2 changes: 1 addition & 1 deletion kubernetes-entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/config"
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/container"
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/daemonset"
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/file"
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/job"
_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/service"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure?

_ "github.com/stackanetes/kubernetes-entrypoint/dependencies/socket"
"github.com/stackanetes/kubernetes-entrypoint/logger"
command "github.com/stackanetes/kubernetes-entrypoint/util/command"
"github.com/stackanetes/kubernetes-entrypoint/util/env"
Expand Down