Skip to content

Commit

Permalink
fixes local run cannot run with apiserver only
Browse files Browse the repository at this point in the history
  • Loading branch information
yue9944882 committed Nov 6, 2020
1 parent e426264 commit fe4313c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/apiserver-boot/boot/build/build_container.go
Expand Up @@ -49,7 +49,7 @@ func AddBuildContainer(cmd *cobra.Command) {

func AddBuildContainerFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&Image, "image", "", "name of the image with tag")
cmd.Flags().StringArrayVar(&buildTargets, "targets", []string{apiserverTarget, controllerTarget}, "The target binaries to build")
cmd.Flags().StringArrayVar(&BuildTargets, "targets", []string{apiserverTarget, controllerTarget}, "The target binaries to build")
}

func RunBuildContainer(cmd *cobra.Command, args []string) {
Expand Down
13 changes: 7 additions & 6 deletions cmd/apiserver-boot/boot/build/build_executables.go
Expand Up @@ -32,7 +32,7 @@ var goarch = "amd64"
var outputdir = "bin"
var Bazel bool
var Gazelle bool
var buildTargets []string
var BuildTargets []string

const (
apiserverTarget = "apiserver"
Expand Down Expand Up @@ -69,12 +69,13 @@ func AddBuildExecutables(cmd *cobra.Command) {
createBuildExecutablesCmd.Flags().StringVar(&outputdir, "output", "bin", "if set, write the binaries to this directory")
createBuildExecutablesCmd.Flags().BoolVar(&Bazel, "bazel", false, "if true, use bazel to build. May require updating build rules with gazelle.")
createBuildExecutablesCmd.Flags().BoolVar(&Gazelle, "gazelle", false, "if true, run gazelle before running bazel.")
createBuildExecutablesCmd.Flags().StringArrayVar(&buildTargets, "targets", []string{apiserverTarget, controllerTarget}, "The target binaries to build")

createBuildExecutablesCmd.Flags().MarkDeprecated("gen-unversioned-client", "using internal clients in external systems is strongly not recommended")
createBuildExecutablesCmd.Flags().StringArrayVar(&BuildTargets, "targets", []string{apiserverTarget, controllerTarget}, "The target binaries to build")
}

func RunBuildExecutables(cmd *cobra.Command, args []string) {
if err := cmd.Flags().Parse(args); err != nil {
klog.Fatal(err)
}
if Bazel {
BazelBuild(cmd, args)
} else {
Expand Down Expand Up @@ -220,7 +221,7 @@ func GoBuild(cmd *cobra.Command, args []string) {
}

func buildApiserver() bool {
for _, t := range buildTargets {
for _, t := range BuildTargets {
if t == apiserverTarget {
return true
}
Expand All @@ -229,7 +230,7 @@ func buildApiserver() bool {
}

func buildController() bool {
for _, t := range buildTargets {
for _, t := range BuildTargets {
if t == controllerTarget {
return true
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/apiserver-boot/boot/run/local.go
Expand Up @@ -34,8 +34,8 @@ import (

var localCmd = &cobra.Command{
Use: "local",
Short: "run the etcd, apiserver and controller-manager",
Long: `run the etcd, apiserver and controller-manager`,
Short: "run the etcd, apiserver and controller",
Long: `run the etcd, apiserver and controller`,
Example: `# Regenerate code and build binaries. Then run them locally.
apiserver-boot run local
Expand Down Expand Up @@ -67,7 +67,7 @@ var certDir string
var securePort int32

func AddLocal(cmd *cobra.Command) {
localCmd.Flags().StringSliceVar(&toRun, "run", []string{"etcd", "apiserver", "controller-manager"}, "path to apiserver binary to run")
localCmd.Flags().StringSliceVar(&toRun, "run", []string{"etcd", "apiserver", "controller"}, "path to apiserver binary to run")
localCmd.Flags().BoolVar(&disableMTLS, "disable-mtls", true,
`If true, disable mTLS serving in the apiserver with --standalone-debug-mode. `+
`This optional requries the apiserver to build with "WithLocalDebugExtension" from apiserver-runtime.`)
Expand All @@ -91,6 +91,7 @@ func AddLocal(cmd *cobra.Command) {

func RunLocal(cmd *cobra.Command, args []string) {
if buildBin {
build.BuildTargets = toRun
build.RunBuildExecutables(cmd, args)
}

Expand Down Expand Up @@ -119,7 +120,7 @@ func RunLocal(cmd *cobra.Command, args []string) {
}

// Start controller manager
if _, f := r["controller-manager"]; f {
if _, f := r["controller"]; f {
RunControllerManager(ctx, cancel)
}

Expand Down Expand Up @@ -266,5 +267,7 @@ users:
{{- if not .DisabltMTLS }}
client-certificate: {{ .Path }}/apiserver.crt
client-key: {{ .Path }}/apiserver.key
{{- else }}
username: apiserver
{{- end }}
`

0 comments on commit fe4313c

Please sign in to comment.