-
Notifications
You must be signed in to change notification settings - Fork 23
feat: support filter list #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yu-Jack
wants to merge
12
commits into
harvester:master
Choose a base branch
from
Yu-Jack:HARV-5059
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d0554d
chore: add yaml module
Yu-Jack d654eba
read from config map
Yu-Jack dba0c5d
feat: add reloading config map when scanner starts
Yu-Jack 2e5caff
chore: add deploy chart
Yu-Jack 3a305e5
add debug info
Yu-Jack 383c9c4
feat: pas env to configmap loader and remove it in main.go
Yu-Jack c74c241
feat: add exclude devices filter when detecting block device
Yu-Jack bf923da
feat: use regex to detect the node name
Yu-Jack fc220d6
test: remove private function test cases
Yu-Jack 42dd6b7
refacotr: remove unused codes
Yu-Jack 6be12fd
fix: apply feedback from AI
Yu-Jack ca1c1ed
feat: move config map from deploy to pkg/data because of managedChart
Yu-Jack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
deploy/charts/harvester-node-disk-manager/templates/configmap.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: {{ include "harvester-node-disk-manager.name" . }} | ||
| namespace: {{ .Release.Namespace }} | ||
Yu-Jack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| labels: | ||
| {{- include "harvester-node-disk-manager.labels" . | nindent 4 }} | ||
| data: | ||
| {{- if .Values.configMap.filters }} | ||
| filters.yaml: | | ||
| {{- toYaml .Values.configMap.filters | nindent 4 }} | ||
| {{- end }} | ||
| {{- if .Values.configMap.autoprovision }} | ||
| autoprovision.yaml: | | ||
| {{- toYaml .Values.configMap.autoprovision | nindent 4 }} | ||
| {{- end }} | ||
Yu-Jack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package blockdevice | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
| "reflect" | ||
|
|
@@ -30,6 +31,7 @@ type Scanner struct { | |
| BlockInfo block.Info | ||
| ExcludeFilters []*filter.Filter | ||
| AutoProvisionFilters []*filter.Filter | ||
| ConfigMapLoader *filter.ConfigMapLoader | ||
| Cond *sync.Cond | ||
| Shutdown bool | ||
| TerminatedChannels *chan bool | ||
|
|
@@ -45,29 +47,29 @@ func NewScanner( | |
| upgrades ctlharvesterv1.UpgradeController, | ||
| bds ctldiskv1.BlockDeviceController, | ||
| block block.Info, | ||
| excludeFilters, autoProvisionFilters []*filter.Filter, | ||
| configMapLoader *filter.ConfigMapLoader, | ||
| cond *sync.Cond, | ||
| shutdown bool, | ||
| ch *chan bool, | ||
| ) *Scanner { | ||
| return &Scanner{ | ||
| NodeName: nodeName, | ||
| Namespace: namespace, | ||
| Blockdevices: bds, | ||
| UpgradeClient: upgrades, | ||
| BlockInfo: block, | ||
| ExcludeFilters: excludeFilters, | ||
| AutoProvisionFilters: autoProvisionFilters, | ||
| Cond: cond, | ||
| Shutdown: shutdown, | ||
| TerminatedChannels: ch, | ||
| NodeName: nodeName, | ||
| Namespace: namespace, | ||
| Blockdevices: bds, | ||
| UpgradeClient: upgrades, | ||
| BlockInfo: block, | ||
| ConfigMapLoader: configMapLoader, | ||
| Cond: cond, | ||
| Shutdown: shutdown, | ||
| TerminatedChannels: ch, | ||
| } | ||
| } | ||
|
|
||
| func (s *Scanner) Start() error { | ||
| if err := s.scanBlockDevicesOnNode(); err != nil { | ||
| func (s *Scanner) Start(ctx context.Context) error { | ||
| if err := s.scanBlockDevicesOnNode(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| go func() { | ||
| for { | ||
| s.Cond.L.Lock() | ||
|
|
@@ -83,7 +85,7 @@ func (s *Scanner) Start() error { | |
| } | ||
|
|
||
| logrus.Infof("scanner waked up, do scan...") | ||
| if err := s.scanBlockDevicesOnNode(); err != nil { | ||
| if err := s.scanBlockDevicesOnNode(ctx); err != nil { | ||
| logrus.Errorf("Failed to rescan block devices on node %s: %v", s.NodeName, err) | ||
| } | ||
| s.Cond.L.Unlock() | ||
|
|
@@ -200,10 +202,84 @@ func (s *Scanner) deactivateBlockDevices(oldBds map[string]*diskv1.BlockDevice) | |
| return nil | ||
| } | ||
|
|
||
| // reloadConfigMapFilters reloads filter and auto-provision configurations from ConfigMap | ||
| // Falls back to environment variables if ConfigMap is not available or empty | ||
| func (s *Scanner) loadConfigMapFilters(ctx context.Context) { | ||
| deviceFilter, vendorFilter, pathFilter, labelFilter, err := s.ConfigMapLoader.LoadFiltersFromConfigMap(ctx) | ||
| if err != nil { | ||
| logrus.Warnf("Failed to reload filters from ConfigMap: %v, using environment variable fallback", err) | ||
| deviceFilter, vendorFilter, pathFilter, labelFilter = s.ConfigMapLoader.GetEnvFilters() | ||
| } else if deviceFilter == "" && vendorFilter == "" && pathFilter == "" && labelFilter == "" { | ||
| // ConfigMap exists but is empty, use env var fallback | ||
| logrus.Info("ConfigMap filter data is empty, using environment variable fallback") | ||
| deviceFilter, vendorFilter, pathFilter, labelFilter = s.ConfigMapLoader.GetEnvFilters() | ||
| } else { | ||
| // Use ConfigMap values (they take precedence) | ||
| logrus.Info("Using filter configuration from ConfigMap") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we need this logger? |
||
| } | ||
Yu-Jack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Update filters | ||
| s.ExcludeFilters = filter.SetExcludeFilters(deviceFilter, vendorFilter, pathFilter, labelFilter) | ||
|
|
||
| autoProvisionFilter, err := s.ConfigMapLoader.LoadAutoProvisionFromConfigMap(ctx) | ||
| if err != nil { | ||
| logrus.Warnf("Failed to reload auto-provision from ConfigMap: %v, using environment variable fallback", err) | ||
| autoProvisionFilter = s.ConfigMapLoader.GetEnvAutoProvisionFilter() | ||
| } else if autoProvisionFilter == "" { | ||
| // ConfigMap exists but is empty, use env var fallback | ||
| logrus.Debug("ConfigMap auto-provision data is empty, using environment variable fallback") | ||
| autoProvisionFilter = s.ConfigMapLoader.GetEnvAutoProvisionFilter() | ||
| } else { | ||
| // Use ConfigMap values (they take precedence) | ||
| logrus.Info("Using auto-provision configuration from ConfigMap") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| } | ||
|
|
||
| // Update auto-provision filters | ||
| s.AutoProvisionFilters = filter.SetAutoProvisionFilters(autoProvisionFilter) | ||
| } | ||
|
|
||
| func (s *Scanner) debugFilter() { | ||
| // Debug: Log final filter details including defaults | ||
| logrus.Debugf("Final filter configuration (including defaults):") | ||
| logrus.Debugf(" Exclude Filters (%d total):", len(s.ExcludeFilters)) | ||
| for i, f := range s.ExcludeFilters { | ||
| diskDetails := "N/A" | ||
| partDetails := "N/A" | ||
| if f.DiskFilter != nil { | ||
| diskDetails = f.DiskFilter.Details() | ||
| } | ||
| if f.PartFilter != nil { | ||
| partDetails = f.PartFilter.Details() | ||
| } | ||
| logrus.Debugf(" [%d] %s", i, f.Name) | ||
| logrus.Debugf(" Disk: %s", diskDetails) | ||
| logrus.Debugf(" Part: %s", partDetails) | ||
| } | ||
|
|
||
| logrus.Debugf(" Auto-Provision Filters (%d total):", len(s.AutoProvisionFilters)) | ||
| for i, f := range s.AutoProvisionFilters { | ||
| diskDetails := "N/A" | ||
| partDetails := "N/A" | ||
| if f.DiskFilter != nil { | ||
| diskDetails = f.DiskFilter.Details() | ||
| } | ||
| if f.PartFilter != nil { | ||
| partDetails = f.PartFilter.Details() | ||
| } | ||
| logrus.Debugf(" [%d] %s", i, f.Name) | ||
| logrus.Debugf(" Disk: %s", diskDetails) | ||
| logrus.Debugf(" Part: %s", partDetails) | ||
| } | ||
| } | ||
|
|
||
| // scanBlockDevicesOnNode scans block devices on the node, and it will either create or update them. | ||
| func (s *Scanner) scanBlockDevicesOnNode() error { | ||
| func (s *Scanner) scanBlockDevicesOnNode(ctx context.Context) error { | ||
| logrus.Debugf("Scan block devices of node: %s", s.NodeName) | ||
|
|
||
| // load filter and auto-provision configurations from ConfigMap | ||
| s.loadConfigMapFilters(ctx) | ||
| s.debugFilter() | ||
|
|
||
| // list all the block devices | ||
| allDevices := s.collectAllDevices() | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.