Skip to content

Commit b7ed725

Browse files
authoredOct 28, 2022
Merge pull request #6 from pluralsh/master
add conditions
2 parents 5dbd1f2 + 50c02c4 commit b7ed725

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed
 

‎apis/database/v1alpha1/database_types.go

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
crhelperTypes "github.com/pluralsh/controller-reconcile-helper/pkg/types"
2021
corev1 "k8s.io/api/core/v1"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
@@ -25,6 +26,14 @@ func init() {
2526
SchemeBuilder.Register(&Database{}, &DatabaseList{})
2627
}
2728

29+
const (
30+
// DatabaseReadyCondition used when database is ready.
31+
DatabaseReadyCondition crhelperTypes.ConditionType = "DatabaseReady"
32+
33+
// FailedToCreateDatabaseReason used when grpc method for database creation failed.
34+
FailedToCreateDatabaseReason = "FailedToCreateDatabase"
35+
)
36+
2837
type DatabaseSpec struct {
2938
// DriverName is the name of driver associated with this database
3039
DriverName string `json:"driverName"`
@@ -62,11 +71,27 @@ type DatabaseStatus struct {
6271
// DatabaseID is the unique id of the database
6372
// +optional
6473
DatabaseID string `json:"databaseID,omitempty"`
74+
75+
// Conditions defines current state.
76+
// +optional
77+
Conditions crhelperTypes.Conditions `json:"conditions,omitempty"`
78+
}
79+
80+
// GetConditions returns the list of conditions for a WireGuardServer API object.
81+
func (db *Database) GetConditions() crhelperTypes.Conditions {
82+
return db.Status.Conditions
83+
}
84+
85+
// SetConditions will set the given conditions on a WireGuardServer object.
86+
func (db *Database) SetConditions(conditions crhelperTypes.Conditions) {
87+
db.Status.Conditions = conditions
6588
}
6689

6790
// +kubebuilder:object:root=true
6891
// +kubebuilder:resource:scope=Cluster
6992
// +kubebuilder:subresource:status
93+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Database ready status"
94+
7095
type Database struct {
7196
metav1.TypeMeta `json:",inline"`
7297
// +optional

‎apis/database/v1alpha1/zz_generated.deepcopy.go

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/database.plural.sh_databases.yaml

+49-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ spec:
1515
singular: database
1616
scope: Cluster
1717
versions:
18-
- name: v1alpha1
18+
- additionalPrinterColumns:
19+
- description: Database ready status
20+
jsonPath: .status.ready
21+
name: Ready
22+
type: string
23+
name: v1alpha1
1924
schema:
2025
openAPIV3Schema:
2126
properties:
@@ -103,6 +108,49 @@ spec:
103108
type: object
104109
status:
105110
properties:
111+
conditions:
112+
description: Conditions defines current state.
113+
items:
114+
properties:
115+
lastTransitionTime:
116+
description: Last time the condition transitioned from one status
117+
to another. This should be when the underlying condition changed.
118+
If that is not known, then using the time when the API field
119+
changed is acceptable.
120+
format: date-time
121+
type: string
122+
message:
123+
description: A human readable message indicating details about
124+
the transition. This field may be empty.
125+
type: string
126+
reason:
127+
description: The reason for the condition's last transition
128+
in CamelCase. The specific API may choose whether or not this
129+
field is considered a guaranteed API. This field may not be
130+
empty.
131+
type: string
132+
severity:
133+
description: Severity provides an explicit classification of
134+
Reason code, so the users or machines can immediately understand
135+
the current situation and act accordingly. The Severity field
136+
MUST be set only when Status=False.
137+
type: string
138+
status:
139+
description: Status of the condition, one of True, False, Unknown.
140+
type: string
141+
type:
142+
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
143+
Many .condition.type values are consistent across resources
144+
like Available, but because arbitrary conditions can be useful
145+
(see .node.status.conditions), the ability to deconflict is
146+
important.
147+
type: string
148+
required:
149+
- lastTransitionTime
150+
- status
151+
- type
152+
type: object
153+
type: array
106154
databaseID:
107155
description: DatabaseID is the unique id of the database
108156
type: string

‎go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.18
44

55
require (
66
github.com/golang/protobuf v1.5.2
7+
github.com/pluralsh/controller-reconcile-helper v0.0.4
78
google.golang.org/grpc v1.50.0
89
google.golang.org/protobuf v1.28.0
910
k8s.io/api v0.25.0

‎go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
5050
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
5151
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
5252
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
53+
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
54+
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
5355
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5456
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5557
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=

0 commit comments

Comments
 (0)