Skip to content

Commit

Permalink
More naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Oct 9, 2023
1 parent aca10db commit 81db52e
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/asn-uniqueness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
TypeASNUniqueness IssueType = "asn-not-unique"
TypeASNUniqueness Type = "asn-not-unique"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/bmc-info-outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
TypeBMCInfoOutdated IssueType = "bmc-info-outdated"
TypeBMCInfoOutdated Type = "bmc-info-outdated"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/bmc-without-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/bmc-without-mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/crash-loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
TypeCrashLoop IssueType = "crashloop"
TypeCrashLoop Type = "crashloop"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/failed-machine-reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
TypeFailedMachineReclaim IssueType = "failed-machine-reclaim"
TypeFailedMachineReclaim Type = "failed-machine-reclaim"
)

type (
Expand Down
10 changes: 5 additions & 5 deletions cmd/metal-api/internal/issues/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +52,7 @@ type (

// spec defines the specification of an issue.
spec struct {
Type IssueType
Type Type
Severity IssueSeverity
Description string
RefURL string
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions cmd/metal-api/internal/issues/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/last-event-error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
TypeLastEventError IssueType = "last-event-error"
TypeLastEventError Type = "last-event-error"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/liveliness-dead.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/liveliness-not-available.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/liveliness-unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/no-event-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
TypeNoEventContainer IssueType = "no-event-container"
TypeNoEventContainer Type = "no-event-container"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/no-partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/non-distinct-bmc-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
TypeNonDistinctBMCIP IssueType = "bmc-no-distinct-ip"
TypeNonDistinctBMCIP Type = "bmc-no-distinct-ip"
)

type (
Expand Down
20 changes: 16 additions & 4 deletions cmd/metal-api/internal/issues/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down
8 changes: 1 addition & 7 deletions cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/service/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 81db52e

Please sign in to comment.