Skip to content

Commit

Permalink
Fixed bug where code panics at filtering omitted values
Browse files Browse the repository at this point in the history
removed fields from node
  • Loading branch information
IsaiasA1 committed Dec 16, 2024
1 parent 94b9f00 commit 88a769c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
5 changes: 1 addition & 4 deletions docs/data-sources/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ data "powerflex_node" "node" {
# discovered_date = ["discoveredDate1", "discoveredDate2"]
# cred_id = ["credId1", "credId2"]
# compliance = ["compliance1", "compliance2"]
# puppet_cert_name = ["puppet_cert_name1","puppet_cert_name2"]
# failures_count = [3, 5]
# facts = ["facts1", "facts2"]
# puppet_cert_managed = ["puppetCertManaged1", "puppetCertManaged2"]
# flex_os_maint_mode=[0]
# esxi_maint_mode=[0]
# }
Expand Down Expand Up @@ -125,7 +124,6 @@ Optional:
- `discovered_date` (Set of String) List of discovered_date
- `display_name` (Set of String) List of display_name
- `esxi_maint_mode` (Set of Number) List of esxi_maint_mode
- `facts` (Set of String) List of facts
- `failures_count` (Set of Number) List of failures_count
- `flex_os_maint_mode` (Set of Number) List of flex_os_maint_mode
- `health` (Set of String) List of health
Expand Down Expand Up @@ -163,7 +161,6 @@ Read-Only:
- `discovered_date` (String) Discovered date of the node.
- `display_name` (String) Display name of the node.
- `esxi_maint_mode` (Number) ESXi maintenance mode.
- `facts` (String) Facts of the node.
- `failures_count` (Number) Failures count.
- `flex_os_maint_mode` (Number) FLEX OS maintenance mode.
- `health` (String) Health of the node.
Expand Down
3 changes: 1 addition & 2 deletions examples/data-sources/powerflex_node/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ data "powerflex_node" "node" {
# discovered_date = ["discoveredDate1", "discoveredDate2"]
# cred_id = ["credId1", "credId2"]
# compliance = ["compliance1", "compliance2"]
# puppet_cert_name = ["puppet_cert_name1","puppet_cert_name2"]
# failures_count = [3, 5]
# facts = ["facts1", "facts2"]
# puppet_cert_managed = ["puppetCertManaged1", "puppetCertManaged2"]
# flex_os_maint_mode=[0]
# esxi_maint_mode=[0]
# }
Expand Down
8 changes: 4 additions & 4 deletions powerflex/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,6 @@ func FilterByField(dataSources reflect.Value, fieldValue reflect.Value, field st

dataSourceValue := reflect.ValueOf(dataSource)
fieldValueInDataSource := dataSourceValue.FieldByName(field)
// if field is not found in the data source then continue
if !fieldValueInDataSource.IsValid() {
continue
}

if fieldValue.Kind() == reflect.Slice || fieldValue.Kind() == reflect.Array {
for n := 0; n < fieldValue.Len(); n++ {
Expand All @@ -387,6 +383,10 @@ func FilterByField(dataSources reflect.Value, fieldValue reflect.Value, field st
if err != nil {
return reflect.Zero(nil), err
}
// if field is not found in the data source then break and continue
if !fieldValueInDataSource.IsValid() || !interFieldValue.IsValid() {
break
}

if fieldValueInDataSource.Interface() == interFieldValue.Interface() {
filteredData = reflect.Append(filteredData, reflect.ValueOf(dataSource))
Expand Down
1 change: 0 additions & 1 deletion powerflex/models/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type NodeFilter struct {
CredID []types.String `tfsdk:"cred_id"`
Compliance []types.String `tfsdk:"compliance"`
FailuresCount []types.Int64 `tfsdk:"failures_count"`
Facts []types.String `tfsdk:"facts"`
PuppetCertName []types.String `tfsdk:"puppet_cert_name"`
FlexosMaintMode []types.Int64 `tfsdk:"flex_os_maint_mode"`
EsxiMaintMode []types.Int64 `tfsdk:"esxi_maint_mode"`
Expand Down
5 changes: 0 additions & 5 deletions powerflex/provider/node_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ var NodeDataSourceSchema schema.Schema = schema.Schema{
MarkdownDescription: "Failures count.",
Computed: true,
},
"facts": schema.StringAttribute{
Description: "Facts of the node.",
MarkdownDescription: "Facts of the node.",
Computed: true,
},
"puppet_cert_name": schema.StringAttribute{
Description: "Puppet cert name of the node.",
MarkdownDescription: "Puppet cert name of the node.",
Expand Down

0 comments on commit 88a769c

Please sign in to comment.