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

Support Conditions on Peering CRDs #1335

Merged
merged 2 commits into from
Jul 21, 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
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FEATURES:
* [Experimental] Cluster Peering:
* Add support for secret watchers on the Peering Acceptor and Peering Dialer controllers. [[GH-1284](https://github.com/hashicorp/consul-k8s/pull/1284)]
* Add support for version annotation on the Peering Acceptor and Peering Dialer controllers. [[GH-1302](https://github.com/hashicorp/consul-k8s/pull/1302)]
* Add validation webhooks for the Peering Acceptor and Peering Dialer CRDs [[GH-1310](https://github.com/hashicorp/consul-k8s/pull/1310)]
* Add validation webhooks for the Peering Acceptor and Peering Dialer CRDs. [[GH-1310](https://github.com/hashicorp/consul-k8s/pull/1310)]
* Add Conditions to the status of the Peering Acceptor and Peering Dialer CRDs. [[GH-1335](https://github.com/hashicorp/consul-k8s/pull/1335)]

IMPROVEMENTS:
* Control Plane
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