Skip to content

Commit

Permalink
Remove Is() as it is not very intuitive.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Oct 9, 2023
1 parent 81db52e commit 8f88066
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 50 deletions.
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 @@ -20,7 +20,7 @@ func (i *IssueLivelinessDead) Spec() *spec {
}

func (i *IssueLivelinessDead) Evaluate(m metal.Machine, ec metal.ProvisioningEventContainer, c *Config) bool {
return ec.Liveliness.Is(string(metal.MachineLivelinessDead))
return ec.Liveliness == metal.MachineLivelinessDead
}

func (i *IssueLivelinessDead) Details() string {
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 @@ -20,7 +20,7 @@ func (i *IssueLivelinessUnknown) Spec() *spec {
}

func (i *IssueLivelinessUnknown) Evaluate(m metal.Machine, ec metal.ProvisioningEventContainer, c *Config) bool {
return ec.Liveliness.Is(string(metal.MachineLivelinessUnknown))
return ec.Liveliness == metal.MachineLivelinessUnknown
}

func (i *IssueLivelinessUnknown) Details() string {
Expand Down
5 changes: 0 additions & 5 deletions cmd/metal-api/internal/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ const (
MachineResurrectAfter time.Duration = time.Hour
)

// Is return true if given liveliness is equal to specific Liveliness
func (l MachineLiveliness) Is(liveliness string) bool {
return string(l) == liveliness
}

// DiskCapacity calculates the capacity of all disks.
func (hw *MachineHardware) DiskCapacity() uint64 {
var c uint64
Expand Down
5 changes: 0 additions & 5 deletions cmd/metal-api/internal/metal/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ var (
// ProvisioningEvents is just a list of ProvisioningEvents
type ProvisioningEvents []ProvisioningEvent

// Is return true if given event is equal to specific EventType
func (p ProvisioningEventType) Is(event ProvisioningEventType) bool {
return p == event
}

// TrimEvents trim the events to maxCount
func (p *ProvisioningEventContainer) TrimEvents(maxCount int) {
if len(p.Events) > maxCount {
Expand Down
36 changes: 0 additions & 36 deletions cmd/metal-api/internal/metal/provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,6 @@ import (
"time"
)

func TestProvisioningEventType_Is(t *testing.T) {
tests := []struct {
name string
event ProvisioningEventType
p ProvisioningEventType
want bool
}{
{
name: "simple",
event: "Waiting",
p: ProvisioningEventWaiting,
want: true,
},
{
name: "simple",
event: "Waiting",
p: ProvisioningEventInstalling,
want: false,
},
{
name: "simple",
event: "Alive",
p: ProvisioningEventAlive,
want: true,
},
}
for i := range tests {
tt := tests[i]
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Is(tt.event); got != tt.want {
t.Errorf("ProvisioningEventType.Is() = %v, want %v", got, tt.want)
}
})
}
}

func TestProvisioningEventContainer_Validate(t *testing.T) {
now := time.Now()
tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ func (r *machineResource) deleteMachine(request *restful.Request, response *rest
r.sendError(request, response, defaultError(err))
return
}
if err == nil && !ec.Liveliness.Is(string(metal.MachineLivelinessDead)) {
if err == nil && ec.Liveliness != metal.MachineLivelinessDead {
r.sendError(request, response, defaultError(errors.New("can only delete dead machines")))
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque
continue
}

if m.State.Value == metal.AvailableState && metal.ProvisioningEventWaiting.Is(pointer.FirstOrZero(ec.Events).Event) {
if m.State.Value == metal.AvailableState && metal.ProvisioningEventWaiting == pointer.FirstOrZero(ec.Events).Event {
cap.Free++
continue
}
Expand Down

0 comments on commit 8f88066

Please sign in to comment.