Skip to content

Commit

Permalink
Add Machine/MachineSet API for MAPI to CAPI migration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed authored and theobarberbany committed Apr 10, 2024
1 parent 3c04614 commit 820fa52
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/v1/feature_gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,10 @@ var (
productScope(ocpSpecific).
enableIn(TechPreviewNoUpgrade).
mustRegister()

FeatureGateMachineAPIMigration = newFeatureGate("MachineAPIMigration").
reportProblemsToJiraComponent("OCPCLOUD").
contactPerson("jspeed").
productScope(ocpSpecific).
mustRegister()
)
45 changes: 45 additions & 0 deletions machine/v1beta1/types_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ const (
PhaseDeleting string = "Deleting"
)

type MachineAuthority string

const (
// MachineAuthorityMachineAPI indicates that the Machine API resource should be the authoritative API.
MachineAuthorityMachineAPI MachineAuthority = "MachineAPI"

// MachineAuthorityClusterAPI indicates that the Cluster API resource should be the authoritative API.
MachineAuthorityClusterAPI MachineAuthority = "ClusterAPI"

// MachineAuthorityMigrating indicates that the authoritative API is currently migrating between states.
// Only applicable for status usages of the MachineAuthority.
MachineAuthorityMigrating MachineAuthority = "Migrating"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down Expand Up @@ -243,6 +257,20 @@ type MachineSpec struct {
// be interfacing with cluster-api as generic provider.
// +optional
ProviderID *string `json:"providerID,omitempty"`

// authoritativeAPI is the API that is authoritative for this resource.
// Valid values are MachineAPI and ClusterAPI.
// When set to MachineAPI, writes to the spec of the machine.openshift.io copy of this resource will be reflected into the cluster.x-k8s.io copy.
// When set to ClusterAPI, writes to the spec of the cluster.x-k8s.io copy of this resource will be reflected into the machine.openshift.io copy.
// Updates to the status will be reflected in both copies of the resource, based on the controller implementing the functionality of the API.
// Currently the authoritative API determines which controller will manage the resource, this will change in a future release.
// To ensure the change has been accepted, please verify that the `status.authoritativeAPI` field has been updated to the desired value and that the `Synchronized` condition is present and set to `True`.
// +kubebuilder:validation:Enum=MachineAPI;ClusterAPI
// +kubebuilder:validation:Default:=MachineAPI
// +default:=MachineAPI
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"`
}

// LifecycleHooks allow users to pause operations on the machine at
Expand Down Expand Up @@ -360,6 +388,23 @@ type MachineStatus struct {

// Conditions defines the current state of the Machine
Conditions Conditions `json:"conditions,omitempty"`

// authoritativeAPI is the API that is authoritative for this resource.
// Valid values are MachineAPI, ClusterAPI and Migrating.
// This value is updated by the migration controller to reflect the authoritative API.
// Machine API and Cluster API controllers use this value to determine whether or not to reconcile the resource.
// When set to Migrating, the migration controller is currently performing the handover of authority from one API to the other.
// +kubebuilder:validation:Enum=MachineAPI;ClusterAPI;Migrating
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"`

// synchronizedGeneration is the generation of the authoritative resource that the non-authoritative resource is synchronised with.
// This field is set when the authoritative resource is updated and the sync controller has updated the non-authoritative resource to match.
// +kubebuilder:validation:Minimum=0
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
SynchronizedGeneration int64 `json:"synchronizedGeneration,omitempty"`
}

// LastOperation represents the detail of the last performed operation on the MachineObject.
Expand Down
31 changes: 31 additions & 0 deletions machine/v1beta1/types_machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ type MachineSetSpec struct {
// insufficient replicas are detected.
// +optional
Template MachineTemplateSpec `json:"template,omitempty"`

// authoritativeAPI is the API that is authoritative for this resource.
// Valid values are MachineAPI and ClusterAPI.
// When set to MachineAPI, writes to the spec of the machine.openshift.io copy of this resource will be reflected into the cluster.x-k8s.io copy.
// When set to ClusterAPI, writes to the spec of the cluster.x-k8s.io copy of this resource will be reflected into the machine.openshift.io copy.
// Updates to the status will be reflected in both copies of the resource, based on the controller implementing the functionality of the API.
// Currently the authoritative API determines which controller will manage the resource, this will change in a future release.
// To ensure the change has been accepted, please verify that the `status.authoritativeAPI` field has been updated to the desired value and that the `Synchronized` condition is present and set to `True`.
// +kubebuilder:validation:Enum=MachineAPI;ClusterAPI
// +kubebuilder:validation:Default:=MachineAPI
// +default:=MachineAPI
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"`
}

// MachineSetDeletePolicy defines how priority is assigned to nodes to delete when
Expand Down Expand Up @@ -134,6 +148,23 @@ type MachineSetStatus struct {
ErrorReason *MachineSetStatusError `json:"errorReason,omitempty"`
// +optional
ErrorMessage *string `json:"errorMessage,omitempty"`

// authoritativeAPI is the API that is authoritative for this resource.
// Valid values are MachineAPI, ClusterAPI and Migrating.
// This value is updated by the migration controller to reflect the authoritative API.
// Machine API and Cluster API controllers use this value to determine whether or not to reconcile the resource.
// When set to Migrating, the migration controller is currently performing the handover of authority from one API to the other.
// +kubebuilder:validation:Enum=MachineAPI;ClusterAPI;Migrating
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
AuthoritativeAPI MachineAuthority `json:"authoritativeAPI,omitempty"`

// synchronizedGeneration is the generation of the authoritative resource that the non-authoritative resource is synchronised with.
// This field is set when the authoritative resource is updated and the sync controller has updated the non-authoritative resource to match.
// +kubebuilder:validation:Minimum=0
// +openshift:enable:FeatureGate=MachineAPIMigration
// +optional
SynchronizedGeneration int64 `json:"synchronizedGeneration,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down

0 comments on commit 820fa52

Please sign in to comment.