Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster/images/hyperkube: create symlink for each server #24511

Merged
merged 2 commits into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions cluster/images/hyperkube/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ RUN chmod a+rx \
/usr/share/google/safe_format_and_mount \
/setup-files.sh \
/make-ca-cert.sh

# Create symlinks for each hyperkube server
RUN /hyperkube --make-symlinks
43 changes: 38 additions & 5 deletions cmd/hyperkube/hyperkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ type HyperKube struct {
Name string // The executable name, used for help and soft-link invocation
Long string // A long description of the binary. It will be world wrapped before output.

servers []Server
baseFlags *pflag.FlagSet
out io.Writer
helpFlagVal bool
servers []Server
baseFlags *pflag.FlagSet
out io.Writer
helpFlagVal bool
makeSymlinksFlagVal bool
}

// AddServer adds a server to the HyperKube object.
Expand Down Expand Up @@ -75,6 +76,8 @@ func (hk *HyperKube) Flags() *pflag.FlagSet {
hk.baseFlags.SetOutput(ioutil.Discard)
hk.baseFlags.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
hk.baseFlags.BoolVarP(&hk.helpFlagVal, "help", "h", false, "help for "+hk.Name)
hk.baseFlags.BoolVar(&hk.makeSymlinksFlagVal, "make-symlinks", false, "create a symlink for each server in current directory")
hk.baseFlags.MarkHidden("make-symlinks") // hide this flag from appearing in servers' usage output

// These will add all of the "global" flags (defined with both the
// flag and pflag packages) to the new flag set we have.
Expand Down Expand Up @@ -117,7 +120,8 @@ func (hk *HyperKube) Printf(format string, i ...interface{}) {
func (hk *HyperKube) Run(args []string) error {
// If we are called directly, parse all flags up to the first real
// argument. That should be the server to run.
baseCommand := path.Base(args[0])
command := args[0]
baseCommand := path.Base(command)
serverName := baseCommand
if serverName == hk.Name {
args = args[1:]
Expand All @@ -133,6 +137,10 @@ func (hk *HyperKube) Run(args []string) error {
return err
}

if hk.makeSymlinksFlagVal {
return hk.MakeSymlinks(command)
}

verflag.PrintAndExitIfRequested()

args = baseFlags.Args()
Expand Down Expand Up @@ -200,7 +208,32 @@ Servers
{{range .Servers}}
{{.Name}}
{{.Long | trim | wrap " "}}{{end}}
Call '{{.Name}} --make-symlinks' to create symlinks for each server in the local directory.
Call '{{.Name}} <server> --help' for help on a specific server.
`
util.ExecuteTemplate(hk.Out(), tt, hk)
}

// MakeSymlinks will create a symlink for each registered hyperkube server in the local directory.
func (hk *HyperKube) MakeSymlinks(command string) error {
wd, err := os.Getwd()
if err != nil {
return err
}

var errs bool
for _, s := range hk.servers {
link := path.Join(wd, s.Name())

err := os.Symlink(command, link)
if err != nil {
errs = true
hk.Println(err)
}
}

if errs {
return errors.New("Error creating one or more symlinks.")
}
return nil
}
1 change: 1 addition & 0 deletions hack/verify-flags/known-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ lock-file
log-flush-frequency
long-running-request-regexp
low-diskspace-threshold-mb
make-symlinks
manifest-url
manifest-url-header
masquerade-all
Expand Down