Skip to content

Commit

Permalink
Display association status (#49)
Browse files Browse the repository at this point in the history
* Display more ElementalMachine info

Signed-off-by: Andrea Mazzotti <[email protected]>

* Display more ElementalHost information

Signed-off-by: Andrea Mazzotti <[email protected]>

---------

Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti authored May 7, 2024
1 parent 1f11125 commit 135f68d
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 10 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/elementalhost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (h *ElementalHost) SetConditions(conditions clusterv1.Conditions) {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster"
//+kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.labels['elementalhost\\.infrastructure\\.cluster\\.x-k8s\\.io/machine-name']",description="Machine object associated to this ElementalHost (through ElementalMachine)"
//+kubebuilder:printcolumn:name="ElementalMachine",type="string",JSONPath=".spec.machineRef.name",description="ElementalMachine object associated to this ElementalHost"
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="ElementalHost ready condition"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ElementalHost"

// ElementalHost is the Schema for the elementalhosts API.
type ElementalHost struct {
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/elementalmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (m *ElementalMachine) SetConditions(conditions clusterv1.Conditions) {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster"
//+kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this ElementalMachine"
//+kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="ElementalMachine ready condition"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ElementalMachine"

// ElementalMachine is the Schema for the elementalmachines API.
type ElementalMachine struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ spec:
singular: elementalhost
scope: Namespaced
versions:
- name: v1beta1
- additionalPrinterColumns:
- description: Cluster
jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name']
name: Cluster
type: string
- description: Machine object associated to this ElementalHost (through ElementalMachine)
jsonPath: .metadata.labels['elementalhost\.infrastructure\.cluster\.x-k8s\.io/machine-name']
name: Machine
type: string
- description: ElementalMachine object associated to this ElementalHost
jsonPath: .spec.machineRef.name
name: ElementalMachine
type: string
- description: ElementalHost ready condition
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Time duration since creation of ElementalHost
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
schema:
openAPIV3Schema:
description: ElementalHost is the Schema for the elementalhosts API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ spec:
singular: elementalmachine
scope: Namespaced
versions:
- name: v1beta1
- additionalPrinterColumns:
- description: Cluster
jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name']
name: Cluster
type: string
- description: Machine object which owns with this ElementalMachine
jsonPath: .metadata.ownerReferences[?(@.kind=="Machine")].name
name: Machine
type: string
- description: Provider ID
jsonPath: .spec.providerID
name: ProviderID
type: string
- description: ElementalMachine ready condition
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Time duration since creation of ElementalMachine
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
schema:
openAPIV3Schema:
description: ElementalMachine is the Schema for the elementalmachines API.
Expand Down
46 changes: 44 additions & 2 deletions infrastructure-elemental/v0.0.0/infrastructure-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,28 @@ spec:
singular: elementalhost
scope: Namespaced
versions:
- name: v1beta1
- additionalPrinterColumns:
- description: Cluster
jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name']
name: Cluster
type: string
- description: Machine object associated to this ElementalHost (through ElementalMachine)
jsonPath: .metadata.labels['elementalhost\.infrastructure\.cluster\.x-k8s\.io/machine-name']
name: Machine
type: string
- description: ElementalMachine object associated to this ElementalHost
jsonPath: .spec.machineRef.name
name: ElementalMachine
type: string
- description: ElementalHost ready condition
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Time duration since creation of ElementalHost
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
schema:
openAPIV3Schema:
description: ElementalHost is the Schema for the elementalhosts API.
Expand Down Expand Up @@ -444,7 +465,28 @@ spec:
singular: elementalmachine
scope: Namespaced
versions:
- name: v1beta1
- additionalPrinterColumns:
- description: Cluster
jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name']
name: Cluster
type: string
- description: Machine object which owns with this ElementalMachine
jsonPath: .metadata.ownerReferences[?(@.kind=="Machine")].name
name: Machine
type: string
- description: Provider ID
jsonPath: .spec.providerID
name: ProviderID
type: string
- description: ElementalMachine ready condition
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Time duration since creation of ElementalMachine
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
schema:
openAPIV3Schema:
description: ElementalMachine is the Schema for the elementalmachines API.
Expand Down
9 changes: 7 additions & 2 deletions internal/controller/elementalmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ func (r *ElementalMachineReconciler) associateElementalHost(ctx context.Context,
}

// Link the ElementalHost to ElementalMachine
elementalHostCandidate.Labels[infrastructurev1beta1.LabelElementalHostMachineName] = elementalMachine.Name
elementalHostCandidate.Spec.MachineRef = &corev1.ObjectReference{
APIVersion: elementalMachine.APIVersion,
Kind: elementalMachine.Kind,
Expand All @@ -599,7 +598,13 @@ func (r *ElementalMachineReconciler) associateElementalHost(ctx context.Context,
Name: *machine.Spec.Bootstrap.DataSecretName,
}

// TODO: Decorate the ElementalHost with useful labels, for example the Cluster name, Control Plane endpoint, etc.
// Propagate the Machine name to ElementalHost
elementalHostCandidate.Labels[infrastructurev1beta1.LabelElementalHostMachineName] = machine.Name

// Propagate the Cluster name to ElementalHost
if name, ok := elementalMachine.Labels[clusterv1.ClusterNameLabel]; ok {
elementalHostCandidate.Labels[clusterv1.ClusterNameLabel] = name
}

// Reconciliation step #10: Set status.addresses to the provider-specific set of instance addresses
// TODO: Fetch the addresses from ElementalHost to update the associated ElementalMachine
Expand Down
9 changes: 5 additions & 4 deletions internal/controller/elementalmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("ElementalMachine controller association", Label("controller",
}
machine := clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Name: "machine-test",
Namespace: namespace.Name,
},
Spec: clusterv1.MachineSpec{
Expand All @@ -62,9 +62,9 @@ var _ = Describe("ElementalMachine controller association", Label("controller",
// ElementalMachine owned by the CAPI Machine (ownership set after creation in BeforeAll())
elementalMachine := v1beta1.ElementalMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Name: "elemental-machine-test",
Namespace: namespace.Name,
Labels: map[string]string{"cluster.x-k8s.io/cluster-name": cluster.Name},
Labels: map[string]string{clusterv1.ClusterNameLabel: cluster.Name},
},
}

Expand Down Expand Up @@ -157,7 +157,8 @@ var _ = Describe("ElementalMachine controller association", Label("controller",
Name: installedHost.Name,
Namespace: installedHost.Namespace,
}, &installedHost)).Should(Succeed())
Expect(installedHost.Labels[v1beta1.LabelElementalHostMachineName]).Should(Equal(elementalMachine.Name), "machine-name label must be set")
Expect(installedHost.Labels[v1beta1.LabelElementalHostMachineName]).Should(Equal(machine.Name), "machine-name label must be set")
Expect(installedHost.Labels[clusterv1.ClusterNameLabel]).Should(Equal(cluster.Name), "cluster name label must be set")
})
It("should not mark machine as ready until cluster's controlplane is initialized ", func() {
// Mark the host as bootstrapped
Expand Down

0 comments on commit 135f68d

Please sign in to comment.