-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build a shim binary that converts node-config.yaml to kubelet args
Will remove the need to have the kubelet start from openshift master
- Loading branch information
1 parent
d0b8275
commit 1ef2f94
Showing
4 changed files
with
94 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/apiserver/pkg/util/logs" | ||
|
||
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest" | ||
"github.com/openshift/origin/pkg/cmd/server/origin/node" | ||
) | ||
|
||
func main() { | ||
logs.InitLogs() | ||
defer logs.FlushLogs() | ||
|
||
rand.Seed(time.Now().UTC().UnixNano()) | ||
|
||
var configFile string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "openshift-node-config", | ||
Long: heredoc.Doc(` | ||
Generate Kubelet configuration from node-config.yaml | ||
This command converts an existing OpenShift node configuration into the appropriate | ||
Kubelet command-line flags. | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
nodeConfig, err := configapilatest.ReadAndResolveNodeConfig(configFile) | ||
if err != nil { | ||
return err | ||
} | ||
return node.WriteKubeletFlags(*nodeConfig) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&configFile, "config", "", "The config file to convert to Kubelet arguments.") | ||
|
||
if err := cmd.RunE(cmd, os.Args); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
||
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" | ||
nodeoptions "github.com/openshift/origin/pkg/cmd/server/kubernetes/node/options" | ||
) | ||
|
||
// safeArgRegexp matches only characters that are known safe. DO NOT add to this list | ||
// without fully considering whether that new character can be used to break shell escaping | ||
// rules. | ||
var safeArgRegexp = regexp.MustCompile(`^[\da-zA-Z\-=_\.,/\:]+$`) | ||
|
||
// shellEscapeArg quotes an argument if it contains characters that my cause a shell | ||
// interpreter to split the single argument into multiple. | ||
func shellEscapeArg(s string) string { | ||
if safeArgRegexp.MatchString(s) { | ||
return s | ||
} | ||
return strconv.Quote(s) | ||
} | ||
|
||
// WriteKubeletFlags writes the correct set of flags to start a Kubelet from the provided node config to | ||
// stdout, instead of launching anything. | ||
func WriteKubeletFlags(nodeConfig configapi.NodeConfig) error { | ||
kubeletArgs, err := nodeoptions.ComputeKubeletFlags(nodeConfig.KubeletArguments, nodeConfig) | ||
if err != nil { | ||
return fmt.Errorf("cannot create kubelet args: %v", err) | ||
} | ||
if err := nodeoptions.CheckFlags(kubeletArgs); err != nil { | ||
return err | ||
} | ||
var outputArgs []string | ||
for _, s := range kubeletArgs { | ||
outputArgs = append(outputArgs, shellEscapeArg(s)) | ||
} | ||
fmt.Println(strings.Join(outputArgs, " ")) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters