Skip to content

Commit 060563a

Browse files
author
CloudNativePG Automated Updates
committed
chore: sync API
1 parent f149d7a commit 060563a

File tree

3 files changed

+550
-0
lines changed

3 files changed

+550
-0
lines changed

pkg/api/v1/publication_types.go

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
Copyright The CloudNativePG Contributors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// PublicationReclaimPolicy defines a policy for end-of-life maintenance of Publications.
25+
// +enum
26+
type PublicationReclaimPolicy string
27+
28+
const (
29+
// PublicationReclaimDelete means the publication will be deleted from Kubernetes on release
30+
// from its claim.
31+
PublicationReclaimDelete PublicationReclaimPolicy = "delete"
32+
33+
// PublicationReclaimRetain means the publication will be left in its current phase for manual
34+
// reclamation by the administrator. The default policy is Retain.
35+
PublicationReclaimRetain PublicationReclaimPolicy = "retain"
36+
)
37+
38+
// PublicationSpec defines the desired state of Publication
39+
type PublicationSpec struct {
40+
// The name of the PostgreSQL cluster that identifies the "publisher"
41+
ClusterRef corev1.LocalObjectReference `json:"cluster"`
42+
43+
// The name of the publication inside PostgreSQL
44+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
45+
Name string `json:"name"`
46+
47+
// The name of the database where the publication will be installed in
48+
// the "publisher" cluster
49+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
50+
DBName string `json:"dbname"`
51+
52+
// Publication parameters part of the `WITH` clause as expected by
53+
// PostgreSQL `CREATE PUBLICATION` command
54+
// +optional
55+
Parameters map[string]string `json:"parameters,omitempty"`
56+
57+
// Target of the publication as expected by PostgreSQL `CREATE PUBLICATION` command
58+
Target PublicationTarget `json:"target"`
59+
60+
// The policy for end-of-life maintenance of this publication
61+
// +kubebuilder:validation:Enum=delete;retain
62+
// +kubebuilder:default:=retain
63+
// +optional
64+
ReclaimPolicy PublicationReclaimPolicy `json:"publicationReclaimPolicy,omitempty"`
65+
}
66+
67+
// PublicationTarget is what this publication should publish
68+
// +kubebuilder:validation:XValidation:rule="(has(self.allTables) && !has(self.objects)) || (!has(self.allTables) && has(self.objects))",message="allTables and objects are mutually exclusive"
69+
type PublicationTarget struct {
70+
// Marks the publication as one that replicates changes for all tables
71+
// in the database, including tables created in the future.
72+
// Corresponding to `FOR ALL TABLES` in PostgreSQL.
73+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="allTables is immutable"
74+
// +optional
75+
AllTables bool `json:"allTables,omitempty"`
76+
77+
// Just the following schema objects
78+
// +kubebuilder:validation:XValidation:rule="!(self.exists(o, has(o.table) && has(o.table.columns)) && self.exists(o, has(o.tablesInSchema)))",message="specifying a column list when the publication also publishes tablesInSchema is not supported"
79+
// +kubebuilder:validation:MaxItems=100000
80+
// +optional
81+
Objects []PublicationTargetObject `json:"objects,omitempty"`
82+
}
83+
84+
// PublicationTargetObject is an object to publish
85+
// +kubebuilder:validation:XValidation:rule="(has(self.tablesInSchema) && !has(self.table)) || (!has(self.tablesInSchema) && has(self.table))",message="tablesInSchema and table are mutually exclusive"
86+
type PublicationTargetObject struct {
87+
// Marks the publication as one that replicates changes for all tables
88+
// in the specified list of schemas, including tables created in the
89+
// future. Corresponding to `FOR TABLES IN SCHEMA` in PostgreSQL.
90+
// +optional
91+
TablesInSchema string `json:"tablesInSchema,omitempty"`
92+
93+
// Specifies a list of tables to add to the publication. Corresponding
94+
// to `FOR TABLE` in PostgreSQL.
95+
// +optional
96+
Table *PublicationTargetTable `json:"table,omitempty"`
97+
}
98+
99+
// PublicationTargetTable is a table to publish
100+
type PublicationTargetTable struct {
101+
// Whether to limit to the table only or include all its descendants
102+
// +optional
103+
Only bool `json:"only,omitempty"`
104+
105+
// The table name
106+
Name string `json:"name"`
107+
108+
// The schema name
109+
// +optional
110+
Schema string `json:"schema,omitempty"`
111+
112+
// The columns to publish
113+
// +optional
114+
Columns []string `json:"columns,omitempty"`
115+
}
116+
117+
// PublicationStatus defines the observed state of Publication
118+
type PublicationStatus struct {
119+
// A sequence number representing the latest
120+
// desired state that was synchronized
121+
// +optional
122+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
123+
124+
// Applied is true if the publication was reconciled correctly
125+
// +optional
126+
Applied *bool `json:"applied,omitempty"`
127+
128+
// Message is the reconciliation output message
129+
// +optional
130+
Message string `json:"message,omitempty"`
131+
}
132+
133+
// +genclient
134+
// +kubebuilder:object:root=true
135+
// +kubebuilder:subresource:status
136+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
137+
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.cluster.name"
138+
// +kubebuilder:printcolumn:name="PG Name",type="string",JSONPath=".spec.name"
139+
// +kubebuilder:printcolumn:name="Applied",type="boolean",JSONPath=".status.applied"
140+
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message",description="Latest reconciliation message"
141+
142+
// Publication is the Schema for the publications API
143+
type Publication struct {
144+
metav1.TypeMeta `json:",inline"`
145+
metav1.ObjectMeta `json:"metadata"`
146+
147+
Spec PublicationSpec `json:"spec"`
148+
Status PublicationStatus `json:"status,omitempty"`
149+
}
150+
151+
// +kubebuilder:object:root=true
152+
153+
// PublicationList contains a list of Publication
154+
type PublicationList struct {
155+
metav1.TypeMeta `json:",inline"`
156+
metav1.ListMeta `json:"metadata,omitempty"`
157+
Items []Publication `json:"items"`
158+
}
159+
160+
func init() {
161+
SchemeBuilder.Register(&Publication{}, &PublicationList{})
162+
}

pkg/api/v1/subscription_types.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
Copyright The CloudNativePG Contributors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// SubscriptionReclaimPolicy describes a policy for end-of-life maintenance of Subscriptions.
25+
// +enum
26+
type SubscriptionReclaimPolicy string
27+
28+
const (
29+
// SubscriptionReclaimDelete means the subscription will be deleted from Kubernetes on release
30+
// from its claim.
31+
SubscriptionReclaimDelete SubscriptionReclaimPolicy = "delete"
32+
33+
// SubscriptionReclaimRetain means the subscription will be left in its current phase for manual
34+
// reclamation by the administrator. The default policy is Retain.
35+
SubscriptionReclaimRetain SubscriptionReclaimPolicy = "retain"
36+
)
37+
38+
// SubscriptionSpec defines the desired state of Subscription
39+
type SubscriptionSpec struct {
40+
// The name of the PostgreSQL cluster that identifies the "subscriber"
41+
ClusterRef corev1.LocalObjectReference `json:"cluster"`
42+
43+
// The name of the subscription inside PostgreSQL
44+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
45+
Name string `json:"name"`
46+
47+
// The name of the database where the publication will be installed in
48+
// the "subscriber" cluster
49+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
50+
DBName string `json:"dbname"`
51+
52+
// Subscription parameters part of the `WITH` clause as expected by
53+
// PostgreSQL `CREATE SUBSCRIPTION` command
54+
// +optional
55+
Parameters map[string]string `json:"parameters,omitempty"`
56+
57+
// The name of the publication inside the PostgreSQL database in the
58+
// "publisher"
59+
PublicationName string `json:"publicationName"`
60+
61+
// The name of the database containing the publication on the external
62+
// cluster. Defaults to the one in the external cluster definition.
63+
// +optional
64+
PublicationDBName string `json:"publicationDBName,omitempty"`
65+
66+
// The name of the external cluster with the publication ("publisher")
67+
ExternalClusterName string `json:"externalClusterName"`
68+
69+
// The policy for end-of-life maintenance of this subscription
70+
// +kubebuilder:validation:Enum=delete;retain
71+
// +kubebuilder:default:=retain
72+
// +optional
73+
ReclaimPolicy SubscriptionReclaimPolicy `json:"subscriptionReclaimPolicy,omitempty"`
74+
}
75+
76+
// SubscriptionStatus defines the observed state of Subscription
77+
type SubscriptionStatus struct {
78+
// A sequence number representing the latest
79+
// desired state that was synchronized
80+
// +optional
81+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
82+
83+
// Applied is true if the subscription was reconciled correctly
84+
// +optional
85+
Applied *bool `json:"applied,omitempty"`
86+
87+
// Message is the reconciliation output message
88+
// +optional
89+
Message string `json:"message,omitempty"`
90+
}
91+
92+
// +genclient
93+
// +kubebuilder:object:root=true
94+
// +kubebuilder:subresource:status
95+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
96+
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.cluster.name"
97+
// +kubebuilder:printcolumn:name="PG Name",type="string",JSONPath=".spec.name"
98+
// +kubebuilder:printcolumn:name="Applied",type="boolean",JSONPath=".status.applied"
99+
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message",description="Latest reconciliation message"
100+
101+
// Subscription is the Schema for the subscriptions API
102+
type Subscription struct {
103+
metav1.TypeMeta `json:",inline"`
104+
metav1.ObjectMeta `json:"metadata"`
105+
106+
Spec SubscriptionSpec `json:"spec"`
107+
Status SubscriptionStatus `json:"status,omitempty"`
108+
}
109+
110+
// +kubebuilder:object:root=true
111+
112+
// SubscriptionList contains a list of Subscription
113+
type SubscriptionList struct {
114+
metav1.TypeMeta `json:",inline"`
115+
metav1.ListMeta `json:"metadata,omitempty"`
116+
Items []Subscription `json:"items"`
117+
}
118+
119+
func init() {
120+
SchemeBuilder.Register(&Subscription{}, &SubscriptionList{})
121+
}

0 commit comments

Comments
 (0)