forked from CrunchyData/postgres-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
140 lines (122 loc) · 5.82 KB
/
cluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package v1
/*
Copyright 2017 - 2020 Crunchy Data Solutions, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// PgclusterResourcePlural ..
const PgclusterResourcePlural = "pgclusters"
// Pgcluster is the CRD that defines a Crunchy PG Cluster
//
// swagger:ignore Pgcluster
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Pgcluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec PgclusterSpec `json:"spec"`
Status PgclusterStatus `json:"status,omitempty"`
}
// PgclusterSpec is the CRD that defines a Crunchy PG Cluster Spec
// swagger:ignore
type PgclusterSpec struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
ClusterName string `json:"clustername"`
Policies string `json:"policies"`
CCPImage string `json:"ccpimage"`
CCPImageTag string `json:"ccpimagetag"`
Port string `json:"port"`
PGBadgerPort string `json:"pgbadgerport"`
ExporterPort string `json:"exporterport"`
NodeName string `json:"nodename"`
PrimaryStorage PgStorageSpec `json:primarystorage`
ArchiveStorage PgStorageSpec `json:archivestorage`
ReplicaStorage PgStorageSpec `json:replicastorage`
BackrestStorage PgStorageSpec `json:backreststorage`
ContainerResources PgContainerResources `json:containerresources`
PrimaryHost string `json:"primaryhost"`
User string `json:"user"`
Database string `json:"database"`
Replicas string `json:"replicas"`
Strategy string `json:"strategy"`
SecretFrom string `json:"secretfrom"`
UserSecretName string `json:"usersecretname"`
RootSecretName string `json:"rootsecretname"`
PrimarySecretName string `json:"primarysecretname"`
CollectSecretName string `json:"collectSecretName"`
Status string `json:"status"`
PswLastUpdate string `json:"pswlastupdate"`
CustomConfig string `json:"customconfig"`
UserLabels map[string]string `json:"userlabels"`
PodAntiAffinity string `json:"podPodAntiAffinity"`
SyncReplication *bool `json:"syncReplication"`
BackrestS3Bucket string `json:"backrestS3Bucket"`
BackrestS3Region string `json:"backrestS3Region"`
BackrestS3Endpoint string `json:"backrestS3Endpoint"`
}
// PgclusterList is the CRD that defines a Crunchy PG Cluster List
// swagger:ignore
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PgclusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Pgcluster `json:"items"`
}
// PgclusterStatus is the CRD that defines PG Cluster Status
// swagger:ignore
type PgclusterStatus struct {
State PgclusterState `json:"state,omitempty"`
Message string `json:"message,omitempty"`
}
// PgclusterState is the crd that defines PG Cluster Stage
// swagger:ignore
type PgclusterState string
// PodAntiAffinityType defines the different types of type of anti-affinity rules applied to pg
// clusters when utilizing the default pod anti-affinity rules provided by the PostgreSQL Operator,
// which are enabled for a new pg cluster by default. Valid Values include "required" for
// requiredDuringSchedulingIgnoredDuringExecution anti-affinity, "preferred" for
// preferredDuringSchedulingIgnoredDuringExecution anti-affinity, and "disabled" to disable the
// default pod anti-affinity rules for the pg cluster all together.
type PodAntiAffinityType string
const (
// PgclusterStateCreated ...
PgclusterStateCreated PgclusterState = "pgcluster Created"
// PgclusterStateProcessed ...
PgclusterStateProcessed PgclusterState = "pgcluster Processed"
// PgclusterStateInitialized ...
PgclusterStateInitialized PgclusterState = "pgcluster Initialized"
// PgclusterStateRestore ...
PgclusterStateRestore PgclusterState = "pgcluster Restoring"
// PodAntiAffinityRequired results in requiredDuringSchedulingIgnoredDuringExecution for any
// default pod anti-affinity rules applied to pg custers
PodAntiAffinityRequired PodAntiAffinityType = "required"
// PodAntiAffinityPreffered results in preferredDuringSchedulingIgnoredDuringExecution for any
// default pod anti-affinity rules applied to pg custers
PodAntiAffinityPreffered PodAntiAffinityType = "preferred"
// PodAntiAffinityDisabled disables any default pod anti-affinity rules applied to pg custers
PodAntiAffinityDisabled PodAntiAffinityType = "disabled"
)
// ValidatePodAntiAffinityType is responsible for validating whether or not the type of pod
// anti-affinity specified is valid
func (p PodAntiAffinityType) Validate() error {
switch p {
case
PodAntiAffinityRequired,
PodAntiAffinityPreffered,
PodAntiAffinityDisabled:
return nil
}
return fmt.Errorf("Invalid pod anti-affinity type. Valid values are '%s', '%s' or '%s'",
PodAntiAffinityRequired, PodAntiAffinityPreffered, PodAntiAffinityDisabled)
}