Skip to content

Commit

Permalink
feat: machine controller draft #3
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Nov 6, 2024
1 parent dc188ec commit 0241cb3
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 19 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/metalstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type Firewall struct {

// MetalStackClusterStatus defines the observed state of MetalStackCluster.
type MetalStackClusterStatus struct {
// Ready denotes that the cluster is ready.
Ready bool `json:"ready"`

// FailureReason indicates that there is a fatal problem reconciling the
// state, and will be set to a token value suitable for
// programmatic interpretation.
Expand All @@ -99,10 +102,7 @@ type MetalStackClusterStatus struct {
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`

// Ready denotes that the cluster is ready.
Ready bool `json:"ready"`

// Conditions defines current service state of the Metal3Cluster.
// Conditions defines current service state of the MetalStackCluster.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}
Expand Down
31 changes: 26 additions & 5 deletions api/v1alpha1/metalstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
)

const (
// MachineFinalizer allows to clean up resources associated with before removing it from the apiserver.
MachineFinalizer = "metal-stack.infrastructure.cluster.x-k8s.io/machine"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// MetalStackMachineSpec defines the desired state of MetalStackMachine.
type MetalStackMachineSpec struct {
// ProviderID points to the metal-stack machine ID.
// +optional
ProviderID string `json:"providerID"`

// Image is the operating system to deploy on the machine
Image string `json:"image"`

Expand All @@ -39,8 +42,26 @@ type MetalStackMachineSpec struct {

// MetalStackMachineStatus defines the observed state of MetalStackMachine.
type MetalStackMachineStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Ready denotes that the cluster is ready.
Ready bool `json:"ready"`

// FailureReason indicates that there is a fatal problem reconciling the
// state, and will be set to a token value suitable for
// programmatic interpretation.
// +optional
FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"`

// FailureMessage indicates that there is a fatal problem reconciling the
// state, and will be set to a descriptive error message.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`

// Conditions defines current service state of the MetalStackCluster.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`

// MachineAddresses contains all host names, external or internal IP addresses and external or internal DNS names.
Addresses clusterv1.MachineAddresses `json:"addresses,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
24 changes: 23 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ func main() {
os.Exit(1)
}
if err = (&controller.MetalStackMachineReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
MetalClient: metalClient,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "MetalStackMachine")
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ spec:
description: Image is the operating system to deploy on the
machine
type: string
providerID:
description: ProviderID points to the metal-stack machine
ID.
type: string
size:
description: Size is the size of the machine
type: string
Expand All @@ -84,6 +88,89 @@ spec:
status:
description: MetalStackMachineStatus defines the observed state
of MetalStackMachine.
properties:
addresses:
description: MachineAddresses contains all host names, external
or internal IP addresses and external or internal DNS names.
items:
description: MachineAddress contains information for the
node's address.
properties:
address:
description: The machine address.
type: string
type:
description: Machine address type, one of Hostname,
ExternalIP, InternalIP, ExternalDNS or InternalDNS.
type: string
required:
- address
- type
type: object
type: array
conditions:
description: Conditions defines current service state of the
MetalStackCluster.
items:
description: Condition defines an observation of a Cluster
API resource operational state.
properties:
lastTransitionTime:
description: |-
Last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
A human readable message indicating details about the transition.
This field may be empty.
type: string
reason:
description: |-
The reason for the condition's last transition in CamelCase.
The specific API may choose whether or not this field is considered a guaranteed API.
This field may not be empty.
type: string
severity:
description: |-
Severity provides an explicit classification of Reason code, so the users or machines can immediately
understand the current situation and act accordingly.
The Severity field MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False,
Unknown.
type: string
type:
description: |-
Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability to deconflict is important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
failureMessage:
description: |-
FailureMessage indicates that there is a fatal problem reconciling the
state, and will be set to a descriptive error message.
type: string
failureReason:
description: |-
FailureReason indicates that there is a fatal problem reconciling the
state, and will be set to a token value suitable for
programmatic interpretation.
type: string
ready:
description: Ready denotes that the cluster is ready.
type: boolean
required:
- ready
type: object
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ spec:
description: MetalStackClusterStatus defines the observed state of MetalStackCluster.
properties:
conditions:
description: Conditions defines current service state of the Metal3Cluster.
description: Conditions defines current service state of the MetalStackCluster.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ spec:
image:
description: Image is the operating system to deploy on the machine
type: string
providerID:
description: ProviderID points to the metal-stack machine ID.
type: string
size:
description: Size is the size of the machine
type: string
Expand All @@ -51,6 +54,87 @@ spec:
type: object
status:
description: MetalStackMachineStatus defines the observed state of MetalStackMachine.
properties:
addresses:
description: MachineAddresses contains all host names, external or
internal IP addresses and external or internal DNS names.
items:
description: MachineAddress contains information for the node's
address.
properties:
address:
description: The machine address.
type: string
type:
description: Machine address type, one of Hostname, ExternalIP,
InternalIP, ExternalDNS or InternalDNS.
type: string
required:
- address
- type
type: object
type: array
conditions:
description: Conditions defines current service state of the MetalStackCluster.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: |-
Last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
A human readable message indicating details about the transition.
This field may be empty.
type: string
reason:
description: |-
The reason for the condition's last transition in CamelCase.
The specific API may choose whether or not this field is considered a guaranteed API.
This field may not be empty.
type: string
severity:
description: |-
Severity provides an explicit classification of Reason code, so the users or machines can immediately
understand the current situation and act accordingly.
The Severity field MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: |-
Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability to deconflict is important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
failureMessage:
description: |-
FailureMessage indicates that there is a fatal problem reconciling the
state, and will be set to a descriptive error message.
type: string
failureReason:
description: |-
FailureReason indicates that there is a fatal problem reconciling the
state, and will be set to a token value suitable for
programmatic interpretation.
type: string
ready:
description: Ready denotes that the cluster is ready.
type: boolean
required:
- ready
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit 0241cb3

Please sign in to comment.