From 50c02c4df9bc7551978c9e15d1a0d3e5e898a600 Mon Sep 17 00:00:00 2001 From: test Date: Fri, 28 Oct 2022 12:17:10 +0200 Subject: [PATCH] add conditions --- apis/database/v1alpha1/database_types.go | 25 ++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 10 +++- .../bases/database.plural.sh_databases.yaml | 50 ++++++++++++++++++- go.mod | 1 + go.sum | 2 + 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/apis/database/v1alpha1/database_types.go b/apis/database/v1alpha1/database_types.go index 1ea71c5..2b1b77a 100644 --- a/apis/database/v1alpha1/database_types.go +++ b/apis/database/v1alpha1/database_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + crhelperTypes "github.com/pluralsh/controller-reconcile-helper/pkg/types" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -25,6 +26,14 @@ func init() { SchemeBuilder.Register(&Database{}, &DatabaseList{}) } +const ( + // DatabaseReadyCondition used when database is ready. + DatabaseReadyCondition crhelperTypes.ConditionType = "DatabaseReady" + + // FailedToCreateDatabaseReason used when grpc method for database creation failed. + FailedToCreateDatabaseReason = "FailedToCreateDatabase" +) + type DatabaseSpec struct { // DriverName is the name of driver associated with this database DriverName string `json:"driverName"` @@ -62,11 +71,27 @@ type DatabaseStatus struct { // DatabaseID is the unique id of the database // +optional DatabaseID string `json:"databaseID,omitempty"` + + // Conditions defines current state. + // +optional + Conditions crhelperTypes.Conditions `json:"conditions,omitempty"` +} + +// GetConditions returns the list of conditions for a WireGuardServer API object. +func (db *Database) GetConditions() crhelperTypes.Conditions { + return db.Status.Conditions +} + +// SetConditions will set the given conditions on a WireGuardServer object. +func (db *Database) SetConditions(conditions crhelperTypes.Conditions) { + db.Status.Conditions = conditions } // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Database ready status" + type Database struct { metav1.TypeMeta `json:",inline"` // +optional diff --git a/apis/database/v1alpha1/zz_generated.deepcopy.go b/apis/database/v1alpha1/zz_generated.deepcopy.go index 5595ce9..929001d 100644 --- a/apis/database/v1alpha1/zz_generated.deepcopy.go +++ b/apis/database/v1alpha1/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ limitations under the License. package v1alpha1 import ( + "github.com/pluralsh/controller-reconcile-helper/pkg/types" "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -32,7 +33,7 @@ func (in *Database) DeepCopyInto(out *Database) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Database. @@ -421,6 +422,13 @@ func (in *DatabaseSpec) DeepCopy() *DatabaseSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatabaseStatus) DeepCopyInto(out *DatabaseStatus) { *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make(types.Conditions, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatabaseStatus. diff --git a/config/crd/bases/database.plural.sh_databases.yaml b/config/crd/bases/database.plural.sh_databases.yaml index e752750..b172ce9 100644 --- a/config/crd/bases/database.plural.sh_databases.yaml +++ b/config/crd/bases/database.plural.sh_databases.yaml @@ -15,7 +15,12 @@ spec: singular: database scope: Cluster versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Database ready status + jsonPath: .status.ready + name: Ready + type: string + name: v1alpha1 schema: openAPIV3Schema: properties: @@ -103,6 +108,49 @@ spec: type: object status: properties: + conditions: + description: Conditions defines current state. + items: + properties: + lastTransitionTime: + description: Last time the condition transitioned from one status + to another. This should be when the underlying condition changed. + If that is not known, then using the time when the API field + changed is acceptable. + format: date-time + type: string + message: + description: A human readable message indicating details about + the transition. This field may be empty. + type: string + reason: + description: The reason for the condition's last transition + in CamelCase. The specific API may choose whether or not this + field is considered a guaranteed API. This field may not be + empty. + type: string + severity: + description: Severity provides an explicit classification of + Reason code, so the users or machines can immediately understand + the current situation and act accordingly. The Severity field + MUST be set only when Status=False. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: Type of condition in CamelCase or in foo.example.com/CamelCase. + Many .condition.type values are consistent across resources + like Available, but because arbitrary conditions can be useful + (see .node.status.conditions), the ability to deconflict is + important. + type: string + required: + - lastTransitionTime + - status + - type + type: object + type: array databaseID: description: DatabaseID is the unique id of the database type: string diff --git a/go.mod b/go.mod index 693ab10..22f2c07 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/golang/protobuf v1.5.2 + github.com/pluralsh/controller-reconcile-helper v0.0.4 google.golang.org/grpc v1.50.0 google.golang.org/protobuf v1.28.0 k8s.io/api v0.25.0 diff --git a/go.sum b/go.sum index c896e10..42bb5bf 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E= +github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=