fix lint error

This commit is contained in:
HirazawaUi
2025-10-10 21:52:24 +08:00
parent d6dec0b345
commit 7b4d4f72c9
6 changed files with 18 additions and 11 deletions

View File

@@ -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)
}
}
}

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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.