Skip to content

Commit

Permalink
Added NetworkInterfaceRef to Machine status (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit-0505 authored Oct 2, 2024
1 parent 2ebf059 commit 07f85be
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 14 deletions.
2 changes: 2 additions & 0 deletions api/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type NetworkInterfaceStatus struct {
VirtualIP *commonv1alpha1.IP `json:"virtualIP,omitempty"`
// State represents the attachment state of a NetworkInterface.
State NetworkInterfaceState `json:"state,omitempty"`
// networkInterfaceRef is the reference to the networkinterface attached to the machine
NetworkInterfaceRef corev1.LocalObjectReference `json:"networkInterfaceRef,omitempty"`
// LastStateTransitionTime is the last time the State transitioned.
LastStateTransitionTime *metav1.Time `json:"lastStateTransitionTime,omitempty"`
}
Expand Down
1 change: 1 addition & 0 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

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

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

4 changes: 4 additions & 0 deletions client-go/applyconfigurations/internal/internal.go

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

9 changes: 8 additions & 1 deletion client-go/openapi/zz_generated.openapi.go

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

56 changes: 56 additions & 0 deletions gen/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -65306,6 +65306,10 @@
"description": "Name is the name of the NetworkInterface to whom the status belongs to.",
"type": "string"
},
"networkInterfaceRef": {
"description": "networkInterfaceRef is the reference to the networkinterface attached to the machine",
"$ref": "#/definitions/io.k8s.api.core.v1.LocalObjectReference"
},
"state": {
"description": "State represents the attachment state of a NetworkInterface.",
"type": "string"
Expand Down Expand Up @@ -66437,6 +66441,13 @@
"networkRef": {
"description": "NetworkRef is the reference to the network to peer with. An empty namespace indicates that the target network resides in the same namespace as the source network.",
"$ref": "#/definitions/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.NetworkPeeringNetworkRef"
},
"prefixes": {
"description": "Prefixes is a list of prefixes that we want only to be exposed to the peered network, if no prefixes are specified no filtering will be done.",
"type": "array",
"items": {
"$ref": "#/definitions/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix"
}
}
}
},
Expand Down Expand Up @@ -66488,6 +66499,13 @@
"description": "Name is the name of the network peering.",
"type": "string"
},
"prefixes": {
"description": "Prefixes contains the prefixes exposed to the peered network",
"type": "array",
"items": {
"$ref": "#/definitions/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus"
}
},
"state": {
"description": "State represents the network peering state",
"type": "string"
Expand Down Expand Up @@ -66777,6 +66795,44 @@
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix": {
"description": "PeeringPrefixes defines prefixes to be exposed to the peered network",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "Name is the semantical name of the peering prefixes",
"type": "string"
},
"prefix": {
"description": "CIDR to be exposed to the peered network",
"$ref": "#/definitions/com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix"
},
"prefixRef": {
"description": "PrefixRef is the reference to the prefix to be exposed to peered network An empty namespace indicates that the prefix resides in the same namespace as the source network.",
"$ref": "#/definitions/io.k8s.api.core.v1.LocalObjectReference"
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus": {
"description": "PeeringPrefixStatus lists prefixes exposed to peered network",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "Name is the name of the peering prefix",
"type": "string"
},
"prefix": {
"description": "CIDR exposed to the peered network",
"$ref": "#/definitions/com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix"
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PrefixSource": {
"type": "object",
"properties": {
Expand Down
9 changes: 9 additions & 0 deletions gen/v3/apis__compute.ironcore.dev__v1alpha1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4791,6 +4791,15 @@
"type": "string",
"default": ""
},
"networkInterfaceRef": {
"description": "networkInterfaceRef is the reference to the networkinterface attached to the machine",
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.LocalObjectReference"
}
]
},
"state": {
"description": "State represents the attachment state of a NetworkInterface.",
"type": "string"
Expand Down
77 changes: 77 additions & 0 deletions gen/v3/apis__networking.ironcore.dev__v1alpha1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11857,6 +11857,18 @@
"$ref": "#/components/schemas/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.NetworkPeeringNetworkRef"
}
]
},
"prefixes": {
"description": "Prefixes is a list of prefixes that we want only to be exposed to the peered network, if no prefixes are specified no filtering will be done.",
"type": "array",
"items": {
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix"
}
]
}
}
}
},
Expand Down Expand Up @@ -11911,6 +11923,18 @@
"type": "string",
"default": ""
},
"prefixes": {
"description": "Prefixes contains the prefixes exposed to the peered network",
"type": "array",
"items": {
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus"
}
]
}
},
"state": {
"description": "State represents the network peering state",
"type": "string"
Expand Down Expand Up @@ -12302,6 +12326,59 @@
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix": {
"description": "PeeringPrefixes defines prefixes to be exposed to the peered network",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "Name is the semantical name of the peering prefixes",
"type": "string",
"default": ""
},
"prefix": {
"description": "CIDR to be exposed to the peered network",
"allOf": [
{
"$ref": "#/components/schemas/com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix"
}
]
},
"prefixRef": {
"description": "PrefixRef is the reference to the prefix to be exposed to peered network An empty namespace indicates that the prefix resides in the same namespace as the source network.",
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.LocalObjectReference"
}
]
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus": {
"description": "PeeringPrefixStatus lists prefixes exposed to peered network",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "Name is the name of the peering prefix",
"type": "string",
"default": ""
},
"prefix": {
"description": "CIDR exposed to the peered network",
"allOf": [
{
"$ref": "#/components/schemas/com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix"
}
]
}
}
},
"com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PrefixSource": {
"type": "object",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions internal/apis/compute/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ type NetworkInterfaceStatus struct {
VirtualIP *commonv1alpha1.IP
// State represents the attachment state of a NetworkInterface.
State NetworkInterfaceState
// networkInterfaceRef is the reference to the networkinterface attached to the machine
NetworkInterfaceRef corev1.LocalObjectReference `json:"networkInterfaceRef,omitempty"`
// LastStateTransitionTime is the last time the State transitioned.
LastStateTransitionTime *metav1.Time
}
Expand Down
2 changes: 2 additions & 0 deletions internal/apis/compute/v1alpha1/zz_generated.conversion.go

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

1 change: 1 addition & 0 deletions internal/apis/compute/zz_generated.deepcopy.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 @@ -376,16 +376,17 @@ func (r *MachineReconciler) convertIRINetworkInterfaceState(state iri.NetworkInt
return "", fmt.Errorf("unknown network interface attachment state %v", state)
}

func (r *MachineReconciler) convertIRINetworkInterfaceStatus(status *iri.NetworkInterfaceStatus) (computev1alpha1.NetworkInterfaceStatus, error) {
func (r *MachineReconciler) convertIRINetworkInterfaceStatus(status *iri.NetworkInterfaceStatus, nicName string) (computev1alpha1.NetworkInterfaceStatus, error) {
state, err := r.convertIRINetworkInterfaceState(status.State)
if err != nil {
return computev1alpha1.NetworkInterfaceStatus{}, err
}

return computev1alpha1.NetworkInterfaceStatus{
Name: status.Name,
Handle: status.Handle,
State: state,
Name: status.Name,
Handle: status.Handle,
State: state,
NetworkInterfaceRef: corev1.LocalObjectReference{Name: nicName},
}, nil
}

Expand All @@ -394,6 +395,7 @@ func (r *MachineReconciler) addNetworkInterfaceStatusValues(now metav1.Time, exi
existing.LastStateTransitionTime = &now
}
existing.Name = newValues.Name
existing.NetworkInterfaceRef = newValues.NetworkInterfaceRef
existing.State = newValues.State
existing.Handle = newValues.Handle
}
Expand All @@ -415,16 +417,18 @@ func (r *MachineReconciler) getNetworkInterfaceStatusesForMachine(
iriNicStatus, ok = iriNicStatusByName[machineNic.Name]
nicStatusValues computev1alpha1.NetworkInterfaceStatus
)
nicName := computev1alpha1.MachineNetworkInterfaceName(machine.Name, machineNic)
if ok {
var err error
nicStatusValues, err = r.convertIRINetworkInterfaceStatus(iriNicStatus)
nicStatusValues, err = r.convertIRINetworkInterfaceStatus(iriNicStatus, nicName)
if err != nil {
return nil, fmt.Errorf("[network interface %s] %w", machineNic.Name, err)
}
} else {
nicStatusValues = computev1alpha1.NetworkInterfaceStatus{
Name: machineNic.Name,
State: computev1alpha1.NetworkInterfaceStatePending,
Name: machineNic.Name,
State: computev1alpha1.NetworkInterfaceStatePending,
NetworkInterfaceRef: corev1.LocalObjectReference{Name: nicName},
}
}

Expand Down
Loading

0 comments on commit 07f85be

Please sign in to comment.