Skip to content
Permalink
Browse files

log error during kubelet startup when restoring /etc with projects fa…

…il and check if project needs to be written to /etc in case it is persisted
  • Loading branch information...
irajdeep committed Sep 11, 2019
1 parent 4807ae6 commit 995277837a1883a7ad36300d80dbbf1753e9f566
Showing with 27 additions and 7 deletions.
  1. +5 −1 pkg/kubelet/kubelet.go
  2. +22 −6 pkg/volume/util/fsquota/quota_linux.go
@@ -1457,7 +1457,11 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) {
if vol.Name != "" && vol.VolumeSource.EmptyDir != nil {
podVolumeDir := kl.getPodVolumeDir(pod.UID, utilstrings.EscapeQualifiedName("kubernetes.io/empty-dir"), pod.Spec.Hostname)
if podVolumeDir != "" {
fsquota.RecordProjectIDOnProjectFiles(podVolumeDir)
if err := fsquota.RecordProjectIDOnProjectFiles(podVolumeDir); err != nil {
// just log the error and continue , nothing much can be done about it
klog.Errorf("failed to records projects in /etc/project files on kubelet startup: %v", err)
}

}
}
}
@@ -447,13 +447,29 @@ func RecordProjectIDOnProjectFiles(podVolumeDir string) error {
if err != nil {
defer closeProjectFiles(fProjects, fProjid)
list := readProjectFiles(fProjects, fProjid)
writeProjid := true
_, writeProjid, err = addDirToProject(podVolumeDir, id, &list)
if err == nil {
if err = writeProjectFiles(fProjects, fProjid, writeProjid, list); err == nil {
return nil
projectList := list.projects
projectIDList := list.projid
foundInProjectList, foundInProjectIDList := false, false

for _, project := range projectList {
if project.id == id && project.data == podVolumeDir {
foundInProjectList = true
break
}
}

for _, projectid := range projectIDList {
if projectid.id == id {
foundInProjectIDList = true
break
}
}
// write to /etc/project and /etc/projid only if the corresponding entry is not found in both project and projectid
// if one of them is true and other is not should it be a no-op? (does it imply corrupted /etc file)
if !foundInProjectIDList && !foundInProjectList {
if _, err = createProjectID(podVolumeDir, id); err != nil {
return fmt.Errorf("unable to get QuotaID from directory path:%s: %v", podVolumeDir, err)
}
return err
}
}
return err

0 comments on commit 9952778

Please sign in to comment.
You can’t perform that action at this time.