diff --git a/cmd/kubeadm/app/phases/controlplane/manifests.go b/cmd/kubeadm/app/phases/controlplane/manifests.go index bbb79d7bfe8..29556ebfd5b 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests.go @@ -154,11 +154,9 @@ func CreateStaticPodFiles(manifestDir, patchesDir string, cfg *kubeadmapi.Cluste if features.Enabled(cfg.FeatureGates, features.RootlessControlPlane) { if isDryRun { fmt.Printf("[control-plane] Would update static pod manifest for %q to run run as non-root\n", componentName) - } else { - if usersAndGroups != nil { - if err := staticpodutil.RunComponentAsNonRoot(componentName, &spec, usersAndGroups, cfg); err != nil { - return errors.Wrapf(err, "failed to run component %q as non-root", componentName) - } + } else if usersAndGroups != nil { + if err := staticpodutil.RunComponentAsNonRoot(componentName, &spec, usersAndGroups, cfg); err != nil { + return errors.Wrapf(err, "failed to run component %q as non-root", componentName) } } } diff --git a/cmd/kubeadm/app/util/staticpod/utils_linux.go b/cmd/kubeadm/app/util/staticpod/utils_linux.go index cdd371f1e74..27003c46f37 100644 --- a/cmd/kubeadm/app/util/staticpod/utils_linux.go +++ b/cmd/kubeadm/app/util/staticpod/utils_linux.go @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package staticpod contains utilities for managing the static pod. package staticpod import ( diff --git a/cmd/kubeadm/app/util/staticpod/utils_others.go b/cmd/kubeadm/app/util/staticpod/utils_others.go index c259f48b3ec..59e520d3856 100644 --- a/cmd/kubeadm/app/util/staticpod/utils_others.go +++ b/cmd/kubeadm/app/util/staticpod/utils_others.go @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package staticpod contains utilities for managing the static pod. package staticpod import ( diff --git a/cmd/kubeadm/app/util/users/users_linux.go b/cmd/kubeadm/app/util/users/users_linux.go index 09308f98d83..8c70bffbd9b 100644 --- a/cmd/kubeadm/app/util/users/users_linux.go +++ b/cmd/kubeadm/app/util/users/users_linux.go @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package users contains utilities for managing the users. package users import ( @@ -238,12 +239,17 @@ func addUsersAndGroupsImpl(pathLoginDef, pathUsers, pathGroups string) (*UsersAn } // Prepare the maps of users and groups. - usersConcat := append(users, usersToCreate...) + var usersConcat []*entry + usersConcat = append(usersConcat, users...) + usersConcat = append(usersConcat, usersToCreate...) mapUsers, err := entriesToEntryMap(usersConcat, usersToCreateSpec) if err != nil { return nil, err } - groupsConcat := append(groups, groupsToCreate...) + + var groupsConcat []*entry + groupsConcat = append(groupsConcat, groups...) + groupsConcat = append(groupsConcat, groupsToCreate...) mapGroups, err := entriesToEntryMap(groupsConcat, groupsToCreateSpec) if err != nil { return nil, err @@ -593,15 +599,15 @@ func openFileWithLock(path string) (f *os.File, close func(), err error) { } } if err != nil { - f.Close() + _ = f.Close() return nil, nil, err } close = func() { // This function should be called once operations with the file are finished. // It unlocks the file and closes it. unlock := syscall.Flock_t{Type: syscall.F_UNLCK} - syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &unlock) - f.Close() + _ = syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &unlock) + _ = f.Close() } return f, close, nil } diff --git a/cmd/kubeadm/app/util/users/users_linux_test.go b/cmd/kubeadm/app/util/users/users_linux_test.go index e0c1368ba05..1baee04ceb9 100644 --- a/cmd/kubeadm/app/util/users/users_linux_test.go +++ b/cmd/kubeadm/app/util/users/users_linux_test.go @@ -579,7 +579,7 @@ func writeTempFile(t *testing.T, contents string) (string, func()) { t.Fatalf("could not write file: %v", err) } close := func() { - os.Remove(file.Name()) + _ = os.Remove(file.Name()) } return file.Name(), close } diff --git a/cmd/kubeadm/app/util/users/users_other.go b/cmd/kubeadm/app/util/users/users_other.go index ba79ebfbb06..6c2b51bda1f 100644 --- a/cmd/kubeadm/app/util/users/users_other.go +++ b/cmd/kubeadm/app/util/users/users_other.go @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package users contains utilities for managing the users. package users // EntryMap is empty on non-Linux.