Skip to content

Commit

Permalink
Support Conditions on Peering CRDs
Browse files Browse the repository at this point in the history
- Add printer columns so describes have more metadata.
  • Loading branch information
thisisnotashwin committed Jul 11, 2022
1 parent 20b969e commit 8a5f105
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 215 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.terraform/
.terraform.tfstate*
.terraform.lock.hcl
terraform.tfstate*
terraform.tfvars
values.dev.yaml
Expand Down
65 changes: 49 additions & 16 deletions charts/consul/templates/crd-peeringacceptors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ spec:
kind: PeeringAcceptor
listKind: PeeringAcceptorList
plural: peeringacceptors
shortNames:
- peering-acceptor
singular: peeringacceptor
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The sync status of the resource with Consul
jsonPath: .status.conditions[?(@.type=="Synced")].status
name: Synced
type: string
- description: The last successful synced time of the resource with Consul
jsonPath: .status.lastSyncedTime
name: Last Synced
type: date
- description: The age of the resource
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: PeeringAcceptor is the Schema for the peeringacceptors API.
Expand Down Expand Up @@ -67,28 +82,46 @@ spec:
status:
description: PeeringAcceptorStatus defines the observed state of PeeringAcceptor.
properties:
lastReconcileTime:
description: LastReconcileTime is the last time the resource was reconciled.
conditions:
description: Conditions indicate the latest available observations
of a resource's current state.
items:
description: 'Conditions define a readiness condition for a Consul
resource. See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties'
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition.
type: string
required:
- status
- type
type: object
type: array
lastSyncedTime:
description: LastSyncedTime is the last time the resource successfully
synced with Consul.
format: date-time
type: string
latestPeeringVersion:
description: LatestPeeringVersion is the latest version of the resource
that was reconciled.
format: int64
type: integer
reconcileError:
description: ReconcileError shows any errors during the last reconciliation
of this resource.
properties:
error:
description: Error is a boolean indicating if there was an error
during the last reconcile of this resource.
type: boolean
message:
description: Message displays the error message from the last
reconcile.
type: string
type: object
secret:
description: SecretRef shows the status of the secret.
properties:
Expand Down
65 changes: 49 additions & 16 deletions charts/consul/templates/crd-peeringdialers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ spec:
kind: PeeringDialer
listKind: PeeringDialerList
plural: peeringdialers
shortNames:
- peering-dialer
singular: peeringdialer
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The sync status of the resource with Consul
jsonPath: .status.conditions[?(@.type=="Synced")].status
name: Synced
type: string
- description: The last successful synced time of the resource with Consul
jsonPath: .status.lastSyncedTime
name: Last Synced
type: date
- description: The age of the resource
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: PeeringDialer is the Schema for the peeringdialers API.
Expand Down Expand Up @@ -67,28 +82,46 @@ spec:
status:
description: PeeringDialerStatus defines the observed state of PeeringDialer.
properties:
lastReconcileTime:
description: LastReconcileTime is the last time the resource was reconciled.
conditions:
description: Conditions indicate the latest available observations
of a resource's current state.
items:
description: 'Conditions define a readiness condition for a Consul
resource. See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties'
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition.
type: string
required:
- status
- type
type: object
type: array
lastSyncedTime:
description: LastSyncedTime is the last time the resource successfully
synced with Consul.
format: date-time
type: string
latestPeeringVersion:
description: LatestPeeringVersion is the latest version of the resource
that was reconciled.
format: int64
type: integer
reconcileError:
description: ReconcileError shows any errors during the last reconciliation
of this resource.
properties:
error:
description: Error is a boolean indicating if there was an error
during the last reconcile of this resource.
type: boolean
message:
description: Message displays the error message from the last
reconcile.
type: string
type: object
secret:
description: SecretRef shows the status of the secret.
properties:
Expand Down
38 changes: 25 additions & 13 deletions control-plane/api/v1alpha1/peeringacceptor_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -20,6 +21,10 @@ func init() {
//+kubebuilder:subresource:status

// PeeringAcceptor is the Schema for the peeringacceptors API.
// +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=".status.conditions[?(@.type==\"Synced\")].status",description="The sync status of the resource with Consul"
// +kubebuilder:printcolumn:name="Last Synced",type="date",JSONPath=".status.lastSyncedTime",description="The last successful synced time of the resource with Consul"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="The age of the resource"
// +kubebuilder:resource:shortName="peering-acceptor"
type PeeringAcceptor struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -61,22 +66,17 @@ type Secret struct {
type PeeringAcceptorStatus struct {
// LatestPeeringVersion is the latest version of the resource that was reconciled.
LatestPeeringVersion *uint64 `json:"latestPeeringVersion,omitempty"`
// LastReconcileTime is the last time the resource was reconciled.
// +optional
LastReconcileTime *metav1.Time `json:"lastReconcileTime,omitempty" description:"last time the resource was reconciled"`
// ReconcileError shows any errors during the last reconciliation of this resource.
// +optional
ReconcileError *ReconcileErrorStatus `json:"reconcileError,omitempty"`
// SecretRef shows the status of the secret.
// +optional
SecretRef *SecretRefStatus `json:"secret,omitempty"`
}

type ReconcileErrorStatus struct {
// Error is a boolean indicating if there was an error during the last reconcile of this resource.
Error *bool `json:"error,omitempty"`
// Message displays the error message from the last reconcile.
Message *string `json:"message,omitempty"`
// Conditions indicate the latest available observations of a resource's current state.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// LastSyncedTime is the last time the resource successfully synced with Consul.
// +optional
LastSyncedTime *metav1.Time `json:"lastSyncedTime,omitempty" description:"last time the condition transitioned from one status to another"`
}

type SecretRefStatus struct {
Expand Down Expand Up @@ -124,3 +124,15 @@ func (pa *PeeringAcceptor) Validate() error {
}
return nil
}

func (pa *PeeringAcceptor) SetSyncedCondition(status corev1.ConditionStatus, reason string, message string) {
pa.Status.Conditions = Conditions{
{
Type: ConditionSynced,
Status: status,
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
},
}
}
31 changes: 25 additions & 6 deletions control-plane/api/v1alpha1/peeringdialer_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -19,6 +20,10 @@ func init() {
//+kubebuilder:subresource:status

// PeeringDialer is the Schema for the peeringdialers API.
// +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=".status.conditions[?(@.type==\"Synced\")].status",description="The sync status of the resource with Consul"
// +kubebuilder:printcolumn:name="Last Synced",type="date",JSONPath=".status.lastSyncedTime",description="The last successful synced time of the resource with Consul"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="The age of the resource"
// +kubebuilder:resource:shortName="peering-dialer"
type PeeringDialer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -46,15 +51,17 @@ type PeeringDialerSpec struct {
type PeeringDialerStatus struct {
// LatestPeeringVersion is the latest version of the resource that was reconciled.
LatestPeeringVersion *uint64 `json:"latestPeeringVersion,omitempty"`
// LastReconcileTime is the last time the resource was reconciled.
// +optional
LastReconcileTime *metav1.Time `json:"lastReconcileTime,omitempty" description:"last time the resource was reconciled"`
// ReconcileError shows any errors during the last reconciliation of this resource.
// +optional
ReconcileError *ReconcileErrorStatus `json:"reconcileError,omitempty"`
// SecretRef shows the status of the secret.
// +optional
SecretRef *SecretRefStatus `json:"secret,omitempty"`
// Conditions indicate the latest available observations of a resource's current state.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// LastSyncedTime is the last time the resource successfully synced with Consul.
// +optional
LastSyncedTime *metav1.Time `json:"lastSyncedTime,omitempty" description:"last time the condition transitioned from one status to another"`
}

func (pd *PeeringDialer) Secret() *Secret {
Expand Down Expand Up @@ -99,3 +106,15 @@ func (pd *PeeringDialer) Validate() error {
}
return nil
}

func (pd *PeeringDialer) SetSyncedCondition(status corev1.ConditionStatus, reason string, message string) {
pd.Status.Conditions = Conditions{
{
Type: ConditionSynced,
Status: status,
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
},
}
}
Loading

0 comments on commit 8a5f105

Please sign in to comment.