forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_types.go
165 lines (133 loc) · 5.05 KB
/
cluster_types.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright 2018 The Kubernetes Authors.
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.
*/
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
capierrors "github.com/chuckha/cluster-api/errors"
)
const ClusterFinalizer = "cluster.cluster.k8s.io"
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
/// [Cluster]
// Cluster is the Schema for the clusters API
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=clusters,shortName=cl
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
Status ClusterStatus `json:"status,omitempty"`
}
/// [Cluster]
/// [ClusterSpec]
// ClusterSpec defines the desired state of Cluster
type ClusterSpec struct {
// Cluster network configuration
// +optional
ClusterNetwork ClusterNetworkingConfig `json:"clusterNetwork"`
// Provider-specific serialized configuration to use during
// cluster creation. It is recommended that providers maintain
// their own versioned API types that should be
// serialized/deserialized from this field.
// +optional
ProviderSpec ProviderSpec `json:"providerSpec,omitempty"`
}
/// [ClusterSpec]
/// [ClusterNetworkingConfig]
// ClusterNetworkingConfig specifies the different networking
// parameters for a cluster.
type ClusterNetworkingConfig struct {
// The network ranges from which service VIPs are allocated.
Services NetworkRanges `json:"services"`
// The network ranges from which Pod networks are allocated.
Pods NetworkRanges `json:"pods"`
// Domain name for services.
ServiceDomain string `json:"serviceDomain"`
}
/// [ClusterNetworkingConfig]
/// [NetworkRanges]
// NetworkRanges represents ranges of network addresses.
type NetworkRanges struct {
CIDRBlocks []string `json:"cidrBlocks"`
}
/// [NetworkRanges]
/// [ClusterStatus]
// ClusterStatus defines the observed state of Cluster
type ClusterStatus struct {
// APIEndpoint represents the endpoint to communicate with the IP.
// +optional
APIEndpoints []APIEndpoint `json:"apiEndpoints,omitempty"`
// NB: Eventually we will redefine ErrorReason as ClusterStatusError once the
// following issue is fixed.
// https://github.com/kubernetes-incubator/apiserver-builder/issues/176
// If set, indicates that there is a problem reconciling the
// state, and will be set to a token value suitable for
// programmatic interpretation.
// +optional
ErrorReason capierrors.ClusterStatusError `json:"errorReason,omitempty"`
// If set, indicates that there is a problem reconciling the
// state, and will be set to a descriptive error message.
// +optional
ErrorMessage string `json:"errorMessage,omitempty"`
// Provider-specific status.
// It is recommended that providers maintain their
// own versioned API types that should be
// serialized/deserialized from this field.
// +optional
ProviderStatus *runtime.RawExtension `json:"providerStatus,omitempty"`
}
/// [ClusterStatus]
/// [APIEndpoint]
// APIEndpoint represents a reachable Kubernetes API endpoint.
type APIEndpoint struct {
// The hostname on which the API server is serving.
Host string `json:"host"`
// The port on which the API server is serving.
Port int `json:"port"`
}
/// [APIEndpoint]
func (o *Cluster) Validate() field.ErrorList {
errors := field.ErrorList{}
// perform validation here and add to errors using field.Invalid
if o.Spec.ClusterNetwork.ServiceDomain == "" {
errors = append(errors, field.Invalid(
field.NewPath("Spec", "ClusterNetwork", "ServiceDomain"),
o.Spec.ClusterNetwork.ServiceDomain,
"invalid cluster configuration: missing Cluster.Spec.ClusterNetwork.ServiceDomain"))
}
if len(o.Spec.ClusterNetwork.Pods.CIDRBlocks) == 0 {
errors = append(errors, field.Invalid(
field.NewPath("Spec", "ClusterNetwork", "Pods"),
o.Spec.ClusterNetwork.Pods,
"invalid cluster configuration: missing Cluster.Spec.ClusterNetwork.Pods"))
}
if len(o.Spec.ClusterNetwork.Services.CIDRBlocks) == 0 {
errors = append(errors, field.Invalid(
field.NewPath("Spec", "ClusterNetwork", "Services"),
o.Spec.ClusterNetwork.Services,
"invalid cluster configuration: missing Cluster.Spec.ClusterNetwork.Services"))
}
return errors
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ClusterList contains a list of Cluster
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}