Skip to content
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

Simplify & Fix Prefix / PrefixAllocation #408

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions apis/ipam/prefix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,25 @@ func (s *PrefixSpec) IsRoot() bool {

// PrefixStatus defines the observed state of Prefix
type PrefixStatus struct {
// Conditions is a list of conditions of a Prefix.
Conditions []PrefixCondition
// Phase is the PrefixPhase of the Prefix.
Phase PrefixPhase
// LastPhaseTransitionTime is the last time the Phase changed values.
LastPhaseTransitionTime *metav1.Time

// Used is a list of used prefixes.
Used []commonv1alpha1.IPPrefix
}

type PrefixConditionType string
// PrefixPhase is a phase a Prefix can be in.
type PrefixPhase string

const (
PrefixReady PrefixConditionType = "Ready"
// PrefixPhasePending marks a prefix as waiting for allocation.
PrefixPhasePending PrefixPhase = "Pending"
// PrefixPhaseAllocated marks a prefix as allocated.
PrefixPhaseAllocated PrefixPhase = "Allocated"
)

type PrefixCondition struct {
Type PrefixConditionType
Status corev1.ConditionStatus
Reason string
Message string
LastTransitionTime metav1.Time
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient

Expand Down
31 changes: 16 additions & 15 deletions apis/ipam/prefixallocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@ type PrefixAllocationSpec struct {
PrefixSelector *metav1.LabelSelector
}

// PrefixAllocationPhase is a phase a PrefixAllocation can be in.
type PrefixAllocationPhase string

const (
// PrefixAllocationPhasePending marks a PrefixAllocation as waiting for allocation.
PrefixAllocationPhasePending PrefixAllocationPhase = "Pending"
// PrefixAllocationPhaseAllocated marks a PrefixAllocation as allocated by a Prefix.
PrefixAllocationPhaseAllocated PrefixAllocationPhase = "Allocated"
// PrefixAllocationPhaseFailed marks a PrefixAllocation as failed.
PrefixAllocationPhaseFailed PrefixAllocationPhase = "Failed"
)

// PrefixAllocationStatus is the status of a PrefixAllocation.
type PrefixAllocationStatus struct {
// Prefix is the allocated prefix, if any
Prefix *commonv1alpha1.IPPrefix
// Conditions represent various state aspects of a PrefixAllocation.
Conditions []PrefixAllocationCondition
}

type PrefixAllocationConditionType string

const (
PrefixAllocationReady PrefixAllocationConditionType = "Ready"
)
// LastPhaseTransitionTime is the last time the Phase changed values.
LastPhaseTransitionTime *metav1.Time

type PrefixAllocationCondition struct {
Type PrefixAllocationConditionType
Status corev1.ConditionStatus
Reason string
Message string
LastTransitionTime metav1.Time
// Phase is the phase of the PrefixAllocation.
Phase PrefixAllocationPhase
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
100 changes: 0 additions & 100 deletions apis/ipam/readiness.go

This file was deleted.

36 changes: 11 additions & 25 deletions apis/ipam/v1alpha1/prefix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,27 @@ type PrefixSpec struct {
ParentSelector *metav1.LabelSelector `json:"parentSelector,omitempty"`
}

func (s *PrefixSpec) IsRoot() bool {
return s.ParentRef == nil && s.ParentSelector == nil
}

// PrefixStatus defines the observed state of Prefix
type PrefixStatus struct {
// Conditions is a list of conditions of a Prefix.
Conditions []PrefixCondition `json:"conditions,omitempty"`
// Phase is the PrefixPhase of the Prefix.
Phase PrefixPhase `json:"phase,omitempty"`
// LastPhaseTransitionTime is the last time the Phase changed values.
LastPhaseTransitionTime *metav1.Time `json:"lastPhaseTransitionTime,omitempty"`

// Used is a list of used prefixes.
Used []commonv1alpha1.IPPrefix `json:"used,omitempty"`
}

type PrefixConditionType string
// PrefixPhase is a phase a Prefix can be in.
type PrefixPhase string

const (
PrefixReady PrefixConditionType = "Ready"
// PrefixPhasePending marks a prefix as waiting for allocation.
PrefixPhasePending PrefixPhase = "Pending"
// PrefixPhaseAllocated marks a prefix as allocated.
PrefixPhaseAllocated PrefixPhase = "Allocated"
)

type PrefixCondition struct {
Type PrefixConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand All @@ -82,15 +77,6 @@ type Prefix struct {
Status PrefixStatus `json:"status,omitempty"`
}

func (p *Prefix) IsRoot() bool {
return p.Spec.IsRoot()
}

func (p *Prefix) Readiness() Readiness {
readiness, _ := GetPrefixConditionsReadinessAndIndex(p.Status.Conditions)
return readiness
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PrefixList contains a list of Prefix
Expand Down
40 changes: 25 additions & 15 deletions apis/ipam/v1alpha1/prefixallocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,36 @@ type PrefixAllocationSpec struct {
PrefixSelector *metav1.LabelSelector `json:"prefixSelector,omitempty"`
}

// PrefixAllocationStatus is the status of a PrefixAllocation.
type PrefixAllocationStatus struct {
// Prefix is the allocated prefix, if any
Prefix *commonv1alpha1.IPPrefix `json:"prefix,omitempty"`
// Conditions represent various state aspects of a PrefixAllocation.
Conditions []PrefixAllocationCondition `json:"conditions,omitempty"`
}
// PrefixAllocationPhase is a phase a PrefixAllocation can be in.
type PrefixAllocationPhase string

type PrefixAllocationConditionType string
func (p PrefixAllocationPhase) IsTerminal() bool {
switch p {
case PrefixAllocationPhaseFailed, PrefixAllocationPhaseAllocated:
return true
default:
return false
}
}

const (
PrefixAllocationReady PrefixAllocationConditionType = "Ready"
// PrefixAllocationPhasePending marks a PrefixAllocation as waiting for allocation.
PrefixAllocationPhasePending PrefixAllocationPhase = "Pending"
// PrefixAllocationPhaseAllocated marks a PrefixAllocation as allocated by a Prefix.
PrefixAllocationPhaseAllocated PrefixAllocationPhase = "Allocated"
// PrefixAllocationPhaseFailed marks a PrefixAllocation as failed.
PrefixAllocationPhaseFailed PrefixAllocationPhase = "Failed"
)

type PrefixAllocationCondition struct {
Type PrefixAllocationConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// PrefixAllocationStatus is the status of a PrefixAllocation.
type PrefixAllocationStatus struct {
// Prefix is the allocated prefix, if any
Prefix *commonv1alpha1.IPPrefix `json:"prefix,omitempty"`

// Phase is the phase of the PrefixAllocation.
Phase PrefixAllocationPhase `json:"phase,omitempty"`
// LastPhaseTransitionTime is the last time the Phase changed values.
LastPhaseTransitionTime *metav1.Time `json:"lastPhaseTransitionTime,omitempty"`
}

// +genclient
Expand Down
101 changes: 0 additions & 101 deletions apis/ipam/v1alpha1/readiness.go

This file was deleted.

Loading