forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
101 lines (86 loc) · 3.35 KB
/
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package kubeapiserver
import (
"io/ioutil"
"os"
"path"
"k8s.io/apimachinery/pkg/runtime"
"github.com/docker/docker/api/types"
"github.com/golang/glog"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
"github.com/openshift/origin/pkg/oc/clusterup/docker/dockerhelper"
"github.com/openshift/origin/pkg/oc/clusterup/docker/run"
"github.com/openshift/origin/pkg/oc/lib/errors"
)
const KubeAPIServerDirName = "kube-apiserver"
const OpenShiftAPIServerDirName = "openshift-apiserver"
const OpenShiftControllerManagerDirName = "openshift-controller-manager"
type KubeAPIServerStartConfig struct {
// MasterImage is the docker image for openshift start master
MasterImage string
Args []string
}
func NewKubeAPIServerStartConfig() *KubeAPIServerStartConfig {
return &KubeAPIServerStartConfig{}
}
// Start starts the OpenShift master as a Docker container
// and returns a directory in the local file system where
// the OpenShift configuration has been copied
func (opt KubeAPIServerStartConfig) MakeMasterConfig(dockerClient dockerhelper.Interface, basedir string) (string, error) {
componentName := "create-master-config"
imageRunHelper := run.NewRunHelper(dockerhelper.NewHelper(dockerClient)).New()
glog.Infof("Running %q", componentName)
createConfigCmd := []string{
"start", "master",
}
createConfigCmd = append(createConfigCmd, opt.Args...)
containerId, rc, err := imageRunHelper.Image(opt.MasterImage).
Privileged().
HostNetwork().
HostPid().
SaveContainerLogs(componentName, path.Join(basedir, "logs")).
Command(createConfigCmd...).Run()
defer func() {
if err = dockerClient.ContainerRemove(containerId, types.ContainerRemoveOptions{}); err != nil {
glog.Errorf("error removing %q: %v", containerId, err)
}
}()
if err != nil {
return "", errors.NewError("could not run %q: %v", componentName, err).WithCause(err)
}
if rc != 0 {
return "", errors.NewError("could not run %q: rc==%v", componentName, rc)
}
// TODO eliminate the linkage that other tasks have on this particular structure
masterDir := path.Join(basedir, KubeAPIServerDirName)
if err := os.MkdirAll(masterDir, 0755); err != nil {
return "", err
}
glog.V(1).Infof("Copying OpenShift config to local directory %s", masterDir)
if err = dockerhelper.DownloadDirFromContainer(dockerClient, containerId, "/var/lib/origin/openshift.local.config", masterDir); err != nil {
if removeErr := os.RemoveAll(masterDir); removeErr != nil {
glog.V(2).Infof("Error removing temporary config dir %s: %v", masterDir, removeErr)
}
return "", err
}
// update some listen information to include starting the DNS server
masterconfigFilename := path.Join(masterDir, "master-config.yaml")
originalBytes, err := ioutil.ReadFile(masterconfigFilename)
if err != nil {
return "", err
}
configObj, err := runtime.Decode(configapilatest.Codec, originalBytes)
if err != nil {
return "", err
}
masterconfig := configObj.(*configapi.MasterConfig)
masterconfig.KubernetesMasterConfig.APIServerArguments["feature-gates"] = []string{"CustomResourceSubresources=true"}
configBytes, err := runtime.Encode(configapilatest.Codec, masterconfig)
if err != nil {
return "", err
}
if err := ioutil.WriteFile(masterconfigFilename, configBytes, 0644); err != nil {
return "", err
}
return masterDir, nil
}