Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #137 from suhanime/hybridOverlayLogs
Browse files Browse the repository at this point in the history
[wmcb] Redirect kubelet log to log directory
  • Loading branch information
openshift-merge-robot authored Jan 31, 2020
2 parents d160e14 + cb3918b commit d0f8ddb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 12 additions & 1 deletion pkg/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type winNodeBootstrapper struct {
svcMgr *mgr.Mgr
// installDir is the directory the the kubelet service will be installed
installDir string
// logDir is the directory that captures log outputs of Kubelet
// TODO: make this directory available in Artifacts
logDir string
// kubeletArgs is a map of the variable arguments that will be passed to the kubelet
kubeletArgs map[string]string
// cni holds all the CNI specific information
Expand Down Expand Up @@ -163,6 +166,7 @@ func NewWinNodeBootstrapper(k8sInstallDir, ignitionFile, kubeletPath string, cni
kubeletConfPath: filepath.Join(k8sInstallDir, "kubelet.conf"),
ignitionFilePath: ignitionFile,
installDir: k8sInstallDir,
logDir: filepath.Join(k8sInstallDir, "log"),
initialKubeletPath: kubeletPath,
svcMgr: svcMgr,
kubeletArgs: make(map[string]string),
Expand Down Expand Up @@ -376,6 +380,13 @@ func (wmcb *winNodeBootstrapper) initializeKubeletFiles() error {
return fmt.Errorf("could not copy kubelet: %s", err)
}
}

// Create log directory
err = os.MkdirAll(wmcb.logDir, os.ModeDir)
if err != nil {
return fmt.Errorf("could not make %s directory: %v", wmcb.logDir, err)
}

// Populate destination directory with the files we need
if wmcb.ignitionFilePath != "" {
ignitionFileContents, err := ioutil.ReadFile(wmcb.ignitionFilePath)
Expand Down Expand Up @@ -406,7 +417,7 @@ func (wmcb *winNodeBootstrapper) createKubeletService() error {
"--cert-dir=" + certDirectory,
"--windows-service",
"--logtostderr=false",
"--log-file=" + filepath.Join(wmcb.installDir, "kubelet.log"),
"--log-file=" + filepath.Join(wmcb.logDir, "kubelet.log"),
// Registers the Kubelet with Windows specific taints so that linux pods won't get scheduled onto
// Windows nodes.
// TODO: Write a `against the cluster` e2e test which checks for the Windows node object created
Expand Down
12 changes: 8 additions & 4 deletions pkg/bootstrapper/bootstrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func testCNIUpdateKubeletArgs(t *testing.T) {
kubeletCmd := "c:\\k\\kubelet.exe --config=c:\\k\\kubelet.conf" +
"--bootstrap-kubeconfig=c:\\k\\bootstrap-kubeconfig --kubeconfig=c:\\k\\kubeconfig " +
"--pod-infra-container-image=mcr.microsoft.com/k8s/core/pause:1.2.0 --cert-dir=c:/var/lib/kubelet/pki/ " +
"--windows-service --logtostderr=false --log-file=c:\\k\\kubelet.log " +
"--windows-service --logtostderr=false --log-file=c:\\k\\log\\kubelet.log " +
"--register-with-taints=os=Windows:NoSchedule --cloud-provider=aws --v=3"

err := cniTest.cni.updateKubeletArgs(&kubeletCmd)
Expand All @@ -528,7 +528,7 @@ func testCNIUpdateKubeletArgs(t *testing.T) {
kubeletCmd := "c:\\k\\kubelet.exe --config=c:\\k\\kubelet.conf" +
"--bootstrap-kubeconfig=c:\\k\\bootstrap-kubeconfig --kubeconfig=c:\\k\\kubeconfig " +
"--pod-infra-container-image=mcr.microsoft.com/k8s/core/pause:1.2.0 --cert-dir=c:/var/lib/kubelet/pki/ " +
"--windows-service --logtostderr=false --log-file=c:\\k\\kubelet.log " +
"--windows-service --logtostderr=false --log-file=c:\\k\\log\\kubelet.log " +
"--register-with-taints=os=Windows:NoSchedule --cloud-provider=aws --v=3 " +
"--resolv-conf=d:\\k\\etc\\resolv.conf--network-plugin=xyz --cni-bin-dir=d:\\k\\cni " +
"--cni-conf-dir=d:\\k\\cni\\config\\cni.conf"
Expand All @@ -552,20 +552,24 @@ func testCNIUpdateKubeletArgs(t *testing.T) {
})
}

// TestPodManifestDirCreation tests if the pod manifest directory was created
func TestPodManifestDirCreation(t *testing.T) {
// TestKubeletDirectoriesCreation tests if the directories needed for Kubelet are initialized as required
func TestKubeletDirectoriesCreation(t *testing.T) {
// Create a temp directory with wmcb prefix
dir, err := ioutil.TempDir("", "wmcb")
require.NoError(t, err, "error creating temp directory")
// Ignore the return error as there is not much we can do if the temporary directory is not deleted
defer os.RemoveAll(dir)
// podManifestDirectory which has to be created by wmcb.
podManifestDirectory := filepath.Join(dir, "etc", "kubernetes", "manifests")
// logDirectory which has to be created by wmcb
logDirectory := filepath.Join(dir, "log")
wnb := winNodeBootstrapper{
installDir: dir,
logDir: logDirectory,
kubeletArgs: make(map[string]string),
}
err = wnb.initializeKubeletFiles()
assert.NoError(t, err, "error initializing kubelet files")
assert.DirExists(t, podManifestDirectory, "pod manifest directory was not created")
assert.DirExists(t, logDirectory, "log directory was not created")
}
Loading

0 comments on commit d0f8ddb

Please sign in to comment.