Skip to content

Commit

Permalink
Merge pull request #1314 from mowangdk/features/add_typos_check
Browse files Browse the repository at this point in the history
Add typo check
  • Loading branch information
mowangdk authored Feb 9, 2025
2 parents f80a063 + 363978d commit 3f5ab1a
Show file tree
Hide file tree
Showing 40 changed files with 140 additions and 112 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/typos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Typos GitHub Action
on: [pull_request]

jobs:
run:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/[email protected]
with:
files: ./
config: ./_typos.toml
12 changes: 12 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[files]
extend-exclude = ["vendor/*", "*.mod", "*.sum", "build/"]

[default]
binary = false


[default.extend-words]
teh = "teh"
ded = "ded"
eles = "eles"
TAGED = "TAGED"
2 changes: 1 addition & 1 deletion cmd/csi-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *FileGrpcServer) ServeOneRequest(method string) error {
func main() {
_, ok := os.LookupEnv("KUBELET_ROOT_DIR")
if !ok {
// This is nessesary to disable the check of sub-directory in NodeServerWithValidator.
// This is necessary to disable the check of sub-directory in NodeServerWithValidator.
// CSI-agent is not invoked by kubelet, so there is no usual kubelet directory structure.
utils.KubeletRootDir = "/"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/nas-dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Parameters:
>
> mode: Optional. Define the mount option in pv spec, which will be used after mount action.
>
> modeType: Optional. Default non-recursive. Define the Mode action behavior, recursive: chmod with -R and chanage all files mode under the mounted directory. non-recursive: chmod without -R and only chanage the directory mode.
> modeType: Optional. Default non-recursive. Define the Mode action behavior, recursive: chmod with -R and change all files mode under the mounted directory. non-recursive: chmod without -R and only change the directory mode.
>
> archiveOnDelete: Optional. decide how to process removal path, if reclaimPolicy defined as delete. If set 'true', the removal path will be archived and not removed really, and if set 'false', the removal path will be removed when pv is deleted.
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/queryserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (ks *QueryServer) RunQueryServer() {
// set router
klog.Infof("Started Query Server with unix socket: %s", QueryServerSocket)
http.HandleFunc("/api/v1/volumeinfo", ks.volumeInfoHandler)
// http.HandleFunc("/api/v1/podruntime", ks.podRunTimeHander)
// http.HandleFunc("/api/v1/podruntime", ks.podRunTimeHandler)
http.HandleFunc("/api/v1/ping", ks.pingHandler)

// Server Listen
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *immutableProvider) Get(key MetadataKey) (string, error) {
if err != nil {
return "", err
}
klog.V(2).InfoS("retrived metadata", "provider", p.name, "key", key, "value", v)
klog.V(2).InfoS("retrieved metadata", "provider", p.name, "key", key, "value", v)
p.values[key] = v
return v, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (endpointMockClient) ProcessCommonRequest(request *requests.CommonRequest)
},
"Endpoint": "ecs-openapi-share.cn-region-for-ut.aliyuncs.com",
"Id": "cn-region-for-ut",
"SerivceCode": "ecs",
"ServiceCode": "ecs",
"Namespace": ""
}
]
Expand Down
12 changes: 6 additions & 6 deletions pkg/disk/attachdetach_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type adSlot interface {
}

type slot interface {
Aquire(ctx context.Context) error
Acquire(ctx context.Context) error
Release()
}

Expand All @@ -63,7 +63,7 @@ type serialADSlot struct {
type serialAD_DetachSlot struct{ *serialADSlot }
type serialAD_AttachSlot struct{ *serialADSlot }

func (s serialAD_DetachSlot) Aquire(ctx context.Context) error {
func (s serialAD_DetachSlot) Acquire(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
}
Expand All @@ -77,7 +77,7 @@ func (s serialAD_DetachSlot) Aquire(ctx context.Context) error {
}
}

func (s serialAD_AttachSlot) Aquire(ctx context.Context) error {
func (s serialAD_AttachSlot) Acquire(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func newMaxConcurrentSlot(maxConcurrency int) maxConcurrentSlot {
}
}

func (s maxConcurrentSlot) Aquire(ctx context.Context) error {
func (s maxConcurrentSlot) Acquire(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
}
Expand All @@ -137,8 +137,8 @@ func (parallelSlot) Attach() slot { return noOpSlot{} }

type noOpSlot struct{}

func (noOpSlot) Aquire(ctx context.Context) error { return ctx.Err() }
func (noOpSlot) Release() {}
func (noOpSlot) Acquire(ctx context.Context) error { return ctx.Err() }
func (noOpSlot) Release() {}

type independentSlot struct {
attach slot
Expand Down
24 changes: 12 additions & 12 deletions pkg/disk/attachdetach_slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDetachPriority(t *testing.T) {
for i := 0; i < 3; i++ {
go func() {
as := s.Attach()
if err := as.Aquire(context.Background()); err != nil {
if err := as.Acquire(context.Background()); err != nil {
t.Error(err)
return
}
Expand All @@ -32,7 +32,7 @@ func TestDetachPriority(t *testing.T) {
}
time.Sleep(100 * time.Millisecond)
ds := s.Detach()
if err := ds.Aquire(context.Background()); err != nil {
if err := ds.Acquire(context.Background()); err != nil {
t.Fatal(err)
}
if seq != 1 {
Expand Down Expand Up @@ -70,10 +70,10 @@ func TestCancelWaiting(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
errs := make(chan error)
go func() {
errs <- s.Detach().Aquire(ctx)
errs <- s.Detach().Acquire(ctx)
}()
go func() {
errs <- s.Attach().Aquire(ctx)
errs <- s.Attach().Acquire(ctx)
}()
time.Sleep(100 * time.Millisecond) // ensure we enter waiting state
cancel()
Expand All @@ -90,7 +90,7 @@ func TestCancelWaiting(t *testing.T) {
}
t.Run("serial", func(t *testing.T) {
s := NewSlots(1, 1).GetSlotFor("node1")
err := s.Detach().Aquire(context.Background()) // occupy the slot
err := s.Detach().Acquire(context.Background()) // occupy the slot
assert.NoError(t, err)
testSlot(t, s)
})
Expand All @@ -99,8 +99,8 @@ func TestCancelWaiting(t *testing.T) {
attach: newMaxConcurrentSlot(1),
detach: newMaxConcurrentSlot(1),
}
assert.NoError(t, s.attach.Aquire(context.Background()))
assert.NoError(t, s.detach.Aquire(context.Background()))
assert.NoError(t, s.attach.Acquire(context.Background()))
assert.NoError(t, s.detach.Acquire(context.Background()))
testSlot(t, s)
})
}
Expand All @@ -111,10 +111,10 @@ func TestCancelNoOccupy(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()

if err := s.Detach().Aquire(ctx); err != context.Canceled {
if err := s.Detach().Acquire(ctx); err != context.Canceled {
t.Fatalf("Expected context.Canceled, got %v", err)
}
if err := s.Attach().Aquire(ctx); err != context.Canceled {
if err := s.Attach().Acquire(ctx); err != context.Canceled {
t.Fatalf("Expected context.Canceled, got %v", err)
}
}
Expand All @@ -135,14 +135,14 @@ func TestSerialDetach(t *testing.T) {

ctx := context.Background()
as := s.Attach()
err := as.Aquire(ctx)
err := as.Acquire(ctx)
if err != nil {
t.Fatal(err)
}

// Attach should not block detach
ds := s.Detach()
err = ds.Aquire(ctx)
err = ds.Acquire(ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -160,7 +160,7 @@ func TestSerialDetach_NoRace(t *testing.T) {
state := -1
for i := 0; i < 2; i++ {
go func(i int) {
s.Aquire(ctx)
s.Acquire(ctx)
state = i
s.Release()
wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion pkg/disk/batcher/low_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type LowLatency[T any] struct {
// The average interval of outgoing batched request traffic is also perRequest, allowing some burst.
//
// If the batch is fully filled, the request is issued immediately, skipping any remaining wait period, and is not limited by perRequest.
// Concurrent outgoing requests are possible if there are too many incomming requests.
// Concurrent outgoing requests are possible if there are too many incoming requests.
func NewLowLatency[T any](ecsClient desc.Client[T], clk clock.WithTicker, perRequest time.Duration, burst int) *LowLatency[T] {
return &LowLatency[T]{
ecsClient: ecsClient,
Expand Down
12 changes: 6 additions & 6 deletions pkg/disk/bdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func FindLines(reader io.Reader, keyword string) []string {
return matched
}

// IsNoSuchDeviceErr nd device error
// IsNoSuchDeviceErr and device error
func IsNoSuchDeviceErr(err error) bool {
if err == nil {
return false
Expand Down Expand Up @@ -248,7 +248,7 @@ func bindBdfDisk(diskID string) (bdf string, err error) {
data, err := os.Readlink(sysPrefix + "/sys/bus/pci/devices/" + bdf + "/driver")
if err != nil {
klog.Errorf("bindBdfDisk: Disk %s bdf %s Readlink with error: %v", diskID, bdf, err)
return bdf, errors.Wrapf(err, "read disk dirver, diskId=%s, bdf=%s", diskID, bdf)
return bdf, errors.Wrapf(err, "read disk driver, diskId=%s, bdf=%s", diskID, bdf)
}
driver := filepath.Base(data)
klog.Infof("bindBdfDisk: Disk %s bdf %s, kernel driver in use: %s", diskID, bdf, driver)
Expand Down Expand Up @@ -524,7 +524,7 @@ func (_type MachineType) BusRegex() (*regexp.Regexp, error) {
}

type Driver interface {
CurentDriver() (string, error)
CurrentDriver() (string, error)
UnbindDriver() error
BindDriver(targetDriver string) error
GetDeviceNumber() string
Expand Down Expand Up @@ -591,7 +591,7 @@ func NewDeviceDriver(volumeId, blockDevice, deviceNumber string, _type MachineTy
for _, pciDriver := range []string{"--nvme", "--blk"} {
output, err := utils.CommandOnNode("xdragon-bdf", pciDriver, fmt.Sprintf("--id=%s", volumeId)).CombinedOutput()
if err != nil {
klog.ErrorS(err, "Failed to excute xdragon-bdf command", "volumeId", volumeId, "output", output)
klog.ErrorS(err, "Failed to execute xdragon-bdf command", "volumeId", volumeId, "output", output)
continue
}
bdf := strings.TrimSpace(string(output))
Expand All @@ -618,10 +618,10 @@ func (d *driver) GetDeviceNumber() string {
return d.deviceNumber
}

func (d *driver) CurentDriver() (string, error) {
func (d *driver) CurrentDriver() (string, error) {
data, err := os.Readlink(filepath.Join(sysPrefix, "sys/bus/", d.machineType.BusName(), "devices", d.deviceNumber, "driver"))
if err != nil {
klog.Errorf("CurentDriver: read symlink err: %v", err)
klog.Errorf("CurrentDriver: read symlink err: %v", err)
return "", err
}
driver := filepath.Base(data)
Expand Down
2 changes: 1 addition & 1 deletion pkg/disk/bdfcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func getDiskUnUsedAndAddTag() ([]string, error) {

// there are unUsedDevices in host;
diskIDList, err := addDiskBdfTag(stillUnusedDevices)
return stillUnusedDevices, fmt.Errorf("UnUsedDisks: %v, Udpate Tags: %v", diskIDList, err)
return stillUnusedDevices, fmt.Errorf("UnUsedDisks: %v, Update Tags: %v", diskIDList, err)
}

// get device mounted as filesystem or block volume
Expand Down
12 changes: 6 additions & 6 deletions pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
}

slot := ad.slots.GetSlotFor(nodeID).Attach()
if err := slot.Aquire(ctx); err != nil {
if err := slot.Acquire(ctx); err != nil {
return "", status.Errorf(codes.Aborted, "AttachDisk: get ad-slot for disk %s failed: %v", diskID, err)
}
defer slot.Release()
Expand Down Expand Up @@ -405,7 +405,7 @@ func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Clien
}
// NodeStageVolume/NodeUnstageVolume should be called by sequence
slot := ad.slots.GetSlotFor(nodeID).Detach()
if err := slot.Aquire(ctx); err != nil {
if err := slot.Acquire(ctx); err != nil {
return status.Errorf(codes.Aborted, "DetachDisk: get ad-slot for disk %s failed: %v", diskID, err)
}
defer slot.Release()
Expand Down Expand Up @@ -905,12 +905,12 @@ func clientToken(name string) string {
return "h:" + base64.RawStdEncoding.EncodeToString(hash.Sum(nil))
}

var vaildDiskNameRegexp = regexp.MustCompile(`^\pL[\pL0-9:_.-]{1,127}$`)
var validDiskNameRegexp = regexp.MustCompile(`^\pL[\pL0-9:_.-]{1,127}$`)

// https://help.aliyun.com/zh/ecs/developer-reference/api-ecs-2014-05-26-createdisk
// 长度为 2~128 个字符,支持 Unicode 中 letter 分类下的字符(其中包括英文、中文等),ASCII 数字(0-9)。可以包含半角冒号(:)、下划线(_)、半角句号(.)或者短划线(-)。必须以 Unicode 中 letter 分类下的字符开头。
func isValidDiskName(name string) bool {
return vaildDiskNameRegexp.MatchString(name)
return validDiskNameRegexp.MatchString(name)
}

// https://help.aliyun.com/zh/ecs/developer-reference/api-ecs-2014-05-26-createsnapshot
Expand All @@ -921,7 +921,7 @@ func isValidSnapshotName(name string) bool {
if strings.HasPrefix(name, "auto") {
return false
}
return vaildDiskNameRegexp.MatchString(name)
return validDiskNameRegexp.MatchString(name)
}

func createDisk(ecsClient cloud.ECSInterface, diskName, snapshotID string, diskVol *diskVolumeArgs, supportedTypes sets.Set[Category], selectedInstance string) (string, createAttempt, error) {
Expand Down Expand Up @@ -1084,7 +1084,7 @@ func createDiskAttempt(req *ecs.CreateDiskRequest, attempt createAttempt, ecsCli
type createAttempt struct {
Category Category
PerformanceLevel PerformanceLevel
// Instance is the ECS instance ID choosed. Only populated if Category.SingleInstance is true
// Instance is the ECS instance ID chosen. Only populated if Category.SingleInstance is true
Instance string
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/disk/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func TestCreateDisk_ParameterMismatch(t *testing.T) {
}
}

func TestCreateDisk_NoInfinitLoop(t *testing.T) {
func TestCreateDisk_NoInfiniteLoop(t *testing.T) {
ctrl := gomock.NewController(t)
client := cloud.NewMockECSInterface(ctrl)

Expand Down
4 changes: 2 additions & 2 deletions pkg/disk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ const (
kubeNodeName = "KUBE_NODE_NAME"
// describeResourceType ...
describeResourceType = "DataDisk"
// NodeSchedueTag in annotations
NodeSchedueTag = "volume.kubernetes.io/selected-node"
// NodeScheduleTag in annotations
NodeScheduleTag = "volume.kubernetes.io/selected-node"
// RetryMaxTimes ...
RetryMaxTimes = 5

Expand Down
6 changes: 3 additions & 3 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
newErrMsg := utils.FindSuggestionByErrorMessage(err.Error(), utils.DiskDelete)
errMsg := fmt.Sprintf("DeleteVolume: Delete disk with error: %s", newErrMsg)
if response != nil {
errMsg = fmt.Sprintf("DeleteVolume: Delete disk with error: %s, with RequstId: %s", newErrMsg, response.RequestId)
errMsg = fmt.Sprintf("DeleteVolume: Delete disk with error: %s, with RequestId: %s", newErrMsg, response.RequestId)
}
klog.Warningf(errMsg)
if strings.Contains(err.Error(), DiskCreatingSnapshot) || strings.Contains(err.Error(), IncorrectDiskStatus) {
Expand Down Expand Up @@ -442,7 +442,7 @@ func getVolumeSnapshotConfig(req *csi.CreateSnapshotRequest) (*createSnapshotPar

vsName := req.Parameters[common.VolumeSnapshotNameKey]
vsNameSpace := req.Parameters[common.VolumeSnapshotNamespaceKey]
// volumesnapshot not in parameters, just retrun
// volumesnapshot not in parameters, just return
if vsName == "" || vsNameSpace == "" {
return &ecsParams, nil
}
Expand Down Expand Up @@ -601,7 +601,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS

func snapshotBeforeDelete(disk *ecs.Disk, ecsClient *ecs.Client) error {
if !AllCategories[Category(disk.Category)].InstantAccessSnapshot {
klog.Infof("snapshotBeforeDelete: Instant Access snapshot required, but current disk.Catagory is: %s", disk.Category)
klog.Infof("snapshotBeforeDelete: Instant Access snapshot required, but current disk.Category is: %s", disk.Category)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/disk/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type DeviceManager struct {
// Disable read serial from sysfs
DisableSerial bool

// Support sole alreadly formatted disk partition
// Support sole already formatted disk partition
EnableDiskPartition bool
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func (m *DeviceManager) WriteSysfs(devicePath, name string, value []byte) error
fileName := filepath.Clean(base + name)
if !strings.HasPrefix(fileName, base) {
// Note this cannot prevent user from accessing other devices through e.g. /sys/block/vda/subsystem/vdb
// But we cannot restrict symlink either because names like `bdi/read_ahead_kb` may be vaild, in which `bdi` is a symlink.
// But we cannot restrict symlink either because names like `bdi/read_ahead_kb` may be valid, in which `bdi` is a symlink.
// Just reject obvious attacks like '../../../root/.ssh/id_rsa'.
return fmt.Errorf("invalid relative path in sysConfig: %s", name)
}
Expand Down
Loading

0 comments on commit 3f5ab1a

Please sign in to comment.