-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MachinePool API Types and Scaffolding
Signed-off-by: Juan-Lee Pang <jpang@microsoft.com>
- Loading branch information
Showing
14 changed files
with
1,026 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
Copyright 2019 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 v1alpha3 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
capierrors "sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
const ( | ||
// MachinePoolFinalizer is used to ensure deletion of dependencies (nodes, infra). | ||
MachinePoolFinalizer = "machinepool.cluster.x-k8s.io" | ||
) | ||
|
||
// ANCHOR: MachinePoolSpec | ||
|
||
// MachinePoolSpec defines the desired state of MachinePool | ||
type MachinePoolSpec struct { | ||
// ClusterName is the name of the Cluster this object belongs to. | ||
// +kubebuilder:validation:MinLength=1 | ||
ClusterName string `json:"clusterName"` | ||
|
||
// Number of desired machines. Defaults to 1. | ||
// This is a pointer to distinguish between explicit zero and not specified. | ||
Replicas *int32 `json:"replicas,omitempty"` | ||
|
||
// Template describes the machines that will be created. | ||
Template MachineTemplateSpec `json:"template"` | ||
|
||
// The deployment strategy to use to replace existing machine instances with | ||
// new ones. | ||
// +optional | ||
Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"` | ||
|
||
// Minimum number of seconds for which a newly created machine instances should | ||
// be ready. | ||
// Defaults to 0 (machine instance will be considered available as soon as it | ||
// is ready) | ||
// +optional | ||
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"` | ||
|
||
// ProviderIDs are the identification IDs of machine instances provided by the provider. | ||
// This field must match the provider IDs as seen on the node objects corresponding to a machine pool's machine instances. | ||
// +optional | ||
ProviderIDs []string `json:"providerIDs,omitempty"` | ||
} | ||
|
||
// ANCHOR_END: MachinePoolSpec | ||
|
||
// ANCHOR: MachinePoolStatus | ||
|
||
// MachinePoolStatus defines the observed state of MachinePool | ||
type MachinePoolStatus struct { | ||
// NodeRefs will point to the corresponding Nodes if it they exist. | ||
// +optional | ||
NodeRefs []corev1.ObjectReference `json:"nodeRefs,omitempty"` | ||
|
||
// Replicas is the most recently observed number of replicas. | ||
// +optional | ||
Replicas int32 `json:"replicas"` | ||
|
||
// The number of ready replicas for this MachinePool. A machine is considered ready when the node has been created and is "Ready". | ||
// +optional | ||
ReadyReplicas int32 `json:"readyReplicas,omitempty"` | ||
|
||
// The number of available replicas (ready for at least minReadySeconds) for this MachinePool. | ||
// +optional | ||
AvailableReplicas int32 `json:"availableReplicas,omitempty"` | ||
|
||
// Total number of unavailable machine instances targeted by this machine pool. | ||
// This is the total number of machine instances that are still required for | ||
// the machine pool to have 100% available capacity. They may either | ||
// be machine instances that are running but not yet available or machine instances | ||
// that still have not been created. | ||
// +optional | ||
UnavailableReplicas int32 `json:"unavailableReplicas,omitempty"` | ||
|
||
// FailureReason indicates that there is a problem reconciling the state, and | ||
// will be set to a token value suitable for programmatic interpretation. | ||
// +optional | ||
FailureReason *capierrors.MachinePoolStatusError `json:"failureReason,omitempty"` | ||
|
||
// FailureMessage indicates that there is a problem reconciling the state, | ||
// and will be set to a descriptive error message. | ||
// +optional | ||
FailureMessage *string `json:"failureMessage,omitempty"` | ||
|
||
// Phase represents the current phase of cluster actuation. | ||
// E.g. Pending, Running, Terminating, Failed etc. | ||
// +optional | ||
Phase string `json:"phase,omitempty"` | ||
|
||
// BootstrapReady is the state of the bootstrap provider. | ||
// +optional | ||
BootstrapReady bool `json:"bootstrapReady"` | ||
|
||
// InfrastructureReady is the state of the infrastructure provider. | ||
// +optional | ||
InfrastructureReady bool `json:"infrastructureReady"` | ||
} | ||
|
||
// ANCHOR_END: MachinePoolStatus | ||
|
||
// MachinePoolPhase is a string representation of a MachinePool Phase. | ||
// | ||
// This type is a high-level indicator of the status of the MachinePool as it is provisioned, | ||
// from the API user’s perspective. | ||
// | ||
// The value should not be interpreted by any software components as a reliable indication | ||
// of the actual state of the MachinePool, and controllers should not use the MachinePool Phase field | ||
// value when making decisions about what action to take. | ||
// | ||
// Controllers should always look at the actual state of the MachinePool’s fields to make those decisions. | ||
type MachinePoolPhase string | ||
|
||
const ( | ||
// MachinePoolPhasePending is the first state a MachinePool is assigned by | ||
// Cluster API MachinePool controller after being created. | ||
MachinePoolPhasePending = MachinePoolPhase("Pending") | ||
|
||
// MachinePoolPhaseProvisioning is the state when the | ||
// MachinePool infrastructure is being created or updated. | ||
MachinePoolPhaseProvisioning = MachinePoolPhase("Provisioning") | ||
|
||
// MachinePoolPhaseProvisioned is the state when its | ||
// infrastructure has been created and configured. | ||
MachinePoolPhaseProvisioned = MachinePoolPhase("Provisioned") | ||
|
||
// MachinePoolPhaseRunning is the MachinePool state when its instances | ||
// have become Kubernetes Nodes in the Ready state. | ||
MachinePoolPhaseRunning = MachinePoolPhase("Running") | ||
|
||
// MachinePoolPhaseDeleting is the MachinePool state when a delete | ||
// request has been sent to the API Server, | ||
// but its infrastructure has not yet been fully deleted. | ||
MachinePoolPhaseDeleting = MachinePoolPhase("Deleting") | ||
|
||
// MachinePoolPhaseFailed is the MachinePool state when the system | ||
// might require user intervention. | ||
MachinePoolPhaseFailed = MachinePoolPhase("Failed") | ||
|
||
// MachinePoolPhaseUnknown is returned if the MachinePool state cannot be determined. | ||
MachinePoolPhaseUnknown = MachinePoolPhase("Unknown") | ||
) | ||
|
||
// SetTypedPhase sets the Phase field to the string representation of MachinePoolPhase. | ||
func (m *MachinePoolStatus) SetTypedPhase(p MachinePoolPhase) { | ||
m.Phase = string(p) | ||
} | ||
|
||
// GetTypedPhase attempts to parse the Phase field and return | ||
// the typed MachinePoolPhase representation as described in `machinepool_phase_types.go`. | ||
func (m *MachinePoolStatus) GetTypedPhase() MachinePoolPhase { | ||
switch phase := MachinePoolPhase(m.Phase); phase { | ||
case | ||
MachinePoolPhasePending, | ||
MachinePoolPhaseProvisioning, | ||
MachinePoolPhaseProvisioned, | ||
MachinePoolPhaseDeleting, | ||
MachinePoolPhaseFailed: | ||
return phase | ||
default: | ||
return MachinePoolPhaseUnknown | ||
} | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:path=machinepools,shortName=mp,scope=Namespaced,categories=cluster-api | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:storageversion | ||
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="MachinePool status such as Terminating/Pending/Provisioning/Running/Failed etc" | ||
// +k8s:conversion-gen=false | ||
|
||
// MachinePool is the Schema for the machinepools API | ||
type MachinePool struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec MachinePoolSpec `json:"spec,omitempty"` | ||
Status MachinePoolStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// MachinePoolList contains a list of MachinePool | ||
type MachinePoolList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []MachinePool `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&MachinePool{}, &MachinePoolList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2019 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 v1alpha3 | ||
|
||
import ( | ||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
func (m *MachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(m). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:verbs=create;update,path=/validate-cluster-x-k8s-io-v1alpha3-machinepool,mutating=false,failurePolicy=fail,groups=cluster.x-k8s.io,resources=machinedeployments,versions=v1alpha3,name=validation.machinepool.cluster.x-k8s.io | ||
// +kubebuilder:webhook:verbs=create;update,path=/mutate-cluster-x-k8s-io-v1alpha3-machinepool,mutating=true,failurePolicy=fail,groups=cluster.x-k8s.io,resources=machinedeployments,versions=v1alpha3,name=default.machinepool.cluster.x-k8s.io | ||
|
||
var _ webhook.Defaulter = &MachinePool{} | ||
var _ webhook.Validator = &MachinePool{} | ||
|
||
// Default implements webhook.Defaulter so a webhook will be registered for the type | ||
func (m *MachinePool) Default() { | ||
// TODO(juan-lee): Add machine pool implementation. | ||
} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type | ||
func (m *MachinePool) ValidateCreate() error { | ||
// TODO(juan-lee): Add machine pool implementation. | ||
return nil | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||
func (m *MachinePool) ValidateUpdate(old runtime.Object) error { | ||
// TODO(juan-lee): Add machine pool implementation. | ||
return nil | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type | ||
func (m *MachinePool) ValidateDelete() error { | ||
// TODO(juan-lee): Add machine pool implementation. | ||
return nil | ||
} |
Oops, something went wrong.