mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
Add ready conditon and cleanup finalizer and status patching (#186)
This change adds a ready condition. It also sets a standard for status fields and documentation. It makes use of helper functions from FluxCD to better manage patching of finalizers and status. Signed-off-by: Philip Laine <philip.laine@gmail.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package v1alpha1
|
||||
|
||||
const NetbirdFinalizer = "finalizers.netbird.io"
|
||||
|
||||
const ReadyCondition = "Ready"
|
||||
|
||||
const (
|
||||
ReconciledReason = "Reconciled"
|
||||
)
|
||||
+27
-15
@@ -4,49 +4,61 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// GroupSpec defines the desired state of Group
|
||||
// GroupSpec defines the desired state of Group.
|
||||
type GroupSpec struct {
|
||||
// name of the group.
|
||||
// Name of the group.
|
||||
// +kubebuilder:validation:MinLength=1
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// GroupStatus defines the observed state of Group.
|
||||
type GroupStatus struct {
|
||||
// ObservedGeneration is the last reconciled generation.
|
||||
// +optional
|
||||
GroupID *string `json:"groupID,omitempty"`
|
||||
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
|
||||
|
||||
// The status of each condition is one of True, False, or Unknown.
|
||||
// Conditions holds the conditions for the Group.
|
||||
// +listType=map
|
||||
// +listMapKey=type
|
||||
// +optional
|
||||
Conditions []metav1.Condition `json:"conditions,omitempty"`
|
||||
|
||||
// GroupID is the id of the created group.
|
||||
// +optional
|
||||
GroupID string `json:"groupID,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:subresource:status
|
||||
// +kubebuilder:resource
|
||||
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
|
||||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
|
||||
|
||||
// Group is the Schema for the groups API
|
||||
// Group is the Schema for the groups API.
|
||||
type Group struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
// metadata is a standard object metadata
|
||||
// +optional
|
||||
metav1.ObjectMeta `json:"metadata,omitzero"`
|
||||
|
||||
// spec defines the desired state of Group
|
||||
// +required
|
||||
Spec GroupSpec `json:"spec"`
|
||||
|
||||
// status defines the observed state of Group
|
||||
// +optional
|
||||
Status GroupStatus `json:"status,omitzero"`
|
||||
// +kubebuilder:default={"observedGeneration":-1}
|
||||
Status GroupStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// GetConditions returns the status conditions of the object.
|
||||
func (g *Group) GetConditions() []metav1.Condition {
|
||||
return g.Status.Conditions
|
||||
}
|
||||
|
||||
// SetConditions sets the status conditions on the object.
|
||||
func (g *Group) SetConditions(conditions []metav1.Condition) {
|
||||
g.Status.Conditions = conditions
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
|
||||
// GroupList contains a list of Group
|
||||
// GroupList contains a list of Group.
|
||||
type GroupList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitzero"`
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// SetupKeySpec defines the desired state of SetupKey
|
||||
// SetupKeySpec defines the desired state of SetupKey.
|
||||
type SetupKeySpec struct {
|
||||
// Ephemeral decides if peers added with the key are ephemeral or not.
|
||||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ephemeral is immutable"
|
||||
@@ -15,42 +15,53 @@ type SetupKeySpec struct {
|
||||
// +optional
|
||||
Duration *metav1.Duration `json:"duration,omitempty"`
|
||||
|
||||
// Groups that will be automatically assigned to resources using setup key.
|
||||
// AutoGroups are groups that will be automatically assigned to peers using setup key.
|
||||
// +optional
|
||||
AutoGroups []ResourceReference `json:"autoGroups,omitempty"`
|
||||
}
|
||||
|
||||
// SetupKeyStatus defines the observed state of SetupKey.
|
||||
type SetupKeyStatus struct {
|
||||
// SetupKeyID of the setup key.
|
||||
SetupKeyID *string `json:"setupKeyID,omitempty"`
|
||||
// ObservedGeneration is the last reconciled generation.
|
||||
// +optional
|
||||
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
|
||||
|
||||
// The status of each condition is one of True, False, or Unknown.
|
||||
// Conditions holds the conditions for the SetupKey.
|
||||
// +listType=map
|
||||
// +listMapKey=type
|
||||
// +optional
|
||||
Conditions []metav1.Condition `json:"conditions,omitempty"`
|
||||
|
||||
// SetupKeyID is the id of the created setup key.
|
||||
SetupKeyID string `json:"setupKeyID,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:subresource:status
|
||||
// +kubebuilder:resource
|
||||
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
|
||||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
|
||||
|
||||
// SetupKey is the Schema for the setupkeys API
|
||||
// SetupKey is the Schema for the setupkeys API.
|
||||
type SetupKey struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
// metadata is a standard object metadata
|
||||
// +optional
|
||||
metav1.ObjectMeta `json:"metadata,omitzero"`
|
||||
|
||||
// spec defines the desired state of SetupKey
|
||||
// +required
|
||||
Spec SetupKeySpec `json:"spec"`
|
||||
|
||||
// status defines the observed state of SetupKey
|
||||
// +optional
|
||||
Status SetupKeyStatus `json:"status,omitzero"`
|
||||
// +kubebuilder:default={"observedGeneration":-1}
|
||||
Status SetupKeyStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// GetConditions returns the status conditions of the object.
|
||||
func (sk *SetupKey) GetConditions() []metav1.Condition {
|
||||
return sk.Status.Conditions
|
||||
}
|
||||
|
||||
// SetConditions sets the status conditions on the object.
|
||||
func (sk *SetupKey) SetConditions(conditions []metav1.Condition) {
|
||||
sk.Status.Conditions = conditions
|
||||
}
|
||||
|
||||
func (sk SetupKey) SecretName() string {
|
||||
@@ -59,7 +70,7 @@ func (sk SetupKey) SecretName() string {
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
|
||||
// SetupKeyList contains a list of SetupKey
|
||||
// SetupKeyList contains a list of SetupKey.
|
||||
type SetupKeyList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitzero"`
|
||||
|
||||
@@ -87,11 +87,6 @@ func (in *GroupSpec) DeepCopy() *GroupSpec {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *GroupStatus) DeepCopyInto(out *GroupStatus) {
|
||||
*out = *in
|
||||
if in.GroupID != nil {
|
||||
in, out := &in.GroupID, &out.GroupID
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Conditions != nil {
|
||||
in, out := &in.Conditions, &out.Conditions
|
||||
*out = make([]v1.Condition, len(*in))
|
||||
@@ -225,11 +220,6 @@ func (in *SetupKeySpec) DeepCopy() *SetupKeySpec {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *SetupKeyStatus) DeepCopyInto(out *SetupKeyStatus) {
|
||||
*out = *in
|
||||
if in.SetupKeyID != nil {
|
||||
in, out := &in.SetupKeyID, &out.SetupKeyID
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Conditions != nil {
|
||||
in, out := &in.Conditions, &out.Conditions
|
||||
*out = make([]v1.Condition, len(*in))
|
||||
|
||||
Reference in New Issue
Block a user