Support nic lingjun node type#1585
Conversation
|
Skipping CI for Draft Pull Request. |
3998323 to
7939ef8
Compare
7939ef8 to
d829b22
Compare
|
/test all |
a7043fc to
1275539
Compare
|
/test all |
1275539 to
cc011d4
Compare
| } | ||
| data, err := os.ReadFile(LingjunConfigFile) | ||
| if err != nil { | ||
| klog.V(1).InfoS("can't read lingjun metadata file, use env metadata only", "file", LingjunConfigFile, "error", err) |
There was a problem hiding this comment.
Maybe we should log "no such file" error at V(3), and other errors with klog.Error
0d98d7c to
1680d9b
Compare
| if data, exists := LingjunTestCases[caseName]; exists { | ||
| return []byte(data) | ||
| } | ||
| // Return default case if not found |
There was a problem hiding this comment.
Why so complex.. Just don't make it not found.
| NimitzInterface []string `json:"NimitzInterface"` | ||
| } | ||
|
|
||
| func NewLingJunMetadata(data []byte) (*LingjunMetaData, error) { |
There was a problem hiding this comment.
Can we hide all the error handling in this func? e.g. just pass in a path, log and return nil on error. Then we just need this in NewMetadata:
if lm := NewLingJunMetadata(path); lm != nil {
defaultMetadata.providers = append(defaultMetadata.providers, newImmutableProvider(lm, "lingjun"))
}So that lingjun.go is more self-contained.
52d808a to
4f73aa0
Compare
|
|
||
| func TestNewLingJunMetadata(t *testing.T) { | ||
| // Create a temporary directory for test files | ||
| tempDir := t.TempDir() |
There was a problem hiding this comment.
Move this to each test case, to avoid any possibility of interference between different cases.
| LingjunConfigFile = filepath.Join(tempDir, "lingjun_config_standard") | ||
| defer func() { | ||
| LingjunConfigFile = originalConfigFile | ||
| }() |
There was a problem hiding this comment.
How about just pass LingjunConfigFile into NewLingJunMetadata? Replacing global variable should only be used as last resort, as it prevents parallel test.
| if err != nil { | ||
| if errors.Is(err, os.ErrNotExist) { | ||
| klog.V(3).InfoS("lingjun metadata file does not exist, use env metadata only", "file", LingjunConfigFile) | ||
| } else { | ||
| klog.ErrorS(err, "Failed to read lingjun metadatafile", "file", LingjunConfigFile) | ||
| } | ||
| return defaultMetadata | ||
| } |
There was a problem hiding this comment.
OK, but I'd prefer these code to also go into NewLingJunMetadata, so that we can have test coverage over it.
| return getLingjunAvailableDiskCount(efloC, lingjunNodeId) | ||
| count, err := getLingjunAvailableDiskCount(efloC, lingjunNodeId) | ||
| if err != nil { | ||
| klog.ErrorS(err, "getAvailableDiskCount: failed to get lingjun available disk count", "lingjunID", lingjunNodeId) |
There was a problem hiding this comment.
Do we want to ignore all errors? Can we be more specific here?
| name: "empty_node_type", | ||
| lingjunID: "node-123", | ||
| setupMock: func() { | ||
| // 模拟返回的 NodeType 为空字符串 |
There was a problem hiding this comment.
Not sure about this case. Do you expect it to return success?
There was a problem hiding this comment.
Also, please avoid Chinese in this repo.
| EniMac string `json:"EniMac"` | ||
| AckNicName string `json:"AckNicName"` | ||
| NimitzNetworkMode string `json:"NimitzNetworkMode"` | ||
| NimitzInterface []string `json:"NimitzInterface"` |
There was a problem hiding this comment.
How about remove fields that we don't use? This way, we:
- reduce the possibility of being breaked by changes of this file.
- slightly improve the performance as we don't need to deserialize these extra fields.
93566a2 to
804a2be
Compare
5d900f7 to
1bf2f25
Compare
| nodeType := "ebmgvn" | ||
| lingjunNodeResp := &eflo.DescribeNodeResponse{ | ||
| Body: &eflo.DescribeNodeResponseBody{ | ||
| NodeType: &nodeType, |
There was a problem hiding this comment.
| NodeType: &nodeType, | |
| NodeType: ptr.To("ebmgvn"), |
Also avoid Chinese.
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| mockEFLOClient := cloud.NewMockEFLOInterface(ctrl) |
There was a problem hiding this comment.
We'd better create a new ctrl/mockEFLOClient for each case, to avoid any interference.
Besides, Finish() is not nessesary:
New in go1.14+, if you are passing a *testing.T into NewController function you no longer need to call ctrl.Finish() in your test methods.
| volumeHandle: "fs-12345+", | ||
| expectedFsId: "fs-12345", | ||
| expectedFsetId: "", | ||
| }, |
There was a problem hiding this comment.
OK, but I'm not sure if you add this by mistake? This is unrelated to other changes.
307b5a5 to
d0a937c
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mowangdk The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
d0a937c to
e3aec60
Compare
|
/lgtm |
What type of PR is this?
What this PR does / why we need it:
Support nic type lingjun node
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: