Skip to content

Commit 853d5de

Browse files
committed
Add Cluster_types and Cluster_controller first iteration
1 parent d8d9f5f commit 853d5de

File tree

52 files changed

+1884
-56564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1884
-56564
lines changed

PROJECT

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,16 @@ resources:
128128
controller: true
129129
domain: splunk.com
130130
group: enterprise
131-
kind: DatabaseClass
131+
kind: ClusterClass
132+
path: github.com/splunk/splunk-operator/api/v4
133+
version: v4
134+
- api:
135+
crdVersion: v1
136+
namespaced: true
137+
controller: true
138+
domain: splunk.com
139+
group: enterprise
140+
kind: Cluster
132141
path: github.com/splunk/splunk-operator/api/v4
133142
version: v4
134143
version: "3"

api/v4/cluster_types.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
Copyright 2021.
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 v4
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
"k8s.io/apimachinery/pkg/api/resource"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
24+
25+
// ClusterSpec defines the desired state of Cluster.
26+
type ClusterSpec struct {
27+
// Reference to ClusterClass for default configuration by name.
28+
// This field is IMMUTABLE after creation.
29+
// +kubebuilder:validation:Required
30+
// +kubebuilder:validation:MinLength=1
31+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="class is immutable"
32+
Class string `json:"class"`
33+
34+
// Storage overrides the storage size from ClusterClass.
35+
// Example: "5Gi"
36+
// +optional
37+
// +kubebuilder:validation:XValidation:rule="self == null || oldSelf == null || quantity(self).compareTo(quantity(oldSelf)) >= 0",message="storage size can only be increased"
38+
Storage *resource.Quantity `json:"storage,omitempty"`
39+
40+
// Instances overrides the number of PostgreSQL instances from ClusterClass.
41+
// +optional
42+
// +kubebuilder:validation:Minimum=1
43+
// +kubebuilder:validation:Maximum=10
44+
Instances *int32 `json:"instances,omitempty"`
45+
46+
// PostgresVersion overrides the PostgreSQL version from ClusterClass.
47+
// Example: "16"
48+
// +optional
49+
PostgresVersion *string `json:"postgresVersion,omitempty"`
50+
51+
// Resources overrides CPU/memory resources from ClusterClass.
52+
// +optional
53+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
54+
55+
// PostgreSQL overrides PostgreSQL engine parameters from ClusterClass.
56+
// Maps to postgresql.conf settings.
57+
// +optional
58+
PostgreSQLConfig map[string]string `json:"postgresqlConfig,omitempty"`
59+
60+
// PgHBA contains pg_hba.conf host-based authentication rules.
61+
// Defines client authentication and connection security (cluster-wide).
62+
// Example: ["hostssl all all 0.0.0.0/0 scram-sha-256"]
63+
// +optional
64+
PgHBA []string `json:"pgHBA,omitempty"`
65+
}
66+
67+
// ClusterStatus defines the observed state of Cluster.
68+
type ClusterStatus struct {
69+
// Phase represents the current phase of the Cluster.
70+
// Values: "Pending", "Provisioning", "Failed", "Ready", "Deleting"
71+
// +optional
72+
Phase string `json:"phase,omitempty"`
73+
74+
// Conditions represent the latest available observations of the Cluster's state.
75+
// +optional
76+
Conditions []metav1.Condition `json:"conditions,omitempty"`
77+
78+
// ProvisionerRef contains reference to the provisioner resource managing this cluster.
79+
// Right now, only CNPG is supported.
80+
// +optional
81+
ProvisionerRef *corev1.ObjectReference `json:"provisionerRef,omitempty"`
82+
}
83+
84+
// +kubebuilder:object:root=true
85+
// +kubebuilder:subresource:status
86+
// +kubebuilder:resource:scope=Namespaced
87+
// +kubebuilder:printcolumn:name="Class",type=string,JSONPath=`.spec.class`
88+
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
89+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
90+
91+
// Cluster is the Schema for the clusters API.
92+
type Cluster struct {
93+
metav1.TypeMeta `json:",inline"`
94+
metav1.ObjectMeta `json:"metadata,omitempty"`
95+
96+
Spec ClusterSpec `json:"spec,omitempty"`
97+
Status ClusterStatus `json:"status,omitempty"`
98+
}
99+
100+
// +kubebuilder:object:root=true
101+
102+
// ClusterList contains a list of Cluster.
103+
type ClusterList struct {
104+
metav1.TypeMeta `json:",inline"`
105+
metav1.ListMeta `json:"metadata,omitempty"`
106+
Items []Cluster `json:"items"`
107+
}
108+
109+
func init() {
110+
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
111+
}

api/v4/clusterclass_types.go

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
Copyright 2021.
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 v4
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
"k8s.io/apimachinery/pkg/api/resource"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
24+
25+
// ClusterClassSpec defines the desired state of ClusterClass.
26+
// ClusterClass is immutable after creation - it serves as a template for Cluster CRs.
27+
type ClusterClassSpec struct {
28+
// Provisioner identifies which database provisioner to use.
29+
// Currently supported: "postgresql.cnpg.io" (CloudNativePG)
30+
// +kubebuilder:validation:Required
31+
// +kubebuilder:validation:Enum=postgresql.cnpg.io
32+
Provisioner string `json:"provisioner"`
33+
34+
// ClusterConfig contains cluster-level configuration.
35+
// These settings apply to database cluster infrastructure.
36+
// Can be overridden in Cluster CR.
37+
// +kubebuilder:default={}
38+
// +optional
39+
ClusterConfig ClusterConfig `json:"clusterConfig,omitempty"`
40+
41+
// CNPG contains CloudNativePG-specific configuration and policies.
42+
// Only used when Provisioner is "postgresql.cnpg.io"
43+
// These settings CANNOT be overridden in Cluster CR (platform policy).
44+
// +optional
45+
CNPG *CNPGConfig `json:"cnpg,omitempty"`
46+
}
47+
48+
// ClusterConfig contains provider-agnostic cluster configuration.
49+
// These fields define database cluster infrastructure and can be overridden in Cluster CR.
50+
type ClusterConfig struct {
51+
// Instances is the number of database instances (1 primary + N replicas).
52+
// Single instance (1) is suitable for development.
53+
// High availability requires at least 3 instances (1 primary + 2 replicas).
54+
// +kubebuilder:validation:Minimum=1
55+
// +kubebuilder:validation:Maximum=10
56+
// +kubebuilder:default=1
57+
// +optional
58+
Instances *int32 `json:"instances,omitempty"`
59+
60+
// Storage is the size of persistent volume for each instance.
61+
// Cannot be decreased after cluster creation (PostgreSQL limitation).
62+
// Recommended minimum: 10Gi for production viability.
63+
// Example: "50Gi", "100Gi", "1Ti"
64+
// +kubebuilder:default="1Gi"
65+
// +optional
66+
Storage *resource.Quantity `json:"storage,omitempty"`
67+
68+
// PostgresVersion is the PostgreSQL version (major or major.minor).
69+
// Examples: "18" (latest 18.x), "18.1" (specific minor), "17", "16"
70+
// +kubebuilder:validation:Pattern=`^[0-9]+(\.[0-9]+)?$`
71+
// +kubebuilder:default="15"
72+
// +optional
73+
PostgresVersion *string `json:"postgresVersion,omitempty"`
74+
75+
// Resources defines CPU and memory requests/limits per instance.
76+
// All instances in the cluster have the same resources.
77+
// +optional
78+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
79+
80+
// PostgreSQLConfig contains PostgreSQL engine configuration parameters.
81+
// Maps to postgresql.conf settings (cluster-wide).
82+
// Example: {"max_connections": "200", "shared_buffers": "2GB"}
83+
// +optional
84+
PostgreSQLConfig map[string]string `json:"postgresqlConfig,omitempty"`
85+
86+
// PgHBA contains pg_hba.conf host-based authentication rules.
87+
// Defines client authentication and connection security (cluster-wide).
88+
// Example: ["hostssl all all 0.0.0.0/0 scram-sha-256"]
89+
// +optional
90+
PgHBA []string `json:"pgHBA,omitempty"`
91+
}
92+
93+
// CNPGConfig contains CloudNativePG-specific configuration.
94+
// These fields control CNPG operator behavior and enforce platform policies.
95+
// Cannot be overridden in Cluster CR.
96+
type CNPGConfig struct {
97+
// PrimaryUpdateMethod determines how the primary instance is updated.
98+
// "restart" - tolerate brief downtime (suitable for development)
99+
// "switchover" - minimal downtime via automated failover (production-grade)
100+
//
101+
// NOTE: When using "switchover", ensure clusterConfig.instances > 1.
102+
// Switchover requires at least one replica to fail over to.
103+
// +kubebuilder:validation:Enum=restart;switchover
104+
// +kubebuilder:default=switchover
105+
// +optional
106+
PrimaryUpdateMethod string `json:"primaryUpdateMethod,omitempty"`
107+
}
108+
109+
// ClusterClassStatus defines the observed state of ClusterClass.
110+
type ClusterClassStatus struct {
111+
// Conditions represent the latest available observations of the ClusterClass state.
112+
// +optional
113+
Conditions []metav1.Condition `json:"conditions,omitempty"`
114+
115+
// Phase represents the current phase of the ClusterClass.
116+
// Valid phases: "Ready", "Invalid"
117+
// +optional
118+
Phase string `json:"phase,omitempty"`
119+
}
120+
121+
// +kubebuilder:object:root=true
122+
// +kubebuilder:subresource:status
123+
// +kubebuilder:resource:scope=Cluster
124+
// +kubebuilder:printcolumn:name="Provisioner",type=string,JSONPath=`.spec.provisioner`
125+
// +kubebuilder:printcolumn:name="Instances",type=integer,JSONPath=`.spec.clusterConfig.instances`
126+
// +kubebuilder:printcolumn:name="Storage",type=string,JSONPath=`.spec.clusterConfig.storage`
127+
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.clusterConfig.postgresVersion`
128+
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
129+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
130+
131+
// ClusterClass is the Schema for the clusterclasses API.
132+
// ClusterClass defines a reusable template and policy for database cluster provisioning.
133+
type ClusterClass struct {
134+
metav1.TypeMeta `json:",inline"`
135+
metav1.ObjectMeta `json:"metadata,omitempty"`
136+
137+
Spec ClusterClassSpec `json:"spec,omitempty"`
138+
Status ClusterClassStatus `json:"status,omitempty"`
139+
}
140+
141+
// +kubebuilder:object:root=true
142+
143+
// ClusterClassList contains a list of ClusterClass.
144+
type ClusterClassList struct {
145+
metav1.TypeMeta `json:",inline"`
146+
metav1.ListMeta `json:"metadata,omitempty"`
147+
Items []ClusterClass `json:"items"`
148+
}
149+
150+
func init() {
151+
SchemeBuilder.Register(&ClusterClass{}, &ClusterClassList{})
152+
}

api/v4/database_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,38 @@ import (
2424

2525
// DatabaseSpec defines the desired state of Database.
2626
type DatabaseSpec struct {
27-
// Class references a DatabaseClass (cluster-scoped) by name.
27+
// Class references a ClusterClass (cluster-scoped) by name.
2828
// This field is IMMUTABLE after creation.
2929
// +kubebuilder:validation:Required
3030
// +kubebuilder:validation:MinLength=1
3131
Class string `json:"class"`
3232

33-
// Storage overrides the storage size from DatabaseClass.
33+
// Storage overrides the storage size from ClusterClass.
3434
// Example: "500Gi"
3535
// +optional
3636
Storage *resource.Quantity `json:"storage,omitempty"`
3737

38-
// Instances overrides the number of PostgreSQL instances from DatabaseClass.
38+
// Instances overrides the number of PostgreSQL instances from ClusterClass.
3939
// +optional
4040
// +kubebuilder:validation:Minimum=1
4141
// +kubebuilder:validation:Maximum=10
4242
Instances *int32 `json:"instances,omitempty"`
4343

44-
// PostgresVersion overrides the PostgreSQL version from DatabaseClass.
44+
// PostgresVersion overrides the PostgreSQL version from ClusterClass.
4545
// Example: "16"
4646
// +optional
4747
PostgresVersion *string `json:"postgresVersion,omitempty"`
4848

49-
// Resources overrides CPU/memory resources from DatabaseClass.
49+
// Resources overrides CPU/memory resources from ClusterClass.
5050
// +optional
5151
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
5252

53-
// PostgreSQL overrides PostgreSQL engine parameters from DatabaseClass.
53+
// PostgreSQL overrides PostgreSQL engine parameters from ClusterClass.
5454
// Maps to postgresql.conf settings.
5555
// +optional
56-
PostgreSQL map[string]string `json:"postgresql,omitempty"`
56+
PostgreSQLConfig map[string]string `json:"postgresqlConfig,omitempty"`
5757

58-
// Extensions overrides PostgreSQL extensions from DatabaseClass.
58+
// Extensions overrides PostgreSQL extensions from ClusterClass.
5959
// +optional
6060
Extensions []string `json:"extensions,omitempty"`
6161

0 commit comments

Comments
 (0)