forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
openshift-node-config.go
69 lines (56 loc) · 1.75 KB
/
openshift-node-config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"math/rand"
"os"
"time"
"github.com/MakeNowJust/heredoc"
"github.com/ghodss/yaml"
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/apiserver/pkg/util/logs"
"github.com/openshift/origin/pkg/cmd/flagtypes"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
configapiv1 "github.com/openshift/origin/pkg/cmd/server/apis/config/v1"
"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 {
configapi.AddToScheme(configapi.Scheme)
configapiv1.AddToScheme(configapi.Scheme)
if len(configFile) == 0 {
return fmt.Errorf("you must specify a --config file to read")
}
nodeConfig, err := configapilatest.ReadAndResolveNodeConfig(configFile)
if err != nil {
return fmt.Errorf("unable to read node config: %v", err)
}
if err := node.FinalizeNodeConfig(nodeConfig); err != nil {
return err
}
if glog.V(2) {
out, _ := yaml.Marshal(nodeConfig)
glog.V(2).Infof("Node config:\n%s", out)
}
return node.WriteKubeletFlags(*nodeConfig)
},
SilenceUsage: true,
}
cmd.Flags().StringVar(&configFile, "config", "", "The config file to convert to Kubelet arguments.")
flagtypes.GLog(cmd.PersistentFlags())
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}