|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes Authors. |
| 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 v1alpha3 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + capierrors "sigs.k8s.io/cluster-api/errors" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | + ClusterFinalizer = "cluster.cluster.x-k8s.io" |
| 27 | +) |
| 28 | + |
| 29 | +// ANCHOR: ClusterSpec |
| 30 | + |
| 31 | +// ClusterSpec defines the desired state of Cluster |
| 32 | +type ClusterSpec struct { |
| 33 | + // Cluster network configuration |
| 34 | + // +optional |
| 35 | + ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"` |
| 36 | + |
| 37 | + // InfrastructureRef is a reference to a provider-specific resource that holds the details |
| 38 | + // for provisioning infrastructure for a cluster in said provider. |
| 39 | + // +optional |
| 40 | + InfrastructureRef *corev1.ObjectReference `json:"infrastructureRef,omitempty"` |
| 41 | +} |
| 42 | + |
| 43 | +// ANCHOR_END: ClusterSpec |
| 44 | + |
| 45 | +// ANCHOR: ClusterNetwork |
| 46 | + |
| 47 | +// ClusterNetwork specifies the different networking |
| 48 | +// parameters for a cluster. |
| 49 | +type ClusterNetwork struct { |
| 50 | + // APIServerPort specifies the port the API Server should bind to. |
| 51 | + // Defaults to 6443. |
| 52 | + // +optional |
| 53 | + APIServerPort *int32 `json:"apiServerPort,omitempty"` |
| 54 | + |
| 55 | + // The network ranges from which service VIPs are allocated. |
| 56 | + // +optional |
| 57 | + Services *NetworkRanges `json:"services,omitempty"` |
| 58 | + |
| 59 | + // The network ranges from which Pod networks are allocated. |
| 60 | + // +optional |
| 61 | + Pods *NetworkRanges `json:"pods,omitempty"` |
| 62 | + |
| 63 | + // Domain name for services. |
| 64 | + // +optional |
| 65 | + ServiceDomain string `json:"serviceDomain,omitempty"` |
| 66 | +} |
| 67 | + |
| 68 | +// ANCHOR_END: ClusterNetwork |
| 69 | + |
| 70 | +// ANCHOR: NetworkRanges |
| 71 | +// NetworkRanges represents ranges of network addresses. |
| 72 | +type NetworkRanges struct { |
| 73 | + CIDRBlocks []string `json:"cidrBlocks"` |
| 74 | +} |
| 75 | + |
| 76 | +// ANCHOR_END: NetworkRanges |
| 77 | + |
| 78 | +// ANCHOR: ClusterStatus |
| 79 | + |
| 80 | +// ClusterStatus defines the observed state of Cluster |
| 81 | +type ClusterStatus struct { |
| 82 | + // APIEndpoints represents the endpoints to communicate with the control plane. |
| 83 | + // +optional |
| 84 | + APIEndpoints []APIEndpoint `json:"apiEndpoints,omitempty"` |
| 85 | + |
| 86 | + // ErrorReason indicates that there is a problem reconciling the |
| 87 | + // state, and will be set to a token value suitable for |
| 88 | + // programmatic interpretation. |
| 89 | + // +optional |
| 90 | + ErrorReason *capierrors.ClusterStatusError `json:"errorReason,omitempty"` |
| 91 | + |
| 92 | + // ErrorMessage indicates that there is a problem reconciling the |
| 93 | + // state, and will be set to a descriptive error message. |
| 94 | + // +optional |
| 95 | + ErrorMessage *string `json:"errorMessage,omitempty"` |
| 96 | + |
| 97 | + // Phase represents the current phase of cluster actuation. |
| 98 | + // E.g. Pending, Running, Terminating, Failed etc. |
| 99 | + // +optional |
| 100 | + Phase string `json:"phase,omitempty"` |
| 101 | + |
| 102 | + // InfrastructureReady is the state of the infrastructure provider. |
| 103 | + // +optional |
| 104 | + InfrastructureReady bool `json:"infrastructureReady"` |
| 105 | + |
| 106 | + // ControlPlaneInitialized defines if the control plane has been initialized. |
| 107 | + // +optional |
| 108 | + ControlPlaneInitialized bool `json:"controlPlaneInitialized"` |
| 109 | +} |
| 110 | + |
| 111 | +// ANCHOR_END: ClusterStatus |
| 112 | + |
| 113 | +// SetTypedPhase sets the Phase field to the string representation of ClusterPhase. |
| 114 | +func (c *ClusterStatus) SetTypedPhase(p ClusterPhase) { |
| 115 | + c.Phase = string(p) |
| 116 | +} |
| 117 | + |
| 118 | +// GetTypedPhase attempts to parse the Phase field and return |
| 119 | +// the typed ClusterPhase representation as described in `machine_phase_types.go`. |
| 120 | +func (c *ClusterStatus) GetTypedPhase() ClusterPhase { |
| 121 | + switch phase := ClusterPhase(c.Phase); phase { |
| 122 | + case |
| 123 | + ClusterPhasePending, |
| 124 | + ClusterPhaseProvisioning, |
| 125 | + ClusterPhaseProvisioned, |
| 126 | + ClusterPhaseDeleting, |
| 127 | + ClusterPhaseFailed: |
| 128 | + return phase |
| 129 | + default: |
| 130 | + return ClusterPhaseUnknown |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +// ANCHOR: APIEndpoint |
| 135 | + |
| 136 | +// APIEndpoint represents a reachable Kubernetes API endpoint. |
| 137 | +type APIEndpoint struct { |
| 138 | + // The hostname on which the API server is serving. |
| 139 | + Host string `json:"host"` |
| 140 | + |
| 141 | + // The port on which the API server is serving. |
| 142 | + Port int `json:"port"` |
| 143 | +} |
| 144 | + |
| 145 | +// ANCHOR_END: APIEndpoint |
| 146 | + |
| 147 | +// +kubebuilder:object:root=true |
| 148 | +// +kubebuilder:resource:path=clusters,shortName=cl,scope=Namespaced,categories=cluster-api |
| 149 | +// +kubebuilder:storageversion |
| 150 | +// +kubebuilder:subresource:status |
| 151 | +// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Cluster status such as Pending/Provisioning/Provisioned/Deleting/Failed" |
| 152 | + |
| 153 | +// Cluster is the Schema for the clusters API |
| 154 | +type Cluster struct { |
| 155 | + metav1.TypeMeta `json:",inline"` |
| 156 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 157 | + |
| 158 | + Spec ClusterSpec `json:"spec,omitempty"` |
| 159 | + Status ClusterStatus `json:"status,omitempty"` |
| 160 | +} |
| 161 | + |
| 162 | +// +kubebuilder:object:root=true |
| 163 | + |
| 164 | +// ClusterList contains a list of Cluster |
| 165 | +type ClusterList struct { |
| 166 | + metav1.TypeMeta `json:",inline"` |
| 167 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 168 | + Items []Cluster `json:"items"` |
| 169 | +} |
| 170 | + |
| 171 | +func init() { |
| 172 | + SchemeBuilder.Register(&Cluster{}, &ClusterList{}) |
| 173 | +} |
0 commit comments