Skip to content

Commit c97992e

Browse files
authored
Merge pull request #41 from jingxu97/Mar/log
Add logs
2 parents e9a8b04 + 479fa06 commit c97992e

File tree

10 files changed

+97
-43
lines changed

10 files changed

+97
-43
lines changed

cmd/csi-proxy/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func main() {
3131
panic(err)
3232
}
3333
s := server.NewServer(apiGroups...)
34+
35+
klog.Info("Starting CSI-Proxy Server ...")
36+
klog.Infof("Version: %s", version)
3437
if err := s.Start(nil); err != nil {
3538
panic(err)
3639
}

cmd/csi-proxy/version.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package main
15+
16+
var (
17+
version string = "Unknown"
18+
)

internal/os/disk/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (APIImplementor) ListDiskLocations() (map[string]shared.DiskLocation, error
2626
cmd := fmt.Sprintf("Get-Disk | select number, location | ConvertTo-Json")
2727
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
2828
if err != nil {
29-
return nil, err
29+
return nil, fmt.Errorf("failed to list disk location. cmd: %q, output: %q, err %v", cmd, string(out), err)
3030
}
3131

3232
var getDisk []map[string]interface{}
@@ -72,9 +72,9 @@ func (APIImplementor) ListDiskLocations() (map[string]shared.DiskLocation, error
7272

7373
func (APIImplementor) Rescan() error {
7474
cmd := "Update-HostStorageCache"
75-
_, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
75+
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
7676
if err != nil {
77-
return fmt.Errorf("error updating host storage cache %v", err)
77+
return fmt.Errorf("error updating host storage cache output: %q, err: %v", string(out), err)
7878
}
7979
return nil
8080
}
@@ -127,7 +127,7 @@ func (APIImplementor) GetDiskNumberByName(diskName string) (string, error) {
127127
out, err := exec.Command("DiskUtil.exe", "-GetDiskNumberWithId", diskName).CombinedOutput()
128128
outString := string(out)
129129
if err != nil {
130-
return "", fmt.Errorf("error getting disk number. %v, output %v", err, out)
130+
return "", fmt.Errorf("error getting disk number by name %s: %v, output %v", diskName, err, out)
131131
}
132132
return strings.TrimSpace(outString), nil
133133
}

internal/os/smb/api.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"os"
66
"os/exec"
77
"strings"
8-
9-
"k8s.io/klog"
108
)
119

1210
type APIImplementor struct{}
@@ -23,7 +21,7 @@ func (APIImplementor) IsSmbMapped(remotePath string) (bool, error) {
2321

2422
out, err := cmd.CombinedOutput()
2523
if err != nil {
26-
return false, fmt.Errorf("error checking smb mapping %s, err: %v", remotePath, err)
24+
return false, fmt.Errorf("error checking smb mapping. cmd %s, output: %s, err: %v", remotePath, string(out), err)
2725
}
2826

2927
if len(out) == 0 || !strings.EqualFold(strings.TrimSpace(string(out)), "OK") {
@@ -46,17 +44,15 @@ func (APIImplementor) NewSmbLink(remotePath, localPath string) error {
4644
fmt.Sprintf("smbremotepath=%s", remotePath),
4745
fmt.Sprintf("smblocalpath=%s", localPath),
4846
)
49-
_, err := cmd.CombinedOutput()
47+
output, err := cmd.CombinedOutput()
5048
if err != nil {
51-
return fmt.Errorf("error linking %s to %s, err: %v", remotePath, localPath, err)
49+
return fmt.Errorf("error linking %s to %s. output: %s, err: %v", remotePath, localPath, string(output), err)
5250
}
5351

5452
return nil
5553
}
5654

5755
func (APIImplementor) NewSmbGlobalMapping(remotePath, username, password string) error {
58-
klog.V(4).Infof("NewSmbGlobalMapping: remotePath:%q", remotePath)
59-
6056
// use PowerShell Environment Variables to store user input string to prevent command line injection
6157
// https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-5.1
6258
cmdLine := fmt.Sprintf(`$PWord = ConvertTo-SecureString -String $Env:smbpassword -AsPlainText -Force` +
@@ -69,18 +65,16 @@ func (APIImplementor) NewSmbGlobalMapping(remotePath, username, password string)
6965
fmt.Sprintf("smbpassword=%s", password),
7066
fmt.Sprintf("smbremotepath=%s", remotePath))
7167
if output, err := cmd.CombinedOutput(); err != nil {
72-
return fmt.Errorf("NewSmbGlobalMapping failed: %v, output: %q", err, string(output))
68+
return fmt.Errorf("NewSmbGlobalMapping failed. output: %q, err: %v", string(output), err)
7369
}
7470
return nil
7571
}
7672

7773
func (APIImplementor) RemoveSmbGlobalMapping(remotePath string) error {
78-
klog.V(4).Infof("RemoveSmbGlobalMapping remotePath (%q)", remotePath)
7974
cmd := exec.Command("powershell", "/c", `Remove-SmbGlobalMapping -RemotePath $Env:smbremotepath -Force`)
8075
cmd.Env = append(os.Environ(), fmt.Sprintf("smbremotepath=%s", remotePath))
8176
if output, err := cmd.CombinedOutput(); err != nil {
82-
klog.Errorf("Remove-SmbGlobalMapping failed: %v, output: %q", err, output)
83-
return fmt.Errorf("UnmountSmbShare failed: %v, output: %q", err, output)
77+
return fmt.Errorf("UnmountSmbShare failed. output: %q, err: %v", string(output), err)
8478
}
8579
return nil
8680
}

internal/os/volume/api.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"os/exec"
66
"strings"
7-
8-
"k8s.io/klog"
97
)
108

119
const formatFilesystem = "ntfs"
@@ -19,9 +17,7 @@ func New() VolAPIImplementor {
1917
}
2018

2119
func runExec(cmd string) ([]byte, error) {
22-
klog.V(5).Infof("Running command: %s", cmd)
2320
out, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
24-
klog.V(5).Infof("Result: %s. Len: %d. Error: %v.", string(out), len(string(out)), err)
2521
return out, err
2622
}
2723

@@ -30,7 +26,7 @@ func (VolAPIImplementor) ListVolumesOnDisk(diskID string) (volumeIDs []string, e
3026
cmd := fmt.Sprintf("(Get-Disk -DeviceId %s |Get-Partition | Get-Volume).UniqueId", diskID)
3127
out, err := runExec(cmd)
3228
if err != nil {
33-
return []string{}, err
29+
return []string{}, fmt.Errorf("error list volumes on disk. cmd: %s, output: %s, error: %v", cmd, string(out), err)
3430
}
3531

3632
volumeIds := strings.Split(strings.TrimSpace(string(out)), "\r\n")
@@ -42,7 +38,7 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {
4238
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Format-Volume -FileSystem %s -Confirm:$false", volumeID, formatFilesystem)
4339
out, err := runExec(cmd)
4440
if err != nil {
45-
return fmt.Errorf("error formatting volume %s: %v, %v", volumeID, out, err)
41+
return fmt.Errorf("error formatting volume. cmd: %s, output: %s, error: %v", cmd, string(out), err)
4642
}
4743
// TODO: Do we need to handle anything for len(out) == 0
4844
return nil
@@ -53,7 +49,7 @@ func (VolAPIImplementor) IsVolumeFormatted(volumeID string) (bool, error) {
5349
cmd := fmt.Sprintf("(Get-Volume -UniqueId \"%s\" -ErrorAction Stop).FileSystemType", volumeID)
5450
out, err := runExec(cmd)
5551
if err != nil {
56-
return false, fmt.Errorf("error checking if volume is formatted %s: %s, %v", volumeID, string(out), err)
52+
return false, fmt.Errorf("error checking if volume is formatted. cmd: %s, output: %s, error: %v", cmd, string(out), err)
5753
}
5854
if len(out) == 0 || !strings.EqualFold(strings.TrimSpace(string(out)), formatFilesystem) {
5955
return false, nil
@@ -64,9 +60,9 @@ func (VolAPIImplementor) IsVolumeFormatted(volumeID string) (bool, error) {
6460
// MountVolume - mounts a volume to a path. This is done using the Add-PartitionAccessPath for presenting the volume via a path.
6561
func (VolAPIImplementor) MountVolume(volumeID, path string) error {
6662
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-Partition | Add-PartitionAccessPath -AccessPath %s", volumeID, path)
67-
_, err := runExec(cmd)
63+
out, err := runExec(cmd)
6864
if err != nil {
69-
return fmt.Errorf("error mount volume %s to path %s. err: %v", volumeID, path, err)
65+
return fmt.Errorf("error mount volume to path. cmd: %s, output: %s, error: %v", cmd, string(out), err)
7066
}
7167
return nil
7268
}
@@ -76,7 +72,7 @@ func (VolAPIImplementor) DismountVolume(volumeID, path string) error {
7672
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-Partition | Remove-PartitionAccessPath -AccessPath %s", volumeID, path)
7773
out, err := runExec(cmd)
7874
if err != nil {
79-
return fmt.Errorf("error getting driver letter to mount volume %s: %v, %v", volumeID, out, err)
75+
return fmt.Errorf("error getting driver letter to mount volume. cmd: %s, output: %s,error: %v", cmd, string(out), err)
8076
}
8177
return nil
8278
}
@@ -88,7 +84,7 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
8884
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-partition | Resize-Partition -Size %d", volumeID, size)
8985
out, err := runExec(cmd)
9086
if err != nil {
91-
return fmt.Errorf("error resizing volume %s: %s, %v", volumeID, string(out), err)
87+
return fmt.Errorf("error resizing volume. cmd: %s, output: %s, error: %v", cmd, string(out), err)
9288
}
9389
return nil
9490
}

internal/server/disk/server.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func NewServer(hostAPI API) (*Server, error) {
3030
}
3131

3232
func (s *Server) ListDiskLocations(context context.Context, request *internal.ListDiskLocationsRequest, version apiversion.Version) (*internal.ListDiskLocationsResponse, error) {
33+
klog.V(4).Infof("calling ListDiskLocations")
3334
response := &internal.ListDiskLocationsResponse{}
3435
m, err := s.hostAPI.ListDiskLocations()
3536
if err != nil {
37+
klog.Errorf("failed ListDiskLocations: %v", err)
3638
return response, err
3739
}
3840

@@ -45,64 +47,69 @@ func (s *Server) ListDiskLocations(context context.Context, request *internal.Li
4547
d.LUNID = v.LUNID
4648
response.DiskLocations[k] = d
4749
}
48-
4950
return response, nil
5051
}
5152

5253
func (s *Server) PartitionDisk(context context.Context, request *internal.PartitionDiskRequest, version apiversion.Version) (*internal.PartitionDiskResponse, error) {
54+
klog.V(4).Infof("calling PartitionDisk with diskID %q", request.DiskID)
5355
response := &internal.PartitionDiskResponse{}
5456
diskID := request.DiskID
5557

56-
klog.Infof("Checking if disk %s is initialized", diskID)
5758
initialized, err := s.hostAPI.IsDiskInitialized(diskID)
5859
if err != nil {
60+
klog.Errorf("failed check IsDiskInitialized %v", err)
5961
return response, err
6062
}
6163
if !initialized {
62-
klog.Infof("Initializing disk %s", diskID)
64+
klog.V(4).Infof("Initializing disk %s", diskID)
6365
err = s.hostAPI.InitializeDisk(diskID)
6466
if err != nil {
67+
klog.Errorf("failed InitializeDisk %v", err)
6568
return response, err
6669
}
6770
} else {
68-
klog.Infof("Disk %s already initialized", diskID)
71+
klog.V(4).Infof("Disk %s already initialized", diskID)
6972
}
7073

71-
klog.Infof("Checking if disk %s is partitioned", diskID)
74+
klog.V(4).Infof("Checking if disk %s is partitioned", diskID)
7275
paritioned, err := s.hostAPI.PartitionsExist(diskID)
7376
if err != nil {
77+
klog.Errorf("failed check PartitionsExist %v", err)
7478
return response, err
7579
}
7680
if !paritioned {
77-
klog.Infof("Creating partition on disk %s", diskID)
81+
klog.V(4).Infof("Creating partition on disk %s", diskID)
7882
err = s.hostAPI.CreatePartition(diskID)
7983
if err != nil {
84+
klog.Errorf("failed CreatePartition %v", err)
8085
return response, err
8186
}
8287
} else {
83-
klog.Infof("Disk %s already partitioned", diskID)
88+
klog.V(4).Infof("Disk %s already partitioned", diskID)
8489
}
85-
8690
return response, nil
8791
}
8892

8993
func (s *Server) Rescan(context context.Context, request *internal.RescanRequest, version apiversion.Version) (*internal.RescanResponse, error) {
94+
klog.V(4).Infof("calling PartitionDisk")
9095
response := &internal.RescanResponse{}
9196
err := s.hostAPI.Rescan()
9297
if err != nil {
98+
klog.Errorf("failed Rescan %v", err)
9399
return nil, err
94100
}
95101
return response, nil
96102
}
97103

98104
func (s *Server) GetDiskNumberByName(context context.Context, request *internal.GetDiskNumberByNameRequest, version apiversion.Version) (*internal.GetDiskNumberByNameResponse, error) {
105+
klog.V(4).Infof("calling GetDiskNumberByName with diskName %q", request.DiskName)
99106
response := &internal.GetDiskNumberByNameResponse{}
100107
diskName := request.DiskName
101108
number, err := s.hostAPI.GetDiskNumberByName(diskName)
102109
if err != nil {
110+
klog.Errorf("failed GetDiskNumberByName %v", err)
103111
return nil, err
104112
}
105-
106113
response.DiskNumber = number
107114
return response, nil
108115
}

internal/server/filesystem/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/kubernetes-csi/csi-proxy/client/apiversion"
1010
"github.com/kubernetes-csi/csi-proxy/internal/server/filesystem/internal"
1111
"github.com/kubernetes-csi/csi-proxy/internal/utils"
12+
"k8s.io/klog"
1213
)
1314

1415
type Server struct {
@@ -117,14 +118,17 @@ func (s *Server) validatePathWindows(pathCtx internal.PathContext, path string)
117118

118119
// PathExists checks if the given path exists on the host.
119120
func (s *Server) PathExists(ctx context.Context, request *internal.PathExistsRequest, version apiversion.Version) (*internal.PathExistsResponse, error) {
121+
klog.V(4).Infof("calling PathExists with path %q", request.Path)
120122
err := s.validatePathWindows(request.Context, request.Path)
121123
if err != nil {
124+
klog.Errorf("failed validatePathWindows %v", err)
122125
return &internal.PathExistsResponse{
123126
Error: err.Error(),
124127
}, err
125128
}
126129
exists, err := s.hostAPI.PathExists(request.Path)
127130
if err != nil {
131+
klog.Errorf("failed check PathExists %v", err)
128132
return &internal.PathExistsResponse{
129133
Error: err.Error(),
130134
}, err
@@ -136,14 +140,17 @@ func (s *Server) PathExists(ctx context.Context, request *internal.PathExistsReq
136140
}
137141

138142
func (s *Server) Mkdir(ctx context.Context, request *internal.MkdirRequest, version apiversion.Version) (*internal.MkdirResponse, error) {
143+
klog.V(4).Infof("calling Mkdir with path %q", request.Path)
139144
err := s.validatePathWindows(request.Context, request.Path)
140145
if err != nil {
146+
klog.Errorf("failed validatePathWindows %v", err)
141147
return &internal.MkdirResponse{
142148
Error: err.Error(),
143149
}, err
144150
}
145151
err = s.hostAPI.Mkdir(request.Path)
146152
if err != nil {
153+
klog.Errorf("failed Mkdir %v", err)
147154
return &internal.MkdirResponse{
148155
Error: err.Error(),
149156
}, err
@@ -155,14 +162,17 @@ func (s *Server) Mkdir(ctx context.Context, request *internal.MkdirRequest, vers
155162
}
156163

157164
func (s *Server) Rmdir(ctx context.Context, request *internal.RmdirRequest, version apiversion.Version) (*internal.RmdirResponse, error) {
165+
klog.V(2).Infof("calling Rmdir with path %q", request.Path)
158166
err := s.validatePathWindows(request.Context, request.Path)
159167
if err != nil {
168+
klog.Errorf("failed validatePathWindows %v", err)
160169
return &internal.RmdirResponse{
161170
Error: err.Error(),
162171
}, err
163172
}
164173
err = s.hostAPI.Rmdir(request.Path, request.Force)
165174
if err != nil {
175+
klog.Errorf("failed Rmdir %v", err)
166176
return &internal.RmdirResponse{
167177
Error: err.Error(),
168178
}, err
@@ -173,21 +183,25 @@ func (s *Server) Rmdir(ctx context.Context, request *internal.RmdirRequest, vers
173183
}
174184

175185
func (s *Server) LinkPath(ctx context.Context, request *internal.LinkPathRequest, version apiversion.Version) (*internal.LinkPathResponse, error) {
186+
klog.V(4).Infof("calling LinkPath with targetPath %q sourcePath %q", request.TargetPath, request.SourcePath)
176187
err := s.validatePathWindows(internal.POD, request.TargetPath)
177188
if err != nil {
189+
klog.Errorf("failed validatePathWindows for target path %v", err)
178190
return &internal.LinkPathResponse{
179191
Error: err.Error(),
180192
}, err
181193
}
182194
err = s.validatePathWindows(internal.PLUGIN, request.SourcePath)
183195
if err != nil {
196+
klog.Errorf("failed validatePathWindows for source path %v", err)
184197
return &internal.LinkPathResponse{
185198
Error: err.Error(),
186199
}, err
187200
}
188201
err = s.hostAPI.LinkPath(request.SourcePath, request.TargetPath)
189202
errString := ""
190203
if err != nil {
204+
klog.Errorf("failed LinkPath %v", err)
191205
errString = err.Error()
192206
}
193207
return &internal.LinkPathResponse{
@@ -196,8 +210,10 @@ func (s *Server) LinkPath(ctx context.Context, request *internal.LinkPathRequest
196210
}
197211

198212
func (s *Server) IsMountPoint(ctx context.Context, request *internal.IsMountPointRequest, version apiversion.Version) (*internal.IsMountPointResponse, error) {
213+
klog.V(4).Infof("calling IsMountPoint with path %q", request.Path)
199214
isMount, err := s.hostAPI.IsMountPoint(request.Path)
200215
if err != nil {
216+
klog.Errorf("failed IsMountPoint %v", err)
201217
return &internal.IsMountPointResponse{
202218
IsMountPoint: false,
203219
Error: err.Error(),

internal/server/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"sync"
77

88
"github.com/Microsoft/go-winio"
9-
"github.com/pkg/errors"
10-
"google.golang.org/grpc"
11-
129
"github.com/kubernetes-csi/csi-proxy/client"
1310
srvtypes "github.com/kubernetes-csi/csi-proxy/internal/server/types"
11+
"github.com/pkg/errors"
12+
"google.golang.org/grpc"
1413
)
1514

1615
// Server aggregates a number of API groups and versions,

0 commit comments

Comments
 (0)