Skip to content

Commit

Permalink
Merge pull request #36 from nifcloud/feature-nifcloud-sdk-debug-log
Browse files Browse the repository at this point in the history
Feature nifcloud sdk debug log
  • Loading branch information
aokumasan authored Jan 17, 2024
2 parents 5f8b6db + 9b3e732 commit 12a92cc
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- --endpoint=$(CSI_ENDPOINT)
{{- if .Values.controller.sdkDebugLog }}
- --nifcloud-sdk-debug-log=true
{{- end}}
- --logtostderr
- --v={{ .Values.controller.logLevel }}
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- --endpoint=$(CSI_ENDPOINT)
{{- if .Values.node.sdkDebugLog }}
- --nifcloud-sdk-debug-log=true
{{- end}}
- --logtostderr
- --v={{ .Values.controller.logLevel }}
env:
Expand Down
2 changes: 2 additions & 0 deletions charts/nifcloud-additional-storage-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ controller:
securityContext:
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
sdkDebugLog: false
logLevel: 2
resources:
requests:
Expand Down Expand Up @@ -76,6 +77,7 @@ node:
securityContext:
privileged: true
readOnlyRootFilesystem: true
sdkDebugLog: false
logLevel: 2
resources:
requests:
Expand Down
7 changes: 5 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (

func main() {
var (
version bool
endpoint string
version bool
endpoint string
nifcloudSdkDebugLog bool
)

flag.BoolVar(&version, "version", false, "Print the version and exit.")
flag.StringVar(&endpoint, "endpoint", driver.DefaultCSIEndpoint, "CSI Endpoint")
flag.BoolVar(&nifcloudSdkDebugLog, "nifcloud-sdk-debug-log", false, "To enable the nifcloud debug log level (default to false).")

klog.InitFlags(nil)
flag.Parse()
Expand All @@ -32,6 +34,7 @@ func main() {

drv, err := driver.NewDriver(
driver.WithEndpoint(endpoint),
driver.WithNifcloudSdkDebugLog(nifcloudSdkDebugLog),
)
if err != nil {
klog.Fatalln(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/nifcloud/nifcloud-additional-storage-csi-driver
go 1.20

require (
github.com/aws/aws-sdk-go-v2 v1.17.4
github.com/aws/smithy-go v1.14.0
github.com/container-storage-interface/spec v1.8.0
github.com/nifcloud/nifcloud-sdk-go v1.21.0
Expand All @@ -17,7 +18,6 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2 v1.17.4 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down
10 changes: 9 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/smithy-go"
"github.com/nifcloud/nifcloud-additional-storage-csi-driver/pkg/util"
"github.com/nifcloud/nifcloud-sdk-go/nifcloud"
Expand Down Expand Up @@ -154,11 +155,18 @@ type cloud struct {
var _ Cloud = &cloud{}

// NewCloud creates the cloud object.
func NewCloud() (Cloud, error) {
func NewCloud(nifcloudSdkDebugLog bool) (Cloud, error) {
accessKeyID := os.Getenv("NIFCLOUD_ACCESS_KEY_ID")
secretAccessKey := os.Getenv("NIFCLOUD_SECRET_ACCESS_KEY")
region := os.Getenv("NIFCLOUD_REGION")
cfg := nifcloud.NewConfig(accessKeyID, secretAccessKey, region)

if nifcloudSdkDebugLog {
cfg.ClientLogMode = aws.LogRequestWithBody | aws.LogRequestEventMessage |
aws.LogResponseWithBody | aws.LogResponseEventMessage |
aws.LogRetries
}

return &cloud{
region: region,
computing: computing.NewFromConfig(cfg),
Expand Down
4 changes: 2 additions & 2 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type controllerService struct {
instanceID string
}

func newControllerService(instanceID string) controllerService {
cloud, err := cloud.NewCloud()
func newControllerService(driverOptions *DriverOptions, instanceID string) controllerService {
cloud, err := cloud.NewCloud(driverOptions.nifcloudSdkDebugLog)
if err != nil {
panic(err)
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type Driver struct {

// DriverOptions is option for CSI driver.
type DriverOptions struct {
endpoint string
endpoint string
nifcloudSdkDebugLog bool
}

// NewDriver creates the new CSI driver
Expand All @@ -43,15 +44,16 @@ func NewDriver(options ...func(*DriverOptions)) (*Driver, error) {
}

driverOptions := DriverOptions{
endpoint: DefaultCSIEndpoint,
endpoint: DefaultCSIEndpoint,
nifcloudSdkDebugLog: false,
}
for _, option := range options {
option(&driverOptions)
}

driver := Driver{
controllerService: newControllerService(instanceID),
nodeService: newNodeService(instanceID),
controllerService: newControllerService(&driverOptions, instanceID),
nodeService: newNodeService(&driverOptions, instanceID),
options: &driverOptions,
}

Expand Down Expand Up @@ -104,6 +106,13 @@ func WithEndpoint(endpoint string) func(*DriverOptions) {
}
}

// WithNifcloudSdkDebugLog sets the nifcloud sdk debug log
func WithNifcloudSdkDebugLog(nifcloudSdkDebugLog bool) func(*DriverOptions) {
return func(o *DriverOptions) {
o.nifcloudSdkDebugLog = nifcloudSdkDebugLog
}
}

func getInstanceID() (string, error) {
instanceID := os.Getenv("NODE_NAME")
if instanceID == "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type nodeService struct {

// newNodeService creates a new node service
// it panics if failed to create the service
func newNodeService(instanceID string) nodeService {
cloud, err := cloud.NewCloud()
func newNodeService(driverOptions *DriverOptions, instanceID string) nodeService {
cloud, err := cloud.NewCloud(driverOptions.nifcloudSdkDebugLog)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 12a92cc

Please sign in to comment.