Skip to content

⚠️ Drop unnecessary fields from machine status.nodeRef #12352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/core/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"unsafe"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -1105,3 +1106,15 @@ func Convert_v1beta2_ExternalPatchDefinition_To_v1beta1_ExternalPatchDefinition(
out.ValidateExtension = in.ValidateTopologyExtension
return nil
}

func Convert_v1_ObjectReference_To_v1beta2_MachineNodeReference(in *corev1.ObjectReference, out *clusterv1.MachineNodeReference, _ apimachineryconversion.Scope) error {
out.Name = in.Name
return nil
}

func Convert_v1beta2_MachineNodeReference_To_v1_ObjectReference(in *clusterv1.MachineNodeReference, out *corev1.ObjectReference, _ apimachineryconversion.Scope) error {
out.Name = in.Name
out.APIVersion = corev1.SchemeGroupVersion.String()
out.Kind = "Node"
return nil
}
10 changes: 10 additions & 0 deletions api/core/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"
"time"

corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -297,6 +298,15 @@ func spokeMachineStatus(in *MachineStatus, c randfill.Continue) {
in.V1Beta2 = nil
}
}

if in.NodeRef != nil {
// Drop everything except name
in.NodeRef = &corev1.ObjectReference{
Name: in.NodeRef.Name,
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "Node",
}
}
}

func MachineSetFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
Expand Down
30 changes: 28 additions & 2 deletions api/core/v1beta1/zz_generated.conversion.go

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

3 changes: 1 addition & 2 deletions api/core/v1beta2/index/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -42,7 +41,7 @@ func TestIndexMachineByNodeName(t *testing.T) {
name: "when the machine has valid a NodeRef",
object: &clusterv1.Machine{
Status: clusterv1.MachineStatus{
NodeRef: &corev1.ObjectReference{
NodeRef: &clusterv1.MachineNodeReference{
Name: "node1",
},
},
Expand Down
11 changes: 10 additions & 1 deletion api/core/v1beta2/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ type MachineStatus struct {

// nodeRef will point to the corresponding Node if it exists.
// +optional
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
NodeRef *MachineNodeReference `json:"nodeRef,omitempty"`

// nodeInfo is a set of ids/uuids to uniquely identify the node.
// More info: https://kubernetes.io/docs/concepts/nodes/node/#info
Expand Down Expand Up @@ -556,6 +556,15 @@ type MachineStatus struct {
Deprecated *MachineDeprecatedStatus `json:"deprecated,omitempty"`
}

// MachineNodeReference is a reference to a the node running on the machine.
type MachineNodeReference struct {
// name of the node.
// +required
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Name string `json:"name"`
}

// MachineInitializationStatus provides observations of the Machine initialization process.
// NOTE: Fields in this struct are part of the Cluster API contract and are used to orchestrate initial Machine provisioning.
type MachineInitializationStatus struct {
Expand Down
17 changes: 16 additions & 1 deletion api/core/v1beta2/zz_generated.deepcopy.go

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

27 changes: 25 additions & 2 deletions api/core/v1beta2/zz_generated.openapi.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1213,19 +1213,15 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {

patchHelper, err = patch.NewHelper(workerMachine, myclient)
g.Expect(err).ShouldNot(HaveOccurred())
workerMachine.Status.NodeRef = &corev1.ObjectReference{
APIVersion: "v1",
Kind: "Node",
Name: "worker-node",
workerMachine.Status.NodeRef = &clusterv1.MachineNodeReference{
Name: "worker-node",
}
g.Expect(patchHelper.Patch(ctx, workerMachine)).To(Succeed())

patchHelper, err = patch.NewHelper(controlPlaneJoinMachine, myclient)
g.Expect(err).ShouldNot(HaveOccurred())
controlPlaneJoinMachine.Status.NodeRef = &corev1.ObjectReference{
APIVersion: "v1",
Kind: "Node",
Name: "control-plane-node",
controlPlaneJoinMachine.Status.NodeRef = &clusterv1.MachineNodeReference{
Name: "control-plane-node",
}
g.Expect(patchHelper.Patch(ctx, controlPlaneJoinMachine)).To(Succeed())

Expand Down
6 changes: 2 additions & 4 deletions bootstrap/util/configowner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,8 @@ func TestHasNodeRefs(t *testing.T) {
Initialization: &clusterv1.MachineInitializationStatus{
InfrastructureProvisioned: true,
},
NodeRef: &corev1.ObjectReference{
Kind: "Node",
Namespace: metav1.NamespaceDefault,
Name: "node-0",
NodeRef: &clusterv1.MachineNodeReference{
Name: "node-0",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ func Test_objectMover_checkProvisioningCompleted(t *testing.T) {
},
},
Status: clusterv1.MachineStatus{
NodeRef: &corev1.ObjectReference{},
NodeRef: &clusterv1.MachineNodeReference{},
},
},
},
Expand Down
42 changes: 5 additions & 37 deletions config/crd/bases/cluster.x-k8s.io_machines.yaml

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

12 changes: 6 additions & 6 deletions controlplane/kubeadm/internal/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,23 @@ func TestHasMachinesToBeRemediated(t *testing.T) {
// healthy machine (without MachineHealthCheckSucceded condition)
healthyMachineNotProvisioned := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "healthyMachine1"}}
// healthy machine (with MachineHealthCheckSucceded == true)
healthyMachineProvisioned := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "healthyMachine2"}, Status: clusterv1.MachineStatus{NodeRef: &corev1.ObjectReference{Kind: "Node", Name: "node1"}}}
healthyMachineProvisioned := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "healthyMachine2"}, Status: clusterv1.MachineStatus{NodeRef: &clusterv1.MachineNodeReference{Name: "node1"}}}
healthyMachineProvisioned.SetConditions([]metav1.Condition{
{
Type: clusterv1.MachineHealthCheckSucceededCondition,
Status: metav1.ConditionTrue,
},
})
// unhealthy machine NOT eligible for KCP remediation (with MachineHealthCheckSucceded == False, but without MachineOwnerRemediated condition)
unhealthyMachineNOTOwnerRemediated := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineNOTOwnerRemediated"}, Status: clusterv1.MachineStatus{NodeRef: &corev1.ObjectReference{Kind: "Node", Name: "node2"}}}
unhealthyMachineNOTOwnerRemediated := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineNOTOwnerRemediated"}, Status: clusterv1.MachineStatus{NodeRef: &clusterv1.MachineNodeReference{Name: "node2"}}}
unhealthyMachineNOTOwnerRemediated.SetConditions([]metav1.Condition{
{
Type: clusterv1.MachineHealthCheckSucceededCondition,
Status: metav1.ConditionFalse,
},
})
// unhealthy machine eligible for KCP remediation (with MachineHealthCheckSucceded == False, with MachineOwnerRemediated condition)
unhealthyMachineOwnerRemediated := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineOwnerRemediated"}, Status: clusterv1.MachineStatus{NodeRef: &corev1.ObjectReference{Kind: "Node", Name: "node3"}}}
unhealthyMachineOwnerRemediated := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineOwnerRemediated"}, Status: clusterv1.MachineStatus{NodeRef: &clusterv1.MachineNodeReference{Name: "node3"}}}
unhealthyMachineOwnerRemediated.SetConditions([]metav1.Condition{
{
Type: clusterv1.MachineHealthCheckSucceededCondition,
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestHasHealthyMachineStillProvisioning(t *testing.T) {

// healthy machine (without MachineHealthCheckSucceded condition) provisioned (with NodeRef)
healthyMachineProvisioned1 := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "healthyMachineProvisioned1"}}
healthyMachineProvisioned1.Status.NodeRef = &corev1.ObjectReference{}
healthyMachineProvisioned1.Status.NodeRef = &clusterv1.MachineNodeReference{}

// unhealthy machine (with MachineHealthCheckSucceded condition) still provisioning (without NodeRef)
unhealthyMachineStillProvisioning1 := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineStillProvisioning1"}}
Expand All @@ -249,7 +249,7 @@ func TestHasHealthyMachineStillProvisioning(t *testing.T) {

// unhealthy machine (with MachineHealthCheckSucceded condition) provisioned (with NodeRef)
unhealthyMachineProvisioned1 := &clusterv1.Machine{ObjectMeta: metav1.ObjectMeta{Name: "unhealthyMachineProvisioned1"}}
unhealthyMachineProvisioned1.Status.NodeRef = &corev1.ObjectReference{}
unhealthyMachineProvisioned1.Status.NodeRef = &clusterv1.MachineNodeReference{}
unhealthyMachineProvisioned1.SetConditions([]metav1.Condition{
{
Type: clusterv1.MachineHealthCheckSucceededCondition,
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestStatusToLogKeyAndValues(t *testing.T) {
healthyMachine := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{Name: "healthy"},
Status: clusterv1.MachineStatus{
NodeRef: &corev1.ObjectReference{Name: "healthy-node"},
NodeRef: &clusterv1.MachineNodeReference{Name: "healthy-node"},
Conditions: []metav1.Condition{
{Type: controlplanev1.KubeadmControlPlaneMachineAPIServerPodHealthyCondition, Status: metav1.ConditionTrue},
{Type: controlplanev1.KubeadmControlPlaneMachineControllerManagerPodHealthyCondition, Status: metav1.ConditionTrue},
Expand Down
Loading