From 81db52e446f742e374e759acca2239b0b2ce3e18 Mon Sep 17 00:00:00 2001 From: Gerrit91 Date: Mon, 9 Oct 2023 14:21:43 +0200 Subject: [PATCH] More naming. --- .../internal/issues/asn-uniqueness.go | 2 +- .../internal/issues/bmc-info-outdated.go | 2 +- .../internal/issues/bmc-without-ip.go | 2 +- .../internal/issues/bmc-without-mac.go | 2 +- cmd/metal-api/internal/issues/crash-loop.go | 2 +- .../internal/issues/failed-machine-reclaim.go | 2 +- cmd/metal-api/internal/issues/issues.go | 10 ++++---- cmd/metal-api/internal/issues/issues_test.go | 24 +++++++++---------- .../internal/issues/last-event-error.go | 2 +- .../internal/issues/liveliness-dead.go | 2 +- .../issues/liveliness-not-available.go | 2 +- .../internal/issues/liveliness-unknown.go | 2 +- .../internal/issues/no-event-container.go | 2 +- cmd/metal-api/internal/issues/no-partition.go | 2 +- .../internal/issues/non-distinct-bmc-ip.go | 2 +- cmd/metal-api/internal/issues/types.go | 20 ++++++++++++---- .../internal/service/machine-service.go | 4 ++-- .../internal/service/partition-service.go | 8 +------ cmd/metal-api/internal/service/v1/machine.go | 4 ++-- 19 files changed, 51 insertions(+), 45 deletions(-) diff --git a/cmd/metal-api/internal/issues/asn-uniqueness.go b/cmd/metal-api/internal/issues/asn-uniqueness.go index 32f47f0ba..51b58db70 100644 --- a/cmd/metal-api/internal/issues/asn-uniqueness.go +++ b/cmd/metal-api/internal/issues/asn-uniqueness.go @@ -9,7 +9,7 @@ import ( ) const ( - TypeASNUniqueness IssueType = "asn-not-unique" + TypeASNUniqueness Type = "asn-not-unique" ) type ( diff --git a/cmd/metal-api/internal/issues/bmc-info-outdated.go b/cmd/metal-api/internal/issues/bmc-info-outdated.go index 3e06a4f50..a6e435a7f 100644 --- a/cmd/metal-api/internal/issues/bmc-info-outdated.go +++ b/cmd/metal-api/internal/issues/bmc-info-outdated.go @@ -8,7 +8,7 @@ import ( ) const ( - TypeBMCInfoOutdated IssueType = "bmc-info-outdated" + TypeBMCInfoOutdated Type = "bmc-info-outdated" ) type ( diff --git a/cmd/metal-api/internal/issues/bmc-without-ip.go b/cmd/metal-api/internal/issues/bmc-without-ip.go index 8a6e2addc..953558851 100644 --- a/cmd/metal-api/internal/issues/bmc-without-ip.go +++ b/cmd/metal-api/internal/issues/bmc-without-ip.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeBMCWithoutIP IssueType = "bmc-without-ip" + TypeBMCWithoutIP Type = "bmc-without-ip" ) type ( diff --git a/cmd/metal-api/internal/issues/bmc-without-mac.go b/cmd/metal-api/internal/issues/bmc-without-mac.go index 959ae429f..2b7f604a8 100644 --- a/cmd/metal-api/internal/issues/bmc-without-mac.go +++ b/cmd/metal-api/internal/issues/bmc-without-mac.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeBMCWithoutMAC IssueType = "bmc-without-mac" + TypeBMCWithoutMAC Type = "bmc-without-mac" ) type ( diff --git a/cmd/metal-api/internal/issues/crash-loop.go b/cmd/metal-api/internal/issues/crash-loop.go index 58744db9a..3e69a63ff 100644 --- a/cmd/metal-api/internal/issues/crash-loop.go +++ b/cmd/metal-api/internal/issues/crash-loop.go @@ -6,7 +6,7 @@ import ( ) const ( - TypeCrashLoop IssueType = "crashloop" + TypeCrashLoop Type = "crashloop" ) type ( diff --git a/cmd/metal-api/internal/issues/failed-machine-reclaim.go b/cmd/metal-api/internal/issues/failed-machine-reclaim.go index 484bb7396..3b1a31a3a 100644 --- a/cmd/metal-api/internal/issues/failed-machine-reclaim.go +++ b/cmd/metal-api/internal/issues/failed-machine-reclaim.go @@ -6,7 +6,7 @@ import ( ) const ( - TypeFailedMachineReclaim IssueType = "failed-machine-reclaim" + TypeFailedMachineReclaim Type = "failed-machine-reclaim" ) type ( diff --git a/cmd/metal-api/internal/issues/issues.go b/cmd/metal-api/internal/issues/issues.go index fe1c0e424..c8e98ecbb 100644 --- a/cmd/metal-api/internal/issues/issues.go +++ b/cmd/metal-api/internal/issues/issues.go @@ -13,14 +13,14 @@ type ( Machines metal.Machines EventContainers metal.ProvisioningEventContainers Severity IssueSeverity - Only []IssueType - Omit []IssueType + Only []Type + Omit []Type LastErrorThreshold time.Duration } // Issue formulates an issue of a machine Issue struct { - Type IssueType + Type Type Severity IssueSeverity Description string RefURL string @@ -52,7 +52,7 @@ type ( // spec defines the specification of an issue. spec struct { - Type IssueType + Type Type Severity IssueSeverity Description string RefURL string @@ -137,7 +137,7 @@ func (mis MachineIssues) Get(id string) *MachineWithIssues { return nil } -func (c *Config) includeIssue(t IssueType) bool { +func (c *Config) includeIssue(t Type) bool { issue, err := NewIssueFromType(t) if err != nil { return false diff --git a/cmd/metal-api/internal/issues/issues_test.go b/cmd/metal-api/internal/issues/issues_test.go index 4a90a38df..503188840 100644 --- a/cmd/metal-api/internal/issues/issues_test.go +++ b/cmd/metal-api/internal/issues/issues_test.go @@ -35,7 +35,7 @@ func TestFindIssues(t *testing.T) { tests := []struct { name string - only []IssueType + only []Type machines func() metal.Machines eventContainers func() metal.ProvisioningEventContainers @@ -58,7 +58,7 @@ func TestFindIssues(t *testing.T) { }, { name: "no partition", - only: []IssueType{TypeNoPartition}, + only: []Type{TypeNoPartition}, machines: func() metal.Machines { noPartitionMachine := machineTemplate("no-partition") noPartitionMachine.PartitionID = "" @@ -87,7 +87,7 @@ func TestFindIssues(t *testing.T) { }, { name: "liveliness dead", - only: []IssueType{TypeLivelinessDead}, + only: []Type{TypeLivelinessDead}, machines: func() metal.Machines { return metal.Machines{ machineTemplate("dead"), @@ -116,7 +116,7 @@ func TestFindIssues(t *testing.T) { }, { name: "liveliness unknown", - only: []IssueType{TypeLivelinessUnknown}, + only: []Type{TypeLivelinessUnknown}, machines: func() metal.Machines { return metal.Machines{ machineTemplate("unknown"), @@ -145,7 +145,7 @@ func TestFindIssues(t *testing.T) { }, { name: "liveliness not available", - only: []IssueType{TypeLivelinessNotAvailable}, + only: []Type{TypeLivelinessNotAvailable}, machines: func() metal.Machines { return metal.Machines{ machineTemplate("n/a"), @@ -174,7 +174,7 @@ func TestFindIssues(t *testing.T) { }, { name: "failed machine reclaim", - only: []IssueType{TypeFailedMachineReclaim}, + only: []Type{TypeFailedMachineReclaim}, machines: func() metal.Machines { failedOld := machineTemplate("failed-old") @@ -220,7 +220,7 @@ func TestFindIssues(t *testing.T) { }, { name: "crashloop", - only: []IssueType{TypeCrashLoop}, + only: []Type{TypeCrashLoop}, machines: func() metal.Machines { return metal.Machines{ machineTemplate("good"), @@ -282,7 +282,7 @@ func TestFindIssues(t *testing.T) { // }, { name: "bmc without mac", - only: []IssueType{TypeBMCWithoutMAC}, + only: []Type{TypeBMCWithoutMAC}, machines: func() metal.Machines { noMac := machineTemplate("no-mac") noMac.IPMI.MacAddress = "" @@ -314,7 +314,7 @@ func TestFindIssues(t *testing.T) { }, { name: "bmc without ip", - only: []IssueType{TypeBMCWithoutIP}, + only: []Type{TypeBMCWithoutIP}, machines: func() metal.Machines { noIP := machineTemplate("no-ip") noIP.IPMI.Address = "" @@ -378,7 +378,7 @@ func TestFindIssues(t *testing.T) { // }, { name: "asn shared", - only: []IssueType{TypeASNUniqueness}, + only: []Type{TypeASNUniqueness}, machines: func() metal.Machines { shared1 := machineTemplate("shared1") shared1.Allocation = &metal.MachineAllocation{ @@ -448,7 +448,7 @@ func TestFindIssues(t *testing.T) { }, { name: "non distinct bmc ip", - only: []IssueType{TypeNonDistinctBMCIP}, + only: []Type{TypeNonDistinctBMCIP}, machines: func() metal.Machines { bmc1 := machineTemplate("bmc1") bmc1.IPMI.Address = "127.0.0.1" @@ -517,7 +517,7 @@ func TestFindIssues(t *testing.T) { } func TestAllIssues(t *testing.T) { - issuesTypes := map[IssueType]bool{} + issuesTypes := map[Type]bool{} for _, i := range AllIssues() { issuesTypes[i.Type] = true } diff --git a/cmd/metal-api/internal/issues/last-event-error.go b/cmd/metal-api/internal/issues/last-event-error.go index c41f43024..997e840e5 100644 --- a/cmd/metal-api/internal/issues/last-event-error.go +++ b/cmd/metal-api/internal/issues/last-event-error.go @@ -8,7 +8,7 @@ import ( ) const ( - TypeLastEventError IssueType = "last-event-error" + TypeLastEventError Type = "last-event-error" ) type ( diff --git a/cmd/metal-api/internal/issues/liveliness-dead.go b/cmd/metal-api/internal/issues/liveliness-dead.go index 8e09eb8b8..35d1a0f00 100644 --- a/cmd/metal-api/internal/issues/liveliness-dead.go +++ b/cmd/metal-api/internal/issues/liveliness-dead.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeLivelinessDead IssueType = "liveliness-dead" + TypeLivelinessDead Type = "liveliness-dead" ) type ( diff --git a/cmd/metal-api/internal/issues/liveliness-not-available.go b/cmd/metal-api/internal/issues/liveliness-not-available.go index 9ba58a575..db6cc7d3a 100644 --- a/cmd/metal-api/internal/issues/liveliness-not-available.go +++ b/cmd/metal-api/internal/issues/liveliness-not-available.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeLivelinessNotAvailable IssueType = "liveliness-not-available" + TypeLivelinessNotAvailable Type = "liveliness-not-available" ) type ( diff --git a/cmd/metal-api/internal/issues/liveliness-unknown.go b/cmd/metal-api/internal/issues/liveliness-unknown.go index f17615db1..a41e83bc9 100644 --- a/cmd/metal-api/internal/issues/liveliness-unknown.go +++ b/cmd/metal-api/internal/issues/liveliness-unknown.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeLivelinessUnknown IssueType = "liveliness-unknown" + TypeLivelinessUnknown Type = "liveliness-unknown" ) type ( diff --git a/cmd/metal-api/internal/issues/no-event-container.go b/cmd/metal-api/internal/issues/no-event-container.go index 7abc2e2c4..d6f1f6399 100644 --- a/cmd/metal-api/internal/issues/no-event-container.go +++ b/cmd/metal-api/internal/issues/no-event-container.go @@ -5,7 +5,7 @@ import ( ) const ( - TypeNoEventContainer IssueType = "no-event-container" + TypeNoEventContainer Type = "no-event-container" ) type ( diff --git a/cmd/metal-api/internal/issues/no-partition.go b/cmd/metal-api/internal/issues/no-partition.go index 990f490b9..7d082b7bd 100644 --- a/cmd/metal-api/internal/issues/no-partition.go +++ b/cmd/metal-api/internal/issues/no-partition.go @@ -3,7 +3,7 @@ package issues import "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" const ( - TypeNoPartition IssueType = "no-partition" + TypeNoPartition Type = "no-partition" ) type ( diff --git a/cmd/metal-api/internal/issues/non-distinct-bmc-ip.go b/cmd/metal-api/internal/issues/non-distinct-bmc-ip.go index a06c127d0..7bcf1e77a 100644 --- a/cmd/metal-api/internal/issues/non-distinct-bmc-ip.go +++ b/cmd/metal-api/internal/issues/non-distinct-bmc-ip.go @@ -7,7 +7,7 @@ import ( ) const ( - TypeNonDistinctBMCIP IssueType = "bmc-no-distinct-ip" + TypeNonDistinctBMCIP Type = "bmc-no-distinct-ip" ) type ( diff --git a/cmd/metal-api/internal/issues/types.go b/cmd/metal-api/internal/issues/types.go index ba7e5e98e..7ee92bdcd 100644 --- a/cmd/metal-api/internal/issues/types.go +++ b/cmd/metal-api/internal/issues/types.go @@ -3,11 +3,11 @@ package issues import "fmt" type ( - IssueType string + Type string ) -func AllIssueTypes() []IssueType { - return []IssueType{ +func AllIssueTypes() []Type { + return []Type{ TypeNoPartition, TypeLivelinessDead, TypeLivelinessUnknown, @@ -24,7 +24,19 @@ func AllIssueTypes() []IssueType { } } -func NewIssueFromType(t IssueType) (issue, error) { +func NotAllocatableIssueTypes() []Type { + return []Type{ + TypeNoPartition, + TypeLivelinessDead, + TypeLivelinessUnknown, + TypeLivelinessNotAvailable, + TypeFailedMachineReclaim, + TypeCrashLoop, + TypeNoEventContainer, + } +} + +func NewIssueFromType(t Type) (issue, error) { switch t { case TypeNoPartition: return &IssueNoPartition{}, nil diff --git a/cmd/metal-api/internal/service/machine-service.go b/cmd/metal-api/internal/service/machine-service.go index 1be575dc9..6e74970ad 100644 --- a/cmd/metal-api/internal/service/machine-service.go +++ b/cmd/metal-api/internal/service/machine-service.go @@ -536,8 +536,8 @@ func (r *machineResource) issues(request *restful.Request, response *restful.Res ms = metal.Machines{} severity = issues.SeverityMinor - only []issues.IssueType - omit []issues.IssueType + only []issues.Type + omit []issues.Type lastErrorThreshold = issues.DefaultLastErrorThreshold() ) diff --git a/cmd/metal-api/internal/service/partition-service.go b/cmd/metal-api/internal/service/partition-service.go index bff122d90..910cf8257 100644 --- a/cmd/metal-api/internal/service/partition-service.go +++ b/cmd/metal-api/internal/service/partition-service.go @@ -365,13 +365,7 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque machinesWithIssues, err := issues.FindIssues(&issues.Config{ Machines: ms, EventContainers: ecs, - Only: []issues.IssueType{ - issues.TypeLivelinessDead, - issues.TypeLivelinessUnknown, - issues.TypeLivelinessNotAvailable, - issues.TypeFailedMachineReclaim, - issues.TypeCrashLoop, - }, + Only: issues.NotAllocatableIssueTypes(), }) if err != nil { return nil, fmt.Errorf("unable to calculate machine issues: %w", err) diff --git a/cmd/metal-api/internal/service/v1/machine.go b/cmd/metal-api/internal/service/v1/machine.go index a964a2f63..e699cb531 100644 --- a/cmd/metal-api/internal/service/v1/machine.go +++ b/cmd/metal-api/internal/service/v1/machine.go @@ -269,8 +269,8 @@ type MachineReinstallRequest struct { type MachineIssuesRequest struct { datastore.MachineSearchQuery - Only []issues.IssueType `json:"only" description:"a list of machine issues to include"` - Omit []issues.IssueType `json:"omit" description:"a list of machine issues to omit"` + Only []issues.Type `json:"only" description:"a list of machine issues to include"` + Omit []issues.Type `json:"omit" description:"a list of machine issues to omit"` Severity string `json:"severity" description:"filters issue for given severity"` LastErrorThreshold time.Duration `json:"last_error_threshold" description:"defines the last error threshold"`