Skip to content

Commit 3d9baf3

Browse files
authored
Merge pull request #1523 from noamran/1502
⚠️ Create v1alpha3 API types
2 parents ff678f6 + aa3d2c2 commit 3d9baf3

File tree

71 files changed

+4242
-1261
lines changed

Some content is hidden

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

71 files changed

+4242
-1261
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
135135
$(CONTROLLER_GEN) \
136136
paths=./api/... \
137137
paths=./controllers/... \
138-
crd:trivialVersions=true \
138+
crd \
139139
rbac:roleName=manager-role \
140140
output:crd:dir=./config/crd/bases
141141
## Copy files in CI folders.

PROJECT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ resources:
1414
- group: cluster
1515
version: v1alpha2
1616
kind: MachineDeployment
17+
- group: cluster
18+
version: v1alpha3
19+
kind: Cluster
20+
- group: cluster
21+
version: v1alpha3
22+
kind: Machine
23+
- group: cluster
24+
version: v1alpha3
25+
kind: MachineSet
26+
- group: cluster
27+
version: v1alpha3
28+
kind: MachineDeployment

api/v1alpha2/cluster_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ type APIEndpoint struct {
146146

147147
// +kubebuilder:object:root=true
148148
// +kubebuilder:resource:path=clusters,shortName=cl,scope=Namespaced,categories=cluster-api
149-
// +kubebuilder:storageversion
150149
// +kubebuilder:subresource:status
151150
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Cluster status such as Pending/Provisioning/Provisioned/Deleting/Failed"
152151

api/v1alpha2/machine_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ type Bootstrap struct {
196196
// +kubebuilder:object:root=true
197197
// +kubebuilder:resource:path=machines,shortName=ma,scope=Namespaced,categories=cluster-api
198198
// +kubebuilder:subresource:status
199-
// +kubebuilder:storageversion
200199
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
201200
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Machine status such as Terminating/Pending/Running/Failed etc"
202201
// +kubebuilder:printcolumn:name="NodeName",type="string",JSONPath=".status.nodeRef.name",description="Node name associated with this machine",priority=1

api/v1alpha2/machinedeployment_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ type MachineDeploymentStatus struct {
180180

181181
// +kubebuilder:object:root=true
182182
// +kubebuilder:resource:path=machinedeployments,shortName=md,scope=Namespaced,categories=cluster-api
183-
// +kubebuilder:storageversion
184183
// +kubebuilder:subresource:status
185184
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
186185

api/v1alpha2/machineset_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ func (m *MachineSet) Default() {
202202

203203
// +kubebuilder:object:root=true
204204
// +kubebuilder:resource:path=machinesets,shortName=ms,scope=Namespaced,categories=cluster-api
205-
// +kubebuilder:storageversion
206205
// +kubebuilder:subresource:status
207206
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
208207

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
// ClusterPhase is a string representation of a Cluster Phase.
20+
//
21+
// This type is a high-level indicator of the status of the Cluster as it is provisioned,
22+
// from the API user’s perspective.
23+
//
24+
// The value should not be interpreted by any software components as a reliable indication
25+
// of the actual state of the Cluster, and controllers should not use the Cluster Phase field
26+
// value when making decisions about what action to take.
27+
//
28+
// Controllers should always look at the actual state of the Cluster’s fields to make those decisions.
29+
type ClusterPhase string
30+
31+
const (
32+
// ClusterPhasePending is the first state a Cluster is assigned by
33+
// Cluster API Cluster controller after being created.
34+
ClusterPhasePending = ClusterPhase("pending")
35+
36+
// ClusterPhaseProvisioning is the state when the Cluster has a provider infrastructure
37+
// object associated and can start provisioning.
38+
ClusterPhaseProvisioning = ClusterPhase("provisioning")
39+
40+
// ClusterPhaseProvisioned is the state when its
41+
// infrastructure has been created and configured.
42+
ClusterPhaseProvisioned = ClusterPhase("provisioned")
43+
44+
// ClusterPhaseDeleting is the Cluster state when a delete
45+
// request has been sent to the API Server,
46+
// but its infrastructure has not yet been fully deleted.
47+
ClusterPhaseDeleting = ClusterPhase("deleting")
48+
49+
// ClusterPhaseFailed is the Cluster state when the system
50+
// might require user intervention.
51+
ClusterPhaseFailed = ClusterPhase("failed")
52+
53+
// ClusterPhaseUnknown is returned if the Cluster state cannot be determined.
54+
ClusterPhaseUnknown = ClusterPhase("")
55+
)

api/v1alpha3/cluster_types.go

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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

Comments
 (0)